For this Python programming challenge, you are going to create a Battle game where two knights will fight each other till death!
Your game will use a text-based user interface (using ASCII art to represent the knights) and will produce a frame based animation of the battle scene:
Here is a structure diagram of the whole game:
Using this structure diagram we can generate the following to do list for you to complete this game step by step:
Generate random knight names for both players
Initialise both health scores to 100
Randomly pick an action for each knight (attack, defend or rest)
Display the battle scene (as stickmen based on the action of each knight)
Update health scores
Display knights’ names and health scores
Repeat process as long as both health scores are positive
Stop the battle as soon as at least one health score is lower or equal to zero
Identify if there is a winner or a draw (when both players have a health score lower or equal to 0)
Output the last scene of the battle and the name of the knight who won the battle
To get started with this project, we will reuse the code from the “Knight Name Generator” challenge.
Note that to create a frame based animation, you can use both the time library (to define the delay between two frames) and the os library (to clear the screen between each frame). For instance, see how this code displays a random number every 1 second.
import random, time, os while True: print(random.randint(0,10)) time.sleep(1) os.system("cls")
Your task is to complete the code below to implement all aspects of this game using the above checklist:
Re-organise your code to make use of OOP concepts.
You should do so by creating a Knight class to store the name, health and state of your knight as properties of the Knight class and use a few methods to let your knight randomly pick an action (new state) or to draw your sprite on screen.