Created
March 27, 2020 15:49
-
-
Save alexroan/0d82755d6372aeb86da56bc74eb22b49 to your computer and use it in GitHub Desktop.
etheremon.sol@3
This file contains hidden or 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
pragma solidity ^0.5.5; | |
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | |
contract Ethermon is ERC721 { | |
struct Monster { | |
string name; | |
uint level; | |
} | |
Monster[] public monsters; | |
address public gameOwner; | |
constructor() public { | |
gameOwner = msg.sender; | |
} | |
function battle(uint _attackingMonster, uint _defendingMonster) public { | |
Monster storage attacker = monsters[_attackingMonster]; | |
Monster storage defender = monsters[_defendingMonster]; | |
if (attacker.level >= defender.level) { | |
attacker.level += 2; | |
defender.level += 1; | |
} | |
else{ | |
attacker.level += 1; | |
attacker.level += 2; | |
} | |
} | |
function createNewMonster(string memory _name, address _to) public { | |
require(msg.sender == gameOwner, "Only game owner can create new monsters"); | |
uint id = monsters.length; | |
monsters.push(Monster(_name, 1)); | |
_safeMint(_to, id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment