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

Instruction

Okay, let's first describe the game we're going to write.

Cyber Battle is a 2D text game written in Python. Two robots, A and B, try to destroy each other with laser shots. In our game, both robots will be controlled by the computer, so it will be more of a simulation than an actual game. However, you can easily change the game later and have two human players fight each other.

The robots are placed on a 4 x 4 board. A robot can be facing right >, left <, up ^ or down v, as shown in the initial board below.

 - - - - - A>- - - - - - - - B<-

Each robot has two lives. In each turn, each robot randomly performs one of the following actions:

1. turn_right() – The robot's direction changes by 90 degrees clockwise. The diagram below shows robot A making two right turns:

 - - - - - A>- - - - - - - - B<- - - - - - Av- - - - - - - - B<- - - - - - A<- - - - - - - - B<-

2. move_forward() – The robot moves forward by one field. If the robot tries to enter a field occupied by the other robot or if the robot is already at one of the board's borders, nothing happens. The table below presents robot A making two forward moves:

 - - - - - A>- - - - - - - - B<- - - - - - - A>- - - - - - - B<- - - - - - - -A> - - - - - - B<-

3. laser_shoot() – The robot shoots a laser beam in the direction it is facing. The beam is always a straight line that reaches the board's border, as shown below:

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

If the laser hits the other robot, the other robot loses one life. The image below shows a laser shot hitting robot B:

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

After each round, the game state is printed, like this:

========================
- - - -
- Av- -
- - - -
- B<- -
Lives left: A - 2, B - 2
========================
- - - -
- - - -
- Av- -
- B^- -
Lives left: A - 2, B - 2
========================

The game lasts for a maximum of 10 rounds. If one of the robots destroys the other within this time limit, the destroying robot wins. So, if robot A destroyed robot B, we'd see:

*** Robot A won! ***

If both robots destroy each other at the same time or if 10 rounds have already passed, the game ends in a draw.

*** Draw! ***

That's quite a complicated game! Don't worry, we're going to break it up for you and guide you through the game creation process! The process will be split into three parts: game elements, the main game loop, and robot moves. Most of the time, you'll be writing independent functions to perform a single game operation. At the very end, we'll put all the pieces together and create the final game.

Exercise

Before we start, let's take a look at what the end result should look like. Play the game and enjoy the battle!