Skip to content

Commit

Permalink
troops, attacking stars
Browse files Browse the repository at this point in the history
  • Loading branch information
connormcn37 committed Jan 14, 2018
1 parent 4a14dab commit c2f1bb6
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions contracts/starfactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,7 @@ contract StarFactory is Ownable {
return result;
}

/*function getMineralsByOwner(address _owner) external view returns(uint) {
uint result = 0;
for (uint i = 0; i < stars.length; i++){
if (starToOwner[i] == _owner) {
result += stars[i].minerals;
}
}
return result;
}*/

function transferStar(uint _starId, address _newOwner) external {
function transferStar(uint _starId, address _newOwner) public {
//require(msg.sender == _currentOwner);
require(starToOwner[_starId] == msg.sender || starToOwner[_starId] == owner);
starToOwner[_starId] = _newOwner;
Expand All @@ -75,4 +65,15 @@ contract StarFactory is Ownable {
stars[_starId].troops = _troopAmount;
}

function attackStar(uint _fromStarId, uint _toStarId){
require(starToOwner[_fromStarId] == msg.sender);
require(stars[_fromStarId].minerals > 0 && stars[_fromStarId].troops > 0);
stars[_fromStarId].minerals--;
if(stars[_fromStarId].troops > stars[_toStarId].troops){
stars[_fromStarId].troops -= stars[_toStarId].troops;
stars[_toStarId].troops = 0;
transferStar(_toStarId, msg.sender);
}
}

}

0 comments on commit c2f1bb6

Please sign in to comment.