Advertisement
ikseek

Untitled

Oct 19th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. int Tetris::findLowestCopmpleteLine() {
  2.   for(size_t y = Y_GLASS_SIZE; y != 0; --y) {
  3.     bool completeLine = true;
  4.     for(size_t x = 1; x<= X_GLASS_SIZE ; ++x) {
  5.       if (GetChar(x, y) == kEmptySymbol) {
  6.         completeLine = false;
  7.         break;
  8.       }
  9.     }
  10.     if (completeLine) {
  11.       return y;
  12.     }
  13.   }
  14.   return -1;
  15. }
  16.  
  17. bool Tetris::tryRemoveCompleteLine() {
  18.   int complete_line = findLowestCopmpleteLine()
  19.   if (complete_line != -1) {
  20.     for (size_t y = complete_line; y!= 1; --y) {
  21.       for (size_t x = 1; x <= X_GLASS_SIZE; ++x) {
  22.         upper_row_symbol = GetChar(x, y-1);;
  23.         SetChar(x, y, upper_row_symbol);
  24.       }
  25.       for (size_t x = 1; x <= X_GLASS_SIZE; ++x) {
  26.         SetChar(x, 1, kEmptySymbol);
  27.       }
  28.     }
  29.     return true;
  30.   } else {
  31.     return false;
  32.   }
  33. }
  34.  
  35. int Tetris::removeCompleteLinesAndDownCells() {
  36.   score = 0;
  37.   while (tryRemoveCompleteLine()) ++score;
  38.   return score;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement