MagOrMin – an old php based game
This is an ooooooold (let’s call it) game I explained for a web programming class in 2003 or 2004.
It was made to explain some basics about Php, sessions, MySql and styles. All in one.
That’s how students learn… all in one and with a real world example.
It’s just a “guess if next number will be higher or slower than the current one” concept, the same that I applied to GuessNext last year.
It’s called MagOrMin and the name comes from the italian translation of “higher” (maggiore) and “lower” (minore).
Simply click to say if next number will be higher or lower, gain extra lives and compete for the high scores.
I plan to port the game in Ajax, adding a so-called “Web 2.0″ style and convert it into a Facebook application with all features… you know… I must monetize everything…
Meanwhile here it is the source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | <?php session_register("game_status"); session_register("actual_number"); session_register("score"); session_register("lives"); session_register("next_extra"); $connection = mysql_connect(localhost, "****", "****"); $db= mysql_select_db(*****,$connection); $old_number = $actual_number; $actual_number = rand(0,9); $page_name = $PHP_SELF; if($guess == "new"){ if($_POST[name]){ $_POST[name] = substr(strip_tags($_POST[name]),0,20); $sql = "insert into ****(***,***) values(\"".stripslashes($_POST[name])."\",$score)"; $result = mysql_query($sql,$connection) or die($sql); } $game_status = "NOT_PLAYING"; } if(!isset($game_status)){ $game_status = "NOT_PLAYING"; } if($game_status == "NOT_PLAYING"){ $lives = 3; $score = 0; $next_extra = 3; $class_to_show = "number"; if(($guess=="bigger")or($guess=="smaller")){ $game_status = "PLAYING"; $sql = "update *** set *** = ***+ 1"; $result = mysql_query($sql,$connection) or die($sql); // echo $sql; } else{ if(isset($old_number)){ $actual_number = $old_number; } } } if($game_status == "PLAYING"){ if ((($guess == "bigger") and ($actual_number >= $old_number)) or (($guess == "smaller") and ($actual_number <= $old_number))){ $score ++; $class_to_show = "number"; $game_status = "PLAYING"; if ($score == $next_extra){ $lives +=1; $next_extra = floor($next_extra*1.5); } } else{ $lives -=1; $class_to_show = "number_wrong"; if ($lives==0){ $game_status = "GAME_OVER"; $perso_ora = true; } } } if ($game_status == "GAME_OVER"){ $class_to_show = "number_wrong"; if(!$perso_ora){ $actual_number = $old_number; } } //echo $game_status; ?> <html> <head> <style> h1{ color:#c4c41f; font-size: 20; } .container{ background-color: #000000; padding: 30px; border: 2px solid #c43d1f; width: 600px; height: 450px; font-family: verdana; font-size: 12px; color:c43d1f; font-weight: bold; text-align:center; } .number{ color:579331; font-family: verdana; font-size: 128px; border: 1px solid #c43d1f; margin-left: 140px; margin-right: 140px; margin-top: 15px; margin-bottom: 15px; background-color:#ffffff; } .number_wrong{ color:#c43d1f; font-family: verdana; font-size: 128px; border: 1px solid #c43d1f; margin-left: 140px; margin-right: 140px; margin-top: 15px; margin-bottom: 15px; background-color:#ffffff; } a:link,a:visited{ padding: 10px; margin: 15px; border: 1px dotted #c43d1f; width = 130px; text-align:center; text-decoration:none; font-size: 18; color:#579331; } .score{ padding: 5px; margin: 10px; border: 1px solid #c43d1f; text-align:center; font-size: 15; color:#c4c41f; } a:hover{ padding: 10px; margin: 15px; border: 1px dotted #c43d1f; width = 130px; text-align:center; text-decoration:none; background-color:#ffffff; font-size: 18; color:579331; } ul { padding-left: 0; margin-left: 0; float: left; width: 100%; } li{ display: inline; } body{ font-family: sans-serif; text-align:center; background-color:#cccccc; } </style> </head> <body onload = "self.focus()"> <div class = "container"> <h1>WELCOME TO PHP-MAGORMIN v1.0</h1> <?php echo "<ul><li class =\"score\">Score: $score<li class = \"score\">Lives: $lives<li class = \"score\">Extra life at $next_extra</ul>"; ?> <br><br>CURRENT NUMBER <div class = "<?php echo $class_to_show; ?>"><?php echo $actual_number; ?></div> <?php if($game_status == "PLAYING"){ ?> I guess next number will be <ul><li><a href = "<?php echo $page_name; ?>?guess=smaller">SMALLER</a><li><a href = "<?php echo $page_name; ?>?guess=bigger">BIGGER</a></ul> <?php } ?> <?php if($game_status == "GAME_OVER"){ ?> GAME OVER<br> <form action = "" method = "post">Enter your name: <input name = "name" type = "text"><input type = "hidden" name ="guess" value = "new"> <input type = "submit" value = "go"></form> <?php } ?> <?php if($game_status == "NOT_PLAYING"){ ?> I guess next number will be <ul><li><a href = "<?php echo $page_name; ?>?guess=smaller">SMALLER</a><li><a href = "<?php echo $page_name; ?>?guess=bigger">BIGGER</a></ul> <?php } ?> </div> </body> </html> |
I’ll explain the entire process to convert it into a Facebook app.
They can be a great start to launch a website of your own and meet the individual needs of your project.
2 Responses to “MagOrMin – an old php based game”
Leave a Reply
- Get up to $100,000 for your next Flash game with Mochi GAME Developer Fund
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines – 17 lines version
- Sell sitelocked version of your Flash games and even .fla sources to Free Online Games
- Protect your work from ActionScript code theft with SWF Protector
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines
- Understanding Box2D’s one-way platforms, aka CLOUDS
- Triqui MochiAds Arcade plugin for WordPress upgraded to 1.2
- Box2D Flash game creation tutorial – part 2
- 11 Flash isometric engines you can use in your games
- Monetize your Flash games with GamesChart
- Create a Lightbox effect only with CSS - no javascript needed
- Flash game creation tutorial - part 1
- Create a Flash Racing Game Tutorial
- Flash game creation tutorial - part 2
- Make a Flash game like Flash Element Tower Defense - Part 2
- Flash game creation tutorial - part 3
- Make a Flash game like Flash Element Tower Defense - Part 1
- Create a flash draw game like Line Rider or others - part 1
- Triqui MochiAds Arcade plugin for WordPress official page
- Create a flash artillery game - step 1
- Flash game creation tutorial – part 5.2 (4.87/5)
- Create a flash artillery game – step 1 (4.79/5)
- Create a Flash Racing Game Tutorial (4.76/5)
- Create a flash artillery game – step 2 (4.74/5)
- Create a survival horror game in Flash tutorial – part 1 (4.73/5)
- Creation of a Flash arcade site using WordPress – step 2 (4.73/5)
- Flash game creation tutorial – part 2 (4.71/5)
- Flash game creation tutorial – part 1 (4.70/5)
- Create a flash draw game like Line Rider or others – part 1 (4.69/5)
- Creation of a platform game with Flash – step 2 (4.68/5)








Nice game.
On line 13, you should use a function to get your number and/or make a loop to get a number that is not the old one because 1 is neither higher or lower than 1.
For your CSS, you could either use 2 classes for the wrong number (ex : with classes number and wrong set) or you could set everything that is common for both classes and then set what is different for each of them.
Beside that, nice game.
Simple and good working game, but i recommend to use mt_rand instead of rand, because its faster and more random :)