Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class pair {
- bool mAmISet;
- int mIndexInBoard;
- };
- pair first, second;
- void on_user_click(int index) // index is which tile the user clicked.
- {
- if (first.mAmISet == false) // not set so we should set the first guy.
- {
- first.mAmISet = true;
- first.mIndexInBoard = index;
- } else if (second.mAmISet == false)
- {
- // if it hits this case it means first guy is already set. if the first
- // case is true but this case is false it means I have the first tile
- // selected but not the second.
- second.mAmISet = true;
- second.mIndexInBoard = index;
- if (myBoard[index].type == myBoard[first.mIndexInBoard].type)
- {
- // the type is the same so kkeep them revealed.
- // also reset the bools so that it never hits the last case
- first.mAmIset = false;
- second.mAmISet = false;
- } else
- {
- // not equals, set the borders red.
- }
- } else
- {
- // so here is when both are selected now, so we should check to see if there
- // is a matching pair.
- if (myBoard[index].type == myBoard[first.mIndexInBoard].type)
- {
- // the type is the same so kkeep them revealed.
- } else
- {
- // type not the same, hide both.
- }
- // reset the first and second selection grid so nothing is selected.
- first.mAmIset = false;
- second.mAmISet = false;
- }
- }
Add Comment
Please, Sign In to add comment