-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy path25-Inheritance-Solution.sol
More file actions
38 lines (30 loc) · 940 Bytes
/
25-Inheritance-Solution.sol
File metadata and controls
38 lines (30 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// 1️⃣ Inherit from the Multiplayer Game
// 2️⃣ Call the parent joinGame() function
// HINT: you might have to use the super keyword
// 3️⃣ Increment playerCount in joinGame() function
// MultiplayerGame contract
contract MultiplayerGame {
mapping(address => bool) public players;
function joinGame() public virtual {
players[msg.sender] = true;
}
}
// Game contract inheriting from MultiplayerGame
contract Game is MultiplayerGame{
string public gameName;
uint256 public playerCount;
constructor(string memory _gameName) {
gameName = _gameName;
playerCount = 0;
}
function startGame() public {
// Perform game-specific logic here
}
function joinGame() public override {
super.joinGame(); // functions from parent contract
// add our own function
playerCount++;
}
}