OSdata.com |
Building a game open source code This is the actual source code from a new web game. See the game at thissideofsanity.com and read how this was built starting at example code.
This is example code from the SlamZee project and This Side of Sanity, released under Apache License 2.0.
Copyright 2013 Milo (for software), Distribution and website handled by Strazbick.com
Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
This narrative uses anchor links so that you can follow the building of this software in chronological order. Go to software explanation to start reading. Go to thissideofsanity.com to see the working software.
This is example code from the SlamZee project and This Side of Sanity, released under Apache License 2.0.
Display a static layout for the game round.
<?php /* FILE: /php/gamefunctions.php */ // include function files for this application require_once('./php/accounts.php'); require_once('./php/databasefunctions.php'); /******************************/ /* GLOBALS */ /******************************/ /******************************/ /* FUNCTIONS */ /******************************/ /******************************/ /* DisplayVilliansRound */ /* display new villians game round */ /******************************/ function DisplayVilliansRound($playernumber) { echo '<p align="center">Round: <span id="roundnumber">number</span> Timer: <span id="countdowntimer">time</span></p>'; /* TWO-UP SLAMS */ ?> <table align="center" border="0" width="100%" style="color:black"> <tr align="center"> <td><img src="./cpict/cr/tedcruz220.png" width="148" height="148"><br>Ted Cruz<br><img src="./testpict/sledge.jpeg" width="104" height="76" border="0"></td> <td><img src="./cpict/ob/barackobama220.png" width="148" height="148"><br>Barack Obama<br><img src="./testpict/sledge.jpeg" width="104" height="76" border="0"></td> </tr> </table> <?php /* CURRENT SCORE */ ?> <table align="center" border="0" width="100%" style="color:black"> <tr align="center"> <td>YOU<br><span id="selfscore">score</span></td> <td>2<br><span id="score2">score</span></td> <td>3<br><span id="score3">score</span></td> </tr> </table> <?php } /* DisplayVilliansRound */ ?>
Create a persistent data base record for a new game.
<?php /* FILE: /php/gamefunctions.php */ // include function files for this application require_once('./php/accounts.php'); require_once('./php/databasefunctions.php'); /******************************/ /* GLOBALS */ /******************************/ /******************************/ /* FUNCTIONS */ /******************************/ /******************************/ /* CreateVillainsGame */ /* create a new villains game record in SQL */ /******************************/ function CreateVillainsGame($playernumber) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ /* get player name (or email) */ $playername1 = GetAccountNameFromAccountNumber($playernumber); if ($playername1 == '') $playername1 = GetEmailFromAccountNumber($playernumber); /* players 2 and 3 are fake for now */ $playername2 = RandomName(); $playername3 = RandomName(); while ($playername2 == $playername3) { $playername3 = RandomName(); } $playername1 = "'".$playername1."'"; $playername2 = "'".$playername2."'"; $playername3 = "'".$playername3."'"; $query = "INSERT INTO games (gametype,player1,player2,player3,name1,name2,name3) VALUES ('V',".$playernumber.",0,0,".$playername1.",".$playername2.",".$playername3.");"; echo '<br>query is *',$query,'*<br>'; return 1; /* TEMPORARY TO CUT DOWN CLUTTER ON DATA BASE DURING TESTING */ $updateresult = mysql_query($query); if(!$updateresult) { return -2; /* FAILURE for SQL INSERT */ } $gamenumber = mysql_insert_id(); return $gamenumber; /* success */ } /* CreateVillainsGame */ /******************************/ /* DisplayVilliansRound */ /* display new villians game round */ /******************************/ function DisplayVilliansRound($playernumber) { echo 'game number is *',$gamenumber,'*<br>'; echo '<p align="center">Round: <span id="roundnumber">number</span> Timer: <span id="countdowntimer">time</span></p>'; /* TEMPORARY */ $newquery = "SELECT name1,name2,name3 FROM games WHERE gamenumber=".$gamenumber." "; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $name1 = $row["name1"]; $name2 = $row["name2"]; $name3 = $row["name3"]; /* END TEMPORARY */ /* TWO-UP SLAMS */ ?> <table align="center" border="0" width="100%" style="color:black"> <tr align="center"> <td><img src="./cpict/cr/tedcruz220.png" width="148" height="148"><br>Ted Cruz<br><img src="./testpict/sledge.jpeg" width="104" height="76" border="0"></td> <td><img src="./cpict/ob/barackobama220.png" width="148" height="148"><br>Barack Obama<br><img src="./testpict/sledge.jpeg" width="104" height="76" border="0"></td> </tr> </table> <?php /* CURRENT SCORE */ ?> <table align="center" border="0" width="100%" style="color:black"> <tr align="center"> <td><?php echo $name1; ?><br><span id="selfscore">score</span></td> <td><?php echo $name2; ?><br><span id="score2">score</span></td> <td><?php echo $name3; ?><br><span id="score3">score</span></td> </tr> </table> <?php } /* DisplayVilliansRound */ /******************************/ /* RandomName */ /* generate random name */ /******************************/ function RandomName() { $namenumber = rand(1,449); if ($namenumber == 1) $outputname = 'Aadhya'; elseif ($namenumber == 2) $outputname = 'Aaliyah'; elseif ($namenumber == 3) $outputname = 'Aarav'; elseif ($namenumber == 4) $outputname = 'Aaron'; elseif ($namenumber == 5) $outputname = 'Abigail'; elseif ($namenumber == 6) $outputname = 'Adam'; elseif ($namenumber == 7) $outputname = 'Addison'; elseif ($namenumber == 8) $outputname = 'Adrian'; elseif ($namenumber == 9) $outputname = 'Agustin'; elseif ($namenumber == 10) $outputname = 'Ahmed'; elseif ($namenumber == 11) $outputname = 'Ai'; elseif ($namenumber == 12) $outputname = 'Aiden'; elseif ($namenumber == 13) $outputname = 'lexa'; elseif ($namenumber == 14) $outputname = 'Alex'; elseif ($namenumber == 15) $outputname = 'Alexander'; elseif ($namenumber == 16) $outputname = 'Alexandra'; elseif ($namenumber == 17) $outputname = 'Alexis'; elseif ($namenumber == 18) $outputname = 'Alfi'; elseif ($namenumber == 19) $outputname = 'Ali'; elseif ($namenumber == 20) $outputname = 'Alice'; elseif ($namenumber == 21) $outputname = 'Alicia'; elseif ($namenumber == 22) $outputname = 'Alina'; elseif ($namenumber == 23) $outputname = 'Allison'; elseif ($namenumber == 24) $outputname = 'Alyssa'; elseif ($namenumber == 25) $outputname = 'Amar'; elseif ($namenumber == 26) $outputname = 'Amelia'; elseif ($namenumber == 27) $outputname = 'Amina'; elseif ($namenumber == 28) $outputname = 'Amit'; elseif ($namenumber == 29) $outputname = 'An'; elseif ($namenumber == 30) $outputname = 'Ananya'; elseif ($namenumber == 31) $outputname = 'Anastasija'; elseif ($namenumber == 32) $outputname = 'Andrew'; elseif ($namenumber == 33) $outputname = 'Andy'; elseif ($namenumber == 34) $outputname = 'Angel'; elseif ($namenumber == 35) $outputname = 'Ann'; elseif ($namenumber == 36) $outputname = 'Anna'; elseif ($namenumber == 37) $outputname = 'Annabelle'; elseif ($namenumber == 38) $outputname = 'Anne'; elseif ($namenumber == 39) $outputname = 'Anthony'; elseif ($namenumber == 40) $outputname = 'Anya'; elseif ($namenumber == 41) $outputname = 'Aoi'; elseif ($namenumber == 42) $outputname = 'Aria'; elseif ($namenumber == 43) $outputname = 'Arianna'; elseif ($namenumber == 44) $outputname = 'Ariel'; elseif ($namenumber == 45) $outputname = 'Aron'; elseif ($namenumber == 46) $outputname = 'Arthur'; elseif ($namenumber == 47) $outputname = 'Asher'; elseif ($namenumber == 48) $outputname = 'Aubrey'; elseif ($namenumber == 49) $outputname = 'Audrey'; elseif ($namenumber == 50) $outputname = 'Austin'; elseif ($namenumber == 51) $outputname = 'Ava'; elseif ($namenumber == 52) $outputname = 'Avery'; elseif ($namenumber == 53) $outputname = 'Avni'; elseif ($namenumber == 54) $outputname = 'Aya'; elseif ($namenumber == 55) $outputname = 'Bailey'; elseif ($namenumber == 56) $outputname = 'Barbara'; elseif ($namenumber == 57) $outputname = 'Bella'; elseif ($namenumber == 58) $outputname = 'Ben'; elseif ($namenumber == 59) $outputname = 'Bence'; elseif ($namenumber == 60) $outputname = 'Benjamin'; elseif ($namenumber == 61) $outputname = 'Bentley'; elseif ($namenumber == 62) $outputname = 'Bi'; elseif ($namenumber == 63) $outputname = 'Blake'; elseif ($namenumber == 64) $outputname = 'Bo'; elseif ($namenumber == 65) $outputname = 'Bob'; elseif ($namenumber == 66) $outputname = 'Brandon'; elseif ($namenumber == 67) $outputname = 'Brayden'; elseif ($namenumber == 68) $outputname = 'Brianna'; elseif ($namenumber == 69) $outputname = 'Brody'; elseif ($namenumber == 70) $outputname = 'Brooke'; elseif ($namenumber == 71) $outputname = 'Brooklyn'; elseif ($namenumber == 72) $outputname = 'Cai'; elseif ($namenumber == 73) $outputname = 'Caleb'; elseif ($namenumber == 74) $outputname = 'Cameron'; elseif ($namenumber == 75) $outputname = 'Caroline'; elseif ($namenumber == 76) $outputname = 'Carson'; elseif ($namenumber == 77) $outputname = 'Carter'; elseif ($namenumber == 78) $outputname = 'Chai-hao'; elseif ($namenumber == 79) $outputname = 'Charles'; elseif ($namenumber == 80) $outputname = 'Charlie'; elseif ($namenumber == 81) $outputname = 'Charlotte'; elseif ($namenumber == 82) $outputname = 'Chase'; elseif ($namenumber == 83) $outputname = 'Cheng'; elseif ($namenumber == 84) $outputname = 'Chloe'; elseif ($namenumber == 85) $outputname = 'Chris'; elseif ($namenumber == 86) $outputname = 'Christopher'; elseif ($namenumber == 87) $outputname = 'Claire'; elseif ($namenumber == 88) $outputname = 'Clara'; elseif ($namenumber == 89) $outputname = 'Cole'; elseif ($namenumber == 90) $outputname = 'Colin'; elseif ($namenumber == 91) $outputname = 'Colton'; elseif ($namenumber == 92) $outputname = 'Connor'; elseif ($namenumber == 93) $outputname = 'Cooper'; elseif ($namenumber == 94) $outputname = 'Daisy'; elseif ($namenumber == 95) $outputname = 'Damia'; elseif ($namenumber == 96) $outputname = 'Dan'; elseif ($namenumber == 97) $outputname = 'Daniel'; elseif ($namenumber == 98) $outputname = 'Daniyar'; elseif ($namenumber == 99) $outputname = 'Dave'; elseif ($namenumber == 100) $outputname = 'David'; elseif ($namenumber == 101) $outputname = 'Davit'; elseif ($namenumber == 102) $outputname = 'De'; elseif ($namenumber == 103) $outputname = 'Declan'; elseif ($namenumber == 104) $outputname = 'Devon'; elseif ($namenumber == 105) $outputname = 'Diego'; elseif ($namenumber == 106) $outputname = 'Dimitra'; elseif ($namenumber == 107) $outputname = 'Dimitrios'; elseif ($namenumber == 108) $outputname = 'Diyah'; elseif ($namenumber == 109) $outputname = 'Dominic'; elseif ($namenumber == 110) $outputname = 'Dorothy'; elseif ($namenumber == 111) $outputname = 'Dylan'; elseif ($namenumber == 112) $outputname = 'Easton'; elseif ($namenumber == 113) $outputname = 'Egzon'; elseif ($namenumber == 114) $outputname = 'Eleanor'; elseif ($namenumber == 115) $outputname = 'Elena'; elseif ($namenumber == 116) $outputname = 'Eli'; elseif ($namenumber == 117) $outputname = 'Eliana'; elseif ($namenumber == 118) $outputname = 'Elias'; elseif ($namenumber == 119) $outputname = 'Elijah'; elseif ($namenumber == 120) $outputname = 'Elise'; elseif ($namenumber == 121) $outputname = 'Ella'; elseif ($namenumber == 122) $outputname = 'Ellen'; elseif ($namenumber == 123) $outputname = 'Ellie'; elseif ($namenumber == 124) $outputname = 'Elizabeth'; elseif ($namenumber == 125) $outputname = 'Emily'; elseif ($namenumber == 126) $outputname = 'Emma'; elseif ($namenumber == 127) $outputname = 'Eric'; elseif ($namenumber == 128) $outputname = 'Esther'; elseif ($namenumber == 129) $outputname = 'Ethan'; elseif ($namenumber == 130) $outputname = 'Eva'; elseif ($namenumber == 131) $outputname = 'Evan'; elseif ($namenumber == 132) $outputname = 'Evelyn'; elseif ($namenumber == 133) $outputname = 'Fang'; elseif ($namenumber == 134) $outputname = 'Fatemeh'; elseif ($namenumber == 135) $outputname = 'Fatima'; elseif ($namenumber == 136) $outputname = 'Feng'; elseif ($namenumber == 137) $outputname = 'Finn'; elseif ($namenumber == 138) $outputname = 'Florencia'; elseif ($namenumber == 139) $outputname = 'Flynn'; elseif ($namenumber == 140) $outputname = 'Francesco'; elseif ($namenumber == 141) $outputname = 'Francisco'; elseif ($namenumber == 142) $outputname = 'Fred'; elseif ($namenumber == 143) $outputname = 'Frederick'; elseif ($namenumber == 144) $outputname = 'Freja'; elseif ($namenumber == 145) $outputname = 'Fynn'; elseif ($namenumber == 146) $outputname = 'Gabriel'; elseif ($namenumber == 147) $outputname = 'Gabriella'; elseif ($namenumber == 148) $outputname = 'Gavin'; elseif ($namenumber == 149) $outputname = 'Gazel'; elseif ($namenumber == 150) $outputname = 'George'; elseif ($namenumber == 151) $outputname = 'Georgios'; elseif ($namenumber == 152) $outputname = 'Gianna'; elseif ($namenumber == 153) $outputname = 'Giorgi'; elseif ($namenumber == 154) $outputname = 'Giulia'; elseif ($namenumber == 155) $outputname = 'Grace'; elseif ($namenumber == 156) $outputname = 'Grayson'; elseif ($namenumber == 157) $outputname = 'Guo'; elseif ($namenumber == 158) $outputname = 'Gustavs'; elseif ($namenumber == 159) $outputname = 'Hailey'; elseif ($namenumber == 160) $outputname = 'Hala'; elseif ($namenumber == 161) $outputname = 'Haley'; elseif ($namenumber == 162) $outputname = 'Hank'; elseif ($namenumber == 163) $outputname = 'Hannah'; elseif ($namenumber == 164) $outputname = 'Hans'; elseif ($namenumber == 165) $outputname = 'Harper'; elseif ($namenumber == 166) $outputname = 'Harrison'; elseif ($namenumber == 167) $outputname = 'Harry'; elseif ($namenumber == 168) $outputname = 'Haruto'; elseif ($namenumber == 169) $outputname = 'Hayden'; elseif ($namenumber == 170) $outputname = 'Henry'; elseif ($namenumber == 171) $outputname = 'Hina'; elseif ($namenumber == 172) $outputname = 'Hiroto'; elseif ($namenumber == 173) $outputname = 'Hong'; elseif ($namenumber == 174) $outputname = 'Hudson'; elseif ($namenumber == 175) $outputname = 'Hugo'; elseif ($namenumber == 176) $outputname = 'Hui'; elseif ($namenumber == 177) $outputname = 'Hunter'; elseif ($namenumber == 178) $outputname = 'Ian'; elseif ($namenumber == 179) $outputname = 'Ida'; elseif ($namenumber == 180) $outputname = 'Ines'; elseif ($namenumber == 181) $outputname = 'Irene'; elseif ($namenumber == 182) $outputname = 'Isaac'; elseif ($namenumber == 183) $outputname = 'Isabella'; elseif ($namenumber == 184) $outputname = 'Isabelle'; elseif ($namenumber == 185) $outputname = 'Isaiah'; elseif ($namenumber == 186) $outputname = 'Isla'; elseif ($namenumber == 187) $outputname = 'Ivan'; elseif ($namenumber == 188) $outputname = 'Jack'; elseif ($namenumber == 189) $outputname = 'Jackson'; elseif ($namenumber == 190) $outputname = 'Jace'; elseif ($namenumber == 191) $outputname = 'Jacob'; elseif ($namenumber == 192) $outputname = 'Jake'; elseif ($namenumber == 193) $outputname = 'Jakov'; elseif ($namenumber == 194) $outputname = 'Jakub'; elseif ($namenumber == 195) $outputname = 'James'; elseif ($namenumber == 196) $outputname = 'Jan'; elseif ($namenumber == 197) $outputname = 'Jana'; elseif ($namenumber == 198) $outputname = 'Jasmine'; elseif ($namenumber == 199) $outputname = 'Jason'; elseif ($namenumber == 200) $outputname = 'Jayden'; elseif ($namenumber == 201) $outputname = 'Jennifer'; elseif ($namenumber == 202) $outputname = 'Jeremiah'; elseif ($namenumber == 203) $outputname = 'Jessica'; elseif ($namenumber == 204) $outputname = 'Jian'; elseif ($namenumber == 205) $outputname = 'Jim'; elseif ($namenumber == 206) $outputname = 'Jimmy'; elseif ($namenumber == 207) $outputname = 'Joe'; elseif ($namenumber == 208) $outputname = 'John'; elseif ($namenumber == 209) $outputname = 'Jon'; elseif ($namenumber == 210) $outputname = 'Jonas'; elseif ($namenumber == 211) $outputname = 'Jonathan'; elseif ($namenumber == 212) $outputname = 'Jordan'; elseif ($namenumber == 213) $outputname = 'Joseph'; elseif ($namenumber == 214) $outputname = 'Joshua'; elseif ($namenumber == 215) $outputname = 'Judy'; elseif ($namenumber == 216) $outputname = 'Julia'; elseif ($namenumber == 217) $outputname = 'Julian'; elseif ($namenumber == 218) $outputname = 'Julie'; elseif ($namenumber == 219) $outputname = 'Juan'; elseif ($namenumber == 220) $outputname = 'Kaitlyn'; elseif ($namenumber == 221) $outputname = 'Kang'; elseif ($namenumber == 222) $outputname = 'Kate'; elseif ($namenumber == 223) $outputname = 'Kavya'; elseif ($namenumber == 224) $outputname = 'Kayla'; elseif ($namenumber == 225) $outputname = 'Kaylee'; elseif ($namenumber == 447) $outputname = 'Keith'; elseif ($namenumber == 226) $outputname = 'Kendall'; elseif ($namenumber == 227) $outputname = 'Kennedy'; elseif ($namenumber == 228) $outputname = 'Khushi'; elseif ($namenumber == 229) $outputname = 'Konstantinos'; elseif ($namenumber == 230) $outputname = 'Kylie'; elseif ($namenumber == 231) $outputname = 'Laila'; elseif ($namenumber == 232) $outputname = 'Lan'; elseif ($namenumber == 233) $outputname = 'Landon'; elseif ($namenumber == 234) $outputname = 'Lars'; elseif ($namenumber == 235) $outputname = 'Lauren'; elseif ($namenumber == 236) $outputname = 'Layla'; elseif ($namenumber == 237) $outputname = 'Leah'; elseif ($namenumber == 238) $outputname = 'Lena'; elseif ($namenumber == 239) $outputname = 'Leo'; elseif ($namenumber == 240) $outputname = 'Leon'; elseif ($namenumber == 241) $outputname = 'Leonard'; elseif ($namenumber == 242) $outputname = 'Levi'; elseif ($namenumber == 243) $outputname = 'Lewis'; elseif ($namenumber == 244) $outputname = 'Liam'; elseif ($namenumber == 245) $outputname = 'Lian'; elseif ($namenumber == 246) $outputname = 'Liang'; elseif ($namenumber == 247) $outputname = 'Lillian'; elseif ($namenumber == 248) $outputname = 'Lilly'; elseif ($namenumber == 249) $outputname = 'Lily'; elseif ($namenumber == 250) $outputname = 'Lina'; elseif ($namenumber == 251) $outputname = 'Lincoln'; elseif ($namenumber == 252) $outputname = 'Linda'; elseif ($namenumber == 253) $outputname = 'Liz'; elseif ($namenumber == 254) $outputname = 'Logan'; elseif ($namenumber == 255) $outputname = 'Lou'; elseif ($namenumber == 256) $outputname = 'Louis'; elseif ($namenumber == 257) $outputname = 'Lucas'; elseif ($namenumber == 258) $outputname = 'Lucy'; elseif ($namenumber == 259) $outputname = 'Luis'; elseif ($namenumber == 260) $outputname = 'Luka'; elseif ($namenumber == 261) $outputname = 'Lukas'; elseif ($namenumber == 262) $outputname = 'Luke'; elseif ($namenumber == 263) $outputname = 'Lyla'; elseif ($namenumber == 264) $outputname = 'Lynn'; elseif ($namenumber == 265) $outputname = 'Mackenzie'; elseif ($namenumber == 266) $outputname = 'Madelyn'; elseif ($namenumber == 267) $outputname = 'Madison'; elseif ($namenumber == 268) $outputname = 'Makayla'; elseif ($namenumber == 269) $outputname = 'Malik'; elseif ($namenumber == 270) $outputname = 'Malk'; elseif ($namenumber == 271) $outputname = 'Manuel'; elseif ($namenumber == 272) $outputname = 'Marc'; elseif ($namenumber == 273) $outputname = 'Margaret'; elseif ($namenumber == 274) $outputname = 'Maria'; elseif ($namenumber == 448) $outputname = 'Mariah'; elseif ($namenumber == 275) $outputname = 'Mariam'; elseif ($namenumber == 276) $outputname = 'Marie'; elseif ($namenumber == 277) $outputname = 'Mark'; elseif ($namenumber == 278) $outputname = 'Marko'; elseif ($namenumber == 279) $outputname = 'Mary'; elseif ($namenumber == 280) $outputname = 'Maryam'; elseif ($namenumber == 281) $outputname = 'Mason'; elseif ($namenumber == 282) $outputname = 'Matas'; elseif ($namenumber == 283) $outputname = 'Mathis'; elseif ($namenumber == 284) $outputname = 'Matt'; elseif ($namenumber == 285) $outputname = 'Matthew'; elseif ($namenumber == 286) $outputname = 'Mattia'; elseif ($namenumber == 287) $outputname = 'Max'; elseif ($namenumber == 288) $outputname = 'Maxim'; elseif ($namenumber == 289) $outputname = 'Maya'; elseif ($namenumber == 290) $outputname = 'Medhi'; elseif ($namenumber == 291) $outputname = 'Mia'; elseif ($namenumber == 292) $outputname = 'Micah'; elseif ($namenumber == 293) $outputname = 'Michael'; elseif ($namenumber == 294) $outputname = 'Mila'; elseif ($namenumber == 295) $outputname = 'Milan'; elseif ($namenumber == 296) $outputname = 'Miles'; elseif ($namenumber == 297) $outputname = 'Min-jun'; elseif ($namenumber == 298) $outputname = 'Miu'; elseif ($namenumber == 299) $outputname = 'Miyu'; elseif ($namenumber == 300) $outputname = 'Mohamed'; elseif ($namenumber == 301) $outputname = 'Mohammed'; elseif ($namenumber == 302) $outputname = 'Molly'; elseif ($namenumber == 303) $outputname = 'Morgan'; elseif ($namenumber == 304) $outputname = 'Moshe'; elseif ($namenumber == 305) $outputname = 'Muhamad'; elseif ($namenumber == 306) $outputname = 'Na'; elseif ($namenumber == 307) $outputname = 'Nanami'; elseif ($namenumber == 308) $outputname = 'Natalie'; elseif ($namenumber == 309) $outputname = 'Nate'; elseif ($namenumber == 310) $outputname = 'Nareh'; elseif ($namenumber == 311) $outputname = 'Nathan'; elseif ($namenumber == 312) $outputname = 'Nathaniel'; elseif ($namenumber == 313) $outputname = 'Neil'; elseif ($namenumber == 314) $outputname = 'Nevaeh'; elseif ($namenumber == 315) $outputname = 'Ni'; elseif ($namenumber == 316) $outputname = 'Nicholas'; elseif ($namenumber == 317) $outputname = 'Nick'; elseif ($namenumber == 449) $outputname = 'Nicki'; elseif ($namenumber == 318) $outputname = 'Nicole'; elseif ($namenumber == 319) $outputname = 'Nikita'; elseif ($namenumber == 320) $outputname = 'Ning'; elseif ($namenumber == 321) $outputname = 'Nino'; elseif ($namenumber == 322) $outputname = 'Noa'; elseif ($namenumber == 323) $outputname = 'Noah'; elseif ($namenumber == 324) $outputname = 'Noam'; elseif ($namenumber == 325) $outputname = 'Nolan'; elseif ($namenumber == 326) $outputname = 'Nora'; elseif ($namenumber == 327) $outputname = 'Nur'; elseif ($namenumber == 328) $outputname = 'Nuray'; elseif ($namenumber == 329) $outputname = 'Odval'; elseif ($namenumber == 330) $outputname = 'Olive'; elseif ($namenumber == 331) $outputname = 'Oliver'; elseif ($namenumber == 332) $outputname = 'Olivia'; elseif ($namenumber == 333) $outputname = 'Omar'; elseif ($namenumber == 334) $outputname = 'Onni'; elseif ($namenumber == 335) $outputname = 'Oscar'; elseif ($namenumber == 336) $outputname = 'Owen'; elseif ($namenumber == 337) $outputname = 'Pablo'; elseif ($namenumber == 338) $outputname = 'Paige'; elseif ($namenumber == 339) $outputname = 'Pari'; elseif ($namenumber == 340) $outputname = 'Parker'; elseif ($namenumber == 341) $outputname = 'Patricia'; elseif ($namenumber == 342) $outputname = 'Paul'; elseif ($namenumber == 343) $outputname = 'Peng'; elseif ($namenumber == 344) $outputname = 'Peter'; elseif ($namenumber == 345) $outputname = 'Peyton'; elseif ($namenumber == 346) $outputname = 'Pihu'; elseif ($namenumber == 347) $outputname = 'Pipaluk'; elseif ($namenumber == 348) $outputname = 'Piper'; elseif ($namenumber == 349) $outputname = 'Qian'; elseif ($namenumber == 350) $outputname = 'Qiong'; elseif ($namenumber == 351) $outputname = 'Quinn'; elseif ($namenumber == 352) $outputname = 'Rania'; elseif ($namenumber == 353) $outputname = 'Raphael'; elseif ($namenumber == 354) $outputname = 'Rasmus'; elseif ($namenumber == 355) $outputname = 'Reagan'; elseif ($namenumber == 356) $outputname = 'Reese'; elseif ($namenumber == 357) $outputname = 'Ren'; elseif ($namenumber == 358) $outputname = 'Richard'; elseif ($namenumber == 359) $outputname = 'Riley'; elseif ($namenumber == 360) $outputname = 'Rimas'; elseif ($namenumber == 361) $outputname = 'Rin'; elseif ($namenumber == 362) $outputname = 'Robert'; elseif ($namenumber == 363) $outputname = 'Robin'; elseif ($namenumber == 364) $outputname = 'Rodigo'; elseif ($namenumber == 365) $outputname = 'Ruby'; elseif ($namenumber == 366) $outputname = 'Ryan'; elseif ($namenumber == 367) $outputname = 'Ryder'; elseif ($namenumber == 368) $outputname = 'Saanvi'; elseif ($namenumber == 369) $outputname = 'Sadie'; elseif ($namenumber == 370) $outputname = 'Sakura'; elseif ($namenumber == 371) $outputname = 'Sam'; elseif ($namenumber == 372) $outputname = 'Samantha'; elseif ($namenumber == 373) $outputname = 'Samuel'; elseif ($namenumber == 374) $outputname = 'Santiago'; elseif ($namenumber == 375) $outputname = 'Sarah'; elseif ($namenumber == 376) $outputname = 'Savannah'; elseif ($namenumber == 377) $outputname = 'Scarlett'; elseif ($namenumber == 378) $outputname = 'Sean'; elseif ($namenumber == 379) $outputname = 'Sebastian'; elseif ($namenumber == 380) $outputname = 'Seo-yeon'; elseif ($namenumber == 381) $outputname = 'Shaimaa'; elseif ($namenumber == 382) $outputname = 'Shan'; elseif ($namenumber == 383) $outputname = 'Shira'; elseif ($namenumber == 384) $outputname = 'Sho'; elseif ($namenumber == 385) $outputname = 'Shota'; elseif ($namenumber == 386) $outputname = 'Shu'; elseif ($namenumber == 387) $outputname = 'Shu-fen'; elseif ($namenumber == 388) $outputname = 'Sienna'; elseif ($namenumber == 389) $outputname = 'Sofia'; elseif ($namenumber == 390) $outputname = 'Somchai'; elseif ($namenumber == 391) $outputname = 'Sophia'; elseif ($namenumber == 392) $outputname = 'Sophie'; elseif ($namenumber == 393) $outputname = 'Sora'; elseif ($namenumber == 394) $outputname = 'Sota'; elseif ($namenumber == 395) $outputname = 'Stella'; elseif ($namenumber == 396) $outputname = 'Sumayah'; elseif ($namenumber == 397) $outputname = 'Susan'; elseif ($namenumber == 398) $outputname = 'Sydney'; elseif ($namenumber == 399) $outputname = 'Tao'; elseif ($namenumber == 400) $outputname = 'Tarik'; elseif ($namenumber == 401) $outputname = 'Taylor'; elseif ($namenumber == 402) $outputname = 'Theo'; elseif ($namenumber == 403) $outputname = 'Theodore'; elseif ($namenumber == 404) $outputname = 'Theresa'; elseif ($namenumber == 405) $outputname = 'Thomas'; elseif ($namenumber == 406) $outputname = 'Ting'; elseif ($namenumber == 407) $outputname = 'Tom'; elseif ($namenumber == 408) $outputname = 'Tommy'; elseif ($namenumber == 409) $outputname = 'Tony'; elseif ($namenumber == 410) $outputname = 'Tristan'; elseif ($namenumber == 411) $outputname = 'Tyler'; elseif ($namenumber == 412) $outputname = 'Veded'; elseif ($namenumber == 413) $outputname = 'Victor'; elseif ($namenumber == 414) $outputname = 'Victoria'; elseif ($namenumber == 415) $outputname = 'Viktoria'; elseif ($namenumber == 416) $outputname = 'Vince'; elseif ($namenumber == 417) $outputname = 'Vivaan'; elseif ($namenumber == 418) $outputname = 'Violet'; elseif ($namenumber == 419) $outputname = 'Wei'; elseif ($namenumber == 420) $outputname = 'Wen'; elseif ($namenumber == 421) $outputname = 'William'; elseif ($namenumber == 422) $outputname = 'Wolf'; elseif ($namenumber == 423) $outputname = 'Wout'; elseif ($namenumber == 424) $outputname = 'Wyatt'; elseif ($namenumber == 425) $outputname = 'Xavier'; elseif ($namenumber == 426) $outputname = 'Xia'; elseif ($namenumber == 427) $outputname = 'Xian'; elseif ($namenumber == 428) $outputname = 'Yamato'; elseif ($namenumber == 429) $outputname = 'Yan'; elseif ($namenumber == 430) $outputname = 'Yabis'; elseif ($namenumber == 431) $outputname = 'Yasmine'; elseif ($namenumber == 432) $outputname = 'Yong'; elseif ($namenumber == 433) $outputname = 'Yousouf'; elseif ($namenumber == 434) $outputname = 'Youssef'; elseif ($namenumber == 435) $outputname = 'Yui'; elseif ($namenumber == 436) $outputname = 'Yuma'; elseif ($namenumber == 437) $outputname = 'Yuina'; elseif ($namenumber == 438) $outputname = 'Yusef'; elseif ($namenumber == 439) $outputname = 'Yuto'; elseif ($namenumber == 440) $outputname = 'Zach'; elseif ($namenumber == 441) $outputname = 'Zachary'; elseif ($namenumber == 442) $outputname = 'Zach'; elseif ($namenumber == 443) $outputname = 'Zahra'; elseif ($namenumber == 444) $outputname = 'Zara'; elseif ($namenumber == 445) $outputname = 'Zeynep'; elseif ($namenumber == 446) $outputname = 'Zoe'; else $outputname = 'Michael'; return $outputname; } /* END RandomName */ ?>
Report the current scores (which better be zero). Note that this code relies on the SQL database assigning a default value of zero to each score when the new game record is created.
Function to fetch current scores.
/******************************/ /* GetScore */ /* find the player scores for */ /* game/player combination */ /******************************/ function GetScore($gamenumber,$playernumber) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ $newquery = "SELECT score1 FROM games WHERE gamenumber=".$gamenumber." "; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $score = $row["score1"]; return $score; /* success */ } /* GetScore */ /******************************/ /* GetScore2 */ /* find the player score for robot player 2 */ /******************************/ function GetScore2($gamenumber) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ $newquery = "SELECT score2 FROM games WHERE gamenumber=".$gamenumber." "; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $score = $row["score2"]; return $score; /* success */ } /* GetScore2 */ /******************************/ /* GetScore3 */ /* find the player score for robot player 3 */ /******************************/ function GetScore3($gamenumber) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ $newquery = "SELECT score3 FROM games WHERE gamenumber=".$gamenumber." "; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $score = $row["score3"]; return $score; /* success */ } /* GetScore3 */
And draw them.
$gamenumber = CreateVillainsGame($playernumber);
<table align="center" border="0" width="100%" style="color:black">
<tr align="center">
<td><?php echo $name1; ?><br><span id="selfscore"><?php echo GetScore($gamenumber,$playernumber); ?></span></td>
<td><?php echo $name2; ?><br><span id="score2"><?php echo GetScore2($gamenumber); ?></span></td>
<td><?php echo $name3; ?><br><span id="score3"><?php echo GetScore3($gamenumber); ?></span></td>
</tr>
</table>
Create the next round for a game.
A new game has an SQL default of round zero, so we can use the same CreateRound function for the first and all subsequent rounds of a game.
/******************************/ /* IncrementVillainsRound */ /* advance to next round in villains game */ /******************************/ function IncrementVillainsRound($gamenumber) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ $newquery = "SELECT currentround FROM games WHERE gamenumber=".$gamenumber." "; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $currentround = $row["currentround"]; $currentround = $currentround + 1; /* increment round number */ $updatequery = "UPDATE games SET currentround = ".$currentround." WHERE gamenumber=".$gamenumber." "; $updateresult = mysql_query($updatequery); } /* IncrementVillainsRound */
Pick the two villains for the round.
/******************************/ /* GetVillain */ /* get a new villain number */ /******************************/ function GetVillain() { $villainnumber = rand(1,32); /* hard coded to number of celebrities */ return $villainnumber; } /* GetVillain */ /******************************/ /* IncrementVillainsRound */ /* advance to next round in villains game */ /******************************/ function IncrementVillainsRound($gamenumber) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ /* GET OLD ROUND NUMBER */ $newquery = "SELECT currentround FROM games WHERE gamenumber=".$gamenumber." "; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $currentround = $row["currentround"]; /* INCREMENT ROUND NUMBER */ $currentround = $currentround + 1; /* increment round number */ /* PICK TWO NEW VILLAINS */ $villain1 = GetVillain(); $villain2 = GetVillain(); while ($villain1 == $villain2) { $villain2 = GetVillain(); } $villain1 = "'".$villain1."'"; $villain2 = "'".$villain2."'"; $roundvillain1title = 'rd'.$currentround.'item1'; $roundvillain2title = 'rd'.$currentround.'item2'; /* UPDATE DATA BASE */ $updatequery = "UPDATE games SET currentround = ".$currentround.", ".$roundvillain1title." = ".$villain1.", ".$roundvillain2title." = ".$villain2." WHERE gamenumber=".$gamenumber." "; $updateresult = mysql_query($updatequery); } /* IncrementVillainsRound */
Display the two villains for the round.
Routine to get the current round number:
/******************************/ /* GetRoundNumber */ /* get the round number of a game */ /******************************/ function GetRoundNumber($gamenumber) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ /* GET OLD ROUND NUMBER */ $newquery = "SELECT currentround FROM games WHERE gamenumber=".$gamenumber." "; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $currentround = $row["currentround"]; return $currentround; } /* GetRoundNumber */
Display the two villains for the round.
/******************************/ /* DisplayVilliansRound */ /* display new villians game round */ /******************************/ function DisplayVilliansRound($playernumber) { $playernumber = GetAccountNumberFromEmail($reporteduser); $gamenumber = CreateVillainsGame($playernumber); echo 'game number is *',$gamenumber,'*
'; $roundnumber = GetRoundNumber($gamenumber); echo '<p align="center">Round: <span id="roundnumber">'.$roundnumber.'</span> Timer: <span id="countdowntimer">time</span></p>';
Generate game input from the browser side.
/* TWO-UP SLAMS */ ?> <table align="center" border="0" width="100%" style="color:black"> <tr align="center"> <td><a href="javascript:void(0);" onclick="submitround(1);"><img src="./cpict/<?php echo $firstpicture; ?>" width="148" height="148" border="0"></a><br><?php echo $firstname; ?><br><a href="javascript:void(0);" onclick="submitround(1);"><img src="./testpict/sledge.jpeg" width="104" height="76" border="0"></a></td> <td><a href="javascript:void(0);" onclick="submitround(2);"><img src="./cpict/<?php echo $secondpicture; ?>" width="148" height="148" border="0"></a><br><?php echo $secondname; ?><br><a href="javascript:void(0);" onclick="submitround(2);"><img src="./testpict/sledge.jpeg" width="104" height="76" border="0"></a></td> </tr> </table> <?php
Utility function to increment a celebrity slam count.
/******************************/ /* IncrementCelebritySlam */ /* increment the slam count for a particular celebrity */ /* returns updated slam count */ /******************************/ function IncrementCelebritySlam($celebritycode) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ /* INSERT VOTE INTO DAILY DATA BASE */ /* already connected and selected database */ // mysql_select_db('strazslam'); /* note that during processing we placed the variable inside the single quotes */ $query = "UPDATE celebrity SET votecount = (votecount + 1) WHERE celebnum=".$celebritycode." "; $updateresult = mysql_query($query); if(!$updateresult) { echo "<p>failed data base insert with error message ".mysql_error()."</p>"; } /* READ NEW TOTAL */ $newquery = "SELECT votecount FROM celebrity WHERE celebnum=".$celebritycode." "; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $newvotecount = $row["votecount"]; return $newvotecount; } /* IncrementCelebritySlam */
Record a slam.
/******************************/ /* UpdatePlayerSlam */ /* get the round number of a game */ /******************************/ function UpdatePlayerSlam($gamechoice,$playernumber,$gamenumber) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ /* GET OLD ROUND NUMBER */ $currentround = GetRoundNumber($gamenumber); /* FIND REAL CELEBRITY NUMBER */ $celebritytitle = 'rd'.$currentround.'item'.$gamechoice; $gamequery = "SELECT ".$celebritytitle." FROM games WHERE gamenumber=".$gamenumber.";"; $gameresult = mysql_query($gamequery); $row = mysql_fetch_array($gameresult); $currentcelebrity = $row[$celebritytitle]; echo 'celebrity number is '.$currentcelebrity.'<br>'; /* DEBUG */ /* INCREMENT SLAM */ $newtotal = IncrementCelebritySlam($currentcelebrity); echo 'celebrity slam count is '.$newtotal.'<br>'; /* DEBUG */ } /* UpdatePlayerSlam */
Fetch the current total for a celebrity slam.
New utility function:
/******************************/ /* ReadCelebritySlam */ /* read the slam count for a particular celebrity */ /* returns current slam count */ /******************************/ function ReadCelebritySlam($celebritycode) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ /* READ NEW TOTAL */ $newquery = "SELECT votecount FROM celebrity WHERE celebnum=".$celebritycode." "; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $newvotecount = $row["votecount"]; return $newvotecount; } /* ReadCelebritySlam */
Call new function from UpdatePlayerSlam.
/* READ NEW TOTAL */ $newvotecount = ReadCelebritySlam($celebritycode);
Start building the round scoring function.
/******************************/ /* UpdateRoundResults */ /* process a game round */ /* returns new round number */ /******************************/ function UpdateRoundResults($gamechoice,$playernumber,$gamenumber) { echo 'updating round results<br>'; /* DEBUG */ $currentround = GetRoundNumber($gamenumber); return $currentround; } /* UpdateRoundResults */
I built this function one section at a time. Rather than bore you (because everything worked on the first attempt), I will show the finished function.
/******************************/ /* UpdateRoundResults */ /* process a game round */ /* returns new round number */ /******************************/ function UpdateRoundResults($gamechoice,$playernumber,$gamenumber) { $currentround = GetRoundNumber($gamenumber); /* GET EACH CELEBRITY SLAM TOTAL */ $firsttitle = 'rd'.$currentround.'item1'; $secondtitle = 'rd'.$currentround.'item2'; $slamquery = "SELECT ".$firsttitle.",".$secondtitle." FROM games WHERE gamenumber=".$gamenumber.";"; $slamresult = mysql_query($slamquery); $row = mysql_fetch_array($slamresult); $firstcelebrity = $row[$firsttitle]; $secondcelebrity = $row[$secondtitle]; $firstslams = ReadCelebritySlam($firstcelebrity); $secondslams = ReadCelebritySlam($secondcelebrity); echo 'celebrity slams are '.$firstslams.' and '.$secondslams.'<br>'; /* DEBUG */ /* COMPUTE PLAYER RESULTS */ $firstchoicetotal = 0; $secondchoicetotal = 0; /* FIRST PLAYER CHOICE IS THE PLAYER SELECTION */ if ( $gamechoice == 1 ) { $firstplayerchoice = $firstcelebrity; $firstchoicetotal = $firstchoicetotal + 1; } else { $firstplayerchoice = $secondcelebrity; $secondchoicetotal = $secondchoicetotal + 1; } /* SECOND PLAYER CHOICE IS BIGGEST TOTAL */ if ( $firstslams > $secondslams ) /* equality goes to second choice */ { $secondplayerchoice = $firstcelebrity; $firstchoicetotal = $firstchoicetotal + 1; } else { $secondplayerchoice = $secondcelebrity; $secondchoicetotal = $secondchoicetotal + 1; } /* THIRD PLAYER CHOICE IS RANDOM */ if ( rand(1,2) == 1 ) { $thirdplayerchoice = $firstcelebrity; $firstchoicetotal = $firstchoicetotal + 1; } else { $thirdplayerchoice = $secondcelebrity; $secondchoicetotal = $secondchoicetotal + 1; } echo 'first is '.$firstchoicetotal.' and second is '.$secondchoicetotal.'<br>'; /* DEBUG */ /* STORE PLAYER CHOICES */ $resulttitle1 = 'rd'.$currentround.'pl1'; $resulttitle2 = 'rd'.$currentround.'pl2'; $resulttitle3 = 'rd'.$currentround.'pl3'; $query = "UPDATE games SET ".$resulttitle1." = ".$firstplayerchoice.",".$resulttitle2." = ".$secondplayerchoice.",".$resulttitle3." = ".$thirdplayerchoice." WHERE gamenumber=".$gamenumber.";"; $updateresult = mysql_query($query); /* COMPUTE WINNERS */ if ( $firstchoicetotal > $secondchoicetotal ) $winner = $firstcelebrity; else $winner = $secondcelebrity; /* STORE PLAYER SCORES */ if ( $firstplayerchoice == $winner ) { $query = "UPDATE games SET score1 = (score1 + 1) WHERE gamenumber=".$gamenumber.";"; $updateresult = mysql_query($query); } if ( $secondplayerchoice == $winner ) { $query = "UPDATE games SET score2 = (score2 + 1) WHERE gamenumber=".$gamenumber.";"; $updateresult = mysql_query($query); } if ( $thirdplayerchoice == $winner ) { $query = "UPDATE games SET score3 = (score3 + 1) WHERE gamenumber=".$gamenumber.";"; $updateresult = mysql_query($query); } /* ADVANCE TO THE NEXT ROUND */ if ( $currentround < 10 ) IncrementVillainsRound($gamenumber); $newround = $currentround + 1; return $newround; } /* UpdateRoundResults */
End of game function.
/******************************/ /* DisplayEndGame */ /* display end of game information */ /******************************/ function DisplayEndGame($playernumber,$gamenumber) { echo 'game number is *',$gamenumber,'*<br>'; /* ANNOUNCE WINNER */ $score1 = GetScore1($gamenumber,$playernumber); $score2 = GetScore2($gamenumber); $score3 = GetScore3($gamenumber); if ( ( $score1 > $score2 ) AND ( $score1 > $score3 ) ) echo '<h1 align="center">You Win!!!</h1>'; elseif ( ( $score1 >= $score2 ) AND ( $score1 >= $score3 ) ) echo '<h1 align="center">You tied for first!!!</h1>'; elseif ( ( $score1 > $score2 ) OR ( $score1 > $score3 ) ) echo '<h1 align="center">You came in second!!!</h1>'; elseif ( ( $score1 >= $score2 ) OR ( $score1 >= $score3 ) ) echo '<h1 align="center">You tied for second!!!</h1>'; else echo '<h1 align="center">You lost.</h1>'; /* CURRENT SCORE */ ?> <table align="center" border="0" width="100%" style="color:black"> <tr align="center"> <td><?php echo $name1; ?><br><span id="selfscore"><?php echo GetScore($gamenumber,$playernumber); ?></span></td> <td><?php echo $name2; ?><br><span id="score2"><?php echo GetScore2($gamenumber); ?></span></td> <td><?php echo $name3; ?><br><span id="score3"><?php echo GetScore3($gamenumber); ?></span></td> </tr> </table> <?php /* OFFER BADGES */ if ( $score1 == 15 ) echo '<h1 align="center" style="color:#9900FF;background-color:#aa88ff">Congratulations!<br>Perfect Game!<</h1>'; /* OFFER ANOTHER GAME */ echo '<h3 align="center"><a href="javascript:void(0);" onclick="startgame();" style="cursor:pointer;"><span style="color:black">Play another game now!</span></a></h3>'; } /* DisplayEndGame */
Record the starting time and date of each game.
/* get current date and time in SQL format */ $currentdatetime = date('Y-m-d H:i:s', time()); $query = "INSERT INTO games (gametype,player1,player2,player3,name1,name2,name3,starttime) VALUES ('V',".$playernumber.",0,0,".$playername1.",".$playername2.",".$playername3.",'$currentdatetime');";
Points double in the bonus rounds (7-9) and triple in last round.
Announce bonus points.
/* ANNOUNCE BONUS ROUNDS */ if ($roundnumber == 10 ) { ?> <h1 align="center" style="color:red">Bonus Round</h1> <h3 align="center" style="color:black">points tripled</h3> <?php } elseif ($roundnumber > 6 ) { ?> <h1 align="center" style="color:red">Bonus Round</h1> <h3 align="center" style="color:black">points doubled</h3> <?php }
Store bonus points.
/* BONUS ROUND POINTS (if rounds 7-10) */ if ( $currentround == 10 ) $pointincrement = 3; if ( $currentround > 6 ) $pointincrement = 2; else $pointincrement = 1; /* STORE PLAYER SCORES */ if ( $firstplayerchoice == $winner ) { $query = "UPDATE games SET score1 = (score1 + $pointincrement) WHERE gamenumber=".$gamenumber.";"; $updateresult = mysql_query($query); } if ( $secondplayerchoice == $winner ) { $query = "UPDATE games SET score2 = (score2 + $pointincrement) WHERE gamenumber=".$gamenumber.";"; $updateresult = mysql_query($query); } if ( $thirdplayerchoice == $winner ) { $query = "UPDATE games SET score3 = (score3 + $pointincrement) WHERE gamenumber=".$gamenumber.";"; $updateresult = mysql_query($query); }
Add graphic bulls eye to show who earned points each round.
Declare flags.
Note that we are using global variables to share information between different functions. Horrible coding technique. Every advocate of functional programming is having a heart attack over the mutable state. When this nightmarish mess of procedural programming gets changed to modern object-oriented programming, the game object will keep track of this information and provide it to the appropriate objects.
global $scoreflag1; global $scoreflag2; global $scoreflag3;
Save info in flags.
/* STORE PLAYER SCORES */ $scoreflag1 = false; $scoreflag2 = false; $scoreflag3 = false; if ( $firstplayerchoice == $winner ) { $scoreflag1 = true; $query = "UPDATE games SET score1 = (score1 + $pointincrement) WHERE gamenumber=".$gamenumber.";"; $updateresult = mysql_query($query); } if ( $secondplayerchoice == $winner ) { $scoreflag2 = true; $query = "UPDATE games SET score2 = (score2 + $pointincrement) WHERE gamenumber=".$gamenumber.";"; $updateresult = mysql_query($query); } if ( $thirdplayerchoice == $winner ) { $scoreflag3 = true; $query = "UPDATE games SET score3 = (score3 + $pointincrement) WHERE gamenumber=".$gamenumber.";"; $updateresult = mysql_query($query); }
Display bullet.
/* CURRENT SCORE */ ?> <table align="center" border="0" width="100%" style="color:black"> <tr align="center"> <td valign="top" width="30%"><?php echo $name1; ?><br><span id="selfscore"><?php echo GetScore1($gamenumber,$playernumber); ?></span><?php if ($scoreflag1) echo '<br><img src="./testpict/bullet.png" width="53" height="53">'; ?></td> <td valign="top" width="30%"><?php echo $name2; ?><br><span id="score2"><?php echo GetScore2($gamenumber); ?></span><?php if ($scoreflag2) echo '<br><img src="./testpict/bullet.png" width="53" height="53">'; ?></td> <td valign="top" width="30%"><?php echo $name3; ?><br><span id="score3"><?php echo GetScore3($gamenumber); ?></span><?php if ($scoreflag3) echo '<br><img src="./testpict/bullet.png" width="53" height="53">'; ?></td> </tr> </table> <?php
Instead of immediately submitting the slams to the server, we now send them to a JavaScript function for animations and eventual submission.
<table align="center" border="0" width="100%" style="color:black"> <tr align="center"> <td><span id="slambox1" style="position:relative;"><a href="javascript:void(0);" onclick="makeslam(1,<?php echo $gamenumber; ?>);"><img src="./cpict/<?php echo $firstpicture; ?>" width="148" height="148" border="0" style="position:absolute;z-index:10;"></a><img src="./testpict/crackedglass.png" width="148" height="148" style="position:absolute;z-index:20;visibility:hidden;" id="broken1"><img src="./testpict/transparentfiller.png" width="148" height="148" style="position:relative;z-index:5;"><br><?php echo $firstname; ?></span><br><a href="javascript:void(0);" onclick="makeslam(1,<?php echo $gamenumber; ?>);"><img src="./testpict/sledge.jpeg" width="104" height="76" border="0"></a></td> <td><span id="slambox2" style="position:relative;"><a href="javascript:void(0);" onclick="makeslam(2,<?php echo $gamenumber; ?>);"><img src="./cpict/<?php echo $secondpicture; ?>" width="148" height="148" border="0" style="position:absolute;z-index:10;"></a><img src="./testpict/crackedglass.png" width="148" height="148" style="position:absolute;z-index:20;visibility:hidden;" id="broken2"><img src="./testpict/transparentfiller.png" width="148" height="148" style="position:relative;z-index:5;"></span><br><?php echo $secondname; ?><br><a href="javascript:void(0);" onclick="makeslam(2,<?php echo $gamenumber; ?>);"><img src="./testpict/sledge.jpeg" width="104" height="76" border="0"></a></td> </tr> </table>
We are going to use a bar graph effect to show the points awarded.
Replace the display of current score with a function (in DisplayEndGame and DisplayVillainsRound).
/* CURRENT SCORE */ DisplayCurrentScores($playernumber,$gamenumber);
Now build the function, with the added bar graph for showing scores.
/******************************/ /* DisplayCurrentScores */ /* display current scores */ /******************************/ function DisplayCurrentScores($playernumber,$gamenumber) { global $scoreflag1; global $scoreflag2; global $scoreflag3; $roundnumber = GetRoundNumber($gamenumber); /* PLAYER NAMES */ $newquery = "SELECT name1,name2,name3 FROM games WHERE gamenumber=".$gamenumber." "; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $name1 = $row["name1"]; $name2 = $row["name2"]; $name3 = $row["name3"]; /* CURRENT SCORE */ $totalscore1 = GetScore1($gamenumber,$playernumber); $totalscore2 = GetScore2($gamenumber,$playernumber); $totalscore3 = GetScore3($gamenumber,$playernumber); /* set height percentages */ $totalheight1 = 7 * $totalscore1; $totalheight2 = 7 * $totalscore2; $totalheight3 = 7 * $totalscore3; if ( $roundnumber == 10 ) $roundadjust = 3; elseif ( $roundnumber >= 7 ) $roundadjust = 2; else $roundadjust = 1; if ( $scoreflag1) $oldpoints1 = $totalscore1 - $roundadjust; else $oldpoints1 = $totalscore1; if ( $scoreflag2) $oldpoints2 = $totalscore2 - $roundadjust; else $oldpoints2 = $totalscore2; if ( $scoreflag3) $oldpoints3 = $totalscore3 - $roundadjust; else $oldpoints3 = $totalscore3; $oldheight1 = 7 * $oldpoints1; $oldheight2 = 7 * $oldpoints2; $oldheight3 = 7 * $oldpoints3; $newpoints1 = 3; $newpoints2 = 3; $newpoints3 = 3; $oldpoints1 = 12; $oldpoints2 = 7; $oldpoints3 = 5; ?> <style type="text/css"> dl#points1, dl#points1 dt, dl#points1 dd, dl#points2, dl#points2 dt, dl#points2 dd, dl#points3, dl#points3 dt, dl#points3 dd{margin:0;padding:0} dl#points1, dl#points2, dl#points3{background-color:bisque;width:70px;height:110px;padding-left:10px;} dl#points1 dt, dl#points2 dt, dl#points3 dt{display:none;} dl#points1 dd, dl#points2 dd, dl#points3 dd{position:relative;float:left;display:inline;width:50px;height:100px;margin-top:10px;} dl#points1 span, dl#points2 span, dl#points3 span{position:absolute;display:block;width:60px;bottom:0;left:0;z-index:1;text-decoration:none;} dl#points1 span b, dl#points2 span b, dl#points3 span b{display:block;font-weight:bold;font-style:normal;float:left;line-height:200%;color:white;position:absolute;top:5px;left:3px;text-align:center;width:23px;} dl#points1 span{height:50%;background-color:cyan;} dl#points2 span{height:50%;background-color:greenyellow;} dl#points3 span{height:50%;background-color:deeppink;} dl#points1 .sub, dl#points2 .sub, dl#points3 .sub{margin-left:-50px;} dl#points1 .sub span{background-color:blue;} dl#points2 .sub span{background-color:green;} dl#points3 .sub span{background-color:firebrick;} dl#points1 .p1 span{height:<?php echo $totalheight1; ?>px} dl#points1 .p2 span{height:<?php echo $oldheight1; ?>px} dl#points2 .p3 span{height:<?php echo $totalheight2; ?>px} dl#points2 .p4 span{height:<?php echo $oldheight2; ?>px} dl#points3 .p5 span{height:<?php echo $totalheight3; ?>px} dl#points3 .p6 span{height:<?php echo $oldheight3; ?>px} </style> <table align="center" border="0" width="100%" style="color:black" cellpadding="0" cellspacing="0"> <tr align="center"> <td valign="top" width="30%"><b><?php echo $name1; ?></b><br><span id="selfscore"><?php echo $totalscore1; ?></span><br><img src="./testpict/<?php if ($scoreflag1) echo 'bullet.png'; else echo 'invisbullet.png'; ?>" width="53" height="<?php if ($roundnumber == 1) echo '0'; else echo '53'; ?>"><br><dl id="points1"><dt><?php echo $name1; ?></dt><dd class="p1"><span><b> </b></span></dd><dd class="sub p2"><span><b> </b></span></dd></dl></td> <td valign="top" width="30%"><b><?php echo $name2; ?></b><br><span id="score2"><?php echo $totalscore2; ?></span><br><img src="./testpict/<?php if ($scoreflag2) echo 'bullet.png'; else echo 'invisbullet.png'; ?>" width="53" height="<?php if ($roundnumber == 1) echo '0'; else echo '53'; ?>"><br><dl id="points2"><dt><?php echo $name2; ?></dt><dd class="p3"><span><b> </b></span></dd><dd class="sub p4"><span><b> </b></span></dd></dl></td> <td valign="top" width="30%"><b><?php echo $name3; ?></b><br><span id="score3"><?php echo $totalscore3; ?></span><br><img src="./testpict/<?php if ($scoreflag3) echo 'bullet.png'; else echo 'invisbullet.png'; ?>" width="53" height="<?php if ($roundnumber == 1) echo '0'; else echo '53'; ?>"><br><dl id="points3"><dt><?php echo $name3; ?></dt><dd class="p5"><span><b> </b></span></dd><dd class="sub p6"><span><b> </b></span></dd></dl></td> </tr> </table> <?php } /* DisplayCurrentScores */
Display the trivia question.
The function call is inserted into DisplayVillainsRound after TWO SLAMS UP and before CURRENT SCORE.
/* DISPLAY TRIVIA QUESTION */ DisplayTriviaQuestion($playernumber,$gamenumber); /* CURRENT SCORE */
The actual function:
/******************************/ /* DisplayTriviaQuestion */ /* display a trivia question */ /******************************/ function DisplayTriviaQuestion($playernumber,$gamenumber, $firstname, $firstnumber, $secondname, $secondnumber) { echo '<p align="left"><big><b>trivia question</b></big><br>'; $roundnumber = GetRoundNumber($gamenumber); /* PICK A QUESTION */ $whichchoice = rand(1,2); /* one of two chocies */ //echo '<br>choice is '.$whichchoice; /* DEBUG */ /* STORE THE CHOICE */ $title = 'rd'.$roundnumber.'trivia'; $query = "UPDATE games SET ".$title." = ".$whichchoice." WHERE gamenumber=".$gamenumber.";"; $updateresult = mysql_query($query); if(!$updateresult) { echo "<p>failed data base insert with error message ".mysql_error()."</p>"; } /* CREATE QUESTION */ /* GET CELEBRITY BIRTH INFO */ if ( $whichchoice == 1) $usenumber = $firstnumber; else $usenumber = $secondnumber; $newquery = "SELECT birthdate,birthborough,birthcity,birthcounty,birthstate,birthsubnation,birthnation FROM celebrity WHERE celebnum=".$usenumber.";"; //echo '<br>query is '.$newquery; /* DEBUG */ $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $birthdate = $row["birthdate"]; $birthborough = $row["birthborough"]; $birthcity = $row["birthcity"]; $birthcounty = $row["birthcounty"]; $birthstate = $row["birthstate"]; $birthsubnation = $row["birthsubnation"]; $birthnation = $row["birthnation"]; /* FORMAT BIRTH PLACE */ $outputstring = 'Who was born in '; if ( $birthborough != '' ) $outputstring = $outputstring.$birthborough.', '; if ( $birthcity != '' ) $outputstring = $outputstring.$birthcity.', '; if ( $birthcounty != '' ) $outputstring = $outputstring.$birthcounty.', '; if ( $birthstate != '' ) $outputstring = $outputstring.$birthstate.', '; if ( $birthsubnation != '' ) $outputstring = $outputstring.$birthsubnation.', '; if ( ( $birthnation != '' ) AND ( ( $birthnation != 'United States' ) ) AND ( ( $birthsubnation == '' ) AND ( $birthnation != 'United Kingdom' ) ) ) $outputstring = $outputstring.$birthnation; if ( ( $birthnation == 'United States' ) OR ( ( $birthsubnation != '' ) AND ( $birthnation == 'United Kingdom' ) ) ) $outputstring = substr($outputstring,0,-2); /* remove trailing comma */ /* FORMAT BIRTH DATE */ $birthdate = $birthdate.' 00:00+00:00'; $birthday = date( "l, F j, Y", strtotime($birthdate) ); $outputstring = $outputstring.' on '.$birthday.'?<br>'; echo $outputstring; ?> <input type="radio" name="trivia" value="1"> <?php echo $firstname; ?><br> <input type="radio" name="trivia" value="2"> <?php echo $secondname; ?><br> <small>trivia question not working yet!!!</small></p> <?php } /* DisplayTriviaQuestion */
Move the bonus round message to the top of the game.
/* ANNOUNCE ROUNDS */ $roundstring = '<p align="center"><span style="font-size:24;'; if ($roundnumber > 6 ) $roundstring = $roundstring.'color:red;">Bonus '; else $roundstring = $roundstring.'color:black;">'; $roundstring = $roundstring.'Round</span> <span id="roundnumber" style="font-size:24;">'.$roundnumber.'</span> <span style="font-size:24;">Timer: </span><span id="countdowntimer" style="font-size:24;">time</span>'; if ($roundnumber == 10) $roundstring= $roundstring.'<br><small><span style="color:red;">points tripled</span></small>'; elseif ($roundnumber > 6) $roundstring= $roundstring.'<br><small><span style="color:blue;">points doubled</span></small>'; $roundstring = $roundstring.'</p>'; echo $roundstring;
React to the form radio buttons.
<br> <input type="radio" name="trivia" value="1" id="trivia1"> <?php echo $firstname; ?> <br> <input type="radio" name="trivia" value="2" id="trivia2"> <?php echo $secondname; ?> <br><small>trivia question not working yet!!!</small></p>
Check to see when the trivia question is answered.
<input type="hidden" id="trivia3" value="<?php echo $gamenumber; ?>">
<span id="triviaanswer"></span>
Remove the question when a choice is made.
Start div.
echo '<div id="triviaquestion"><p align="left"><big><b>trivia question:</b></big><br>';
End div
</div><!--end triviaquestion-->
Set player points based on trivia answer.
Find the player answer and the real answer to the trivia question.
/* COMPUTE TRIVIA POINTS FOR PLAYER */ $playertitle = 'rd'.$currentround.'trivia1'; $answertitle = 'rd'.$currentround.'trivia'; $triviaquery = "SELECT ".$playertitle.",".$answertitle." FROM games WHERE gamenumber=".$gamenumber." "; $triviaresult = mysql_query($triviaquery); if(!$triviaresult) { echo "<p>failed data base insert with error message ".mysql_error()."</p>"; } $row = mysql_fetch_array($triviaresult); $correctanswer = $row[$answertitle]; $playeranswer = $row[$playertitle];
Score player points accordingly
/* if ( $firstplayerchoice == $winner ) */ if ( $correctanswer == $playeranswer )
Make the points chart variable height. Compute in routine DisplayCurrentScores.
if ($totalheight1 >= $totalheight2) $tallestheight = $totalheight1; else $tallestheight = $totalheight2; if ($tallestheight <= $totalheight3) $tallestheight = $totalheight3;
Change display from:
dl#points1, dl#points2, dl#points3{background-color:bisque;width:70px;height:110px;padding-left:10px;}
To:
dl#points1, dl#points2, dl#points3{background-color:bisque;width:70px;height:px;padding-left:10px;} dd{position:relative;float:left;display:inline;width:50px;height:px;margin-top:10px;}
A question generator function.
if ( $whichchoice == 1 ) echo CreateTriviaQuestion($firstnumber,$secondnumber); else echo CreateTriviaQuestion($secondnumber,$firstnumber);
/******************************/ /* CreateTriviaQuestion */ /* create a trivia question */ /******************************/ function CreateTriviaQuestion($correctcelebrity,$wrongcelebrity) { /* $correctcelebrity is the celebrity number of the correct choice */ /* $wrongcelebrity is the celebrity number of the correct choice */ //return; /* DEBUG */ /* CREATE QUESTION */ /* GET CELEBRITY BIRTH INFO */ $usenumber = $correctcelebrity; $newquery = "SELECT birthdate,birthborough,birthcity,birthcounty,birthstate,birthsubnation,birthnation FROM celebrity WHERE celebnum=".$usenumber.";"; //echo '<br>query is '.$newquery; /* DEBUG */ $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $birthdate = $row["birthdate"]; $birthborough = $row["birthborough"]; $birthcity = $row["birthcity"]; $birthcounty = $row["birthcounty"]; $birthstate = $row["birthstate"]; $birthsubnation = $row["birthsubnation"]; $birthnation = $row["birthnation"]; /* FORMAT BIRTH PLACE */ $outputstring = 'Who was born in '; if ( $birthborough != '' ) $outputstring = $outputstring.$birthborough.', '; if ( $birthcity != '' ) $outputstring = $outputstring.$birthcity.', '; if ( $birthcounty != '' ) $outputstring = $outputstring.$birthcounty.', '; if ( $birthstate != '' ) $outputstring = $outputstring.$birthstate.', '; if ( $birthsubnation != '' ) $outputstring = $outputstring.$birthsubnation.', '; if ( ( $birthnation != '' ) AND ( ( $birthnation != 'United States' ) ) AND ( ( $birthsubnation == '' ) AND ( $birthnation != 'United Kingdom' ) ) ) $outputstring = $outputstring.$birthnation; if ( ( $birthnation == 'United States' ) OR ( ( $birthsubnation != '' ) AND ( $birthnation == 'United Kingdom' ) ) ) $outputstring = substr($outputstring,0,-2); /* remove trailing comma */ /* FORMAT BIRTH DATE */ $birthdate = $birthdate.' 00:00+00:00'; $birthday = date( "l, F j, Y", strtotime($birthdate) ); $outputstring = $outputstring.'?<br>'; //$outputstring = $outputstring.' on '.$birthday.'?'; return $outputstring; } /* CreateTriviaQuestion */
Add the love or like button.
<img src="./testpict/kisslips.png" width="148" height="148" style="position:absolute;z-index:30;visibility:hidden;" id="kiss1">
<img src="./testpict/kisslips.png" width="148" height="148" style="position:absolute;z-index:30;visibility:hidden;" id="kiss2">>
<a href="javascript:void(0);" onclick="makelove(1,<?php echo $gamenumber; ?>);"><img src="./testpict/lovebutton.png" width="37" height="31" border="0"></a>
<a href="javascript:void(0);" onclick="makelove(2,<?php echo $gamenumber; ?>);"><img src="./testpict/lovebutton.png" width="37" height="31" border="0"></a>
/******************************/ /* UpdatePlayerLove */ /* get the round number of a game */ /******************************/ function UpdatePlayerLove($gamechoice,$playernumber,$gamenumber) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ /* GET OLD ROUND NUMBER */ $currentround = GetRoundNumber($gamenumber); /* FIND REAL CELEBRITY NUMBER */ $celebritytitle = 'rd'.$currentround.'item'.$gamechoice; $gamequery = "SELECT ".$celebritytitle." FROM games WHERE gamenumber=".$gamenumber.";"; $gameresult = mysql_query($gamequery); $row = mysql_fetch_array($gameresult); $currentcelebrity = $row[$celebritytitle]; /* INCREMENT SLAM */ $newtotal = IncrementCelebrityLove($currentcelebrity); } /* UpdatePlayerLove */
/******************************/ /* IncrementCelebrityLove */ /* increment the love count for a particular celebrity */ /* returns updated love count */ /******************************/ function IncrementCelebrityLove($celebritycode) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ /* INSERT VOTE INTO DAILY DATA BASE */ /* already connected and selected database */ // mysql_select_db('strazslam'); /* note that during processing we placed the variable inside the single quotes */ $query = "UPDATE celebrity SET lovecount = (lovecount + 1) WHERE celebnum=".$celebritycode." "; $updateresult = mysql_query($query); if(!$updateresult) return -2; /* FAILURE to connect */ /* READ NEW TOTAL */ $newlovecount = ReadCelebrityLove($celebritycode); return $newlovecount; } /* IncrementCelebrityLove */
/******************************/ /* ReadCelebrityLove */ /* read the love count for a particular celebrity */ /* returns current love count */ /******************************/ function ReadCelebrityLove($celebritycode) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ /* READ NEW TOTAL */ $newquery = "SELECT lovecount FROM celebrity WHERE celebnum=".$celebritycode." "; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $newlovecount = $row["lovecount"]; return $newlovecount; } /* ReadCelebrityLove */
Use game object.
Check to see if birth places of two celebrities match.
/******************************/ /* CheckForBirthClash */ /* see if two celebrities have the same birth place */ /******************************/ function CheckForBirthClash($correctcelebrity,$wrongcelebrity) { /* $correctcelebrity is the celebrity number of the correct choice */ /* $wrongcelebrity is the celebrity number of the correct choice */ /* return true if DIFFERENT (acceptable) */ /* GET CORRECT CELEBRITY BIRTH INFO */ $usenumber = $correctcelebrity; $newquery = "SELECT birthcity FROM celebrity WHERE celebnum=".$usenumber.";"; //echo '
query is '.$newquery; /* DEBUG */ $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $correctbirthcity = $row["birthcity"]; /* GET WRONG CELEBRITY BIRTH INFO */ $usenumber = $wrongcelebrity; $newquery = "SELECT birthcity FROM celebrity WHERE celebnum=".$usenumber.";"; //echo '
query is '.$newquery; /* DEBUG */ $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $wrongbirthcity = $row["birthcity"]; /* RETURN RESULT */ if ( $correctbirthcity != $wrongbirthcity ) return true; else return false; } /* CheckForBirthClash */
Generate a trivia question about a celebrity birth place.
/******************************/ /* CreateBirthPlaceQuestion */ /* create a birthplace trivia question */ /******************************/ function CreateBirthPlaceQuestion($celebritynumber) { /* CREATE QUESTION */ /* GET CELEBRITY BIRTH INFO */ $usenumber = $celebritynumber; $newquery = "SELECT birthdate,birthborough,birthcity,birthcounty,birthstate,birthsubnation,birthnation FROM celebrity WHERE celebnum=".$usenumber.";"; //echo '<br>query is '.$newquery; /* DEBUG */ $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $birthdate = $row["birthdate"]; $birthborough = $row["birthborough"]; $birthcity = $row["birthcity"]; $birthcounty = $row["birthcounty"]; $birthstate = $row["birthstate"]; $birthsubnation = $row["birthsubnation"]; $birthnation = $row["birthnation"]; /* FORMAT BIRTH PLACE */ $outputstring = 'Who was born in '; if ( $birthborough != '' ) $outputstring = $outputstring.$birthborough.', '; if ( $birthcity != '' ) $outputstring = $outputstring.$birthcity.', '; if ( $birthcounty != '' ) $outputstring = $outputstring.$birthcounty.', '; if ( $birthstate != '' ) $outputstring = $outputstring.$birthstate.', '; if ( $birthsubnation != '' ) $outputstring = $outputstring.$birthsubnation.', '; if ( ( $birthnation != '' ) AND ( ( $birthnation != 'United States' ) ) AND ( ( $birthsubnation == '' ) AND ( $birthnation != 'United Kingdom' ) ) ) $outputstring = $outputstring.$birthnation; if ( ( $birthnation == 'United States' ) OR ( ( $birthsubnation != '' ) AND ( $birthnation == 'United Kingdom' ) ) ) $outputstring = substr($outputstring,0,-2); /* remove trailing comma */ return $outputstring; } /* CreateBirthPlaceQuestion */
Generate a trivia question about a celebrity birth date.
/******************************/ /* CreateBirthDateQuestion */ /* create a trivia birth date question */ /******************************/ function CreateBirthDateQuestion($celebritynumber) { /* GET CELEBRITY BIRTH INFO */ $usenumber = $celebritynumber; $newquery = "SELECT birthdate FROM celebrity WHERE celebnum=".$usenumber.";"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $birthdate = $row["birthdate"]; /* FORMAT BIRTH DATE */ $outputstring = 'Who was born on '; $birthdate = $birthdate.' 00:00+00:00'; $birthday = date( "l, F j, Y", strtotime($birthdate) ); $outputstring = $outputstring.$birthday.'?'; return $outputstring; } /* CreateBirthDateQuestion */
And new dispatcher:
/* CREATE QUESTION */ if ( CheckForBirthClash($correctcelebrity,$wrongcelebrity) ) $outputstring = CreateBirthPlaceQuestion($correctcelebrity); else $outputstring = CreateBirthDateQuestion($correctcelebrity); return $outputstring;
Generate a trivia question about a celebrity real name.
Function to check if the question would be valid.
/******************************/ /* CheckForRealName */ /* returns true if the celebrity real name is valid question */ /******************************/ function CheckForRealName($celebritynumber) { /* GET CORRECT CELEBRITY BIRTH INFO */ $newquery = "SELECT quizname FROM celebrity WHERE celebnum=".$celebritynumber.";"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $quizname = $row["quizname"]; /* RETURN RESULT */ if ( $quizname == 'Y' ) return true; else return false; } /* CheckForRealName */
Function to return the question.
/******************************/ /* CreateRealnameQuestion */ /* create a celebrity real name trivia question */ /******************************/ function CreateRealnameQuestion($celebritynumber) { /* GET CORRECT CELEBRITY BIRTH INFO */ $newquery = "SELECT realname FROM celebrity WHERE celebnum=".$celebritynumber.";"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $realname = $row["realname"]; /* FORMAT QUESTION */ $outputstring = 'Whose real name is '.$realname.'?
'; /* RETURN RESULT */ return $outputstring; } /* CreateRealnameQuestion */
Change the question dispatcher.
/* CREATE QUESTION */ $whichchoice = rand(1,2); /* one half chance */ if ( CheckForRealName($correctcelebrity) AND ($whichchoice == 1) ) $outputstring = CreateRealnameQuestion($correctcelebrity); elseif ( CheckForBirthClash($correctcelebrity,$wrongcelebrity) ) $outputstring = CreateBirthPlaceQuestion($correctcelebrity); else $outputstring = CreateBirthDateQuestion($correctcelebrity);
Add the info button.
<a href="javascript:void(0);" onclick="makeinfo(1,<?php echo $gamenumber; ?>);"><img src="./testpict/infobutton.png" width="30" height="31" border="0" style="visibility:hidden;" id="info1"></a>
If the screen is narrow (smartphones), have info button or picture activate the celebrity info in the trivia area.
Change the two calls from makeslam
to makeinfo
in the two-up celebrity pictures. The new routine is only called manually.
Add occupation questions to the trivia game.
Modify the CreateTriviaQuestion
function.
/* CREATE QUESTION */ $whichchoice = rand(1,3); /* one third chance */ $occupationrandom = rand(1,3); /* two third chance */ if ( $occupationrandom <= 2 ) $outputstring = TryOccupationQuestion($correctcelebrity,$wrongcelebrity); else $outputstring = ''; if ( $outputstring != '' ) /* using job question */ $x1 = 0; /* NULL statement */ elseif ( CheckForRealName($correctcelebrity) AND ($whichchoice == 1) ) /* 1/3 chance of real name question */ $outputstring = CreateRealnameQuestion($correctcelebrity); elseif ( CheckForBirthClash($correctcelebrity,$wrongcelebrity) ) /* birthday clash question */ $outputstring = CreateBirthPlaceQuestion($correctcelebrity); else $outputstring = CreateBirthDateQuestion($correctcelebrity);
Create the TryOccupationQuestion
function.
/******************************/ /* TryOccupationQuestion */ /* attempt to create a job question */ /* if success, return the question */ /* on failure, return empty string */ /******************************/ function TryOccupationQuestion($correctcelebrity,$wrongcelebrity) { //echo 'TryOccupationQuestion <br>'; /* DEBUG */ $outputstring = ''; /* just in case of failure */ /* GET CELEBRITY JOB INFO */ $newquery = "SELECT majorcategory,subcategories FROM celebrity WHERE celebnum=".$correctcelebrity.";"; //echo '<br>query is '.$newquery; /* DEBUG */ $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $correctmajorcategory = $row["majorcategory"]; $correctsubcategories = $row["subcategories"]; $newquery = "SELECT majorcategory,subcategories FROM celebrity WHERE celebnum=".$wrongcelebrity.";"; //echo '<br>query is '.$newquery; /* DEBUG */ $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $wrongmajorcategory = $row["majorcategory"]; $wrongsubcategories = $row["subcategories"]; /* NOW SEEK AN UNMATCHED JOB */ if ( ( strpos($correctsubcategories,'c') !== false ) AND ( strpos($wrongsubcategories,'c') === false ) ) $outputstring = 'Who is a comedian?<br>'; elseif ( ( strpos($correctmajorcategory,'P') !== false ) AND ( strpos($wrongmajorcategory,'P') === false ) ) $outputstring = 'Who is a politician?<br>'; elseif ( ( strpos($correctsubcategories,'d') !== false ) AND ( strpos($wrongsubcategories,'d') === false ) ) $outputstring = 'Who is a director?<br>'; elseif ( ( strpos($correctsubcategories,'D') !== false ) AND ( strpos($wrongsubcategories,'D') === false ) ) $outputstring = 'Who is a DJ?<br>'; elseif ( ( strpos($correctsubcategories,'r') !== false ) AND ( strpos($wrongsubcategories,'r') === false ) ) $outputstring = 'Who is a rapper?<br>'; elseif ( ( strpos($correctmajorcategory,'m') !== false ) AND ( strpos($wrongmajorcategory,'m') === false ) ) $outputstring = 'Who is a model?<br>'; elseif ( ( strpos($correctsubcategories,'S') !== false ) AND ( strpos($wrongsubcategories,'S') === false ) ) $outputstring = 'Who is a singer?<br>'; elseif ( ( strpos($correctsubcategories,'d') !== false ) AND ( strpos($wrongsubcategories,'d') === false ) ) $outputstring = 'Who is a drummer?<br>'; elseif ( ( strpos($correctsubcategories,'g') !== false ) AND ( strpos($wrongsubcategories,'g') === false ) ) $outputstring = 'Who is a guitarist?<br>'; elseif ( ( strpos($correctsubcategories,'p') !== false ) AND ( strpos($wrongsubcategories,'p') === false ) ) $outputstring = 'Who is a keyboardist?<br>'; elseif ( ( strpos($correctmajorcategory,'a') !== false ) AND ( strpos($wrongmajorcategory,'a') === false ) ) $outputstring = 'Who is an actor?<br>'; elseif ( ( strpos($correctmajorcategory,'M') !== false ) AND ( strpos($wrongmajorcategory,'M') === false ) ) $outputstring = 'Who is a musician?<br>'; elseif ( ( strpos($correctmajorcategory,'A') !== false ) AND ( strpos($wrongmajorcategory,'A') === false ) ) $outputstring = 'Who is an athlete?<br>'; elseif ( ( strpos($correctsubcategories,'j') !== false ) AND ( strpos($wrongsubcategories,'j') === false ) ) $outputstring = 'Who is a journalist?<br>'; return $outputstring; } /* TryOccupationQuestion */
Add the spin button.
Call the code to write the image and javascript call.
/* DISPLAY SPINNER */ DisplaySpinner();
Drawing function.
/******************************/ /* DisplaySpinner */ /* display spinner button */ /******************************/ function DisplaySpinner() { echo '<a href="javascript:void(0);" onclick="spin();"><img src="./testpict/spinbuttonplus.png" width="320" height="86" border="0"></a>'; } /* DisplaySpinner */
Add the red and green buttons.
/******************************/ /* DisplaySpinner */ /* display spinner button */ /******************************/ function DisplaySpinner() { echo '<map name="threebutttonsmap" id="threebutttonsmap"> <area shape="rect" coords="0,0,107,86" href=javascript:void(0);" onclick="redbuttonaction();"> <area shape="rect" coords="108,0,214,86" href=javascript:void(0);" onclick="spin();"> <area shape="rect" coords="215,0,320,86" href=javascript:void(0);" onclick="greenbuttonaction();"> </map>'; echo '<img src="./testpict/spinbuttonplus.png" width="320" height="86" border="0" usemap="#threebutttonsmap">'; } /* DisplaySpinner */
Add three indicators, two of which have unknown purposes.
Call the new drawing routine.
/* DISPLAY THREE INDICATORS */ DisplayThreeIndicators();
Drawing function.
/******************************/ /* DisplayThreeIndicators */ /* display three indicators */ /******************************/ function DisplayThreeIndicators() { echo '<br><img src="./testpict/threeindicators.png" width="320" height="67" border="0">'; } /* DisplayThreeIndicators */
Realized that we werent recording the slams or loves in the game database (just which celebrity the action was on, not what the action was). So some quick updates to record that information.
Change function parameters:
function UpdateRoundResults($gamechoice,$playernumber,$gamenumber,$kindofaction)
Change database update:
/* STORE PLAYER CHOICES */ $resulttitle1 = 'rd'.$currentround.'pl1'; /* player 1 celebrity choice */ $resulttitle2 = 'rd'.$currentround.'pl2'; /* player 2 celebrity choice */ $resulttitle3 = 'rd'.$currentround.'pl3'; /* player 3 celebrity choice */ $kindtitle = 'rd'.$currentround.'kind1'; /* love or slam */ $kindofaction = "'".$kindofaction."'"; /* put into single quotes */ $query = "UPDATE games SET ".$resulttitle1." = ".$firstplayerchoice.",".$resulttitle2." = ".$secondplayerchoice.",".$resulttitle3." = ".$thirdplayerchoice.",".$kindtitle." = "$kindofaction." WHERE gamenumber=".$gamenumber.";";
/* UPDATE PLAYER CREDITS */ if ($scoreflag1 == true) /* only grant points if the answer is correct */ { $query = "UPDATE accounts SET credit = (credit + ".$pointincrement.") WHERE accountnumber=".$playernumber.";"; $updateresult = mysql_query($query); } /* END IF update credits */
Display the token, credit, and money results.
/******************************/ /* DisplayMoneyColumn */ /* display current tokens, credits, and money*/ /******************************/ function DisplayMoneyColumn($playernumber) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ $newquery = "SELECT token,credit,money FROM accounts WHERE accountnumber=".$playernumber.";"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $tokens = $row["token"]; $credits = $row["credit"]; $money = $row["money"]; ?> <table border="2" style="color:black;" align="left"> <tr><td align="left">tokens: <?php echo $tokens; ?></td></tr> <tr><td align="left">credits: <?php echo $credits; ?></td></tr> <tr><td align="left">money: <?php echo $money; ?></td></tr> </table> <?php } /* DisplayMoneyColumn */
Add new game segment for slots.
ProcessSlots (new function):
/******************************/ /* ProcessSlots */ /* display slot machine */ /******************************/ function ProcessSlots($playernumber) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ $newquery = "SELECT token,credit,money FROM accounts WHERE accountnumber=".$playernumber.";"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $tokens = $row["token"]; $credits = $row["credit"]; $money = $row["money"]; ?> <div id="machine"> <div id="a"></div> <div id="b"></div> <div id="c"></div> </div> <div id="navigation" style="display:block; text-align:center;"> <?php DisplaySpinner(); ?> </div> <div id="results" style="visibility:hidden;"></div> <div id="moneycolumn"> <?php DisplayMoneyColumn(GetAccountNumberFromEmail($accountemail)); ?> </div><!--moneycolumn--> <div id="credits"><h1 align="center">Tokens: <?php echo $tokens; ?> Credits: <?php echo $credits; ?> Cash: $0.0<?php echo $money; ?></h1></div> <?php } /* ProcessSlots */
Removed end of DisplayCelebrityRound (modified function):
DisplayThreeIndicators (modified function):
/******************************/ /* DisplayThreeIndicators */ /* display three indicators */ /******************************/ function DisplayThreeIndicators($playernumber) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ $newquery = "SELECT token,credit,money FROM accounts WHERE accountnumber=".$playernumber.";"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $tokens = $row["token"]; $credits = $row["credit"]; $money = $row["money"]; echo '<div id="moneybox">'; echo '<div id="threeindicator" style="background-image: url(./testpict/threeindicators.png); height:67px; width:320px; margin-left:auto; margin-right:auto; color:#ffffff;"> TOKENS<br><big> '.$tokens.' '.$credits.' '.$money.'</big></div>'; ?> <div id="credits"><h1 align="center">Tokens: <?php echo $tokens; ?> Credits: <?php echo $credits; ?> Cash: <?php echo $money; ?></h1></div> <?php echo '</div><!--moneybox-->'; } /* DisplayThreeIndicators */
Remove end of DisplayTriviaQuestion (modified function).
Spin functions collection (moved functions):
function Spin0() { global $part1; global $part2; global $part3; global $part4; global $part5; global $part6; global $part7; global $part8; $picturl = $part1.'&part2='.$part2.'&part3='.$part3.'&part4='.$part4.'&part5='.$part5.'&part6='.$part6.'&part7='.$part7.'&part8='.$part8; return $picturl; } /* END function Spin0 */ function Spin1() { global $part1; global $part2; global $part3; global $part4; global $part5; global $part6; global $part7; global $part8; $picturl = $part2.'&part2='.$part3.'&part3='.$part4.'&part4='.$part5.'&part5='.$part6.'&part6='.$part7.'&part7='.$part8.'&part8='.$part1; return $picturl; } /* END function Spin1 */ function Spin2() { global $part1; global $part2; global $part3; global $part4; global $part5; global $part6; global $part7; global $part8; $picturl = $part3.'&part2='.$part4.'&part3='.$part5.'&part4='.$part6.'&part5='.$part7.'&part6='.$part8.'&part7='.$part1.'&part8='.$part2; return $picturl; } /* END function Spin2 */ function Spin3() { global $part1; global $part2; global $part3; global $part4; global $part5; global $part6; global $part7; global $part8; $picturl = $part4.'&part2='.$part5.'&part3='.$part6.'&part4='.$part7.'&part5='.$part8.'&part6='.$part1.'&part7='.$part2.'&part8='.$part3; return $picturl; } /* END function Spin3 */ function Spin4() { global $part1; global $part2; global $part3; global $part4; global $part5; global $part6; global $part7; global $part8; $picturl = $part5.'&part2='.$part6.'&part3='.$part7.'&part4='.$part8.'&part5='.$part1.'&part6='.$part2.'&part7='.$part3.'&part8='.$part4; return $picturl; } /* END function Spin4 */ function Spin5() { global $part1; global $part2; global $part3; global $part4; global $part5; global $part6; global $part7; global $part8; $picturl = $part6.'&part2='.$part7.'&part3='.$part8.'&part4='.$part1.'&part5='.$part2.'&part6='.$part3.'&part7='.$part4.'&part8='.$part5; return $picturl; } /* END function Spin5 */ function Spin6() { global $part1; global $part2; global $part3; global $part4; global $part5; global $part6; global $part7; global $part8; $picturl = $part7.'&part2='.$part8.'&part3='.$part1.'&part4='.$part2.'&part5='.$part3.'&part6='.$part4.'&part7='.$part5.'&part8='.$part6; return $picturl; } /* END function Spin6 */ function Spin7() { global $part1; global $part2; global $part3; global $part4; global $part5; global $part6; global $part7; global $part8; $picturl = $part8.'&part2='.$part1.'&part3='.$part2.'&part4='.$part3.'&part5='.$part4.'&part6='.$part5.'&part7='.$part6.'&part8='.$part7; return $picturl; } /* END function Spin7 */ function SpinByNumber($spinnumber) { if ( $spinnumber == 0 ) return Spin0(); elseif ( $spinnumber == 1 ) return Spin1(); elseif ( $spinnumber == 2 ) return Spin2(); elseif ( $spinnumber == 3 ) return Spin3(); elseif ( $spinnumber == 4 ) return Spin4(); elseif ( $spinnumber == 5 ) return Spin5(); elseif ( $spinnumber == 6 ) return Spin6(); else /* should be case of 7 */ return Spin7(); } /* END function SpinByNumber */ function StartSlots() { global $part1; global $part2; global $part3; global $part4; global $part5; global $part6; global $part7; global $part8; global $spinresult; global $scrollpict1url; global $scrollpict2url; global $scrollpict3url; global $randomchoice1; global $randomchoice2; global $randomchoice3; /* create celebrity numbers */ $part1 = GetCelebrity(); $part2 = GetCelebrity(); while ($part2 == $part1) { $part2 = GetCelebrity(); } /* END WHILE $part2 */ $part3 = GetCelebrity(); while ( ($part3 == $part1) OR ($part3 == $part2) ) { $part3 = GetCelebrity(); } /* END WHILE $part3 */ /* part 4 is the winner */ $part4 = GetCelebrity(); while ( ($part4 == $part1) OR ($part4 == $part2) OR ($part4 == $part3) ) { $part4 = GetCelebrity(); } /* END WHILE $part4 */ $part5 = GetCelebrity(); while ( ($part5 == $part1) OR ($part5 == $part2) OR ($part5 == $part3) OR ($part5 == $part4) ) { $part5 = GetCelebrity(); } /* END WHILE $part5 */ $part6 = GetCelebrity(); while ( ($part6 == $part1) OR ($part6 == $part2) OR ($part6 == $part3) OR ($part6 == $part4) OR ($part6 == $part5) ) { $part6 = GetCelebrity(); } /* END WHILE $part6 */ $part7 = GetCelebrity(); while ( ($part7 == $part1) OR ($part7 == $part2) OR ($part7 == $part3) OR ($part7 == $part4) OR ($part7 == $part5) OR ($part7 == $part6) ) { $part7 = GetCelebrity(); } /* END WHILE $part7 */ $part8 = GetCelebrity(); while ( ($part8 == $part1) OR ($part8 == $part2) OR ($part8 == $part3) OR ($part8 == $part4) OR ($part8 == $part5) OR ($part8 == $part6) OR ($part8 == $part7) ) { $part8 = GetCelebrity(); } /* END WHILE $part7 */ /* determine winning conditions */ $randomnumber = rand(0,7); if ($randomnumber == 0) { /* have a three way winner */ $spinresult = 1; } /* END three way winner */ elseif ($randomnumber == 3) { /* have a two way winner */ $tempnumber = rand(0,2); If ($tempnumber == 0) $spinresult = 2; elseIf ($tempnumber == 1) $spinresult = 3; else $spinresult = 4; } /* END two way winner */ else { /* have a loser */ $tempnumber = rand(0,3); If ($tempnumber == 0) $spinresult = 5; elseIf ($tempnumber == 1) $spinresult = 6; elseIf ($tempnumber == 1) $spinresult = 7; else $spinresult = 8; } /* END loser */ /* set picture options */ /* amount of shift = a = any other than 0 or match */ /* 1 = 0 0 0 */ /* 2 = 0 a 0 */ /* 3 = 0 0 a */ /* 4 = a 0 0 */ /* 5 = 0 a a */ /* 6 = a 0 a */ /* 7 = a a 0 */ /* 8 = a a a */ if ( $spinresult == 1 ) { $scrollpict1url = 'makepicture.php?part1='.Spin0(); $scrollpict2url = 'makepicture.php?part1='.Spin0(); $scrollpict3url = 'makepicture.php?part1='.Spin0(); } elseif ( $spinresult == 2 ) { $randomchoice = rand(1,7); $scrollpict1url = 'makepicture.php?part1='.Spin0(); $scrollpict2url = 'makepicture.php?part1='.SpinByNumber($randomchoice); $scrollpict3url = 'makepicture.php?part1='.Spin0(); } elseif ( $spinresult == 3 ) { $randomchoice = rand(1,7); $scrollpict1url = 'makepicture.php?part1='.Spin0(); $scrollpict2url = 'makepicture.php?part1='.Spin0(); $scrollpict3url = 'makepicture.php?part1='.SpinByNumber($randomchoice); } elseif ( $spinresult == 4 ) { $randomchoice = rand(1,7); $scrollpict1url = 'makepicture.php?part1='.SpinByNumber($randomchoice); $scrollpict2url = 'makepicture.php?part1='.Spin0(); $scrollpict3url = 'makepicture.php?part1='.Spin0(); } elseif ( $spinresult == 5 ) { $randomchoice1 = rand(1,7); $randomchoice2 = rand(1,7); while ($randomchoice1 == $randomchoice2) { $randomchoice2 = rand(1,7); } $scrollpict1url = 'makepicture.php?part1='.Spin0(); $scrollpict2url = 'makepicture.php?part1='.SpinByNumber($randomchoice1); $scrollpict3url = 'makepicture.php?part1='.SpinByNumber($randomchoice2); } elseif ( $spinresult == 6 ) { $randomchoice1 = rand(1,7); $randomchoice2 = rand(1,7); while ($randomchoice1 == $randomchoice2) { $randomchoice2 = rand(1,7); } $scrollpict1url = 'makepicture.php?part1='.SpinByNumber($randomchoice1); $scrollpict2url = 'makepicture.php?part1='.Spin0(); $scrollpict3url = 'makepicture.php?part1='.SpinByNumber($randomchoice2); } elseif ( $spinresult == 7 ) { $randomchoice1 = rand(1,7); $randomchoice2 = rand(1,7); while ($randomchoice1 == $randomchoice2) { $randomchoice2 = rand(1,7); } $scrollpict1url = 'makepicture.php?part1='.SpinByNumber($randomchoice1); $scrollpict2url = 'makepicture.php?part1='.SpinByNumber($randomchoice2); $scrollpict3url = 'makepicture.php?part1='.Spin0(); } else /* should be case of 8 */ { $randomchoice1 = rand(1,7); $randomchoice2 = rand(1,7); while ($randomchoice1 == $randomchoice2) { $randomchoice2 = rand(1,7); } $randomchoice3 = rand(1,7); while ( ($randomchoice1 == $randomchoice3) OR ($randomchoice2 == $randomchoice3) ) { $randomchoice3 = rand(1,7); } $scrollpict1url = 'makepicture.php?part1='.SpinByNumber($randomchoice1); $scrollpict2url = 'makepicture.php?part1='.SpinByNumber($randomchoice2); $scrollpict3url = 'makepicture.php?part1='.SpinByNumber($randomchoice3); } } /* END function StartSlots */
DisplaySlotStart (new function):
/******************************/ /* DisplaySlotStart */ /* set up a slots game */ /******************************/ function DisplaySlotStart($playernumber,$gamenumber) { global $scrollpict1url; global $scrollpict2url; global $scrollpict3url; AddRoundTokens($playernumber); /* located in gamefunctions.php */ StartSlots(); ?> <div id="machine"> <div id="a" style="background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(0,0,0,.6)), to(rgba(0,0,0,.6)), color-stop(.3,rgba(0,0,0,0)), color-stop(.7,rgba(0,0,0,0))), url('<?php echo $scrollpict1url; ?>'); -webkit-animation: spin 0.7s infinite linear;"></div> <div id="b" style="background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(0,0,0,.6)), to(rgba(0,0,0,.6)), color-stop(.3,rgba(0,0,0,0)), color-stop(.7,rgba(0,0,0,0))), url('<?php echo $scrollpict2url; ?>'); -webkit-animation: spin 1.2s infinite linear;"></div> <div id="c" style="background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(0,0,0,.6)), to(rgba(0,0,0,.6)), color-stop(.3,rgba(0,0,0,0)), color-stop(.7,rgba(0,0,0,0))), url('<?php echo $scrollpict3url; ?>'); -webkit-animation: spin 2.0s infinite linear;"></div> </div> <div id="navigation" style="display:block; text-align:center;"> <?php DisplaySpinner(); ?> </div> <div id="results" style="visibility:hidden;"></div> <div id="moneycolumn"> <?php DisplayMoneyColumn($playernumber); ?> </div><!--moneycolumn--> <?php DisplayThreeIndicators($playernumber); //echo "<br>first picture url is ".$scrollpict1url; /* DEBUG */ //echo "<br>second picture url is ".$scrollpict2url; /* DEBUG */ //echo "<br>third picture url is ".$scrollpict3url; /* DEBUG */ } /* DisplaySlotStart */
AdvanceNewRound (new function):
/******************************/ /* AdvanceNewRound */ /* advance to next round */ /******************************/ function AdvanceNewRound($playernumber,$gamenumber) { $currentround = GetRoundNumber($gamenumber); /* ADVANCE TO THE NEXT ROUND */ if ( $currentround < 10 ) IncrementCelebrityRound($gamenumber); $newround = $currentround + 1; if ( $newround == 11 ) DisplayEndGame($playernumber,$gamenumber); /* located in gamefunctions.php */ else DisplayCelebrityRound($playernumber,$gamenumber); /* located in gamefunctions.php */ } /* AdvanceNewRound */
Change the picture so that it also an answer during trivia.
Show money in DisplayThreeIndicators.
$money = $row["money"]; $dollarpart = (int) ($money/100); $centspart = $money % 100; if ($centspart < 10) { $centspart = '0'.$centspart; } $money = '$'.$dollarpart.'.'.$centspart;
Add tokens with any slam or love.
/******************************/ /* AddRoundTokens */ /* add bonux tokens for slam or love */ /******************************/ function AddRoundTokens($playernumber) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ $incrementamount = rand(1,5); $newquery = "UPDATE accounts SET token = (token + ".$incrementamount.") WHERE accountnumber=".$playernumber.";"; //echo "<br>query is ".$newquery."<br>"; $updateresult = mysql_query($newquery); } /* AddRoundTokens */
Hide the slot pictures at the start of slot, then reveal on a spin.
Insert a blank white picture (repeat for each slot).
<img src="./testpict/blankslot.png" id="slota" width="100" height="160">
The slot machine starts with three pictures labelled begin, so we are going to activate these and make them begin buttons.
Add this link to all three images:
Show round number in slots.
In function DisplaySlotStart
:
DisplayRoundNumber($playernumber,$gamenumber,'slots');
In function DisplayCelebrityRound
:
DisplayRoundNumber($playernumber,$gamenumber,'trivia');
Add new function DisplayRoundNumber
:
/******************************/ /* DisplayRoundNumber */ /* display new celebrity game round */ /******************************/ function DisplayRoundNumber($playernumber,$gamenumber,$phaseflag) { /* ANNOUNCE ROUNDS */ $roundnumber = GetRoundNumber($gamenumber); $roundstring = '<p align="center"><span style="font-size:24;'; if ( ( $phaseflag == 'trivia') AND ($roundnumber > 6 ) ) $roundstring = $roundstring.'color:red;">Bonus '; else $roundstring = $roundstring.'color:black;">'; $roundstring = $roundstring.'Round</span> <span id="roundnumber" style="font-size:24;">'.$roundnumber.'</span> <span style="font-size:24;">Timer: </span><span id="countdowntimer" style="font-size:24;">time</span>'; if ( ( $phaseflag == 'trivia') AND ($roundnumber == 10) ) $roundstring= $roundstring.'<br><small><span style="color:red;">points tripled</span></small>'; elseif ( ( $phaseflag == 'trivia') AND ($roundnumber > 6) ) $roundstring= $roundstring.'<br><small><span style="color:blue;">points doubled</span></small>'; $roundstring = $roundstring.'</p>'; echo $roundstring; } /* END FUNCTION DisplayRoundNumber */
Shrink the size of the slots to fit in portrait format on smart phones. First picture resize shown below, all three pictures are rsized the same.
<a href=javascript:void(0);" onclick="slotspin();"><img src="./testpict/blankslot.png" id="slota" width="90" height="160"></a>
We want to show the trivia points in the entire game, including the slots section. We therefore need persistent (database) storage of the current point earner, as well as add the code to show the trivia points display under the slots.
New function SetTriviaBullets
.
/******************************/ /* SetTriviaBullets */ /* store who has trivia bullets */ /* smallint as number of points scored */ /******************************/ function SetTriviaBullets($gamenumber,$player1bullet,$player2bullet,$player3bullet) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ /* INSERT TRIVIA POINTS INTO DATA BASE */ $query = "UPDATE games SET ply1trivbullet = ".$player1bullet.", ply2trivbullet = ".$player2bullet.", ply3trivbullet = ".$player3bullet." WHERE gamenumber=".$gamenumber.";"; $updateresult = mysql_query($query); if(!$updateresult) { echo "<p>failed data base insert with error message ".mysql_error()."</p>"; } } /* SetTriviaBullets */
New function ReadTriviaBullets
.
/******************************/ /* ReadTriviaBullets */ /* read who has trivia bullets */ /******************************/ function ReadTriviaBullets($gamenumber) { /* GET OLD ROUND NUMBER */ $newquery = "SELECT ply1trivbullet, ply2trivbullet, ply3trivbullet FROM games WHERE gamenumber=".$gamenumber." "; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $player1bullet = $row["ply1trivbullet"]; $player2bullet = $row["ply2trivbullet"]; $player3bullet = $row["ply3trivbullet"]; return array ($player1bullet, $player2bullet, $player3bullet); } /* ReadTriviaBullets */
Remove everywhere:
global $scoreflag1; global $scoreflag2; global $scoreflag3;
Changes in function UpdateRoundResults
.
/* UPDATE TRIVIA BULLETS */ if ( $scoreflag1 == true) $player1bullet = $pointincrement; else $player1bullet = 0; if ( $scoreflag2 == true) $player2bullet = $pointincrement; else $player2bullet = 0; if ( $scoreflag3 == true) $player3bullet = $pointincrement; else $player3bullet = 0; SetTriviaBullets($gamenumber,$player1bullet,$player2bullet,$player3bullet);
Changes in function DisplayCurrentScores
.
list($player1bullet,$player2bullet,$player3bullet) = ReadTriviaBullets($gamenumber); if ( $player1bullet > 0 ) $oldpoints1 = $totalscore1 - $roundadjust; else $oldpoints1 = $totalscore1; if ( $player2bullet > 0 ) $oldpoints2 = $totalscore2 - $roundadjust; else $oldpoints2 = $totalscore2; if ( $player3bullet > 0 ) $oldpoints3 = $totalscore3 - $roundadjust; else $oldpoints3 = $totalscore3;
And change the table in function DisplayCurrentScores
. if ($scoreflag1)
becomes if ($player1bullet > 0)
(and similar for all three bullets).
Insert into the end of function DisplaySlotStart
:
DisplayCurrentScores($playernumber,$gamenumber);
Grant the tokens and credits for winning slots.
Return the spin result from function StartSlots
.
return $spinresult; /* coded slots results */
Capture the spin result near beginning of function DisplaySlotStart
.
$spinresult; = StartSlots();
Update tokens and credits in function DisplaySlotStart
.
/* UPDATE TOKENS AND CREDITS */ if ($spinresult == 1) $incrementamount = 6; elseif ($spinresult <= 4) $incrementamount = 2; else $incrementamount = 1; if ($incrementamount == 1) $tokenincrement = 0; else $tokenincrement = $incrementamount; $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ $newquery = "UPDATE accounts SET token = (token + ".$tokenincrement."), credit = (credit + ".$incrementamount.") WHERE accountnumber=".$playernumber.";"; $updateresult = mysql_query($newquery);
Message for slot winnings. Includes winning amounts. Inside function ProcessSlots
.
/* WINNING RESULTS */ /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$result) return -1; /* FAILURE to connect */ /* GET SPIN RESULTS */ $newquery = "SELECT slotresult FROM games WHERE gamenumber=".$gamenumber." "; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $spinresult = $row["slotresult"]; //echo "<br>spinresult is ".$spinresult.'<br>'; /* DEBUG */ /* REPORTING RESULTS */ if ($spinresult == 1) echo '<h1 style="color:green">You win six credits!</h1>'; /* 3 way winner */ elseif ($spinresult <= 4) echo '<h1 style="color:green">You win two credits!</h1>'; /* two-way winner */ else echo '<h1 style="color:green">You win one credit!</h1>'; /* loser */
Message for slot winnings. Includes link for next round. Inside function ProcessSlots
.
echo '<h1 align="center"><a href="javascript:void(0);" onclick="advancetonewround();" style="cursor:pointer;"><span style="color:black">play next '.$outputoption.'</span></a></h1>';
Add specialty rounds for different categories of celebrities.
New functions:
/******************************/ /* GetActor */ /* get a new actor number */ /******************************/ function GetActor() { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ /* COUNT ACTORS */ $newquery = "SELECT COUNT(*) as total FROM celebrity WHERE majorcategory LIKE '%B%';"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $counttotal = $row["total"]; $celebritynumber = rand(1,$counttotal) -1; /* GET Nth ACTOR */ $newquery = "SELECT celebnum FROM celebrity WHERE majorcategory LIKE '%B%' LIMIT ".$celebritynumber.",1 ORDER BY celebnum;"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $celebritynumber = $row["celebnum"]; return $celebritynumber; } /* GetActor */ /******************************/ /* GetMusician */ /* get a new musician number */ /******************************/ function GetMusician() { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ /* COUNT MUSICIANS */ $newquery = "SELECT COUNT(*) as total FROM celebrity WHERE majorcategory LIKE '%M%';"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $counttotal = $row["total"]; $celebritynumber = rand(1,$counttotal) -1; /* GET Nth MUSICIAN */ $newquery = "SELECT celebnum FROM celebrity WHERE majorcategory LIKE '%M%' LIMIT ".$celebritynumber.",1 ORDER BY celebnum;"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $celebritynumber = $row["celebnum"]; return $celebritynumber; } /* GetMusician */ /******************************/ /* GetModel */ /* get a new model number */ /******************************/ function GetModel() { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ /* COUNT MODELS */ $newquery = "SELECT COUNT(*) as total FROM celebrity WHERE majorcategory LIKE '%N%';"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $counttotal = $row["total"]; $celebritynumber = rand(1,$counttotal) -1; /* GET Nth MODEL */ $newquery = "SELECT celebnum FROM celebrity WHERE majorcategory LIKE '%N%' LIMIT ".$celebritynumber.",1 ORDER BY celebnum;"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $celebritynumber = $row["celebnum"]; return $celebritynumber; } /* GetModel */
In IncrementCelebrityRound
function, add code for specialty rounds:
/* ROUND SPECIALS */ if ($currentround == 1) /* musician round */ { $celebrity1 = GetMusician(); $celebrity2 = GetMusician(); while ($celebrity1 == $celebrity2) { $celebrity2 = GetMusician(); } } /* END IF musician round */ elseif ($currentround == 2) /* actor round */ { $celebrity1 = GetActor(); $celebrity2 = GetActor(); while ($celebrity1 == $celebrity2) { $celebrity2 = GetActor(); } } /* END IF actor round */ elseif ($currentround == 3) /* model round */ { $celebrity1 = GetModel(); $celebrity2 = GetModel(); while ($celebrity1 == $celebrity2) { $celebrity2 = GetModel(); } } /* END IF model round */
In DisplayRoundNumber
function, announce specialty rounds:
elseif ( ( $phaseflag == 'trivia') AND ($roundnumber == 1) ) $roundstring= $roundstring.'<br><small><span style="color:blue;">musicians</span></small>'; elseif ( ( $phaseflag == 'trivia') AND ($roundnumber == 2) ) $roundstring= $roundstring.'<br><small><span style="color:blue;">actors</span></small>'; elseif ( ( $phaseflag == 'trivia') AND ($roundnumber == 3) ) $roundstring= $roundstring.'<br><small><span style="color:blue;">models</span></small>';
Convert credits to money at the end of a game.
Added to function DisplayEndGame
.
/* PAY OUT MONEY */ ShowMoneyPayOut($playernumber);
New function:
/******************************/ /* ShowMoneyPayOut */ /* display money pay out information */ /******************************/ function ShowMoneyPayOut($playernumber) { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ /* READ CURRENT CREDITS */ $newquery = "SELECT credit FROM accounts WHERE accountnumber=".$playernumber.";"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $credits = $row["credit"]; /* SUBTRACT CREDITS */ if ($credits >= 101) $newcredits = $credits - 100; elseif ($credits >= 51) $newcredits = $credits - 50; elseif ($credits >= 26) $newcredits = $credits - 25; elseif ($credits >= 11) $newcredits = $credits - 10; elseif ($credits >= 2) $newcredits = $credits - 1; else $newcredits = 0; /* STORE NEW CREDITS TOTAL */ if ($newcredits > 0) { $query = "UPDATE accounts SET credit =".$newcredits." WHERE accountnumber=".$playernumber." "; $updateresult = mysql_query($query); } /* STORE NEW MONEY TOTAL */ if ($newcredits > 0) { $query = "UPDATE accounts SET money = (money + 1) WHERE accountnumber=".$playernumber." "; $updateresult = mysql_query($query); } /* REPORT EARNING MONEY */ if ($newcredits > 0) { $newquery = "SELECT money FROM accounts WHERE accountnumber=".$playernumber.";"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $money = $row["money"]; $dollarpart = (int) ($money/100); $centspart = $money % 100; if ($centspart < 10) { $centspart = '0'.$centspart; } $money = '$'.$dollarpart.'.'.$centspart; echo '<h1 align="center" style"color:green">You earned another penny for a total of '.$money.'</h1>'; } } /* ShowMoneyPayOut */
Changed the end of game message.
if (GetRoundNumber($gamenumber) < 10) $outputoption = 'play next round'; else $outputoption = 'end of game summary'; echo '<h1 align="center"><a href="javascript:void(0);" onclick="advancetonewround();" style="cursor:pointer;"><span style="color:black">'.$outputoption.'</span></a></h1>';
Added more categories for celebrity game rounds.
Add new functions:
/******************************/ /* GetPolitician */ /* get a new politician number */ /******************************/ function GetPolitician() { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ /* COUNT POLITICIANS */ $newquery = "SELECT COUNT(*) as total FROM celebrity WHERE majorcategory LIKE '%P%';"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $counttotal = $row["total"]; //echo '<br>count is '.$counttotal.'<br>'; /* DEBUG */ $celebritynumber = rand(1,$counttotal) -1; //echo 'random is '.$celebritynumber.'<br>'; /* DEBUG */ /* GET Nth POLITICIAN */ $newquery = "SELECT celebnum FROM celebrity WHERE majorcategory LIKE '%P%' LIMIT ".$celebritynumber.",1;"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $celebritynumber = $row["celebnum"]; //echo 'celebrity is '.$celebritynumber.'<br>'; /* DEBUG */ return $celebritynumber; } /* GetPolitician */ /******************************/ /* GetSinger */ /* get a new singer number */ /******************************/ function GetSinger() { /* DATABASE CONNECTION */ $result = ConnectCelebDataBase(0); /* located in databasefunctions.php */ /* COUNT SINGERS */ $newquery = "SELECT COUNT(*) as total FROM celebrity WHERE subcategories LIKE '%S%';"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $counttotal = $row["total"]; //echo '<br>count is '.$counttotal.'<br>'; /* DEBUG */ $celebritynumber = rand(1,$counttotal) -1; //echo 'random is '.$celebritynumber.'<br>'; /* DEBUG */ /* GET Nth SINGER */ $newquery = "SELECT celebnum FROM celebrity WHERE subcategories LIKE '%S%' LIMIT ".$celebritynumber.",1;"; $selectresult = mysql_query($newquery); $row = mysql_fetch_array($selectresult); $celebritynumber = $row["celebnum"]; //echo 'celebrity is '.$celebritynumber.'<br>'; /* DEBUG */ return $celebritynumber; } /* GetSinger */
Connect them up in function IncrementCelebrityRound
:
/* ROUND SPECIALS */ if ($currentround == 2) /* politician round */ { $celebrity1 = GetPolitician(); $celebrity2 = GetPolitician(); while ($celebrity1 == $celebrity2) { $celebrity2 = GetPolitician(); } } /* END IF politician round */ elseif ($currentround == 3) /* singer round */ { $celebrity1 = GetSinger(); $celebrity2 = GetSinger(); while ($celebrity1 == $celebrity2) { $celebrity2 = GetSinger(); } } /* END IF singer round */ elseif ($currentround == 4) /* actor round */ { $celebrity1 = GetActor(); $celebrity2 = GetActor(); while ($celebrity1 == $celebrity2) { $celebrity2 = GetActor(); } } /* END IF actor round */ elseif ($currentround == 5) /* model round */ { $celebrity1 = GetModel(); $celebrity2 = GetModel(); while ($celebrity1 == $celebrity2) { $celebrity2 = GetModel(); } } /* END IF model round */ elseif ($currentround == 6) /* musician round */ { $celebrity1 = GetMusician(); $celebrity2 = GetMusician(); while ($celebrity1 == $celebrity2) { $celebrity2 = GetMusician(); } } /* END IF musician round */
Connect them up in function DisplayRoundNumber
:
if ( ( $phaseflag == 'trivia') AND ($roundnumber == 10) ) $roundstring= $roundstring.'<br><small><span style="color:red;">points tripled</span></small>'; elseif ( ( $phaseflag == 'trivia') AND ($roundnumber > 6) ) $roundstring= $roundstring.'<br><small><span style="color:blue;">points doubled</span></small>'; elseif ( ( $phaseflag == 'trivia') AND ($roundnumber == 2) ) $roundstring= $roundstring.'<br><small><span style="color:blue;">politicians</span></small>'; elseif ( ( $phaseflag == 'trivia') AND ($roundnumber == 3) ) $roundstring= $roundstring.'<br><small><span style="color:blue;">singers</span></small>'; elseif ( ( $phaseflag == 'trivia') AND ($roundnumber == 4) ) $roundstring= $roundstring.'<br><small><span style="color:blue;">actors</span></small>'; elseif ( ( $phaseflag == 'trivia') AND ($roundnumber == 5) ) $roundstring= $roundstring.'<br><small><span style="color:blue;">models</span></small>'; elseif ( ( $phaseflag == 'trivia') AND ($roundnumber == 6) ) $roundstring= $roundstring.'<br><small><span style="color:blue;">musicians</span></small>';
Dont confuse singers and rappers on trivia questions.
elseif ( ( strpos($correctsubcategories,'S') !== false ) AND ( strpos($wrongsubcategories,'r') === false ) AND ( strpos($wrongsubcategories,'S') === false ) ) $outputstring = 'Who is the singer?<br>';
OSdata.com is used in more than 300 colleges and universities around the worldFind out how to get similar high web traffic and search engine placement. |
OSdata.com is used in more than 300 colleges and universities around the world |
Tweets by @osdata |
A web site on dozens of operating systems simply cant be maintained by one person. This is a cooperative effort. If you spot an error in fact, grammar, syntax, or spelling, or a broken link, or have additional information, commentary, or constructive criticism, please e-mail Milo. If you have any extra copies of docs, manuals, or other materials that can assist in accuracy and completeness, please send them to Milo, PO Box 1361, Tustin, CA, USA, 92781.
Click here for our privacy policy.
previous page | next page |
This web site handcrafted on Macintosh computers using Tom Benders Tex-Edit Plus and served using FreeBSD .
Names and logos of various OSs are trademarks of their respective owners.
Copyright © 2013 Milo
Last Updated: December 27, 2013
Created: October 1, 2013
previous page | next page |