-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathRSPGame3.sol
36 lines (27 loc) · 1.04 KB
/
RSPGame3.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
pragma solidity ^0.4.24;
contract RSP {
enum Rsp { Rock, Scissors, Paper }
address player1; address player2;
Rsp player1Choice; Rsp player2Choice;
bytes32 player1ChoiceHash; bytes32 player2ChoiceHash;
event Winner(string msg,address player);
function play(bytes32 choiceHash) external {
if ( player1 == address(0) ) {
player1 = msg.sender; player1ChoiceHash = choiceHash;
}
else if ( player2 == address(0) ) {
player2 = msg.sender; player2ChoiceHash = choiceHash;
}
}
function hashForChoice(Rsp choice,uint nonce) external pure returns (bytes32) {
return keccak256(choice,nonce);
}
function submit(Rsp choice,nonce) external {
if ( msg.sender == player1 ) {
if ( keccak256(choice,nonce) == player1ChoiceHash ) { player1Choice = choice; }
}
else if ( msg.sender == player2 ) {
if ( keccak256(choice,nonce) == player2ChoiceHash ) { player2Choice = choice;}
}
}
}