dqc3469 2013-07-18 09:30
浏览 36

PHP - RPS - '多人'摇滚,纸张,剪刀迷你游戏 - 如何存储和传递变量?

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序
    • ¥15 多址通信方式的抗噪声性能和系统容量对比
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 Centos / PETSc / PETGEM