Hello!
I was assigned to create a simple php game as a part of my grade. I'm not really a php expert and this isnt really working. I copied some of the code from this website, but this isn't really working for me. I don't really know how to solve the problem and connect that two files.
Part 1:
<html>
<head>
<title>PHP based example Game - Earth & Wind & Fire (aka Paper-Scissors-Rock)</title>
</head>
<body>
<center>
<div id="game">
<a href="?item=earth">Earth<br /><img src="images/sand.png" width="135" height="135" alt="Earth"></a><br /><a href="?item=wind">Wind<br /><img src="images/wind.png" width="135" height="135" alt="Wind"></a><br /><a href="?item=fire">Fire<br /><img src="images/fire.png" width="135" height="135" alt="Fire"></a><br /></div>
</center>
</body>
</html>
Part 2:
<?php
function showComponents($items = null)
{
$pictures =
array(
"earth" => '<a href="?item=earth">Earth<br /><img src="images/sand.png" width="135" height="135" alt="Earth"></a><br />',
"wind" => '<a href="?item=wind">Wind<br /><img src="images/wind.png" width="135" height="135" alt="Wind"></a><br />',
"fire" => '<a href="?item=fire">Fire<br /><img src="images/fire.png" width="135" height="135" alt="Fire"></a><br />',
);
if ($items == null) :
foreach( $pictures as $items => $value ):
echo $value;
endforeach;
else:
echo str_replace("?item={$items}", "#", $pictures[$items]);
endif;
}
function game() {
if ( isset($_GET['item']) == TRUE ) :
$pictures = array('earth','wind','fire');
$playerPic = strtolower($_GET['item']);
$computerPic = $pictures[rand(0, 2)];
echo '<div><a href="http://mapswidgets.com/game.php">New game</a></div>';
if (in_array($playerPic, $pictures) == FALSE):
echo "Play as either Earth, Wind or Fire.";
die;
endif;
if ( $playerPic == 'fire' && $computerPic == 'wind' OR
$playerPic == 'earth' && $computerPic == 'fire' OR
$playerPic == 'wind' && $computerPic == 'earth' ):
echo '<h2>You Win!</h2>';
endif;
if ( $computerPic == 'fire' && $playePic == 'wind' OR
$computerPic == 'earth' && $playerPic == 'fire' OR
$computerPic == 'wind' && $playerPic == 'earth' ):
echo '<h2>Computer wins!</h2>';
endif;
if ($playerPic == $computerPic) :
echo '<h2>House wins! =)</h2>';
endif;
showComponents($playerPic);
showComponents($computerPic);
else :
showComponents();
endif;
}
?>
Thanks for your time and help!