elif event type =mousebuttondown this is the start of mouse click or mouse drag lastmousedownxlastmousedowny event pos if clickedspace and not firstselectedgem this was the first gem clicked on firstselectedgem clickedspace elif clickedspace and firstselectedgem two gems have been clicked on and selected swap the gems firstswappinggemsecondswappinggem getswappinggems(gameboardfirstselectedgemclickedspace if firstswappinggem =none and secondswappinggem =none if both are nonethen the gems were not adjacent firstselectedgem none deselect the first gem continue show the swap animation on the screen boardcopy getboardcopyminusgems(gameboard(firstswappinggemsecondswappinggem) animatemovinggems(boardcopy[firstswappinggemsecondswappinggem][]score swap the gems in the board data structure gameboard[firstswappinggem[' ']][firstswappinggem[' ']secondswappinggem['imagenum' gameboard[secondswappinggem[' ']][secondswappinggem[' ']firstswappinggem['imagenum' see if this is matching move matchedgems findmatchinggems(gameboard if matchedgems =[] was not matching moveswap the gems back gamesounds['bad swap'play( animatemovinggems(boardcopy[firstswappinggemsecondswappinggem][]score gameboard[firstswappinggem[' ']][firstswappinggem[' ']firstswappinggem['imagenum' gameboard[secondswappinggem[' ']][secondswappinggem[' ']secondswappinggem['imagenum' else this was matching move scoreadd while matchedgems ![] remove matched gemsthen pull down the board