diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-03-19 15:22:00 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-03-19 15:22:00 +0100 |
| commit | 19ae4e74aedbbfde9aaed9241f616decc3ec9059 (patch) | |
| tree | c4eca1b207261e24b645d5d861b3b27631ead75e /src/graphics.cpp | |
| parent | c435852cc6147a0af23ef12cc0a07a195ac60756 (diff) | |
| download | 2048-19ae4e74aedbbfde9aaed9241f616decc3ec9059.tar.gz 2048-19ae4e74aedbbfde9aaed9241f616decc3ec9059.tar.bz2 2048-19ae4e74aedbbfde9aaed9241f616decc3ec9059.zip | |
Interface for ai (tested with random AI)
Diffstat (limited to 'src/graphics.cpp')
| -rw-r--r-- | src/graphics.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/graphics.cpp b/src/graphics.cpp index 4985b5a..7732bd2 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -2,8 +2,9 @@ #define CELL_GAP 5 #define GRID_BORDER 10 +#define AI_TIME_STEP 100 -Graphics::Graphics(Game *g, std::string t, int w, int h) +Graphics::Graphics(Game *g, std::string t, int w, int h, AI *a) { running = true; game = g; @@ -11,6 +12,9 @@ Graphics::Graphics(Game *g, std::string t, int w, int h) width = w; height = h; gridSize = std::min(width, height); + ai = a; + aiTimeStep = AI_TIME_STEP; + aiNextTime = SDL_GetTicks(); if (SDL_Init(SDL_INIT_VIDEO) < 0) error(); @@ -58,6 +62,14 @@ void Graphics::update() drawGame(); drawScore(); SDL_RenderPresent(renderer); + if (ai != NULL) + { + if (SDL_TICKS_PASSED(SDL_GetTicks(), aiNextTime)) + { + aiNextTime = SDL_GetTicks() + aiTimeStep; + game->move(ai->move()); + } + } SDL_Delay(3); } |
