-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiceGame.sol
59 lines (38 loc) · 1.49 KB
/
DiceGame.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
pragma solidity ^0.4.20;
contract DiceGame{
event DiceResult(uint256 value);
uint256 public participant1_count;
uint256 participant1_amount;
uint256 participant1_diceresult;
address participant1_address;
address owner;
function placeBet( uint256 _diceresult) payable public returns (bool success){
participant1_count +=1;
if(participant1_count == 1){
participant1_diceresult = _diceresult;
participant1_amount = msg.value;
participant1_address = msg.sender;
emit DiceResult(999); // Play still going on
}
if(participant1_count == 2){
if(participant1_diceresult == _diceresult){
msg.sender.transfer( msg.value);
participant1_address.transfer(participant1_amount);
emit DiceResult(0); // Draw
}
if(participant1_diceresult > _diceresult){
participant1_address.transfer(address(this).balance);
emit DiceResult(1); //participant1 wins
}
if(participant1_diceresult < _diceresult){
msg.sender.transfer(address(this).balance);
emit DiceResult(2); //participant2 wins
}
participant1_amount = 0;
participant1_count = 0;
participant1_diceresult = 0;
participant1_address = 0x0;
}
return true;
}
}