Guest User

Untitled

a guest
Jun 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. class pair {
  2.   bool mAmISet;
  3.   int mIndexInBoard;
  4. };
  5.  
  6. pair first, second;
  7.  
  8. void on_user_click(int index) // index is which tile the user clicked.
  9. {
  10.   if (first.mAmISet == false) // not set so we should set the first guy.
  11.   {
  12.     first.mAmISet = true;
  13.     first.mIndexInBoard = index;
  14.   } else if (second.mAmISet == false)
  15.   {
  16.     // if it hits this case it means first guy is already set. if the first
  17.     // case is true but this case is false it means I have the first tile
  18.     // selected but not the second.
  19.    
  20.     second.mAmISet = true;
  21.     second.mIndexInBoard = index;
  22.    
  23.     if (myBoard[index].type == myBoard[first.mIndexInBoard].type)
  24.     {
  25.       // the type is the same so kkeep them revealed.
  26.  
  27.       // also reset the bools so that it never hits the last case
  28.       first.mAmIset = false;
  29.       second.mAmISet = false;
  30.     } else
  31.     {
  32.       // not equals, set the borders red.
  33.     }
  34.  
  35.   } else
  36.   {
  37.     // so here is when both are selected now, so we should check to see if there
  38.     // is a matching pair.
  39.     if (myBoard[index].type == myBoard[first.mIndexInBoard].type)
  40.     {
  41.       // the type is the same so kkeep them revealed.
  42.     } else
  43.     {
  44.       // type not the same, hide both.
  45.     }
  46.    
  47.     // reset the first and second selection grid so nothing is selected.
  48.     first.mAmIset = false;
  49.     second.mAmISet = false;
  50.   }
  51. }
Add Comment
Please, Sign In to add comment