Click to See Complete Forum and Search --> : game I made


PunkSktBrdr01
07-06-2003, 09:21 PM
I made this little game thing where you click on table cells and try to find the yellow one. I want the game to stop once the the player finds the yellow square, but I don't know how to do this. Here's the source code:


<?
include('status.php');
echo "<link rel=\"STYLESHEET\" type=\"text/css\" href=\"frame.css\">\n";
echo "<style>\n";
echo "td.game { background-color: #0000FF; }\n";
echo "</style>\n";
echo "<script language=\"JavaScript\">\n";
echo "function countClick() {\n";
echo "if(document.num_form.num_click.value == 0) {\n";
echo "alert(\"GAME OVER!\");\n";
echo "}\n}\n";
echo "</script>";
echo "<body $status_load><font color=#55CC7A>\n";
echo "<br><br>";
$i = 0;
$big = 4;
$javascript = "style=\"cursor: hand;\"";
$num5 = array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
$num4 = array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
$num3 = array(1, 0, 0, 0, 0, 0, 0, 0, 0);
if($big == 5) {
$num = $num5;
$clicks_left = 10;
}
elseif($big == 4) {
$num = $num4;
$clicks_left = 7;
}
elseif($big == 3) {
$num = $num3;
$clicks_left = 4;
}
shuffle($num);
echo "<center>\n";
echo "<form name=\"num_form\">";
echo "<table name=\"click_table\">\n";
for($x = 0; $x < $big; $x++) {
echo "<tr>\n";
for($y = 0; $y < $big; $y++) {
if($num[$i] == 1) {
$bg = "#FFFF00";
}
else {
$bg = "#FF0000";
}
echo "<td name=\"td$i\"class=\"game\" width=\"50\" height=\"50\" $javascript onClick=\"this.style.backgroundColor='$bg'; document.num_form.num_click.value--; countClick();\"></td>\n";
$i++;
}
echo "</tr>\n";
}
echo "</table>\n";
echo "<br><br>\n";
echo "<input name=\"num_click\" type=\"text\" value=\"$clicks_left\" readonly>\n";
echo "</center>\n";
?>


Here's a link to the live code (http://www.radioactiverabbit.com/site/game1.php) . Any help would be greatly appreciated.

crs
07-07-2003, 02:18 AM
onClick you needs also another statement reading like this:

if (this.style.backgroundColor==YELLOW) {alert('Well done!');}

PunkSktBrdr01
07-07-2003, 11:21 AM
I tried what you suggested, but it doesn't seem to work. Also, is there a way to make the game end when the yellow square is found? Something like disableing clicking? Here's the new code:


<?
include('status.php');
echo "<link rel=\"STYLESHEET\" type=\"text/css\" href=\"frame.css\">\n";
echo "<style>\n";
echo "td.game { background-color: #0000FF; }\n";
echo "</style>\n";
echo "<script language=\"JavaScript\">\n";
echo "function countClick() {\n";
echo "document.num_form.num_click.value--;";
echo "if(document.num_form.num_click.value <= 0) {\n";
echo "alert(\"GAME OVER!\");\n";
echo "}\n}\n";
echo "</script>";
echo "<body $status_load><font color=#55CC7A>\n";
echo "<br><br>";
$i = 0;
$big = 4;
$javascript = "style=\"cursor: hand;\"";
$num5 = array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
$num4 = array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
$num3 = array(1, 0, 0, 0, 0, 0, 0, 0, 0);
if($big == 5) {
$num = $num5;
$clicks_left = 10;
}
elseif($big == 4) {
$num = $num4;
$clicks_left = 7;
}
elseif($big == 3) {
$num = $num3;
$clicks_left = 4;
}
shuffle($num);
echo "<center>\n";
echo "<form name=\"num_form\">";
echo "<table name=\"click_table\">\n";
for($x = 0; $x < $big; $x++) {
echo "<tr>\n";
for($y = 0; $y < $big; $y++) {
if($num[$i] == 1) {
$bg = "#FFFF00";
}
else {
$bg = "#FF0000";
}
echo "<td name=\"td$i\"class=\"game\" width=\"50\" height=\"50\" $javascript onClick=\"this.style.backgroundColor='$bg'; if(this.style.backgroundColor=='#FFFF00') {alert('You won!');}; countClick();\"></td>\n";
$i++;
}
echo "</tr>\n";
}
echo "</table>\n";
echo "<br><br>\n";
echo "<input name=\"num_click\" type=\"text\" value=\"$clicks_left\" readonly>\n";
echo "</center>\n";
?>


Thanks!