Summer Deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Cyber Battle Game
Game elements
Main Game Loop
Robot moves
Final game

Instruction

Excellent! We'll now move on to shooting laser beams.

A robot can shoot a laser beam in the direction it is facing. A laser beam is visualized with asterisks (*) and can be either horizontal:

- - - -
* * A<-
- - - -
- - B<-

or vertical:

- Av- -
- * - -
- * - -
- * B<-

We'll need four helper functions: one for shooting in each direction (left, right, up, or down). We'll start with shooting left.

Exercise

Write a laser_shoot_left(board, robot, lives_left) function that presents shooting left. We'll use this function when the shooting robot is facing left. It should decrease lives_left of the robot (if there is one on the left of robot, in the same row). It should put a '*' in those places on left of the robot which are empty ('-') to reflect where the laser beam was shot.

Example 1: no hit

- - - -
* * A<-
- - - -
- - B<-

Example 2: robot B hit

- - - -
* B^* A<
- - - -
- - - -

The get_position() and get_opponent_name() helper functions may come in handy here as well, so we've put them in the template code.

Stuck? Here's a hint!

For each field with a vertical left laser beam, perform the following check:

if board[robot_row][i] == get_opponent_name(robot):
  lives_left[get_opponent_name(robot)] -= 1
else:
  board[robot_row][i] = '*'