Question: PHP Create a PHP script simulates two players playing rock-paper-scissors. When visited, the PHP page should generate two random values between 0 and 2 (inclusive)

PHP

Create a PHP script simulates two players playing rock-paper-scissors.

When visited, the PHP page should generate two random values between 0 and 2 (inclusive) representing the two players moves. You can use the function rand(0,2) to generate each value. These values represent rock (0), paper (1), and scissors (2).

Next, determine whether player 1, player 2, or neither player has won.

For reference, the rules of rock paper scissors are:

  • paper beats rock
  • rock beats scissors
  • scissors beats paper

If the two plays are the same (e.g. rock and rock, paper and paper, or scissors and scissors) then it is a tie.

The page should use PHP sessions to maintain a running total of games won by each player to be shown between page loads.

Finally, the page should display the following information:

  • The number of games Player 1 has won.
  • The number of games Player 2 has won.
  • Player 1s move (see $symbols below).
  • Player 2s move (see $symbols below).
  • A message describing which player won the latest game, or whether it was a tie.

For fun, here is an array which can be used to map the generated values to an appropriate HTML entity:

$symbols = Array(0 => '✊', // Rock

1 => '✋', // Paper

2 => '✌'); // Scissors

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!