Created
May 18, 2022 23:10
-
-
Save andrejrakic/c5472d7cf8a4ab93dc4e10ce21992af7 to your computer and use it in GitHub Desktop.
Middleman contract example for DevConnect Game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
// x -----> | |
// _______________ | |
// y |____|____|_____ | |
// |____|____|_____ | |
// |____|____|_____ | |
// |____|____|_____ | |
enum MoveDirection { | |
Up, // 0 | |
Down, // 1 | |
Left, // 2 | |
Right // 3 | |
} | |
struct Position { | |
uint8 x; | |
uint8 y; | |
} | |
interface IGame { | |
function register() external; | |
function collectTokens() external; | |
function collectHealth() external; | |
function update(address newContract) external; | |
function move(MoveDirection direction) external; | |
function currentPosition() external view returns(Position memory); | |
function positionOf(address player) external view returns(Position memory); | |
} | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
contract Caller is Ownable, IGame { | |
IGame public registry; | |
constructor(address _registry, address _owner) { | |
registry = IGame(_registry); | |
transferOwnership(_owner); | |
} | |
function setRegistry(address _registry) public onlyOwner { | |
registry = IGame(_registry); | |
} | |
function register() public override onlyOwner { | |
registry.register(); | |
} | |
function move(MoveDirection direction) public override onlyOwner { | |
registry.move(direction); | |
} | |
function collectTokens() public override onlyOwner { | |
registry.collectTokens(); | |
} | |
function collectHealth() public override onlyOwner { | |
registry.collectHealth(); | |
} | |
function update(address myNewContract) public override onlyOwner { | |
registry.update(myNewContract); | |
} | |
function currentPosition() public override view returns(Position memory) { | |
return registry.currentPosition(); | |
} | |
function positionOf(address player) public override view returns(Position memory) { | |
return registry.positionOf(player); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment