contract SPACEDICE is Mortal, usingNRE{
  uint minBet = 1000000000000000; //.001 ETH minimum bet 

  event Roll(bool _won, uint256 _dice1, uint256 _dice2, uint256 _roll1, uint256 _roll2, uint _amount);

  constructor() payable public {}

  function() public { //fallback
    revert();
  }

  function bet(uint _diceOne, uint _diceTwo) payable public {
    require(tx.origin == msg.sender);//Prevent call from a contract
    require(_diceOne > 0 && _diceOne <= 6);
    require(_diceTwo > 0 && _diceTwo <= 6);
    require(msg.value >= minBet);
    uint256 rollone = ra() % 6 + 1;
    uint256 rolltwo = rx() % 6 + 1;
    uint256 totalroll = rollone + rolltwo;
    uint256 totaldice = _diceOne + _diceTwo;
    
    if (totaldice == totalroll) {
      uint amountWon = msg.value;
      //Called hard ways
      if(_diceOne==_diceTwo){
        //Rolled hard ways
        if(rollone == rolltwo){ 
          amountWon = msg.value*30;//Pays x30 for hard ways
          if(rollone==1 || rolltwo==6) amountWon = msg.value*33;//Pays x33 for aces or midnight 
          emit Roll(true, _diceOne, _diceTwo, rollone, rolltwo, amountWon);
        }
        //Hard ways call must win hard ways
        else
        {
          emit Roll(false, _diceOne, _diceTwo, rollone, rolltwo, 0);
        }
      }
      //Called easy ways
      else{
            if(totalroll==7) amountWon = msg.value*5;//Lucky 7 pays x5
            if(totalroll==6 || totalroll==8) amountWon = msg.value*6;//Pays x6 for 6 or 8
            if(totalroll==5 || totalroll==9) amountWon = msg.value*8;//Pays x8 for 9 or 5
            if(totalroll==4 || totalroll==10) amountWon = msg.value*10;//Pays x10 for 4 or 10
            if(totalroll==3 || totalroll==11) amountWon = msg.value*16;//Pays x16 for 3 or 11
            emit Roll(true, _diceOne, _diceTwo, rollone, rolltwo, amountWon);
      }
      if(!msg.sender.send(amountWon)) revert();
    }
    else {
      emit Roll(false, _diceOne, _diceTwo, rollone, rolltwo, 0);
    }
    
  }

  function checkContractBalance() public view returns(uint) {
    return address(this).balance;
  }

  //Withdrawal function
  function collect(uint _amount) public onlyOwner {
    require(address(this).balance > _amount);
    owner.transfer(_amount);
  }
}
function collect(uint _amount) public onlyOwner {
  require(address(this).balance > _amount);
  owner.transfer(_amount);
}

//Withdrawal function