update numbergame bapp

This commit is contained in:
elegant651
2020-03-26 15:16:54 +09:00
parent 6a95428c6b
commit c1e2973803
21 changed files with 4853 additions and 3141 deletions

View File

@@ -1,8 +1,8 @@
pragma solidity ^0.4.18;
pragma solidity >=0.4.24 <=0.5.6;
contract Ownable {
address owner;
function Ownable() public {
constructor() public {
owner = msg.sender;
}
@@ -14,39 +14,36 @@ contract Ownable {
contract Mortal is Ownable {
function kill() public Owned {
selfdestruct(owner);
selfdestruct(msg.sender);
}
}
contract Betting is Mortal {
uint minBet; //
uint winRate; // (%)
contract Game is Mortal {
uint minBet; //
event Won(bool _result, uint _amount);
function Betting(uint _minBet, uint _winRate) payable public {
require(_minBet > 0);
require(_winRate <= 100);
minBet = _minBet;
winRate = _winRate;
constructor(uint _minBet) payable public {
require(_minBet > 0);
minBet = _minBet;
}
function() public {
function() external {
revert();
}
function bet(uint _num) payable public {
function play(uint _num) payable public {
require(_num > 0 && _num <= 5);
require(msg.value >= minBet);
uint winNum = random();
if (_num == winNum) {
uint amtWon = msg.value * (100 - winRate)/10;
uint amtWon = msg.value * 2;
if(!msg.sender.send(amtWon)) revert();
Won(true, amtWon);
emit Won(true, amtWon);
} else {
Won(false, 0);
emit Won(false, 0);
}
}
@@ -55,7 +52,6 @@ contract Betting is Mortal {
}
function random() public view returns (uint) {
return uint(keccak256(block.difficulty, block.number, now)) % 5 + 1;
return uint(keccak256(abi.encodePacked(now, msg.sender))) % 5 + 1;
}
}
}