In this assignment, you will be tasked to complete stateful smart contract for a game. When the contract is deployed, a monster with a fixed amount of health is created. Participating accounts can repeatedly attack the monster till it dies. The account that does the most damage gets rewarded with Algos.
Complete the code in game_approval.py
. The smart contract should contain the following functions,
Creates a new monster with a specified amount of health (e.g. 5 to 50). The monster must have at least 5 health points. Also initialize the global state of the maximum damage dealt to 0. You should also prevent the player from making multiple opt in transactions.
Reduces the monster's health by 2 if the monster's health is not 0. Contract will keep track of the player that does the most damage to that monster, as well as the maximum damage dealt. The player's local state should also keep track of the damage dealt to that monster.
Send 1 Algos to the player that does the most damage if the monster is dead. This function can only be accessed by the creator.
Complete the code in scripts/deploy_game.js
to deploy contract and fund it with 1.1 Algos.
Complete the code in scripts/actions/optIn.js
so that acc1
is able to participate as a game player.
Complete the code in scripts/actions/attack.js
so that acc1
can peform an application call to perform attacks on the monster.
Complete the code in scripts/actions/reward.js
so that the smart contract can dispense reward to the player that does the most damage.
- The recipient of an inner transaction must be in the accounts array. This means that you will need to get the best player's address from the global state, process it (because it returns as base64 format) and pass it into the accounts array when rewarding the player.
run algokit bootstrap poetry
within this folder
run yarn install
- Copy
.env.example
to.env
- Update Algorand Sandbox credentials in
.env
file - Update accounts in
.env
file
run poetry shell
- run
python game_approval.py
- run
python game_clearstate.py