PHP Rock, Paper, Scissors Game - Rae Soria
This application is a simple Rock, Paper, Scissors game that users can play against AI. Users must be logged in in order to play. There are five total files:
- Bootstrap
- RPS Game
- Index
- Login
- CSS
You can find the files here:
https://www.wa4e.com/
Web Applications For Everyone by Dr. Charles Severance
There's a lot of neat stuff on that site.
Assuming the user has logged in, they may participate in the game.
Rock Paper Scissors Game PHP Code - Try it Yourself!
You'll have to make a login and an index page but you can probably find that on the website I linked earlier or GitHub. :)<?php
if ( ! isset($_GET['name']) || strlen($_GET['name']) < 1 ) {
die("Name parameter missing");
}
if ( isset($_POST['logout']) ) {
header('Location: index.php');
return;
}
$names = array('Rock', 'Paper', 'Scissors');
$human = isset($_POST['human']) ? $_POST['human']+0 : -1;
$computer = rand(0,2);
function check($computer, $human) {
if ( $human == $computer ) {
return "Tie";
}
else if ( ($human == 0 && $computer == 2) ||
($human == 1 && $computer == 0) ||
($human == 2 && $computer == 1) ) {
return "You Win";
}
else {
return "You Lose";
}
}
$result = false;
if ( $human >= 0 && $human < 3 ) {
$result = check($computer, $human);
}
?>