Snoke
Labyrinth_displayHandler.h
Go to the documentation of this file.
1 #ifndef LABYRINTH_DISPLAYHANDLER_H
2 #define LABYRINTH_DISPLAYHANDLER_H
3 
12 #include "shared.h"
13 #include "Labyrinth/labyrinth.h"
14 
18 TEST(Labyrinth_displayHandler, test1)
19 {
20  initscr();
21  gameFieldSize.x = 40;
22  gameFieldSize.y = 20;
23  Labyrinth labyrinth;
24 
25  bool retVal = labyrinth.setLabyrinth(gameFieldSize);
26  if(!retVal)
27  {
28  FAIL();
29  }
30 
31  Snake snake;
32  Point begin;
33  begin.x = 1;
34  begin.y = 1;
35  short direction = MVRIGHT;
36  int length = 5;
37 
38  retVal = snake.init(begin, direction, length);
39  if(!retVal)
40  {
41  FAIL();
42  }
43 
44  retVal = labyrinth.addSnake(&snake);
45  if(!retVal)
46  {
47  FAIL();
48  }
49 
50  labyrinth.displayHandler();
51  endwin();
52  SUCCEED();
53 }
54 
55 TEST(Labyrinth_displayHandler, test2)
56 {
57  initscr();
58  gameFieldSize.x = 40;
59  gameFieldSize.y = 20;
60  Labyrinth labyrinth;
61 
62  bool retVal = labyrinth.setLabyrinth(gameFieldSize);
63  if(!retVal)
64  {
65  FAIL();
66  }
67 
68  Snake snake;
69  Point begin;
70  begin.x = 1;
71  begin.y = 1;
72  short direction = MVRIGHT;
73  int length = 5;
74 
75  retVal = snake.init(begin, direction, length);
76  if(!retVal)
77  {
78  FAIL();
79  }
80 
81  retVal = labyrinth.addSnake(&snake);
82  if(!retVal)
83  {
84  FAIL();
85  }
86 
87  labyrinth.displayHandler(DISPPART);
88  endwin();
89  SUCCEED();
90 }
91 
95 TEST(Labyrinth_displayHandler, test3)
96 {
97  initscr();
98  gameFieldSize.x = 40;
99  gameFieldSize.y = 20;
100  Labyrinth labyrinth;
101 
102  bool retVal = labyrinth.setLabyrinth(gameFieldSize);
103  if(!retVal)
104  {
105  FAIL();
106  }
107 
108  Snake snake;
109  Point begin;
110  begin.x = 1;
111  begin.y = 1;
112  short direction = MVRIGHT;
113  int length = 5;
114 
115  retVal = snake.init(begin, direction, length);
116  if(!retVal)
117  {
118  FAIL();
119  }
120 
121  retVal = labyrinth.addSnake(&snake);
122  if(!retVal)
123  {
124  FAIL();
125  }
126 
127  labyrinth.displayHandler();
128 
129  retVal = snake.move(&labyrinth);
130  if(retVal)
131  {
132  FAIL();
133  }
134 
135  labyrinth.displayHandler();
136  endwin();
137  SUCCEED();
138 }
139 
140 TEST(Labyrinth_displayHandler, test4)
141 {
142  initscr();
143  gameFieldSize.x = 40;
144  gameFieldSize.y = 20;
145  Labyrinth labyrinth;
146 
147  bool retVal = labyrinth.setLabyrinth(gameFieldSize);
148  if(!retVal)
149  {
150  FAIL();
151  }
152 
153  Snake snake;
154  Point begin;
155  begin.x = 1;
156  begin.y = 1;
157  short direction = MVRIGHT;
158  int length = 5;
159 
160  retVal = snake.init(begin, direction, length);
161  if(!retVal)
162  {
163  FAIL();
164  }
165 
166  retVal = labyrinth.addSnake(&snake);
167  if(!retVal)
168  {
169  FAIL();
170  }
171 
172  labyrinth.displayHandler(DISPFULL);
173  endwin();
174  SUCCEED();
175 }
176 
177 TEST(Labyrinth_displayHandler, test5)
178 {
179  initscr();
180  gameFieldSize.x = 40;
181  gameFieldSize.y = 20;
182  Labyrinth labyrinth;
183 
184  bool retVal = labyrinth.setLabyrinth(gameFieldSize);
185  if(!retVal)
186  {
187  FAIL();
188  }
189 
190  Snake snake;
191  Point begin;
192  begin.x = 1;
193  begin.y = 1;
194  short direction = MVRIGHT;
195  int length = 5;
196 
197  retVal = snake.init(begin, direction, length);
198  if(!retVal)
199  {
200  FAIL();
201  }
202 
203  retVal = labyrinth.addSnake(&snake);
204  if(!retVal)
205  {
206  FAIL();
207  }
208 
209  labyrinth.displayHandler(DISPUPD);
210  endwin();
211  SUCCEED();
212 }
213 
214 #endif // LABYRINTH_DISPLAYHANDLER_H
TEST(Labyrinth_displayHandler, test1)
method runs with noraml parameters
short x
Definition: common.h:55
class for containing and displaying the game field
Definition: labyrinth.h:66
Definitions and prototypes for Labyrinth class.
bool move(Labyrinth *labyrinth)
The snake movement on the game field(should be called in each iteration of the game cycle...
Definition: snake.cpp:80
bool setLabyrinth(Point dimensions)
Sets the default values fro the variables as well as generating the labyritnh array with borders...
Definition: labyrinth.cpp:17
const int DISPPART
the whole labyrinth doesn't fit, so we are displaying it partialy
Definition: labyrinth.h:48
bool init(Point begin, short direction, int length)
Initializes snake as an entity without ancoring it anywhere.
Definition: snake.cpp:20
const int DISPFULL
the whole labyrinth can fit and was redrawed
Definition: labyrinth.h:44
shared functions for testing
Point gameFieldSize
Definition: game.cpp:17
short y
Definition: common.h:56
Describes the Snake entity of the game.
Definition: snake.h:79
bool addSnake(Snake *snake)
Adding snake to the laburinth and getting the host snake(firest added snake)
Definition: labyrinth.cpp:110
const int MVRIGHT
snake's head is moving right
Definition: snake.h:52
const int DISPUPD
the whole labyrinth can fit and was already fully redrawn so we just need to redraw the changed Point...
Definition: labyrinth.h:52
void displayHandler(int displayMethod=-1)
A method which decides what dispaly method will be used in each situation.
Definition: labyrinth.cpp:152
Coordinates and style of the cell in console window.
Definition: common.h:52