Our Scripts Vault contains many game scripts that you can use to create your own game!
<?phpinclude_once 'connect.php';session_start();include_once 'logo.php';?> <link href="style.css" rel="stylesheet" type="text/css" /><div id="login2" div align="center"><?phpif (isset($_SESSION['player'])){ $player=$_SESSION['player'];}else{ echo "Not Logged in <br><br> <A href='login.php'>Login</a>"; exit;}$bypass = 0;?></div><?php$playerinfo="SELECT * from players where name='$player'";$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");$playerinfo3=mysql_fetch_array($playerinfo2);include_once 'statpanel.php'; ?> <div id ="locations"> <?php$playerhp = $playerinfo3['hpoints'];if ($playerhp < 1){ echo "You are dead!" ; echo "<br><a href='useitem.php'>Use an Item"; exit;}?><?phpif(isset($_GET['map'])){$bypass=1;echo "<a href='index.php?mapchange=1&mapname=Ovendale'>Ovendale</a><br>";}if(isset($_GET['mapchange'])){$bypass=1;$mapname = $_GET['mapname'];$updateplayer="update players set location='$mapname' where name='$playerinfo3[name]'"; mysql_query($updateplayer) or die("Could not update player"); echo "You have traveled to " . $mapname . ".<br>";echo "<a href='index.php?id=7162533'>To location</a><br>";}if($bypass != 1){echo "<b><big><u>" . $playerinfo3['location'] . "</u></big></b><br>";echo "<a href='store.php'>Grocery Store</a><br>";echo "<a href='weaponshop.php'>Weapon Shop</a><br>";echo "<a href='armorshop.php'>Armor Shop</a><br>";echo "<a href='inn.php'>The Rusty Doorknob</a><br>";echo "<a href='spelltrainer.php'>Spell Trainer</a><br>";/////echo "<a href='battle.php'>Battle in Arena</a><br>"; ////////////echo "<a href='index.php?map=1'>Go to Map</a><br>"; ///////echo "<a href='travelattack1.php'>The West Gate</a><br>";}?><?phpif(isset($_GET['map'])){$bypass=2;echo "<a href='index.php?mapchange=2&mapname=GremishForest'>Gremish Forest</a><br>";}if(isset($_GET['mapchange'])){$bypass=2;$mapname = $_GET['mapname'];$updateplayer="update players set location='$mapname' where name='$playerinfo3[name]'"; mysql_query($updateplayer) or die("Could not update player"); }if($bypass != 2){echo "<b><big><u>" . $playerinfo3['location'] . "</u></big></b><br>";echo "<a href='store.php'>Grocery Store</a><br>";echo "<a href='weaponshop.php'>Weapon Shop</a><br>";echo "<a href='armorshop.php'>Armor Shop</a><br>";echo "<a href='inn.php'>The Mossy Knowle</a><br>";echo "<a href='spelltrainer.php'>Spell Trainer</a><br>";}?> </div><div id="logout"><?phpecho "<br><a href='logout.php'><img src='images/logout.bmp'></a>";?></div>
<?php$a = 1;$b = 2;$c = 3;$var = mt_rand (1, 3);// Wrong way!if ($var != $b && $var != $c){ echo 'Must be a!';}if ($var != $a && $var != $c){ echo 'Must be b!';}if ($var != $a && $var != $b){ echo 'Must be c!';}// Correct way.if ($var == $a){ echo 'It is a!';}if ($var == $b){ echo 'It is b!';}if ($var == $c){ echo 'It is c!';}?>
case_list: /* empty */ | case_list T_CASE expr case_separator inner_statement_list | T_DEFAULT case_separator inner_statement_list ;
Just as an aside, I'd also be tempted to use if..else to short circuit the evaluation of all those if statements. If the number of if statements grows to say 50 and the first if statement is true, as it stands at the moment your code would then perform 49 unnecessary comparisons.
Alternatively, you might consider using a switch statement.
Hmm... will a switch work? Yes, because PHP expects the case keyword to be followed by an expr (expression)...
It was meant to be an example so I wasn't worried about optimization. The part that I wanted to get across was what the expression was saying about the code rather than the actual structure itself.