Solution: Part 1
Build our own play-to-earn game.
We'll cover the following
Inheritance structure
For clarity and code maintainability, we'll separate VRF-related code from the parts of our game that don't depend on randomness.
TreasureHuntNoVRF.sol
is a base contract containing state variables and modifiers that don't depend on the VRF.TreasureHuntVRF.sol
will inherit fromTreasureHuntNoVRF.sol
and contain all VRF-related inheritance, state variables, and anoverride
implementation of the VRFfullfillRandomWords()
function. However, it will not implement the constructor inherited from the VRF contracts; we'll save its implementation for the last contract in our inheritance structure. Therefore, we'll have to declareTreasureHuntVRF.sol
as an abstract contract.TreasureHunt.sol
is our final derived contract. Inheriting fromTreasureHuntVRF.sol
(and hence, fromTreasureHuntNoVRF.sol
), it will implement the constructor, game, and payment functions, as well as admin and security design patterns (ownability, pausability, and reentrancy guard).
Non-VRF-related base contract
First, we'll define a base contract TreasureHuntNoVRF.sol
that contains the parts of our game that do not depend on randomness and Chainlink's VRF. Later we'll add those components in a separate contract TreasureHuntVRF.sol
that will inherit from the present contract.
Get hands-on with 1200+ tech skills courses.