@@ -4,18 +4,20 @@ pragma solidity ^0.8.13;
44
55contract rockPaperScissorsGame {
66
7+ enum GameResult = (pending, Draw, player1Wins, player2Wins);
8+
79 struct Player {
810 address addr;
9- bytes32 committedMoves;
10- string revealedMoves;
11+ string committedMove;
1112 bool hasCommitted;
12- bool hasRevealed;
13- string secret;
13+ string revealMove;
1414 }
1515 Player public player1;
16- Player player2;
17- bool hasStarted;
18- bool hasended;
16+ Player public player2;
17+ bool public hasStarted;
18+ bool public hasended;
19+
20+ GameResult public result;
1921
2022
2123 event Winner (address _player );
@@ -24,19 +26,21 @@ contract rockPaperScissorsGame{
2426
2527
2628 error AlreadyCommitted ();
29+ error mustCommit ();
2730 error invalidPlayer ();
2831 error AlreadyStarted ();
32+ error wrongHash ();
2933
3034
3135 constructor (address _player1 ) {
3236 player1 = Player ({
3337 addr: _player1,
34- committedMoves: bytes32 (0 ),
35- revealedMoves: "" ,
38+ committedMove: "" ,
3639 hasCommitted: false ,
37- hasRevealed: false ,
38- secret: ""
40+ revealedMove: ""
3941 });
42+
43+ result = result.pending;
4044 }
4145
4246 function joinGame (address _player2 ) external {
@@ -45,39 +49,41 @@ contract rockPaperScissorsGame{
4549
4650 player2 = Player ({
4751 addr: _player2;
48- committedMoves: bytes32 (0 ),
49- revealedMoves: "" ,
52+ committedMove: ,
5053 hasCommited: false ,
51- hasRevealed: false ,
52- secret: ""
54+ revealedMove ""
55+
5356 })
5457
5558 bool hasStarted = true ;
5659 }
57- function commitMoves (string memory _move , string memory _secret ) external {
60+ function commitMoves (string memory _move , address _player ) external {
5861
5962
60- bytes32 hash = keccak256 (abi.encodePacked (_move, _secret));
63+ // bytes32 hash = keccak256(abi.encodePacked(_move, _secret));
6164
6265 if (msg .sender == player1.addr){
6366
6467 if ( ! (player1.hasCommited) ) revert AlreadyCommitted ();
65- player1.committedMoves = hash;
66- player1.hasCommited = true ;
67- player1.secret = _secret;
68+ player1.committedMove = _move;
69+ player1.hasCommitted = true ;
6870
6971 }else if (msg .sender == player2.addr){
7072
7173 if ( ! (player2.hasCommited) ) revert AlreadyCommitted ();
72- player2.committedMoves = hash;
73- player2.hasCommited = true ;
74- player2.secret = _secret;
74+ player2.committedMove = hash;
75+ player2.hasCommitted = true ;
76+
77+ } else {
78+
79+ "invalid Player " ;
7580 }
7681
77- emit moveCommitted (player);
82+ emit moveCommitted (_player);
83+
7884 }
79- }
8085
86+ }
8187
8288contract gameSessionFactory {
8389
0 commit comments