Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. void deleteAllMatchesOfType(int crystalType)
  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.             if (grid[row][column] = crystalType) // Check for only this type of crystal.
  20.             {
  21.                 if (excludeVerticalCheck == false)
  22.                 {
  23.  
  24.                     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.
  25.                     {
  26.                         gridCoordinate top, mid, bot;
  27.  
  28.                         top.row = row - 1;
  29.                         top.column = column;
  30.  
  31.  
  32.                         mid.row = row;
  33.                         mid.column = column;
  34.  
  35.  
  36.                         bot.row = row + 1;
  37.                         bot.column = column;
  38.  
  39.  
  40.                         crystalCoordinatesToClear.push_back(top);
  41.                         crystalCoordinatesToClear.push_back(mid);
  42.                         crystalCoordinatesToClear.push_back(bot);
  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.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement