Chapter 2: Making the Shell and revealing the Kernel
Defining the shell
uint256 shellStrength; // The strength of the Walnut's shell.
constructor(uint256 _shellStrength, suint256 _kernel) {
shellStrength = _shellStrength; // Set the initial shell strength.
kernel = _kernel; // Initialize the kernel.
}Adding the hit function
// Event to log hits
event Hit(address indexed hitter, uint256 remainingShellStrength);
// Function to hit the walnut shell
function hit() public {
shellStrength--; // Decrease the shell strength.
emit Hit(msg.sender, shellStrength); // Log the hit event.
}
// Modifier to ensure the shell is not cracked.
modifier requireIntact() {
require(shellStrength > 0, "SHELL_ALREADY_CRACKED");
_;
}What's happening here?
Example call:
Revealing the Kernel
Updated contract with hit, shake and look
PreviousChapter 1: Making the KernelNextChapter 3: Reset Mechanism, Rounds, and a more conditional Kernel Reveal
Last updated

