aboutsummaryrefslogtreecommitdiff
path: root/include/graphics.hpp
blob: ccebdaeb9b954fe44ce90155950f5902e44a626c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef GRAPHICS_HPP
# define GRAPHICS_HPP

#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <utility>
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include "game.hpp"
#include "2048.hpp"

class Graphics
{
    public:
    Graphics(Game *g, std::string t, int w, int h);
    ~Graphics();

    void update();
    void drawGame();
    void drawCell(int x, int y);
    bool isRunning();

    private:
    bool running;
    std::string title;
    int width;
    int height;
    Game *game;
    SDL_Renderer *renderer;
    SDL_Window *window;
    TTF_Font *font;
    std::vector< std::pair<int, SDL_Texture*> > numberTexBuf;
    std::map< int, SDL_Color > palette;

    void handleEvent();
    SDL_Texture *addNumberTex(int n);
    SDL_Texture *getNumberTex(int n);
    void error();
};

#endif