public function run() { $rview = new RockPaperScissorsView(); $user_item = $rview->getUserItem(); //var_dump($user_item); $rpsModel = new RockPaperScissor(); //Succesfully played if ($rpsModel->play($user_item)) { //Player Win if ($rpsModel->getPlayerWin()) { $rview->setPlayerWin(); } else { if ($rpsModel->getPlayerTie()) { $rview->setPlayerTie(); } else { $rview->setPlayerLoose(); } } $rview->setUserItem($rpsModel->getUserItem()); $rview->setCompItem($rpsModel->getCompItem()); } else { $rview->setMessageBadChoise(); $rview->response(); } }
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/RockPaperScissor.php"; //initialize $_SESSION array to hold results session_start(); if (empty($_SESSION['list_of_moves'])) { $_SESSION['list_of_moves'] = array(); } $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get("/", function () use($app) { RockPaperScissor::deleteAll(); return $app['twig']->render('player_one_form.html.twig'); }); $app->get("/player_two_form", function () use($app) { $player1_input = new RockPaperScissor($_GET['player1']); $player1_input->save(); return $app['twig']->render('player_two_form.html.twig'); }); $app->get("/gameover", function () use($app) { $new_game = RockPaperScissor::getAll()[0]; $new_game->setPlayer2($_GET['player2']); $game_results = $new_game->play_rock($new_game->getPlayer1(), $new_game->getPlayer2()); return $app['twig']->render('results.html.twig', array('result' => $game_results, 'player1' => $new_game->getPlayer1(), 'player2' => $_GET['player2'])); }); return $app;
<?php require_once "clientDB.php.inc"; require_once "RockPaperScissor.php.inc"; $db = new clientDB('connect.ini'); $rps = new RockPaperScissor(); $rock = "rock"; $paper = "paper"; $scissor = "scissor"; $hands = array($rock, $paper, $scissor); $ans2; $request = $_POST['request']; $ans1 = $_POST['hand']; $pName = $_POST['playerName']; switch ($request) { case 'move': $key = array_rand($hands); $ans2 = $hands[$key]; $rps->beats($ans1, $ans2); $db->addNewPlayer($pName); $db->addNewMatch($pName, $db->addNewPlayer($pName)); case 'challenge': }
function test_scissor_paper() { //Arrange $test_RockPaperScissor = new RockPaperScissor(); $first_input = "scissors"; $second_input = "paper"; //Act $result = $test_RockPaperScissor->play_rock($first_input, $second_input); //Assert $this->assertEquals("Player One Wins", $result); }
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/RockPaperScissor.php"; session_start(); $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); //initialize $_SESSION array to hold results if (empty($_SESSION['results_array'])) { $_SESSION['results_array'] = array(); } $app->get("/", function () use($app) { var_dump($_SESSION['results_array']); return $app['twig']->render('player_one_form.html.twig'); }); $app->get("/player_two_form", function () use($app) { array_push($_SESSION['results_array'], $_GET['player1']); return $app['twig']->render('player_two_form.html.twig'); }); $app->get("/gameover", function () use($app) { $new_game = new RockPaperScissor(); array_push($_SESSION['results_array'], $_GET['player2']); $game_results = $new_game->play_rock($_SESSION['results_array'][0], $_SESSION['results_array'][1]); return $app['twig']->render('results.html.twig', array('result' => $game_results)); }); return $app;