Location: PHPKode > projects > Crown of Evanion > final/cup.php
<?php
/*
*   This file is part of 'Crown of Evanion'.
*
*    'Crown of Evanion' is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    'Crown of Evanion' is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with 'Crown of Evanion'; if not, write to the Free Software
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

$title = "Pea in a Cup";
include("include.php");

$errors = array(
'1' => "That is not one of my cups!",
);

if(!$page) {
	echo "<div align=\"center\">
	<h3>Pea in a Cup</h3>
	$errors[$error]
	<p>Welcome to my game! Can you keep your eye on the pea long enough? If you can, you'll win some money! Oh, and it costs 4 money to play!</p>
	<p><strong>Select your cup to play!</strong></p>
	<a href=\"$PHP_SELF?page=play&cup=1\"><img src=\"images/egg.gif\" border=\"0\"></a><a href=\"$PHP_SELF?page=play&cup=2\"><img src=\"images/egg.gif\" border=\"0\"></a><a href=\"$PHP_SELF?page=play&cup=3\"><img src=\"images/egg.gif\" border=\"0\"></a>
	</div>
	";
}

if($page == "play") {
	$cup = $_REQUEST['cup'];
	if(!$cup || $cup > 3 || $cup <= 0) {
		header("location: $PHP_SELF?error=1");
		die;
	}

	mysql_query("UPDATE users SET money = money-4 WHERE id = '$UserID'");
	
	$under = rand(1,3);
	$winnings = rand(1,10);
	
	if($cup == $under) {
		mysql_query("UPDATE users SET money = money+$winnings WHERE id = '$UserID'");
		echo "<div align=\"center\"><h2>You win!</h2>
		<p>You recived $winnings money!</p></div>";
	} else {
		echo "<div align=\"center\"><h2>You lose!</h2>
		<p>You recived nothing.</p></div>";
	}
}

include("footer.php");
?>
Return current item: Crown of Evanion