A Level Programming Challenge:
RPG
Scenario:
Your challenge is to create a text-based RPG simulator where players choose and
control characters to battle until one is defeated. Characters can attack, take damage,
and use class-based special abilities. You can decide the setting - this could be a
magical land, the ocean, outer space etc. and the story behind the game.
Challenge Objectives:
Essential Tasks:
Define a Character Class
- Include attributes for name, class_type, health, and strength.
Add a method to take damage
- Create a take_damage(self, damage) method that reduces health by a given
amount.
- Ensure health never drops below zero.
Create at least two characters
- Instantiate two characters with different names, classes, health, and strength
values.
- Display their initial status.
Developing the game:
Instantiate at least 2 more characters
Implement the contest
- Write an attack(attacker, defender) function that reduces the defender’s health by
the attacker’s strength.
- Print combat updates showing who attacked and the new health value.
Add player interaction
- Use input() to let the user choose which character attacks each turn.
- Display a menu of characters and current health each round.
Repeat the contests until a character’s health is 0
- Use a loop to continue the fight until one character’s health reaches 0.
- Declare the winner at the end of the battle.
Extension Tasks:
Difficulty levels
- Add a function to set "Easy", "Medium", or "Hard" modes.
- Adjust characters’ health and strength based on difficulty.
Special abilities
- Each class should have a unique ability (e.g., Warrior can block damage, Mage can
cast a fireball).
- Use input to allow players to trigger abilities.
Critical hits
- Add a 20% chance to do extra damage during any attack.
- Use random.random() and random.randint().
Combat history log
- Store each action (e.g., attack or ability use) in a list.
- Display the full combat log at the end of the game.