tetris: one time step at game over
Stefan Schuermans

Stefan Schuermans commited on 2019-07-15 19:08:34
Showing 2 changed files, with 7 additions and 13 deletions.

... ...
@@ -51,7 +51,7 @@ Tetris::Tetris(const std::string &name, Mgrs &mgrs, const Directory &dirBase):
51 51
   m_gameOverDelay(c_gameOverDelayDescr.default_),
52 52
   m_pConn(NULL),
53 53
   m_stone(-1), m_rot(-1), m_posX(-1), m_posY(-1),
54
-  m_dropping(false), m_blinking(0), m_completed(0), m_gameOver(0),
54
+  m_dropping(false), m_blinking(0), m_completed(0), m_gameOver(false),
55 55
   m_field(), m_rowsBlink()
56 56
 {
57 57
   // open operator connection interfaces for player
... ...
@@ -162,7 +162,7 @@ void Tetris::opConnRecvKey(OpConn *pConn, char key)
162 162
 
163 163
   /** normal keys for controlling game,
164 164
       deactivated if dropping stone, rows blinking or end of game */
165
-  if (m_dropping || m_blinking > 0 || m_gameOver > 0) {
165
+  if (m_dropping || m_blinking > 0 || m_gameOver) {
166 166
     return;
167 167
   }
168 168
 
... ...
@@ -277,7 +277,7 @@ void Tetris::reinitialize()
277 277
   // no rows blinking or completed, game not over yet
278 278
   m_blinking = 0;
279 279
   m_completed = 0;
280
-  m_gameOver = 0;
280
+  m_gameOver = false;
281 281
 
282 282
   // start with new stone
283 283
   newStone();
... ...
@@ -317,7 +317,7 @@ void Tetris::redraw()
317 317
 void Tetris::timeStep()
318 318
 {
319 319
   // count time at end of game
320
-  if (m_gameOver > 0) {
320
+  if (m_gameOver) {
321 321
     timeGameOver();
322 322
   // blinking of completed rows
323 323
   } else if (m_blinking > 0) {
... ...
@@ -334,11 +334,6 @@ void Tetris::timeStep()
334 334
 /// count time at end of game
335 335
 void Tetris::timeGameOver()
336 336
 {
337
-  // count time
338
-  ++m_gameOver;
339
-
340
-  // terminate game after some time
341
-  if (m_gameOver >= 8) {
342 337
   // close operator connection
343 338
   if (m_pConn) {
344 339
     forgetOpConn(m_pConn); // remove from requests (if it was in)
... ...
@@ -348,7 +344,6 @@ void Tetris::timeGameOver()
348 344
   // deactivate game
349 345
   deactivate();
350 346
 }
351
-}
352 347
 
353 348
 /// blink completed rows
354 349
 void Tetris::timeBlinkRows()
... ...
@@ -407,7 +402,7 @@ void Tetris::timeStone()
407 402
       // unset stone
408 403
       m_stone = -1;
409 404
       // game over
410
-      m_gameOver = 1;
405
+      m_gameOver = true;
411 406
       playOpConnSound(m_pConn, m_fileGameOverSound);
412 407
     }
413 408
 
... ...
@@ -481,7 +476,7 @@ void Tetris::planTimeStep()
481 476
   // compute interval based on game state
482 477
   int interval_ms = m_delay;
483 478
   int speedup = m_completed;
484
-  if (m_gameOver > 0) {
479
+  if (m_gameOver) {
485 480
     interval_ms = m_gameOverDelay;
486 481
     speedup = 0;
487 482
   } else if (m_blinking > 0) {
... ...
@@ -205,7 +205,7 @@ protected:
205 205
   bool m_dropping;  ///< whether currently dropping a stone
206 206
   int  m_blinking;  ///< step of blinking: 0 not blinking, lsb == 0 -> visible
207 207
   int  m_completed; ///< number of overall completed rows
208
-  int   m_gameOver;  ///< counter at end of game: 0 means game is running
208
+  bool m_gameOver;  ///< counter at end of game: 0 means game is running
209 209
 
210 210
   /// tetris field (y * m_width + x), -1 for free, >= 0 for pixel from stone
211 211
   std::vector<int> m_field;
212 212