I have made the structure of the game (I can play it vs the bot), but I want to make it a player vs player game. How do I store and pass variables then? Should I store it in my database (one table for game id, one for 'move' id) or is there a simpler way? I do not intent to keep a score count or store anything for the next time the same player want's to play again.
Here is the code I have so far (the player vs bot/ structure of the game. This does not include the form and the other HTML on the page):
$X = $_POST['X'];
$Y = rand(1, 3);
$A = $X-$Y+3;
$R = fmod($A, 3);
if ($R == 0) {
echo 'draw!';
} elseif ($R == 1) {
echo 'you won!';
} elseif ($R == 2) {
echo 'you lost!';
} else {
echo 'an error occurred!';
}
If you want to see the full script, please let me know.
My idea of the database and the tables:
Table: Users
UserID Username (I don't include email, password and salt here...)
1 Espen
2 Test
Table: Games
GameID Participant1 Participant2 Winner
1 1 2 1
1 1 2 2
Table: Moves
MoveID GameID UserID Move
1 1 1 2
2 1 2 1
3 2 1 3
4 2 2 1
Values of moves: 1-rock, 2-paper, 3-scissors
Thanks in advance!
-Espen