Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 74 additions & 23 deletions functions.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,77 @@
<?php

/**
* Computer's Throw
*
* Return a random throw.
* Options: rock, paper, or scissors
*
* @return string
*/
function computers_throw() {
return '';
}
/**
* Computer's Throw
*
* Return a random throw.
* Options: rock, paper, or scissors
*
* @return string
*/
function computers_throw() {
$theThrow = rand(1,5);

/**
* Who Wins?
*
* Accept two throws and return a winner.
*
* @param $users_throw
* @param $computers_throw
* @return string
*/
function who_wins( $users_throw, $computers_throw) {
return '';
}
switch ($theThrow) {
case ( 1 ):
return "Rock";
case ( 2 ):
return "Paper";
case ( 3 ):
return "Scissors";
case ( 4 ):
return "Lizard";
default:
return "Spock";
}

}

/**
* Who Wins?
*
* Accept two throws and return a winner.
*
* @param $users_throw
* @param $computers_throw
* @return string
*/
function who_wins( $users_throw, $computers_throw) {

if (strtoupper($users_throw) == strtoupper($computers_throw))
{ return "Tie."; }

$cthrow = strtoupper($computers_throw);

switch ( $users_throw ) {
case ( "Rock" ):
if ( "LIZARD" == $cthrow || "SCISSORS" == $cthrow )
{ return "User wins. Rock beats " . $computers_throw . "<br>" ; }
else
{ return "Computer wins. Rock loses to " . $computers_throw . "<br>" ; }
case ( "Scissors" ):
if ( "LIZARD" == $cthrow || "PAPER" == $cthrow )
{ return "User wins. Scissors beats " . $computers_throw . "<br>" ; }
else
{ return "Computer wins. Scissors loses to " . $computers_throw . "<br>" ; }
case ( "Paper" ):
if ( "ROCK" == $cthrow || "SPOCK" == $cthrow )
{ return "User wins. Paper beats " . $computers_throw . "<br>" ; }
else
{ return "Computer wins. Paper loses to " . $computers_throw . "<br>" ; }
case ( "Lizard" ):
if ( "SPOCK" == $cthrow || "PAPER" == $cthrow )
{ return "User wins. Lizard beats " . $computers_throw . "<br>" ; }
else
{ return "Computer wins. Lizard loses to " . $computers_throw . "<br>" ; }
case ( "Spock" ):
if ( "ROCK" == $cthrow || "SCISSORS" == $cthrow )
{ return "User wins. Spock beats " . $computers_throw . "<br>" ; }
else
{ return "Computer wins. Spock loses to " . $computers_throw . "<br>" ; }
default:
return "Improper value given.";

}
//return '';
}
?>
8 changes: 5 additions & 3 deletions views/home.tmpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
</p>

<ul>
<li><a href="?throw=rock">Rock</a></li>
<li><a href="?throw=paper">Paper</a></li>
<li><a href="?throw=scissors">Scissors</a></li>
<li><a href="?throw=Rock">Rock</a></li>
<li><a href="?throw=Paper">Paper</a></li>
<li><a href="?throw=Scissors">Scissors</a></li>
<li><a href="?throw=Lizard">Lizard</a></li>
<li><a href="?throw=Spock">Spock</a></li>
</ul>

{results_view}
Expand Down