Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. void deleteAllMatches()
  2. {
  3.     vector<gridCoordinate> crystalCoordinatesToClear;
  4.  
  5.     for (int row = 0; row < gridSize; row++)
  6.     {
  7.  
  8.         for (int column = 0; column < gridSize; column++)
  9.         {
  10.  
  11.             bool excludeHorizontalCheck = false, excludeVerticalCheck = false;
  12.  
  13.             if (row == 0 || row == (gridSize - 1)) // If it is the top or bottom row do not check above or bellow.
  14.                 excludeVerticalCheck = true;
  15.  
  16.             if (column == 0 || column == (gridSize - 1)) // If it is the left or right edge do not check horizontally for matches.
  17.                 excludeHorizontalCheck = true;
  18.  
  19.  
  20.             if (excludeVerticalCheck == false)
  21.             {
  22.  
  23.                 if (grid[row][column] == grid[row - 1][column] && grid[row][column] == grid[row + 1][column]) // If above and bellow crystal have same value as crystal consider this a match.
  24.                 {
  25.                     gridCoordinate top,mid,bot;
  26.  
  27.                     top.row = row - 1;
  28.                     top.column = column;
  29.                    
  30.  
  31.                     mid.row = row;
  32.                     mid.column = column;
  33.                    
  34.  
  35.                     bot.row = row + 1;
  36.                     bot.column = column;
  37.                    
  38.  
  39.                     crystalCoordinatesToClear.push_back(top);
  40.                     crystalCoordinatesToClear.push_back(mid);
  41.                     crystalCoordinatesToClear.push_back(bot);
  42.  
  43.  
  44.                 }
  45.  
  46.             }
  47.  
  48.             if (excludeHorizontalCheck == false)
  49.             {
  50.  
  51.                 if (grid[row][column] == grid[row][column - 1] && grid[row][column] == grid[row][column + 1]) // If left and right crystal have same value as crystal consider this a match.
  52.                 {
  53.  
  54.                     gridCoordinate left, mid, right;
  55.  
  56.                     left.row = row;
  57.                     left.column = column - 1;
  58.  
  59.  
  60.                     mid.row = row;
  61.                     mid.column = column;
  62.  
  63.  
  64.                     right.row = row;
  65.                     right.column = column + 1;
  66.  
  67.  
  68.                     crystalCoordinatesToClear.push_back(left);
  69.                     crystalCoordinatesToClear.push_back(mid);
  70.                     crystalCoordinatesToClear.push_back(right);
  71.  
  72.                 }
  73.  
  74.             }
  75.  
  76.         }
  77.  
  78.     }
  79.  
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement