aboutsummaryrefslogtreecommitdiff
path: root/include/graphics.hpp
blob: 42de214bfd8857f24113ae4f99c717c1a635d8b0 (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
45
46
47
48
49
50
51
52
53
54
55
#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"
#include "ai.hpp"

class Graphics
{
    public:
    Graphics(Game &game, std::string title, int width, int height, AI *ai = NULL);
    ~Graphics();

    void update();
    bool isRunning() const;

    private:
    bool         m_running;
    Game         &m_game;
    std::string  m_title;
    int          m_width;
    int          m_height;
    AI           *m_ai;
    Uint32       m_aiTimeStep;
    int          m_gridSize;
    Uint32       m_aiNextTime;
    SDL_Renderer *m_renderer;
    SDL_Window   *m_window;
    TTF_Font     *m_font;
    SDL_Texture  *m_scoreText;

    std::vector< std::pair<int, SDL_Texture*> >
        m_numberTexBuf;
    std::map< int, SDL_Color >
        m_palette;

    void        drawGame();
    void        drawCell(int x, int y);
    void        drawScore();
    void        handleEvent();
    SDL_Texture *addNumberTex(int n);
    SDL_Texture *getNumberTex(int n) const;
    SDL_Texture *newTextTex(std::string s, SDL_Color c);
    void        error() const;
};

#endif