Spring Deals - hours only!Up to 70% off on all courses and bundles.-Close
Introduction
Cyber Battle Game
Game elements
Main Game Loop
Final game
22. Step 10a – small changes in created functions

Instruction

Great job! Our code is almost ready!

Exercise

We need to change our functions a little:

  1. act_robot(): Add board as the first variable of the function. Then, instead of printing the robot and the words "right", "move forward" or "laser shoot", invoke the actual functions you wrote previously – the turn_right(), laser_shoot(), and move_forward() functions.
  2. Add board as the first argument in the play_round() function. Remember to pass a board when invoking the function in the main loop.

Stuck? Here's a hint!

Your act_robot() function should look like this:

def act_robot(board, robot, lives_left):
  action = random.randint(0, 2)
  if action == 0:
    turn_right(robot)
  elif action == 1:
    laser_shoot(board, robot, lives_left)
  elif action == 2:
    move_forward(board, robot)