Hardware Reference
In-Depth Information
12. Similarly, the main game loop also needs to be modified to simulate the human
player's game moves:
if turn == HUMAN:
animatePlayerMoving(mainBoard,0)
makeMove(mainBoard, RED, 0)
moves_sound.play()
if isWinner(mainBoard, RED):
winnerImg = HUMANWINNERIMG
break
turn = COMPUTER # switch to other player's turn
13. The next step is to interface the butons to the game. The following code needs to
be added under the human player's turn:
#wait for a button press
while column == 0:
column = pfio.read_input()
column_position = 0
if column == 1:
column_position = 0
elif column == 2:
column_position = 1
elif column == 4:
column_position = 2
elif column == 8:
column_position = 3
elif column == 16:
column_position = 4
elif column == 32:
column_position = 5
elif column == 64:
column_position = 6
14. We use the read_input() funcion to detect any buton press. When a buton is
pressed, the returned value can be anywhere between 1 and 64. The return value is
used to idenify the column posiion and the coin movement is simulated.
15. Similarly, the main menu of the game needs to be modified to be controlled using
butons. The game is launched when buton 1 is pressed and the player leaves the
game when a buton is pressed:
if e.type == EVENT_CHANGE_STATE:
if state == 0:
rect_list,state = menu.update(e,state)
 
Search WWH ::




Custom Search