원하는 대로 조합하여 가위바위보를 기반으로 한 규칙으로 게임을 만들어 보세요. 유효성 검사 규칙은 유효한 게임을 만들기 위한 올바른 길을 가고 있는지 확인합니다.
이 프로젝트는 나에게 있어 대부분 재미있는 운동이다. 101 이동 RPS 스타일 게임을 본 후 PHP에서 해당 게임을 다시 만드는 것이 멋지다고 생각했습니다. 그러나 나는 대신 도서관을 만들기로 결정했습니다. 어쩌면 게임이 곧 나올 수도 있습니다.
아직 개선해야 할 부분이 많지만 전반적으로 제 역할을 하고 있다고 생각합니다.
라이브러리를 개발하는 데 사용하는 Dockerfile이 있습니다. 저는 이를 사용하여 PHP 환경을 빠르게 설정한 다음 PHPUnit과 Composer를 컨테이너에 다운로드합니다. 또한 PHPStorm을 사용하여 원격 디버깅 및 원격 단위 테스트를 수행할 수 있도록 SSH를 설치합니다. 이 Dockerfile에는 개발용 PHP 구성(예: display_errors)을 포함하여 많은 사항이 누락되어 있습니다. 내 TODO에 있습니다.
지금은 컨테이너를 빌드하고 실행하기만 하면 됩니다.
docker build -t librps .
docker run -ti [-p 22] -v YOUR_PATH:CONTAINER_PATH librps
그런 다음 컨테이너 내부에 있을 때 SSH 데몬을 시작해야 원격 개발 도구를 사용할 수 있습니다.
물론 첫 번째 단계는 저장소를 복제하는 것입니다. 그런 다음 작성기 라이브러리를 업데이트한 다음 테스트 스위트를 실행해야 합니다.
git clone https://github.com/rvelhote/librockpaperscissor.git
cd librockpaperscissor
composer update
phpunit
Composer 또는 PHPUnit이 설치되어 있지 않은 경우 해당 웹사이트에서 최신 설치 지침을 참조하세요.
가위바위보, 가위바위보 도마뱀 스팍 등 마음이 원하는 모든 것을 바탕으로 규칙을 적용하여 게임을 만드세요.
David C. Lovelace라는 놀라운 사람은 내가 본 것 중 가장 충격적인 RPS 게임을 만들었습니다. 그것들을 확인하고 그것들을 사용하여 매우 멋진 게임을 만들 수 있습니다. 이러한 규칙은 매우 복잡합니다(항상 그렇지는 않지만)... 사람들이 이 규칙을 구현하는 데 도움이 되는 PHP 라이브러리만 있었다면 말이죠. 아 잠깐만요.
구현 세부 사항은 몇 가지 예를 보여주는 테스트 모음을 참조할 수 있습니다. 어쨌든, 요점은 이렇습니다. 클래식 가위바위보 게임을 위해서는 다음이 필요합니다:
// Players of the gaaaaame!
$ player1 = new Player ( " Ricardo V. " , " Rock " );
$ player2 = new Player ( " Anna B. " , " Paper " );
// The ruleset for a regular Rock Paper Scissor game.
$ rules = new RuleCollection ();
$ rules -> add ( new Rule ( " Paper " , " Rock " , " Covers " ));
$ rules -> add ( new Rule ( " Scissor " , " Paper " , " Cuts " ));
$ rules -> add ( new Rule ( " Rock " , " Scissor " , " Smashes " ));
// You should validate it first to make sure it's all good
$ validationResult = $ rules -> validate ();
if ( $ validationResult -> isValid ()) {
$ game = new Game ( $ player1 , $ player2 , $ rules );
$ result = $ game -> result ();
// A game result can be either a Win or a Tie. A Win contains the players that participated (and their plays) as well
// as the winning rule. A Tie just contains the players. You can do whatever you want with the data.
if ( $ result instanceof Tie) {
/** @var WelhottRockPaperScissorGameResultTie $result */
print "n » " . $ result -> getPlayer1 ()-> getName (). " tied " . $ result -> getPlayer2 ()-> getName (). "n" ;
print " » " . $ result -> getPlayer1 ()-> getName (). " played " . $ result -> getPlayer1 ()-> getPlay (). "n" ;
print " » " . $ result -> getPlayer2 ()-> getName (). " played " . $ result -> getPlayer2 ()-> getPlay (). "n" ;
} else if ( $ result instanceof Win) {
/** @var WelhottRockPaperScissorGameResultWin $result */
print "n » " . $ result -> getRule ()-> getText (). "n ================ n" ;
// Detailed
print " » " . $ result -> getWinner ()-> getName (). " played " . $ result -> getWinner ()-> getPlay (). "n" ;
print " » " . $ result -> getLoser ()-> getName (). " played " . $ result -> getLoser ()-> getPlay (). "n" ;
print " » " . $ result -> getRule ()-> getWinner (). " " . $ result -> getRule ()-> getOutcome (). " " . $ result -> getRule ()-> getLoser (). "n" ;
print " » " . $ result -> getWinner ()-> getName (). " Win(s)! nn" ;
} else {
echo " Oops :P " ;
}
} else {
$ reflection = new ReflectionClass ( "\ Welhott \ RockPaperScissor \ Validation \ ValidationMessage " );
$ constants = $ reflection -> getConstants ();
/** @var WelhottRockPaperScissorValidationValidationMessage $message */
foreach ( $ validationResult -> getMessages () as $ message ) {
$ constant = array_search ( $ message -> getType (), $ constants );
print " » " . $ constant . " » " . $ message -> getMessage (). "n" ;
}
}
라이브러리 개선을 제안하고 직접 기여하실 수 있습니다. :)
이 프로젝트의 코드는 MIT 라이선스에 따라 라이선스가 부여됩니다.