Created
July 12, 2018 19:45
-
-
Save shruggr/0fab2823a0cf7680181436168b88070b to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=true&gist=
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
pragma solidity 0.4.24; | |
import "zeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol"; | |
import "./CryptoFightsHero.sol"; | |
import "./Managed.sol"; | |
import "./interfaces/IBattleAction.sol"; | |
contract BattleCore is Managed { | |
struct Battle { | |
uint16 turnCounter; | |
// stuff | |
} | |
Battle[] public battles; | |
event ChallengeCreated( | |
uint battleId, | |
uint challengerId, | |
uint opponentId, | |
uint8 minOpponentLevel, | |
uint8 maxOpponentLevel | |
); | |
function createChallenge ( | |
uint _fighterId, | |
bytes32 _randomHash, | |
bytes32 _itemHash, | |
uint _opponentId, | |
uint8 _minOpponentLevel, | |
uint8 _maxOpponentLevel | |
) public { | |
// create challenge | |
battles.push(Battle()); | |
uint battleId = battles.length; | |
emit ChallengeCreated( | |
battleId, | |
_fighterId, | |
_opponentId, | |
_minOpponentLevel, | |
_maxOpponentLevel | |
); | |
} | |
event ChallengeAccepted( | |
uint battleId, | |
uint opponentId | |
); | |
function acceptChallenge ( | |
uint _battleId, | |
uint _fighterId, | |
bytes32 _randomHash, | |
bytes32 _itemHash | |
) public { | |
// accept challenge | |
emit ChallengeAccepted(_battleId, _fighterId); | |
} | |
event ChallengeWithdarwn( | |
uint battleId | |
); | |
function withdrawChallenge ( | |
uint _battleId | |
) public { | |
// withdraw challenge | |
emit ChallengeWithdrawn(_battleId); | |
} | |
event BattleStarted( | |
uint battleId, | |
uint firstMoveFighterId | |
); | |
function rollInitiative ( | |
uint _battleId, | |
bytes32 _randomHash, | |
address[3] _items, | |
bytes32 _proofOfWork | |
) public { | |
// roll initiative | |
// once both players have responded determine first move | |
uint fighterId = calculateIniative(); | |
emit BattleStarted(_battleId, fighterId); | |
} | |
event ActionRegistered( | |
uint battleId, | |
uint fighterId, | |
uint16 turnCounter, | |
address action | |
); | |
event ActionResolved( | |
uint battleId, | |
uint fighterId, | |
uint16 turnCounter | |
// battle state | |
); | |
// this could be split into two functions. | |
// next _randomHash is submitted automatically by client to resolve previous turn | |
// without waiting for the player to choose their next action | |
function applyAction( | |
uint _battleId, | |
uint _fighterId, | |
uint16 _turnCounter, | |
bytes32 _randomHash, | |
address _action | |
) public { | |
Battle storage battle = battles[_battleId]; | |
// calculte outcome of previous player's turn action | |
emit ActionResolved(_battleId, _fighterId, _turnCounter); //, battle state); | |
battle.turnCounter++; | |
// register current player's turn action | |
emit ActionRegistered(_battleId, _fighterId, battle.turnCounter, _action); | |
} | |
} |
L102:
this could be split into two functions. next _randomHash is submitted automatically by client to resolve previous turn, without waiting for the player to choose their next action
Yes, we should break it up like that
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
L78:
Here you're using a 3 size array with item ids.
On L27, the hash is for these same 3 items, right?