forked from khalladay/InsecureSnake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawing.cpp
More file actions
71 lines (59 loc) · 1.53 KB
/
drawing.cpp
File metadata and controls
71 lines (59 loc) · 1.53 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <curses.h>
#include <stdint.h>
#include "drawing.h"
#include "snake_game.h"
WindowSize initializeWindow()
{
initscr();
cbreak();
noecho();
clear();
curs_set(false);
WindowSize outSize;
getmaxyx(stdscr, outSize.h, outSize.w);
scrollok(stdscr, TRUE);
nodelay(stdscr, true);
return outSize;
}
void drawGame(class SnakeGame* game)
{
if (game->currentMode == PLAYING)
{
start_color(); /* Start color */
init_color(COLOR_BLACK, 0, 0, 0);
init_pair(1, COLOR_WHITE, COLOR_BLACK);
attron(COLOR_PAIR(1));
//draw game board
for (int32_t x = 0; x < game->worldSize.x; ++x)
{
for (int32_t y = 0; y < game->worldSize.y; ++y)
{
mvprintw(y, x, " "); // Print our "ball" at the current xy position
}
}
attroff(COLOR_PAIR(1));
//draw snake
for (auto i = game->snakeSegments.begin(); i != game->snakeSegments.end(); ++i)
{
mvprintw(i->y, i->x, "O");
}
//draw target
mvprintw(game->targetPos.y, game->targetPos.x, "X");
}
else
{
clear();
mvprintw(game->worldSize.y/2, game->worldSize.x/2 - 10, "Game Over");
char scoreString[64];
sprintf(scoreString, "Score: %i", game->score);
mvprintw(game->worldSize.y/2 + 1, game->worldSize.x/2 - 10, &scoreString[0]);
}
refresh();
}
void shutdownDrawing()
{
echo();
nocbreak();
curs_set(true);
endwin();
}