Player
Last updated
Last updated
The Player
class is a crucial component of the Forgotten Empires, managing player-related activities such as creating new players, leveling up, and changing kingdoms.
Structures
PlayerEntity: A structure to represent a player, including level
, xp
(experience points), and kingdom
.
State
players
: A mapping from a PublicKey
to a PlayerEntity
, representing the registered players in the game.
newPlayer(kingdom: UInt64)
Creates a new player with initial settings for this.transaction.sender
Parameters:
kingdom
: The initial kingdom to which the player belongs.
Functionality:
Verifies that there isn't an existing player associated with the sender's address.
Initializes a new player with level 1, 1000 XP and the specified kingdom.
Usage:
This method should be called when a new player wants to play the game.
levelUP()
Levels up a player if they have enough experience points (XP).
Functionality:
Checks if a player exists at the sender's address.
Retrieves the player's current XP and level.
Verifies that the player has at least 1000 XP.
Increases the player's level by 1 and deducts 1000 XP.
Usage:
Players call this method to level up.
changeKingdom(kingdom: UInt64)
Changes a player's kingdom.
Parameters:
kingdom
: The new kingdom to which the player wants to move.
Functionality:
Checks if a player exists at the sender's address.
Retrieves the player's current kingdom.
Ensures the new kingdom is different from the current one.
Updates the player's kingdom.
Usage:
Players use this method to change their allegiance to a different kingdom.