Ch 2: Stamina and Robbing Secrets
Defining the stamina bar
uint256 initialClownStamina; // Starting stamina restored on reset.
uint256 clownStamina; // Remaining stamina before the clown is down.
constructor(uint256 _clownStamina) {
initialClownStamina = _clownStamina; // Set starting stamina.
clownStamina = _clownStamina; // Initialize remaining stamina.
round = 1; // Start with the first round.
}Adding the hit function
// Event to log hits.
event Hit(uint256 indexed round, address indexed hitter, uint256 remaining);
// Hit the clown to reduce stamina.
function hit() public requireStanding {
clownStamina--; // Decrease stamina.
emit Hit(round, msg.sender, clownStamina); // Log the hit.
}
// Modifier to ensure the clown is still standing.
modifier requireStanding() {
require(clownStamina > 0, "CLOWN_ALREADY_DOWN");
_;
}What's happening here?
Adding a stamina getter
Robbing the clown
What's happening here?
Updated contract with hit and rob
Last updated

