Skip to content

Instantly share code, notes, and snippets.

@Raz0r
Created May 21, 2018 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raz0r/7ddaf461aef6b0bf5da074cb7ad01fb9 to your computer and use it in GitHub Desktop.
Save Raz0r/7ddaf461aef6b0bf5da074cb7ad01fb9 to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.16;
contract WheelOfFortune {
Game[] public games;
struct Game {
address player;
uint id;
uint bet;
uint blockNumber;
}
function spin(uint256 _bet) public payable {
require(msg.value >= 0.01 ether);
uint gameId = games.length;
games.length++;
games[gameId].id = gameId;
games[gameId].player = msg.sender;
games[gameId].bet = _bet;
games[gameId].blockNumber = block.number;
if (gameId > 0) {
uint lastGameId = gameId - 1;
uint num = rand(block.blockhash(games[lastGameId].blockNumber), 100);
if(num == games[lastGameId].bet) {
games[lastGameId].player.transfer(this.balance);
}
}
}
function rand(bytes32 hash, uint max) pure private returns (uint256 result){
return uint256(keccak256(hash)) % max;
}
function() public payable {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment