jarrett / rockpaperscissorsspocklizard
基于由Sam Kass和Karen Bryla创建的游戏,并由"Big Bang Theory"流行起来的游戏。
1.1.4-stable
2017-09-07 17:43 UTC
Requires (Dev)
- phpunit/php-code-coverage: ^5.2
- phpunit/phpunit: ^6.3
- satooshi/php-coveralls: ^1.0
This package is not auto-updated.
Last update: 2024-09-28 02:03:15 UTC
README
RockPaperScissorsSpockLizard 游戏(PHP实现)
Sam Kass和Karen Bryla创建的Rock Paper Scissors Spock Lizard的PHP类实现,并由"Big Bang Theory"推广。
添加您想要的任何数量的玩家(或机器人)。然后一次性让所有玩家相互对战!
可以在以下位置找到Packagist:jarrett/rockpaperscissorsspocklizard
入门指南
通过composer安装
composer install jarrett/rockpaperscissorsspocklizard
并需要composer自动加载器
require 'vendor/autoload.php';
基本示例
use Jarrett\RockPaperScissorsSpockLizard;
use Jarrett\RockPaperScissorsSpockLizard\Player;
// ...
$player = new Player();
$player->move('rock');
$bot = new Player();
$bot->isBot(true);
$game = new RockPaperScissorsSpockLizard();
$game->addPlayers($player, $bot)
->play();
$outcome = $game->getOutcomes();
2人示例
use Jarrett\RockPaperScissorsSpockLizard;
use Jarrett\RockPaperScissorsSpockLizard\Player;
// ...
$player1 = new Player();
$player1->move('rock');
$player2 = new Player();
$player2->move('scissors');
$game = new RockpaperScissorsSpockLizard();
$game->setRounds(3)
->addPlayers($player1, $player2);
->play();
$outcome = $this->getOutcomes()
5人示例
use Jarrett\RockPaperScissorsSpockLizard;
use Jarrett\RockPaperScissorsSpockLizard\Player;
// ...
// human
$player1 = new Player();
$player1->move('rock');
// human
$player2 = new Player();
$player2->move('paper');
// and 3 bots
$player3 = new Player();
$player4 = new Player();
$player5 = new Player();
$game = new RockpaperScissorsSpockLizard();
$game->addPlayers($player1, $player2, $player3, $player4, $player5)
->play();
// returns an array containing all wins, ties, and losses
$outcomes = $this->getOutcomes()
... 或者直接将玩家实例化传递给addPlayers()方法
$game = new RockpaperScissorsSpockLizard();
$game->addPlayers($player1, $player2, (new Player), (new Player), (new Player))
->play();
类方法参考
Player( string $player_name )
move( string $move)
设置你的动作
setName()
设置玩家名称。也可以通过构造函数传递。如果名称为空,将使用通用的"玩家1,2,3"。
getName()
获取玩家名称。
getMoveHistory()
获取玩家的动作历史。
getLastMove()
获取玩家的最后动作。
RockPaperScissorsSpockLizard()
play()
进行回合
restart()
重启游戏
setRounds( string $number, bool $lock = false)
设置本游戏的回合数。默认为1,如果未指定。
参数
$number integer
- 选择赢家之前的最大回合数
$lock bool
- 如果为true,则不允许更改本游戏的回合数
- 如果为false(默认),则在确定赢家后,最大回合数仍然可以更改。
getRounds()
返回所有回合结果。
getOutcome()
返回最后回合结果。
addPlayer()
将玩家添加到游戏中。
addPlayers()
将多个玩家添加到游戏中。
getPlayers()
返回游戏中的玩家。
getTotalPlayers()
返回正在玩游戏的玩家数量。
getRoundWinner()
返回赢得最后一轮的玩家。
getOutcomes()
返回所有玩家的结果。
getWinners()
返回赢得游戏的玩家。