Guest User

Untitled

a guest
May 20th, 2018
138
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 "./zombiehelper.sol";
  4.  
  5. contract ZombieBattle is ZombieHelper {
  6. uint randNonce = 0;
  7. uint attackVictoryProbability = 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 attack(uint _zombieId, uint _targetId) external ownerOf(_zombieId) {
  15. Zombie storage myZombie = zombies[_zombieId];
  16. Zombie storage enemyZombie = zombies[_targetId];
  17. uint rand = randMod(100);
  18. if (rand <= attackVictoryProbability) {
  19. myZombie.winCount++;
  20. myZombie.level++;
  21. enemyZombie.lossCount++;
  22. feedAndMultiply(_zombieId, enemyZombie.dna, "zombie");
  23. } // start here
  24. else {
  25. myZombie.lossCount++;
  26. enemyZombie.winCount++;
  27. _triggerCooldown(myZombie);
  28. }
  29. }
  30. }
Add Comment
Please, Sign In to add comment