9. Battlefield
9. The Battlefield Class
The Battlefield
class is a container used for battle related objects. For 2 opponents to enter a proper battle, a battlefield must be created. The two opponents are entered in parameters when starting a battle loop. The battle loop allows for a turn-based battle system. This turn-based battle system allows for attack that take multiple turns to charge, attacks that may take turns to recharge, or even something like automatic HP regeneration over time or mana regeneration.
9.1 Battlefield initialization
Battlefield
instances can be used for a variety of purposed. You can define a name and a description for the battlefield when creating it. This can be used toward the story-line or to add detail to your game. Four parameters are required when initializing a battlefield instance:
name
The name of the battlefield
Description
A description about the battlefield (can be short or long)
player
This is the current player instance that is battling (enemy vs enemy not yet supported)
enemy
This is the enemy that the player will be battling
The player
and enemy
parameters must be class instances
Usage Example:
9.2 Battlefield.start_battle
Battlefield.start_battle()
Calling Battlefield.start_battle()
starts a battle loop between the player and the enemy that you specified when the battlefield was initialized. When the loop starts, the player will be prompted to select an action. As of now, there are only 2 possible actions: attack or use a potion. When the player selects attack, the Player.atk
function will be called on the enemy and the appropriate damage will be dealt. If the player selects "Use health potion", the user will be prompted with a list of all of the potions they have available for use. This loop will continue until either the player or the enemy die. Once the loop ends, it returns True
or False
. If the player won, True
will be returned, otherwise, False
will be returned. This can be used to preform actions after the battle based on who won. If the player looses, Player.kill
will be called. The game will not end, but a death message will be shown and the player's health will be reset.
Usage Example:
Last updated