Guest User

Untitled

a guest
Jun 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. pragma solidity ^0.4.19;
  2.  
  3. import "./playerhelper.sol";
  4.  
  5. contract PlayerChallenge is PlayerHelper {
  6. uint randNonce = 0;
  7. uint victoryProbability = 70;
  8.  
  9. function randMod(uint _modulus) internal returns(uint) {
  10. randNonce++;
  11. return uint(keccak256(now, msg.sender, randNonce)) % _modulus;
  12. }
  13.  
  14. function challenge(uint _footballerId, uint _targetId) external onlyOwnerOf(_footballerId) {
  15. Footballer storage myPlayer = players[_footballerId];
  16. Footballer storage opponentPlayer = players[_targetId];
  17. uint rand = randMod(100);
  18.  
  19. if (rand <= victoryProbability) {
  20. myPlayer.winCount = myPlayer.winCount.add(1);
  21. myPlayer.level = myPlayer.level.add(1);
  22. opponentPlayer.lossCount = opponentPlayer.lossCount.add(1);
  23. clone(_footballerId, opponentPlayer.dna, "footballer");
  24. } // start here
  25. }
  26. }
Add Comment
Please, Sign In to add comment