PHP - Tic Tac Toe Game Help
I have a tic tac toe game that I've been working on for a school project. When I attempt to run it a parse error comes up saying "syntax error, unexpected $end" on line 311. If anyone wants to try and run it. go here http://itstudents.ccs.uconn.edu/~iskm218st38/newnewnewtictactoe.html I'm trying to make the computer randomly select a tile after the human player selects but the first issue I need help with is why i'm getting this syntax error on a line that doesnt have code on.
This is the html gameboard Code: [Select] <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Untitled</title> <meta name="generator" content="BBEdit 16.0" /> </head> <body> <center> <?php session_start() ?> <form action="tictactoe.php" method="post"> <table> <tr> <td colspan="3" align="center"> <input type="text" size="9" name="message" style="border:none; text-align:center;" /></td> </tr> <tr align="center"> <tr> <td> <input type="text" size="1" name="box1" pattern="[X|O{2}]" title="X or O" /></td> <td align="center"> <input type="text" size="1" name="box2" pattern="[X|O{2}]" title="X or O" /></td> <td align="right"> <input type="text" size="1" name="box3" pattern="[X|O{2}]" title="X or O" /></td> <td align="right"> <input type="text" size="1" name="box4" pattern="[X|O{2}]" title="X or O" /></td> </tr> <tr> <td> <input type="text" size="1" name="box5" pattern="[X|O{2}]" title="X or O" /></td> <td align="center"> <input type="text" size="1" name="box6" pattern="[X|O{2}]" title="X or O" /></td> <td align="right"> <input type="text" size="1" name="box7" pattern="[X|O{2}]" title="X or O" /></td> <td align="right"> <input type="text" size="1" name="box8" pattern="[X|O{2}]" title="X or O" /></td> </tr> <tr> <td> <input type="text" size="1" name="box9" pattern="[X|O{2}]" title="X or O" /></td> <td align="center"> <input type="text" size="1" name="box10" pattern="[X|O{2}]" title="X or O" /></td> <td align="right"> <input type="text" size="1" name="box11" pattern="[X|O{2}]" title="X or O" /></td> <td align="right"> <input type="text" size="1" name="box12" pattern="[X|O{2}]" title="X or O" /></td> </tr> <tr> <td> <input type="text" size="1" name="box13" pattern="[X|O{2}]" title="X or O" /></td> <td align="center"> <input type="text" size="1" name="box14" pattern="[X|O{2}]" title="X or O" /></td> <td align="right"> <input type="text" size="1" name="box15" pattern="[X|O{2}]" title="X or O" /></td> <td align="right"> <input type="text" size="1" name="box16" pattern="[X|O{2}]" title="X or O" /></td> </tr> <tr> <td colspan="3"><input type="button" value="new game" onclick="new_game(); play();" /></td> <td colspan="3"><input type="button" value="submit" onclick="submit();" /></td> </tr> </center> </body> </html> And this is the tictactoe.php file. Code: [Select] <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Untitled</title> <meta name="generator" content="BBEdit 16.0" /> </head> <body> <center> <?php //refer to the comment below $box1 = ''; $box2 = ''; $box3 = ''; $box4 = ''; $box5 = ''; $box6 = ''; $box7 = ''; $box8 = ''; $box9 = ''; $box10 = ''; $box11 = ''; $box12 = ''; $box13 = ''; $box14 = ''; $box15 = ''; $box16 = ''; $human = ''; $computer = ''; $players = array ($human, $computer); $gameboard = array( $box1, $box2, $box3, $box4, $box5, $box6, $box7, $box8, $box9, $box10, $box11, $box12, $box13, $box14, $box15, $box16, ); switch ($box1) { case "O": echo $_POST["box1"]; break; case "X": echo $_POST["box1"]; break; } switch ($box2) { case "O": echo $_POST["box2"]; break; case "X": echo $_POST["box2"]; break; } switch ($box3) { case "O": echo $_POST["box3"]; break; case "X": echo $_POST["box3"]; break; } switch ($box4) { case "O": echo $_POST["box4"]; break; case "X": echo $_POST["box4"]; break; } switch ($box5) { case "O": echo $_POST["box5"]; break; case "X": echo $_POST["box5"]; break; } switch ($box6) { case "O": echo $_POST["box6"]; break; case "X": echo $_POST["box6"]; break; } switch ($box7) { case "O": echo $_POST["box7"]; break; case "X": echo $_POST["box7"]; break; } switch ($box8) { case "O": echo $_POST["box8"]; break; case "X": echo $_POST["box8"]; break; } switch ($box9) { case "O": echo $_POST["box9"]; break; case "X": echo $_POST["box9"]; break; } switch ($box10) { case "O": echo $_POST["box10"]; break; case "X": echo $_POST["box10"]; break; } switch ($box11) { case "O": echo $_POST["box11"]; break; case "X": echo $_POST["box11"]; break; } switch ($box12) { case "O": echo $_POST["box12"]; break; case "X": echo $_POST["box12"]; break; } switch ($box13) { case "O": echo $_POST["box13"]; break; case "X": echo $_POST["box13"]; break; } switch ($box14) { case "O": echo $_POST["box14"]; break; case "X": echo $_POST["box14"]; break; } switch ($box15) { case "O": echo $_POST["box15"]; break; case "X": echo $_POST["box15"]; break; } switch ($box16) { case "O": echo $_POST["box16"]; break; case "X": echo $_POST["box16"]; break; } /*$gameboard = array_rand($box1, $box2, $box3, $box4, $box5, $box6, $box7, $box8, $box9, $box10, $box11, $box12, $box13, $box14, $box15, $box16 ); foreach ($gameboard as &$value) { $value = 'O'; }*/ // $gameboard is now array_rand() as &$value = O unset($value); // break the reference with the last element if ($box1=="X") echo $gameboard[$rand_keys[0]] . "\n"; if ($box2=="X") echo $gameboard[$rand_keys[0]] . "\n"; if ($box3=="X") echo $gameboard[$rand_keys[0]] . "\n"; if ($box4=="X") echo $gameboard[$rand_keys[0]] . "\n"; if ($box5=="X") echo $gameboard[$rand_keys[0]] . "\n"; if ($box6=="X") echo $gameboard[$rand_keys[0]] . "\n"; if ($box7=="X") echo $gameboard[$rand_keys[0]] . "\n"; if ($box8=="X") echo $gameboard[$rand_keys[0]] . "\n"; if ($box9=="X") echo $gameboard[$rand_keys[0]] . "\n"; if ($box10=="X") echo $gameboard[$rand_keys[0]] . "\n"; if ($box11=="X") echo $gameboard[$rand_keys[0]] . "\n"; if ($box12=="X") echo $gameboard[$rand_keys[0]] . "\n"; if ($box13=="X") echo $gameboard[$rand_keys[0]] . "\n"; if ($box14=="X") echo $gameboard[$rand_keys[0]] . "\n"; if ($box15=="X") echo $gameboard[$rand_keys[0]] . "\n"; if ($box16=="X") echo $gameboard[$rand_keys[0]] . "\n"; /* unset($b); $b[] = "box1|box2|box3|box4"; $b[] = "box5|box6|box7|box8"; $b[] = "box9|box10|box11|box12"; $b[] = "box13|box14|box15|box16"; */ /* $boardtile = (); $gameboard = array( array(box1, box2, box3), array(box4, box5, box6), array(box7, box8, box9)); public static GUI_Box */ $Human = true; function check_input( $box1 ) { if( preg_match( "X|O", $text ) ) { return false; } else { return true; // human wins if if( //horizontal ($box1 == $human && $box2 == $human && $box3 == $human && $box4 == $human) or ($box5 == $human && $box6 == $human && $box7 == $human && $box8 == $human) or ($box9 == $human && $box10 == $human && $box11 == $human && $box12 == $human) or ($box9 == $human && $box10 == $human && $box11 == $human && $box12 == $human) or //vertical ($box1 == $human && $box5 == $human && $box9 == $human && $box13 == $human) or ($box2 == $human && $box6 == $human && $box10 == $human && $box14 == $human) or ($box3 == $human && $box7 == $human && $box11 == $human && $box15 == $human) or ($box4 == $human && $box8 == $human && $box12 == $human && $box16 == $human) or //diagonal ($box4 == $human && $box7 == $human && $box10 == $human && $box13 == $human) or ($box1 == $human && $box6 == $human && $box11 == $human && $box16 == $human)) echo("human "+$players[0]+" won") ; //computer wins if if( //horizontal ($box1 == $computer && $box2 == $computer && $box3 == $computer && $box4 == $computer) or ($box5 == $computer && $box6 == $computer && $box7 == $computer && $box8 == $computer) or ($box9 == $computer && $box10 == $computer && $box11 == $computer && $box12 == $computer) or ($box9 == $computer && $box10 == $computer && $box11 == $computer && $box12 == $computer) or //vertical ($box1 == $computer && $box5 == $computer && $box9 == $computer && $box13 == $computer) or ($box2 == $computer && $box6 == $computer && $box10 == $computer && $box14 == $computer) or ($box3 == $computer && $box7 == $computer && $box11 == $computer && $box15 == $computer) or ($box4 == $computer && $box8 == $computer && $box12 == $computer && $box16 == $computer) or //diagonal ($box4 == $computer && $box7 == $computer && $box10 == $computer && $box13 == $computer) or ($box1 == $computer && $box6 == $computer && $box11 == $computer && $box16 == $computer)) echo("computer "+$players[1]+" won") ; } ?> </center> </body> </html> Similar TutorialsHello, I am building an online game(users make a character and move on a map and so on...)
All user data is stored in a mySQL database and I want the users to interact in real-time, but there can be a 1-3 second delay between the communication, but not exceed 3 seconds even if 500 players are playing at the same time.
But for the purpose of the question let's say the users can only chat between one another, if I'll have a solution for that then I can use the same method for more parts of the game.
I can't use websockets because my webhost doesn't support it( I don't want to use pusher.com).
I know I can make real-time apps with ajax long polling, but I think that with 500 players playing at the same time it's not the best solution.
So, finally:
How can I make user interaction as close as possible to a real-time game?
(Without too much load on the hosting server)
(I am sorry if some of my terms are not correct - I am just getting back to coding after a long time...)
Edited by Mythion, 17 August 2014 - 02:34 AM. hi iam finished from my online strategy game but iwant add map to it players can see cities and their troops on map any 1 can give me code? Can someone point me to a layman's tutorial for a simple hangman game? I downloaded one off the internet, but it doesn't do what I want. The one I use doesn't allow capitalized letters or spaces! I can live without the capitlization but MOST of the words will have spaces and therefore, this code will not work. I want to start a brand new code from scratch but I can't seem to figure it out. I am new to coding and have been coding my site using MySQL, and that's fine, but ALL of the coding for hangman is very confusing for me! Code: [Select] $letters = array('a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z', ' '); if(empty($_POST)) { $rightcount = '0'; $wrongcount = '0'; $words = explode("\n", file_get_contents('words.list.txt')); $right = array_fill_keys($letters, ' _ '); $wrong = array(); shuffle($words); $word = strtolower($words[0]); $rightstr = serialize($right); $wrongstr = serialize($wrong); $wordletters = str_split($word); $show = ''; foreach($wordletters as $letter) { $show .= $right[$letter]; } } else { $show = $_POST['show']; $word = $_POST['word']; $lettercount = strlen($word); echo $lettercount . "<br>"; $word = htmlspecialchars($word); $word = mysql_real_escape_string($word); $rightcount = $_POST['rightcount']; $wrongcount = $_POST['wrongcount']; $guess = strtolower($_POST['guess']); $guess = ctype_alpha($guess); if($guess == TRUE) { $guess = strtolower($_POST['guess']); } else { echo "<b>Please use only letters.</b><br>"; $guess = ''; } $letterinstance = @substr_count($word, $guess); $right = unserialize($_POST['rightstr']); $wrong = unserialize($_POST['wrongstr']); $wordletters = str_split($word); if(!(empty($guess))) { if(stristr($word, $guess)) { $show = ''; $right[$guess] = $guess; $wordletters = str_split($word); $rightcount = $rightcount + (1*$letterinstance); foreach($wordletters as $letter) { $show .= $right[$letter]; } } else { $show = ''; $wrong[$guess] = $guess; $wrongcount = $wrongcount + 1; if(count($wrong) == 6) { $show = $word; echo "You lost this round of hangman.<br>"; } else { foreach($wordletters as $letter) { $show .= $right[$letter]; } } } } $rightstr = serialize($right); $wrongstr = serialize($wrong); echo "Right: $rightcount<br>Wrong: $wrongcount<br>"; if($rightcount == $lettercount) { echo "You win!<br>"; } } echo "Incorrect Guesses: "; echo implode(', ', $wrong); echo "<br>"; echo $show; echo "<br />"; echo "<form method='post'> <input name='guess'>"; echo "<input type='hidden' name='show' value='$show'> "; echo "<input type='hidden' name='rightcount' value='$rightcount'> "; echo "<input type='hidden' name='wrongcount' value='$wrongcount'> "; echo "<input type='hidden' name='word' value='$word'> "; echo "<input type='hidden' name='rightstr' value='$rightstr'>"; echo "<input type='hidden' name='wrongstr' value='$wrongstr'>"; echo "<input type='submit' value='guess'> "; echo "</form>"; echo "<a href='hangman.php'>Reset</a>"; That is the code I am using now. The connect to the database and rewarding the user when they guess all the letters work fine, but I need for my other details to be in there and I have NO clue how to do that. I've tried a lot of things but everything just screws up. Here's the code I have now that is from scratch, and it's very basic. I really have no freakin' clue where to go from there. Code: [Select] <?php $words = explode(";", file_get_contents('words.list.txt')); shuffle($words); $word = $words[0]; $upletters = array('a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z'); $lowletters = array('A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); echo $word . "<br>"; $word1 = str_replace($upletters, ' _ ', $word); $word1 = str_replace($lowletters, ' _ ', $word1); echo $word1 . "<br><br>"; echo "<form action = '1.php' method = 'POST'>"; echo "<input type = 'text' name = 'guess' size = '10'>"; echo "<input type = 'hidden' name = 'word' value = '$word'>"; echo "<input type = 'hidden' name = 'word1' value = '$word1'>"; echo "<br><input type = 'submit' value = 'Guess!'></form>"; ?> Can someone PLEASE point me in the right direction! Or give me all the functions I need to use to get through this! Thanks in advance. Hey First let me say I am not asking exactly how to do this. Just the best method of what I want to do. The idea is to have a database of every model of a dirt bike. A user who is logged in to the system can submit data for a dirt bike (I can create forms for this). On the main page of the database I need to be able to have the user select what model bike and year or years to find the information people submitted in a nice list. Do you think this is to big of a project? I'm doing this as a hobby type thing so there really is no time schedule. For making the database: Would an array be best? Are there any examples somewhat close to what I'm talking about? how would you code a map for a browser game like travian? i know how it works but i cant code that sort of stuff. ive got my database set up like this x y player 1 1 1 2 etc.... so i when you click an arrow it will got to the next square along. Hello everyone and thanks for reading my request for help
I am working on a basic game where 3 - 5 images will be displayed on each page for the user to see (there should be about 5 pages), each of these images will have a value e.g. -1, +1, 0, -10, +12. When the user clicks on an image his/her score will change and the next page with 3 - 5 new images will be shown. When all of the pages have been shown and the user has a score of lets just say 20 or more then more pages will be displayed, if not then a new page will display stating that the game is over.
My question is how do I give each image a value and how do I show a new set of images based on the overall "score" of the player after the first set of pages have been shown?
And is there a way to display the players score on the page?
Thanks and any answers will be appreciated.
If you know of any videos which may help please tell me
:-\
Wow, I have no clue what I'm doing.. I'm trying to make a random game and if you roll a 6, you will win 500 rp and I'm trying to insert the 500 rp into the user who is logged in ($_SESSION['username'). But I... just don't know where to begin. Here is my crappy coding that I just.. am stumped on: <p><?php $dice = rand(1,6); if($dice == 1){ echo "You rolled a <br><b>1</b>"; }if($dice == 2){ echo "You rolled a <br><b>2</b>"; }if($dice == 3){ echo "You rolled a <br><b>3</b>"; }if($dice == 4){ echo "You rolled a <br><b>4</b>"; }if($dice == 5){ echo "You rolled a <br><b>5</b>"; }if($dice == 6){ echo "You rolled a <br><b>6</b>"; } $winner = "500"; if($dice == 6); { include("haha.php"); $cxn = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase); $sql = "INSERT INTO Member (rp) VALUES ('$winner')"; mysqli_query($cxn,$sql); } ?> Hello Everyone, I am using some code for a hangman game. It is written in PHP. I am using code directly from this website http://www.daniweb.com/code/snippet267046.html and am having issues with it. I have the php file on my web server, and I also have a words.txt file on the server as well. However, I am getting errors, and the game also automatically says "you win!" even when entering just one letter. I'm not sure what is going on, as I am using the exact code from the website. Here is where the file is located: http://www.littlehousegardening.com/hangman/hangmanfinal.php Errors I am encountering: Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0 code: Code: [Select] <?php session_start(); // The following function returns a word of dots, each dot represents a letter function word2dots($word) { $wordlength = strlen($word); $dotWord = ""; for ($i = 0; $i < $wordlength; $i++) { $dotWord = "".$dotWord."."; } return $dotWord; } // The following function opens the file, reads it, saves it into an array and returns a random word function getWord() { // Opening and reading file $filename = "words.txt"; // You can change this into whatever words file you'd like, as long as it's local. $filehandle = fopen($filename,"r"); $filecontent = fread($filehandle,filesize($filename)); fclose($filehandle); if (!$filehandle) { $_SESSION['message'] = "Could not open ".$filename; } // Splitting the content into the $words array $words = split("\|", $filecontent); $words_amount = count($words); // Calculating random number $random_number = mt_rand(0,$words_amount); // Returning random word $theWord2 = $words[$random_number]; return $theWord2; } // Resetting the message $_SESSION['message'] = ""; // Retrieving the guessWord, theWord and the amount of errors. if (isset($_POST['send_letter']) && $_SESSION['gameEnded'] != true) { if (isset($_POST['HangManLetter']) && preg_match("/[A-Z\s_]/i", $_POST['HangManLetter']) > 0) { // Getting the $letter value $letter = htmlentities(stripslashes($_POST['HangManLetter'])); // Retrieving session variables $theWord = $_SESSION['theWord']; $guessWord = $_SESSION['guessWord']; $error_amount = $_SESSION['error_amount']; // Checking wether the $letter occurs in the word // Filling the arrays: for ($d = 0; $d < strlen($theWord); $d++) { $theWordArray[$d] = substr($theWord, $d, 1); $guessWordArray[$d] = substr($guessWord, $d, 1); } // Checking occurance of the letter in theWord $letterOccured = false; for ($f = 0; $f < strlen($theWord); $f++) { if ($theWordArray[$f] == $letter) { $letterOccured = true; $guessWordArray[$f] = $theWordArray[$f]; } } // Updating the guessWord: $guessWord = ""; for ($r = 0; $r < strlen($theWord); $r++) { $guessWord = "".$guessWord."".$guessWordArray[$r].""; } $_SESSION['guessWord'] = $guessWord; if ($_SESSION['guessWord'] == $_SESSION['theWord']) { $_SESSION['message'] = "You won! <input type='submit' name='reset' value='Try again?' />"; unset($_SESSION['theWord']); unset($_SESSION['guessWord']); $_SESSION['gameEnded'] = true; $_SESSION['guessWord'] = $theWord; } if ($letterOccured == false) { $error_amount++; $_SESSION['error_amount'] = $error_amount; // If the error_amount is higher as 9, the player lost if ($error_amount > 9) { $_SESSION['message'] = "You lost! <input type='submit' name='reset' value='Try again?' />"; unset($_SESSION['theWord']); unset($_SESSION['guessWord']); $_SESSION['gameEnded'] = true; $_SESSION['guessWord'] = $theWord; } } } else { // Showing the message if (preg_match("/[A-Z\s_]/i", $_POST['letter']) < 0) { $_SESSION['message'] = "Only alphanumeric symbols are allowed!"; } else { $_SESSION['message'] = "Enter a letter!"; } // End of else isaplha ($_POST['HangManLetter']) } // End of else isset($_POST['HangManLetter']) and preg_match("/[A-Z\s_]/i", $_POST['HangManLetter']) } else { // If the game has been resetted or there has not yet been a game played $theWord = getWord(); $guessWord = word2dots($theWord); $error_amount = 0; $_SESSION['theWord'] = $theWord; $_SESSION['guessWord'] = $guessWord; $_SESSION['error_amount'] = $error_amount; $_SESSION['gameEnded'] = false; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <link rel="stylesheet" href="style1.css" type="text/css" /> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Hangman</title> </head> <body onload="document.getElementById('HangManInput').focus()"> <div style="background-color:#EFEFEF;position:relative; top:0px; left:0px; border:2px ridge #BBBBBB; width:200px; height:280px; font-family:Times New Roman; font-weight:normal; font-style:normal; text-decoration:none;"> <form action="" method="post" onsubmit="return true;"> <div id="HangManTitle" style="font-size:22px; position:absolute; top:5px; width:200px; text-align:center;"> Hangman </div> <div id="HangManConsole" style="font-size:16px; position:absolute; top:34px; text-align:center; width:200px;"> Enter a letter: <input type="text" maxlength="1" size="1" id="HangManInput" name="HangManLetter" /><input type="hidden" value="true" name="send_letter" /><input type="submit" value="Go" name="send_letter_button" /><br /> The word: <span id="HangManGuessWord"><?php echo $_SESSION['guessWord']; ?></span><br /> </div> <div id="HangManImage" style="position:absolute; top:85px; left:22px;"> <img src="http://www.hangman.symbolwebdesign.nl/hmimgs/hm<?php echo $_SESSION['error_amount']; ?>.bmp" id="HangManIMG" style="border:1px ridge #BBBBBB;" /> </div> <div id="HangManMessage" style="font-size:16px; position:absolute; top:250px; width:200px; text-align:center;"> <?php echo $_SESSION['message']; ?> </div> </form> </div> </body> </html> Haven't done much in PHP for a while, and as a refresher and a bit of a challenge to myself I have decided to write up a simple game of sorts. Basically in the game I have townships, every play has their own town. And I want these towns to have events every 3-10 hours, and have these events have results such as births/deaths/fires/flooding/etc. At the moment I'm looking at this kind of setup: A database table with the city information.. city_id, city_owner_id, city_name, etc. I figure I can make another field such as city_nextevent and fill it with a timestamp plus a random number of seconds. then when the user views their city if city_nextevent is older than current time then run the event function and set the next event time. In my head this idea seems to work well, until I realised that if the user doesn't log on for 20+ hours the events will not stack, they will only get the one event when they next view their town when several events should have passed. I realise I could use a cronjob to check all events across all towns, but is there a better way of doing it. I had also though about adding several fields to the database containing say the next five event times, then updating each field after time had passed. Which gives more events if the user has been offline for 20+ hours. So if the play was offline for say a week, their town would pretty much dry up until they returned. Basically, I want their town to run while they're offline. But was trying to avoid using a cronjob. Anyone have any thoughts on how this could be done? OK so i am having a little trouble putting guilds in my game, everything shows up but when you go to create a new guild it say can not update player stats, but it shows up that the guild has been created in the top guild list, it just doesnt let you use it here is the script could someone tell me if they see a problem Code: [Select] <?php require 'connect.php'; include 'header.php'; include 'headin.php'; ?> <script type="text/javascript"> function stats() { var no=document.getElementById("Name") var option=no.options[no.selectedIndex].value var y="guild.php?stats=1&&guild="+option window.open(y,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=400, height=500") } function redirect() { window.location="./guild.php" } </script> <?php if(!isset($_COOKIE['member_id'])) die('Not logged in, please <a href=login.php>login</a>'); $Player=$_COOKIE['member_id']; $Option=$_POST['option']; $Create=$_POST['create']; $Join=$_POST['join']; $Submit=$_POST['submit']; $Tax=$_POST['tax']; $Guild=$_GET['guild']; $Deny=$_GET['deny']; $Add=$_GET['add']; $Stats=$_GET['stats']; $Kick=$_GET['kick']; $Kickname=$_GET['kickname']; $Addname=$_GET['addname']; $Abandon=$_POST['abandon']; $Coleader=$_GET['coleader']; if(isset($Abandon)) $Option="Abandon"; if($Option=="") $Option=$_GET['option']; if(isset($Option)) { if($Option=='Create a guild') { ?> <p>It costs 1,000,000 gold to create a Guild.<br /><br /></p> <form method="post" action="guild.php"> Name:<input class="text" type="text" name="name" /> <input class="button" name="create" type="submit" value="submit" /> </form> <?php } elseif($Option=='Join a guild') { print "<form class=\"form\" action='guild.php' method='post'>"; print "<select class=\"select\" name='Name' id='Name' length='20' id='blah'>"; $Guild="SELECT * from Guilds order by ID asc"; $Guild2=mysql_query($Guild) or die("Could not select Guilds"); while ($Guild3=mysql_fetch_array($Guild2)) { $Name=str_replace(" ","%20",$Guild3['Name']); print "<option value=\"$Name\">$Guild3[Name]</option>"; } print "</select><br />"; print "<input class=\"button\" type='Submit' name='join' value='Join' /> "; ?><input class=button type="button" onclick="stats()" value="Stats" /></form> <?php } elseif($Option=='Raise your guilds tax') { $Query="SELECT * from Users where ID='$Player'"; $Query2=mysql_query($Query) or die("Could not get user stats"); $User=mysql_fetch_array($Query2); $Name=$User['Guild']; $Guild1="SELECT * from Guilds where Name='$Name'"; $Guild2=mysql_query($Guild1) or die("Could not select Guilds"); $Guild=mysql_fetch_array($Guild2); if($Guild['Tax']>90){ mysql_query("UPDATE Guilds SET Tax='90' WHERE Name='$Name'"); } if($Guild['Owner']==$User['Playername'] || $Guild['Coleader']==$User['Playername']){ print "<form class=\"form\" action='guild.php' method='post'>"; print "Amount: <input type=text class=\"select\" name='tax' id='tax' length='3' id='tax'>"; print "<br /><br>"; print "<input class=\"button\" type='Submit' name='submit' value='Raise' /></form> "; }else{ echo"You may not edit your Guild Tax, since you are not a leader or co-leader."; exit; } } elseif($Option=='Guild stats') { $Query="SELECT * from Users where ID='$Player'"; $Query2=mysql_query($Query) or die("Could not get user stats"); $User=mysql_fetch_array($Query2); $Guild1="SELECT * from Guilds where Name='$User[Guild]'"; $Guild2=mysql_query($Guild1) or die("Could not select Guilds"); $Guild=mysql_fetch_array($Guild2); $Query="SELECT * from Users where Guild='$Guild[Name]' order by Level desc"; $Query2=mysql_query($Query) or die("Could not get user stats"); if($Guild['Name']!="") { print "<table class=\"table\" align=\"center\"><tr><td>"; $AttackPower=number_format(pow($Guild['AttackPower']+10, 5)); $DefenceStance=number_format(pow($Guild['DefenceStance']+10, 5)); $Agility=number_format(pow($Guild['Agility']+10, 5)); $Gold=pow($Guild['Gold']+12,3)*4; $Gold=number_format($Gold); $Exp=pow($Guild['Exp']+9, 4)+500; $Exp=number_format($Exp); $Itemfind=number_format(pow($Guild['Itemfind']+10, 5)); $Itemquality=number_format(pow($Guild['Itemquality']+10, 5)); print "Guild Name: $Guild[Name]<br />Guild Owner: $Guild[Owner]<br />Guild Co-Owner: $Guild[Coleader]<br />Guild Bank: $Guild[Bank]<br />Guild Tax: $Guild[Tax]%<br />Last Guild Battle: $Guild[LastFight]<br />Battles won: $Guild[Won]<br />Battles Lost: $Guild[Lost]<br />"; if($Guild['Owner']==$User['Playername'] || $Guild['Coleader']==$User['Playername'] || $User['Admin']==1){ echo "<form class=\"form\" method=\"post\" action=\"guildbonus.php\">"; echo "Attack Power:".$Guild['AttackPower']."% <input class=\"button\" type='Submit' name='AttackPower' value='Increase' /> $AttackPower gold<br />"; echo "Defence Stance:".$Guild['DefenceStance']."% <input class=\"button\" type='Submit' name='DefenceStance' value='Increase' /> $DefenceStance gold<br />"; echo "Agility:".$Guild['Agility']."% <input class=\"button\" type='Submit' name='Agility' value='Increase' /> $Agility gold<br />"; echo"Exp:".$Guild['Exp']."% <input class=\"button\" type='Submit' name='Exp' value='Increase' /> $Exp gold<br />"; echo "Gold:".$Guild['Gold']."% <input class=\"button\" type='Submit' name='Gold' value='Increase' /> $Gold gold<br />"; echo "Item Find:".$Guild['Itemfind']."% <input class=\"button\" type='Submit' name='Itemfind' value='Increase' /> $Itemfind gold<br />"; echo "Item Quality:".$Guild['Itemquality']."% <input class=\"button\" type='Submit' name='Itemquality' value='Increase' /> $Itemquality gold<br />"; }else{ echo "<form class=\"form\" method=\"post\" action=\"guildbonus.php\">"; echo "Attack Power:".$Guild['AttackPower']."% <br />"; echo "Defence Stance:".$Guild['DefenceStance']."% <br />"; echo "Agility:".$Guild['Agility']."% <br />"; echo "Experience".$Guild['Exp']."% <br />"; echo "Gold:".$Guild['Gold']."% <br />"; echo "Item Find:".$Guild['Itemfind']."% <br />"; echo "Item Quality:".$Guild['Itemquality']."% <br />"; } print "Donate:<input class=\"text\" type=\"text\" name=\"Amount\" value=\"$User[Gold]\" /><input class=\"button\" type='Submit' name='Donate' value='Donate' /></form><br />"; if($User['Playername']==$Guild['Owner']||$User['Playername']==$Guild['Coleader']||$Player=="1"){ print"<a href=\"attackguild.php\">Attack Other Guilds</a><br><br>"; } if($User['Playername']==$Guild['Owner']||$User['Playername']==$Guild['Coleader']||$Player=="1") { $Name=str_replace(" ","%20",$Guild['Name']); echo "<a href=\"guild.php?coleader=1&&Guild=$Name\">Assign coleader</a><br />"; } print "</td></tr></table>"; } else echo "You are not in a guild, below is a listing of all people not in a guild."; print "<table class=\"table\" align=\"right\"><tr><td>"; print "<form class=\"form\" action='guild.php' method='post'>"; print "<table><tr><td>"; print "Members:<br />To kick a member out the guild must pay half of what the User has donated.<br><br><table id=\"table\"><tr><td>Player</td><td>Level</td><td>Donated</td>"; if($User['Playername']==$Guild['Owner']||$User['Playername']==$Guild['Coleader']||$Player=="1"){ print "<td>Kick</td>"; } print "</tr>"; while($topplayer3=mysql_fetch_array($Query2)) { print "<tr><td>$topplayer3[Playername]</td><td>$topplayer3[Level]</td><td>$topplayer3[GuildDonate]</td>"; if($User['Playername']==$Guild['Owner']||$User['Playername']==$Guild['Coleader']||$Player=="1"){ print "<td><a href=\"guild.php?kick=$topplayer3[ID]&&kickname=$Guild[ID]\">Kick</a></td>"; } print "</tr>"; } print "</table></form></td><td></td><td>"; if($User['Playername']==$Guild['Owner']||$User['Playername']==$Guild['Coleader']||$Player=="1") { $Name = $Guild['Name']; $Guild['Name' ]= str_replace(" ","%20",$Guild['Name']); $Query = mysql_query("select * from Users where Applied='$Name'"); print "Requests:<br /><table id=\"table\"><tr><td>Name</td><td>Level</td><td>Accept?</td><td>Deny?</td></tr>"; while($joinee = mysql_fetch_array($Query)) { echo "<tr><td>$joinee[Playername]</td>"; echo "<td>$joinee[Level]</td>"; echo "<td><a href=\"guild.php?add=$joinee[ID]&&addname=$Guild[Name]\">Accept</a></td><td><a href=\"guild.php?deny=$joinee[ID]\">Deny</a></td></tr>"; } print "</table>"; print "</td></tr></table>"; } print "</td></tr></table><br />"; } elseif($Option=='Leave guild') { $Query="SELECT * from Users where ID='$Player'"; $Query2=mysql_query($Query) or die("Could not get user stats"); $User=mysql_fetch_array($Query2); $Name=$User['Guild']; $Guild1="SELECT * from Guilds where Name='$Name'"; $Guild2=mysql_query($Guild1) or die("Could not select Guilds"); $Guild=mysql_fetch_array($Guild2); if($Guild['Owner']==$User['Playername']) { echo "Are you sure you want to abandon and delete your guild?"; echo "<form action=\"guild.php\" method=\"post\"><input type=\"hidden\" value=\"$Guild[Name]\" name=\"Guild\" /><input class=\"button\" type=\"submit\" name=\"abandon\" value=\"yes\" /><input class=\"button\" type=\"button\" value=\"no\" onclick=\"redirect()\" /></form>"; } else { mysql_query("UPDATE Users SET GuildDonate='0' WHERE ID='$Player'"); mysql_query("Update Users set Guild='' where ID='$Player'") or die("Could not update player stats"); mysql_query("update Guilds set Members=Members-'1' where Name='$Guild[Name]'") or die("Could not decrease number of members"); print "You have left the guild."; } } elseif($Option=="Abandon") { $Guild=$_POST['Guild']; $Query="Select * from Users where Guild='$Guild'"; $Query2=mysql_query($Query) or die("Zomg"); while($User=mysql_fetch_array($Query2)) { $ID=$User['ID']; $Update="Update Users set Guild='' where ID='$ID'"; mysql_query($Update) or die("No clan update."); } $Query="Delete from Guilds where Name='$Guild'"; mysql_query($Query) or die("Can't delete guild."); echo "Clan deleted."; } } elseif(isset($Kick)) { $Query="SELECT * from Users where ID='$Player'"; $Query2=mysql_query($Query) or die("Could not get user stats"); $User=mysql_fetch_array($Query2); $Querty="SELECT * from Users where ID='$Kick'"; $Querty2=mysql_query($Querty) or die("Could not get user stats"); $Kicking=mysql_fetch_array($Querty2); $Name=$User['Guild']; $Guild1="SELECT * from Guilds where Name='$Name'"; $Guild2=mysql_query($Guild1) or die("Could not select Guilds"); $Guild=mysql_fetch_array($Guild2); $KickAmount=$Kicking['GuildDonate']/2; if($User['Playername']!=$Guild['Owner'] AND $User['Playername']!=$Guild['Coleader'] AND $User['Admin']!=1){ echo"You cannot kick users because you are not the leader or coleader of this guild!"; exit; } elseif($Kicking['Playername']==$Guild['Owner']){ echo"You may not kick out the creator of this guild!"; exit; } elseif($KickAmount>$Guild['Bank']){ echo"You do not have enough gold to kick this player out. To kick out a member you must be able to pay half of what they have donated."; exit; } else{ mysql_query("UPDATE Guilds SET Bank=Bank-'$KickAmount' WHERE ID='$Kickname'"); mysql_query("UPDATE Guilds SET Members=Members-'1' WHERE Name='$Guild[Name]'"); mysql_query("UPDATE Users SET Gold=Gold'$KickAmount' WHERE ID='$Kick'"); mysql_query("UPDATE Users SET GuildDonate='0' WHERE ID='$Kick'"); mysql_query("UPDATE Users SET Guild='' WHERE ID='$Kick'"); echo"Player kicked from your guild! <a href='guild.php'>Back</a>"; } } elseif(isset($Submit)) { $Query="SELECT * from Users where ID='$Player'"; $Query2=mysql_query($Query) or die("Could not get user stats"); $User=mysql_fetch_array($Query2); $Name=$User['Guild']; $Guild1="SELECT * from Guilds where Name='$Name'"; $Guild2=mysql_query($Guild1) or die("Could not select Guilds"); $Guild=mysql_fetch_array($Guild2); if($Tax<0 || $Tax>90){ echo"Do you want people leaving your guild?"; exit; }else{ mysql_query("Update Guilds set Tax='$Tax' where Name='$Name'"); echo "Tax set to $Tax!"; } } elseif(isset($Create)) { if(isset($_POST['name'])) { $Name=$_POST['name']; $Player=$_COOKIE['member_id']; $Query=mysql_query("select * from Users where ID='$Player'") or die("Could not query Users"); $User=mysql_fetch_array($Query); $check="SELECT * from Guilds where Name='$Name'"; $check2=mysql_query($check) or die("Could not query guilds"); while($check3=mysql_fetch_array($check2)) { $Clan=$check3['Name']; } if($Clan) print "Sorry there is already a guild of that name."; elseif($User['Guild'] != "") echo "You have to leave your clan before you can create your own."; elseif($User['Gold']>=1000000) { $Query="INSERT into Guilds(Name, Owner) VALUES ('$Name', '$User[Playername]')"; mysql_query($Query) or die("could not create clan"); $Update="Update Users set Guild='$Name', Applied='', Gold=Gold-'1000000' where ID='$Player'"; mysql_query($Update) or die("Could not update player stats"); print "Clan created."; } else print "You do not have enough gold."; } } elseif(isset($Join)) { if(isset($_POST['Name'])) { $Name=$_POST['Name']; $Player=$_COOKIE['member_id']; $Name=str_replace("%20"," ",$Name); $Query=mysql_query("SELECT * FROM Guilds where Name='$Name'") or die("Could not fetch guild stats"); $Guild=mysql_fetch_array($Query); $Query=mysql_query("Select * from Users where ID='$Player'"); $User=mysql_fetch_array($Query); if($User['Guild'] != "") echo "Leave your other guild first before you join a new one.<br /><a href=\"guild.php\">Go back</a>"; elseif($Guild[Members]==15){ echo "Guild is full, sorry, go pick another. <a href=fight.php>Go</a>"; }else { mysql_query("update Users set Applied='$Name' where ID='$Player'"); if($Guild['Members'] >= 15) echo "You are accepted, but the guild is currently full. you may have to wait an extended amount of time before you are accepted."; else echo "You applied for the clan. Now wait until either the owner or the coleader accepts you."; } } } elseif(isset($Deny)){ $Query="SELECT * from Users where ID='$Player'"; $Query2=mysql_query($Query) or die("Could not get user stats"); $User=mysql_fetch_array($Query2); $Name=$User['Guild']; $Guild1="SELECT * from Guilds where Name='$Name'"; $Guild2=mysql_query($Guild1) or die("Could not select Guilds"); $Guild=mysql_fetch_array($Guild2); if($User['Playername']!=$Guild['Owner'] AND $User['Playername']!=$Guild['Coleader'] AND $User['Admin']!=1){ echo"You cannot deny users because you are not the leader or coleader of this guild!"; exit; }else{ $Update="Update Users set Applied='' where ID='$Deny'"; mysql_query($Update) or die("Could not update player stats"); print "Player denied.<br /><a href=\"guild.php\">Go back</a>"; } } elseif(isset($Add)) { $Query="SELECT * from Users where ID='$Player'"; $Query2=mysql_query($Query) or die("Could not get user stats"); $User=mysql_fetch_array($Query2); $Name=$User['Guild']; $Guild1="SELECT * from Guilds where Name='$Name'"; $Guild2=mysql_query($Guild1) or die("Could not select Guilds"); $Guild=mysql_fetch_array($Guild2); if($User['Playername']!=$Guild['Owner'] AND $User['Playername']!=$Guild['Coleader'] AND $User['Admin']!=1){ echo"You cannot add users because you are not the leader or coleader of this guild!"; exit; }else{ $Addname=str_replace("%20"," ",$Addname); $Query=mysql_query("SELECT * from Guilds where Name='$Addname'") or die("Could not get guild stats"); $Guild=mysql_fetch_array($Query); if($Guild['Members'] <= 15) { $Query2=mysql_query("SELECT * FROM Users where ID='$Add'") or die("Could not get player stats"); $User=mysql_fetch_array($Query2); mysql_query("Update Guilds set Members=Members+'1' where Name='$Addname'") or die("Could not update guilds"); $Update="Update Users set Guild='$Addname', Applied='' where ID='$Add'"; mysql_query($Update) or die("Could not update player stats"); print "Player accepted.<br /><a href=\"guild.php?option=Guild%20stats\">Go back</a>"; } else print "Clan is full, cannot accept player.<br /><a href=\"guild.php?option=Guild%20stats\">Go back</a>"; } } elseif(isset($Guild)) { $Query="SELECT * from Guilds where Name='$Guild'"; $Query2=mysql_query($Query) or die("Could not get guild stats"); $Guild=mysql_fetch_array($Query2); $Query3="SELECT * from Users where Guild='$Guild[Name]'"; $Query4=mysql_query($Query3) or die("Could not get user stats"); print "Guild name: $Guild[Name]<br />Guild Owner: $Guild[Owner]<br />Clan bank: $Guild[Bank]<br />"; echo "Exp:".number_format($Guild['Exp'])."%<br />"; echo "Gold:".number_format($Guild['Gold'])."%<br />"; print "Members:<br /><table id=\"table\"><tr><td>Player</td><td>Level</td></tr>"; while($topplayer3=mysql_fetch_array($Query4)) { print "<tr><td>$topplayer3[Playername]</td><td>$topplayer3[Level]</td></tr>"; } print "</table>"; } elseif($Coleader==1) { $Guild=str_replace("%20"," ",$_GET['Guild']); $Query="SELECT * from Users where Guild='$Guild' order by Level desc"; $Query2=mysql_query($Query) or die("Could not get user stats"); $Guild1="SELECT * from Guilds where Name='$Guild'"; $Guild2=mysql_query($Guild1) or die("Could not select Guilds"); $Guild=mysql_fetch_array($Guild2); print "<table><tr><td>"; print "Members:<br /><table id=\"table\"><tr><td>Player</td><td>Level</td></tr>"; while($Member=mysql_fetch_array($Query2)) { if($Member['Playername']!=$Guild['Owner']) { $Name=str_replace(" ","%20",$Member['Playername']); $Guild=str_replace(" ","%20",$_GET['Guild']); print "<tr><td><a href=\"guild.php?coleader=$Name&&Guild=$Guild\">$Member[Playername]<a></td><td>$Member[Level]</td></tr>"; } } print "</table><br /><a href=\"guild.php?option=Guild%20stats\">Go back</a>"; } elseif($Coleader) { $Name=str_replace("%20"," ",$Coleader); $Guild=$_GET['Guild']; $Query="Update Guilds set Coleader='$Name' where Name='$Guild'"; mysql_query($Query) or die("Could not set coleader."); echo "Coleader assigned. <a href=\"guild.php?option=Guild%20stats\">Go back</a>"; } else { $Query="SELECT * from Users where ID='$Player'"; $Query2=mysql_query($Query) or die("Could not get user stats"); $User=mysql_fetch_array($Query2); $Guild1="SELECT * from Guilds where Name='$User[Guild]'"; $Guild2=mysql_query($Guild1) or die("Could not select Guilds"); $Guild=mysql_fetch_array($Guild2); print"<form method=\"post\" action=\"guild.php\">"; print"<select class=\"select\" name=\"option\">"; if($Guild['Name']!=""){ print"<option>Guild stats</option>"; print"<option>Raise your guilds tax</option>"; print"<option>Leave guild</option>"; }else{ print"<option>Create a guild</option>"; print"<option>Join a guild</option>"; } print"</select>"; print"<input class=\"button\" type=\"submit\" value=\"submit\" name=\"guild\">"; print"</form>"; print"</body>"; } ?> Hello I am making a game trading web application for class. Here are the requirements: You must be able to register and log in, you must be able to list games you have to trade and games you want, you must be able to search users that want games you have and users that have games you want, you must be able to accept and make trades, on trade finalization screen you must be able to rate user 1-5, view the users shipping address, and leave a comment on the users page. You do not have to be able to view other users pages, but on your home page you must be able to view your average rating. I am the most advanced programmer in my group so this has been a little tough. I have a login page and a registration page, I have a user home page, a add games page, a view feedback/ratings page, and a my games page where you can delete games. What I'm stuck on is the page that allows you to search users by games they want and games you want, and the trade finalization page. On the search page I would like to combine the functionality of searching for users with games you want and games they want with the ability to make a trade offer. The way we have it drawn up is using radio buttons to select either show people with games I want and show people wanting my games. When one is selected it will populate a list of usersnames in a drop down menu that fit whichever choice was made. We drew up four list boxes that populate lists when we select a user name, one box populates the games they have, one populates the games they want, one populates the games I have and one populates games I want. We want to be able to select game titles and move them to a list box of games I want and another to a list box of games willing to trade, lastly a submit offer button. We are debating on if this is the best set up given the requirements needing to be met. I think there is more here than what we need, we have 1 week to do this and I am doing all the programming so I am looking for the easiest way to search users that want games I have/have games I want and display the results giving me the option to select games to trade and make an offer. We are also arguing on if we have to use JavaScript to do this or if it can all be done within php. The trade finalization page would have a drop down menu where you select the user name of completed trades and upon selection lists will be populated of games they gave, games I gave and the address to send the game. It will also have a form where we can rate the user and leave a comment. This page I need help with cause again we disagree on having to use JavaScript or not. We are using phpMyAdmin and the db tables we have a tblgame - list of games I have added tblgamestatuscode - gives game a code that determines if it is wanted, to trade, or traded tblmember - member registration tblplatform - platform the game is on (Xbox, Xbox 360, Playstation2, Playstation3, PC, and Wii) tbltransaction - date traded and a status change code tbltransactiondetail - gameID and trans ID tbltransactionparty - memberID, transID, rating, comments, status change accepted We are also using adodb. Please help if you can. I will gladly give more information if needed. I am supposed to create a guessing game in PHP that uses sessions to store a random number between 0 and 100, along with the number of guesses the user has attempted. Each time the user guesses wrong, display the number of times the user has guessed. And a give up link that displays the generated number for the current game. I have been working on this for a week and I can't figure it out. Any help would be appreciated. Here's my code thus far: game.php Code: [Select] <?php session_start(); if (!isset($_SESSION["randNum"])) { $_SESSION["randNum"]=rand(1,100); } $randNum=intval($_SESSION["randNum"]); ?> <html> <body> <center><form action="game_check.php" method="POST"> Guess a number 1-100:<input type="text" name="userGuess"/> <input type="submit" value="Guess"/> </form></center> <center><form action="game.php"> <input type="submit" value="Restart"/> </form></center> </body> </html>game_check.php Code: [Select] <?php session_start(); $_SESSION["randNum"] = $_POST["randNum"]; $userGuess=$_POST["userGuess"]; if (isset($randNum)) { if ($userGuess<$randNum) { echo "<center>You guessed too low!</center>"; } if ($userGuess>$randNum) { echo "<center>You guessed too high!</center>"; } if ($userGuess==$randNum) { echo "<center>Congratulations You're right!!!</center>"; unset($_SESSION["randNum"]); } } else { echo "Uh oh"; } ?> Hello, I am trying to create a simple game random number guessing game in PHP. Currently, I have an HTML page with a form on it where the user enters a number. Then when the user clicks the submit button on the form, their number is passed onto the second page. On the second page, I have some PHP code that generates a random number between 1 and 20, then it checks to see if the two numbers are the same. If they are the same, it says correct. If the guess is higher, it says so. If the guess is lower, it says so. I also made it display a form to re-guess the number (if the initial guess was incorrect). The problem I have is when the user attempts to re-guess the number. Whenever the user attempts to enter a new guess, the random number changes. I want to make it so that the random number stays the same as it is. Any help? Here is the Code for the first HTML page: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>phpNumberGame</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="main"></div> <div id="enterNumber"> <form action="result.php" method="post"> Enter a number: <input type="text" name="inputnumber" /><br /> <input type="submit" value="Guess" /> </form> </div> </body> </html> Here is the code for the second page: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>result</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="main"></div> <div id="enterNumber"> <?php $number_actual = rand (1,20); $number_guess = $_REQUEST["inputnumber"]; echo "You chose: " . $number_guess . "<br />"; echo "The random number is: " . $number_actual . "<br />"; if ($number_guess==$number_actual) echo "You guessed <b>Correctly!</b>"; elseif ($number_guess<$number_actual) { echo "You are too <b>Low</b>!"; echo "<br />"; echo "<br />"; echo "Try guessing again..."; echo "<form> <input type='text' name='inputnumber' /> <input type='submit' value='Guess' /> </form>"; } elseif ($number_guess>$number_actual) { echo "You are too <b>High</b>!"; echo "<br />"; echo "<br />"; echo "Try guessing again..."; echo "<form> <input type='text' name='inputnumber' /> <input type='submit' value='Guess' /> </form>"; } ?> </div> </body> </html> Here is what I have so far on my website, you can see it he http://joshkautz.com/phpNumberGame/phpNumberGame.html I think I included everything necessary for people to give input, if not please let me know and I will give more information! Do I need to redo things completely? Any advice would be greatly appreciated. Thanks a ton! so i have an idea for a system that basicly shows a swf, how to play, and description all managed by sql. the url would be like: "www.example.com/play.php?id=531" my sql table would be like this: ___________________ id name swfname description howto 1 example ex1.swf destroy your enemies with your gun mouse to aim, click to shoot 2 example2 ex2.swf race your friends with this new game! Arrow keys to move. Space to use powerup. ________________ I need help creating a system that looks at the id provided in the url, then grabs the information in the sql and broadcasts the swf, and posts the title up top and the description and howto below. anyone have any idea how to do this? Hi I'm attempting to learn more advanced PHP, such as OOP and the integration of XML, by making a browser-based version of the old Richard Garfield card game "Netrunner". I have a few years experience with pretty basic (bordering on intermediate) PHP. I've done some very basic coding for the game with PHP forms and I've researched some OOP (classes, objects, methods, etc.) but I'm not finding the beginner tutorials that I need. Everything I find has terminology and code that is beyond me. Does anyone have any book or website suggestions for me? I've tried the PHP online manual, but even that throws in advanced stuff all over the place. My goal is to better learn how to use PHP (because I've already put time into it) to create browser based games. Many thanks, Andy Hi!
I was assigned to create a simple php game as a part of my grade, but i got stuck. I'm not really a php expert and this isnt really working. I managed to get some of the code/game working, but it's pointless imo. I'm looking for someone who would take 3 mins and fix this code for me. The game is called "Random number guessing game." From the title you can see that the game is not really complicated.
Code:
<html> <head> <title></title> </head> <body> <h1> Ugani Random!</h1> <? php if(isset($_POST['submit'])) $x = $_POST['x']; $num = $_POST['num']; $x = rand(1, 10) if($num<$x) { echo " Your number is higher! "<br /> } if($num==$x) { echo " Correct! Press Reset to try again! "<br /> } if($num>$x) { echo " Your number is lower! "<br /> } ?> <p> <form> <input type="number" name="quantity"> <br /> <button type="submit" value="<? echo $x?>">Submit</button> <button type="reset" value="<? echo $num?>">Reset</button> </form> </p> </body> </html> Basically, I've created a game serverlist in php.
After some time, I've noticed in the console of two of my game servers I noticed it's spamming connections every time a user connects to the page(this happens a LOT, since people check the SLN often), it's been causing a bit of lag ingame when there is 10+ simultaneous connections from my webserver.
Is there a way I can have the php code only execute every X minutes, so even if a user is connecting to the page, it will show the outputted data from the last check in? I'm using the fsockopen function to check the server's status, and other methods to query the server for information.
This is the last thing I need to do for this project to be perfect, some help would be greatly appreciated ^^
I have a little experience in coding php and am wanting to code a browser-based RPG. (One of the click the link games). I know how to code the login, registration, player list, lost password, etc., but I have no idea where to start with coding the attack, throwing in random chance, strength, agility and so forth; stores, items, money, and so on and so on. Can someone help me? I have just did this php code for the high-low game but the $tries variable always goes down to 0 when I refresh..Can someone help me to return the $tries to browser with the url? Thank you
<html>
<?php function High_Low($guess){
hey im new to this web site im looking for some help with my code its suppose to be a black jack game im trying to make an array that can hold the value of the cards once the person presses the hit me button please help me i havent fully develop code yet so you can ignore the comments code if you like thanks for looking at it. Code: [Select] <html> <head> <title>poker dice</title> <style type = "text/css"> body { background: green; color: tan; } </style> </head> <body> <center> <h1>Poker Dice</h1> <form> <? $number = $_REQUEST["number"]; $statue = $_REQUEST["statue"]; $number2 = unserialize(urldecode($number)); //check to see if this is first time on the page. if ($statue == null){ if ((!$cash) && (!$card_counter)){ Print "You will start out with a value of 100 dollars and points of 0."; $cash = 100; $card_counter = 0; } // end if Cards($number); printPage(); }else if($statue == 1){ Cards2($number); printPage(); // print "this is the second page"; }else if($statue == 2){ Cards3($number); printPage(); // print "this is the second page"; }else if($statue == 3){ Cards4($number); printPage(); // print "this is the second page"; }else if($statue == 4){ Cards5($number); printPage(); // print "this is the second page"; }else if($statue == 5){ Cards6($number); printPage(); // print "this is the second page"; }else if($statue == 6){ Cards7($number); printPage(); // print "this is the second page"; }else if($statue == 7){ Cards8($number); printPage(); // print "this is the second page"; }else{ Cards9($number); printPage(); // print "this is the second page"; } //rollDice(); if ($secondRoll == TRUE){ print "<h2>Second roll</h2>\n"; $secondRoll = FALSE; evaluate(); } else { print "<h2>First roll</h2>\n"; $secondRoll = TRUE; } // end if printStuff(); function Cards($number){ $Diamonds = array( "Ace of Diamonds", "Two of Diamonds", "Three of Diamonds", "Four of Diamonds", "Five of Diamonds", "Six of Diamonds", "Seven of Diamonds", "Eight of Diamonds", "Nine of Diamonds", "Ten of Diamonds", "Jack of Diamonds", "Queen of Diamonds", "King of Diamonds"); $Clubs = array( "Ace of Clubs", "Two of Clubs", "Three of Clubs", "Four of Clubs", "Five of Clubs", "Six of Clubs", "Seven of Clubs", "Eight of Clubs", "Nine of Clubs", "Ten of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs"); $Hearts = array( "Ace of Hearts", "Two of Hearts", "Three of Hearts", "Four of Hearts", "Five of Hearts", "Six of Hearts", "Seven of Hearts", "Eight of Hearts", "Nine of Hearts", "Ten of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts"); $Spades = array( "Ace of Spades", "Two of Spades", "Three of Spades", "Four of Spades", "Five of Spades", "Six of Spades", "Seven of Spades", "Eight of Spades", "Nine of Spades", "Ten of Spades", "Jack of Spades", "Queen of Spades", "King of Spades"); $Cards = array_merge($Diamonds, $Clubs); $Cards = array_merge($Cards, $Hearts); $Cards = array_merge($Cards, $Spades); //$Deck = shuffle($Cards); $num1 = rand(1,52); $num2 = rand(1,52); echo $Cards[$num1]; //echo " ____ "; echo $Cards[$num2]; // }else{ // echo "There is no cards being displayed."; // }//close second if statement // }//close first if statement $cards_array[0] = $Cards[$num1]; $cards_array[1] = $Cards[$num2]; //it take the object of a string and pass it as a array. $serialCards = urlencode(serialize($cards_array)); print_r($cards_array); print "<br>"; print $serialCards; print $cards_array[0]; print $cards_array[1]; print <<<HERE </tr></td> <tr> <td colspan = "5"> <center> <form methods = "post" action = "PokerFinal.php"> <input type = "submit" value = "Hit Me"> <input type = "hidden" name = "number" value = "$serialCards"> <input type ="hidden" name ="statue" value = "1"> </form> </center> </td> </tr> </table> HERE; print <<<HERE </tr></td> <tr> <td colspan = "5"> <center> <input type = "submit" value = "roll again"> </center> </td> </tr> </table> HERE; // by using the number and requestinh it will store the value of that array. //it good using a hidden box for this method. //if ($Deck[$num1] == TRUE || $Deck[$num2] == TRUE) { //} //$CurrentHand = $Deck[$num1]; //$Deck = explode(",",$CurrentHand[0]); //$Hit = array_shift($Deck); //$Cards = implode(",",$Deck); //if (isset($CurrentHand[1])) // $PlayersHand = explode("~", $CurrentHand[1]); //$PlayersHand[] = $Hit; //$CardCount = 0; /*$Aces = 0; for ($i=0; $i<count($PlayersHand); ++$i) { if (strpos($PlayersHand[$i], "Ace") !== FALSE) ++$Aces; else if (strpos($PlayersHand[$i], "Two") !== FALSE) $CardCount += 2; else if (strpos($PlayersHand[$i], "Three") !== FALSE) $CardCount += 3; else if (strpos($PlayersHand[$i], "Four") !== FALSE) $CardCount += 4; else if (strpos($PlayersHand[$i], "Five") !== FALSE) $CardCount += 5; else if (strpos($PlayersHand[$i], "Six") !== FALSE) $CardCount += 6; else if (strpos($PlayersHand[$i], "Seven") !== FALSE) $CardCount += 7; else if (strpos($PlayersHand[$i], "Eight") !== FALSE) $CardCount += 8; else if (strpos($PlayersHand[$i], "Nine") !== FALSE) $CardCount += 9; else if (strpos($PlayersHand[$i], "Ten") !== FALSE) $CardCount += 10; else if (strpos($PlayersHand[$i], "Jack") !== FALSE) $CardCount += 10; else if (strpos($PlayersHand[$i], "Queen") !== FALSE) $CardCount += 10; else if (strpos($PlayersHand[$i], "King") !== FALSE) $CardCount += 10; } $Cards = $Cards .implode("~", $PlayersHand); if ($Aces > 0) { for ($i=1; $i<=$Aces;++$i) { if ($CardCount+11 <= 21) $CardCount += 11; else $CardCount += 1; } } if ($CardCount == 21) $Cards = $Cards . "\nYou win!"; else if ($CardCount> 21) $Cards = $Cards . "\nYou lose!"; //print $Deck; print <<<HERE </tr></td> <tr> <td colspan = "7"> <center> <input type = "submit" value = "play hand"> </center> </td> </tr> </table> HERE;*/ }//end function function Cards2($number){ $Diamonds = array( "Ace of Diamonds", "Two of Diamonds", "Three of Diamonds", "Four of Diamonds", "Five of Diamonds", "Six of Diamonds", "Seven of Diamonds", "Eight of Diamonds", "Nine of Diamonds", "Ten of Diamonds", "Jack of Diamonds", "Queen of Diamonds", "King of Diamonds"); $Clubs = array( "Ace of Clubs", "Two of Clubs", "Three of Clubs", "Four of Clubs", "Five of Clubs", "Six of Clubs", "Seven of Clubs", "Eight of Clubs", "Nine of Clubs", "Ten of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs"); $Hearts = array( "Ace of Hearts", "Two of Hearts", "Three of Hearts", "Four of Hearts", "Five of Hearts", "Six of Hearts", "Seven of Hearts", "Eight of Hearts", "Nine of Hearts", "Ten of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts"); $Spades = array( "Ace of Spades", "Two of Spades", "Three of Spades", "Four of Spades", "Five of Spades", "Six of Spades", "Seven of Spades", "Eight of Spades", "Nine of Spades", "Ten of Spades", "Jack of Spades", "Queen of Spades", "King of Spades"); $Cards = array_merge($Diamonds, $Clubs); $Cards = array_merge($Cards, $Hearts); $Cards = array_merge($Cards, $Spades); //$Deck = shuffle($Cards); $num1 = rand(1,52); echo $Cards[$num1]; //echo " ____ "; // }else{ // echo "There is no cards being displayed."; // }//close second if statement // }//close first if statement $cards_array[2] = $Cards[$num1]; //it take the object of a string and pass it as a array. $serialCards = urlencode(serialize($cards_array)); print_r($cards_array); print "<br>"; print $serialCards; print $cards_array[0]; print $cards_array[1]; print $cards_array[2]; print <<<HERE </tr></td> <tr> <td colspan = "5"> <center> <form methods = "post" action = "PokerFinal.php"> <input type = "submit" value = "Hit Me"> <input type = "hidden" name = "number" value = "$serialCards"> <input type ="hidden" name ="statue" value = "2"> </form> </center> </td> </tr> </table> HERE; print <<<HERE </tr></td> <tr> <td colspan = "5"> <center> <input type = "submit" value = "roll again"> </center> </td> </tr> </table> HERE; } function Cards3($number){ $Diamonds = array( "Ace of Diamonds", "Two of Diamonds", "Three of Diamonds", "Four of Diamonds", "Five of Diamonds", "Six of Diamonds", "Seven of Diamonds", "Eight of Diamonds", "Nine of Diamonds", "Ten of Diamonds", "Jack of Diamonds", "Queen of Diamonds", "King of Diamonds"); $Clubs = array( "Ace of Clubs", "Two of Clubs", "Three of Clubs", "Four of Clubs", "Five of Clubs", "Six of Clubs", "Seven of Clubs", "Eight of Clubs", "Nine of Clubs", "Ten of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs"); $Hearts = array( "Ace of Hearts", "Two of Hearts", "Three of Hearts", "Four of Hearts", "Five of Hearts", "Six of Hearts", "Seven of Hearts", "Eight of Hearts", "Nine of Hearts", "Ten of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts"); $Spades = array( "Ace of Spades", "Two of Spades", "Three of Spades", "Four of Spades", "Five of Spades", "Six of Spades", "Seven of Spades", "Eight of Spades", "Nine of Spades", "Ten of Spades", "Jack of Spades", "Queen of Spades", "King of Spades"); $Cards = array_merge($Diamonds, $Clubs); $Cards = array_merge($Cards, $Hearts); $Cards = array_merge($Cards, $Spades); //$Deck = shuffle($Cards); $num1 = rand(1,52); echo $Cards[$num1]; //echo " ____ "; // }else{ // echo "There is no cards being displayed."; // }//close second if statement // }//close first if statement $cards_array[3] = $Cards[$num1]; //it take the object of a string and pass it as a array. $serialCards = urlencode(serialize($cards_array)); print_r($cards_array); print "<br>"; print $serialCards; print $cards_array[0]; print $cards_array[1]; print $cards_array[2]; print $cards_array[3]; print <<<HERE </tr></td> <tr> <td colspan = "5"> <center> <form methods = "post" action = "PokerFinal.php"> <input type = "submit" value = "Hit Me"> <input type = "hidden" name = "number" value = "$serialCards"> <input type ="hidden" name ="statue" value = "3"> </form> </center> </td> </tr> </table> HERE; print <<<HERE </tr></td> <tr> <td colspan = "5"> <center> <input type = "submit" value = "roll again"> </center> </td> </tr> </table> HERE; } function Cards4($number){ $Diamonds = array( "Ace of Diamonds", "Two of Diamonds", "Three of Diamonds", "Four of Diamonds", "Five of Diamonds", "Six of Diamonds", "Seven of Diamonds", "Eight of Diamonds", "Nine of Diamonds", "Ten of Diamonds", "Jack of Diamonds", "Queen of Diamonds", "King of Diamonds"); $Clubs = array( "Ace of Clubs", "Two of Clubs", "Three of Clubs", "Four of Clubs", "Five of Clubs", "Six of Clubs", "Seven of Clubs", "Eight of Clubs", "Nine of Clubs", "Ten of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs"); $Hearts = array( "Ace of Hearts", "Two of Hearts", "Three of Hearts", "Four of Hearts", "Five of Hearts", "Six of Hearts", "Seven of Hearts", "Eight of Hearts", "Nine of Hearts", "Ten of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts"); $Spades = array( "Ace of Spades", "Two of Spades", "Three of Spades", "Four of Spades", "Five of Spades", "Six of Spades", "Seven of Spades", "Eight of Spades", "Nine of Spades", "Ten of Spades", "Jack of Spades", "Queen of Spades", "King of Spades"); $Cards = array_merge($Diamonds, $Clubs); $Cards = array_merge($Cards, $Hearts); $Cards = array_merge($Cards, $Spades); //$Deck = shuffle($Cards); $num1 = rand(1,52); echo $Cards[$num1]; //echo " ____ "; // }else{ // echo "There is no cards being displayed."; // }//close second if statement // }//close first if statement $cards_array[4] = $Cards[$num1]; //it take the object of a string and pass it as a array. $serialCards = urlencode(serialize($cards_array)); print_r($cards_array); print "<br>"; print $serialCards; print <<<HERE </tr></td> <tr> <td colspan = "5"> <center> <form methods = "post" action = "PokerFinal.php"> <input type = "submit" value = "Hit Me"> <input type = "hidden" name = "number" value = "$serialCards"> <input type ="hidden" name ="statue" value = "4"> </form> </center> </td> </tr> </table> HERE; print <<<HERE </tr></td> <tr> <td colspan = "5"> <center> <input type = "submit" value = "roll again"> </center> </td> </tr> </table> HERE; } function Cards5($number){ $Diamonds = array( "Ace of Diamonds", "Two of Diamonds", "Three of Diamonds", "Four of Diamonds", "Five of Diamonds", "Six of Diamonds", "Seven of Diamonds", "Eight of Diamonds", "Nine of Diamonds", "Ten of Diamonds", "Jack of Diamonds", "Queen of Diamonds", "King of Diamonds"); $Clubs = array( "Ace of Clubs", "Two of Clubs", "Three of Clubs", "Four of Clubs", "Five of Clubs", "Six of Clubs", "Seven of Clubs", "Eight of Clubs", "Nine of Clubs", "Ten of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs"); $Hearts = array( "Ace of Hearts", "Two of Hearts", "Three of Hearts", "Four of Hearts", "Five of Hearts", "Six of Hearts", "Seven of Hearts", "Eight of Hearts", "Nine of Hearts", "Ten of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts"); $Spades = array( "Ace of Spades", "Two of Spades", "Three of Spades", "Four of Spades", "Five of Spades", "Six of Spades", "Seven of Spades", "Eight of Spades", "Nine of Spades", "Ten of Spades", "Jack of Spades", "Queen of Spades", "King of Spades"); $Cards = array_merge($Diamonds, $Clubs); $Cards = array_merge($Cards, $Hearts); $Cards = array_merge($Cards, $Spades); //$Deck = shuffle($Cards); $num1 = rand(1,52); $num2 = rand(1,52); echo $Cards[$num1]; //echo " ____ "; // }else{ // echo "There is no cards being displayed."; // }//close second if statement // }//close first if statement $cards_array[5] = $Cards[$num1]; //it take the object of a string and pass it as a array. $serialCards = urlencode(serialize($cards_array)); print_r($cards_array); print "<br>"; print $serialCards; print <<<HERE </tr></td> <tr> <td colspan = "5"> <center> <form methods = "post" action = "PokerFinal.php"> <input type = "submit" value = "Hit Me"> <input type = "hidden" name = "number" value = "$serialCards"> <input type ="hidden" name ="statue" value = "5"> </form> </center> </td> </tr> </table> HERE; print <<<HERE </tr></td> <tr> <td colspan = "5"> <center> <input type = "submit" value = "roll again"> </center> </td> </tr> </table> HERE; } function Cards6($number){ $Diamonds = array( "Ace of Diamonds", "Two of Diamonds", "Three of Diamonds", "Four of Diamonds", "Five of Diamonds", "Six of Diamonds", "Seven of Diamonds", "Eight of Diamonds", "Nine of Diamonds", "Ten of Diamonds", "Jack of Diamonds", "Queen of Diamonds", "King of Diamonds"); $Clubs = array( "Ace of Clubs", "Two of Clubs", "Three of Clubs", "Four of Clubs", "Five of Clubs", "Six of Clubs", "Seven of Clubs", "Eight of Clubs", "Nine of Clubs", "Ten of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs"); $Hearts = array( "Ace of Hearts", "Two of Hearts", "Three of Hearts", "Four of Hearts", "Five of Hearts", "Six of Hearts", "Seven of Hearts", "Eight of Hearts", "Nine of Hearts", "Ten of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts"); $Spades = array( "Ace of Spades", "Two of Spades", "Three of Spades", "Four of Spades", "Five of Spades", "Six of Spades", "Seven of Spades", "Eight of Spades", "Nine of Spades", "Ten of Spades", "Jack of Spades", "Queen of Spades", "King of Spades"); $Cards = array_merge($Diamonds, $Clubs); $Cards = array_merge($Cards, $Hearts); $Cards = array_merge($Cards, $Spades); //$Deck = shuffle($Cards); $num1 = rand(1,52); echo $Cards[$num1]; //echo " ____ "; // }else{ // echo "There is no cards being displayed."; // }//close second if statement // }//close first if statement $cards_array[6] = $Cards[$num1]; //it take the object of a string and pass it as a array. $serialCards = urlencode(serialize($cards_array)); print_r($cards_array); print "<br>"; print $serialCards; print <<<HERE </tr></td> <tr> <td colspan = "5"> <center> <form methods = "post" action = "PokerFinal.php"> <input type = "submit" value = "Hit Me"> <input type = "hidden" name = "number" value = "$serialCards"> <input type ="hidden" name ="statue" value = "6"> </form> </center> </td> </tr> </table> HERE; print <<<HERE </tr></td> <tr> <td colspan = "5"> <center> <input type = "submit" value = "roll again"> </center> </td> </tr> </table> HERE; } function Cards7($number){ $Diamonds = array( "Ace of Diamonds", "Two of Diamonds", "Three of Diamonds", "Four of Diamonds", "Five of Diamonds", "Six of Diamonds", "Seven of Diamonds", "Eight of Diamonds", "Nine of Diamonds", "Ten of Diamonds", "Jack of Diamonds", "Queen of Diamonds", "King of Diamonds"); $Clubs = array( "Ace of Clubs", "Two of Clubs", "Three of Clubs", "Four of Clubs", "Five of Clubs", "Six of Clubs", "Seven of Clubs", "Eight of Clubs", "Nine of Clubs", "Ten of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs"); $Hearts = array( "Ace of Hearts", "Two of Hearts", "Three of Hearts", "Four of Hearts", "Five of Hearts", "Six of Hearts", "Seven of Hearts", "Eight of Hearts", "Nine of Hearts", "Ten of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts"); $Spades = array( "Ace of Spades", "Two of Spades", "Three of Spades", "Four of Spades", "Five of Spades", "Six of Spades", "Seven of Spades", "Eight of Spades", "Nine of Spades", "Ten of Spades", "Jack of Spades", "Queen of Spades", "King of Spades"); $Cards = array_merge($Diamonds, $Clubs); $Cards = array_merge($Cards, $Hearts); $Cards = array_merge($Cards, $Spades); //$Deck = shuffle($Cards); $num1 = rand(1,52); $num2 = rand(1,52); echo $Cards[$num1]; //echo " ____ "; // }else{ // echo "There is no cards being displayed."; // }//close second if statement // }//close first if statement $cards_array[7] = $Cards[$num1]; //it take the object of a string and pass it as a array. $serialCards = urlencode(serialize($cards_array)); print_r($cards_array); print "<br>"; print $serialCards; print <<<HERE </tr></td> <tr> <td colspan = "5"> <center> <form methods = "post" action = "PokerFinal.php"> <input type = "submit" value = "Hit Me"> <input type = "hidden" name = "number" value = "$serialCards"> <input type ="hidden" name ="statue" value = "7"> </form> </center> </td> </tr> </table> HERE; print <<<HERE </tr></td> <tr> <td colspan = "5"> <center> <input type = "submit" value = "roll again"> </center> </td> </tr> </table> HERE; } function Cards8($number){ $Diamonds = array( "Ace of Diamonds", "Two of Diamonds", "Three of Diamonds", "Four of Diamonds", "Five of Diamonds", "Six of Diamonds", "Seven of Diamonds", "Eight of Diamonds", "Nine of Diamonds", "Ten of Diamonds", "Jack of Diamonds", "Queen of Diamonds", "King of Diamonds"); $Clubs = array( "Ace of Clubs", "Two of Clubs", "Three of Clubs", "Four of Clubs", "Five of Clubs", "Six of Clubs", "Seven of Clubs", "Eight of Clubs", "Nine of Clubs", "Ten of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs"); $Hearts = array( "Ace of Hearts", "Two of Hearts", "Three of Hearts", "Four of Hearts", "Five of Hearts", "Six of Hearts", "Seven of Hearts", "Eight of Hearts", "Nine of Hearts", "Ten of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts"); $Spades = array( "Ace of Spades", "Two of Spades", "Three of Spades", "Four of Spades", "Five of Spades", "Six of Spades", "Seven of Spades", "Eight of Spades", "Nine of Spades", "Ten of Spades", "Jack of Spades", "Queen of Spades", "King of Spades"); $Cards = array_merge($Diamonds, $Clubs); $Cards = array_merge($Cards, $Hearts); $Cards = array_merge($Cards, $Spades); //$Deck = shuffle($Cards); $num1 = rand(1,52); echo $Cards[$num1]; //echo " ____ "; // }else{ // echo "There is no cards being displayed."; // }//close second if statement // }//close first if statement $cards_array[8] = $Cards[$num1]; //it take the object of a string and pass it as a array. $serialCards = urlencode(serialize($cards_array)); print_r($cards_array); print "<br>"; print $serialCards; print <<<HERE </tr></td> <tr> <td colspan = "5"> <center> <form methods = "post" action = "PokerFinal.php"> <input type = "submit" value = "Hit Me"> <input type = "hidden" name = "number" value = "$serialCards"> <input type ="hidden" name ="statue" value = "8"> </form> </center> </td> </tr> </table> HERE; print <<<HERE </tr></td> <tr> <td colspan = "5"> <center> <input type = "submit" value = "roll again"> </center> </td> </tr> </table> HERE; } function Cards9($number){ $Diamonds = array( "Ace of Diamonds", "Two of Diamonds", "Three of Diamonds", "Four of Diamonds", "Five of Diamonds", "Six of Diamonds", "Seven of Diamonds", "Eight of Diamonds", "Nine of Diamonds", "Ten of Diamonds", "Jack of Diamonds", "Queen of Diamonds", "King of Diamonds"); $Clubs = array( "Ace of Clubs", "Two of Clubs", "Three of Clubs", "Four of Clubs", "Five of Clubs", "Six of Clubs", "Seven of Clubs", "Eight of Clubs", "Nine of Clubs", "Ten of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs"); $Hearts = array( "Ace of Hearts", "Two of Hearts", "Three of Hearts", "Four of Hearts", "Five of Hearts", "Six of Hearts", "Seven of Hearts", "Eight of Hearts", "Nine of Hearts", "Ten of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts"); $Spades = array( "Ace of Spades", "Two of Spades", "Three of Spades", "Four of Spades", "Five of Spades", "Six of Spades", "Seven of Spades", "Eight of Spades", "Nine of Spades", "Ten of Spades", "Jack of Spades", "Queen of Spades", "King of Spades"); $Cards = array_merge($Diamonds, $Clubs); $Cards = array_merge($Cards, $Hearts); $Cards = array_merge($Cards, $Spades); //$Deck = shuffle($Cards); $num1 = rand(1,52); echo $Cards[$num1]; //echo " ____ "; // }else{ // echo "There is no cards being displayed."; // }//close second if statement // }//close first if statement $cards_array[9] = $Cards[$num1]; //it take the object of a string and pass it as a array. $serialCards = urlencode(serialize($cards_array)); print_r($cards_array); print "<br>"; print $serialCards; // print <<<HERE // </tr></td> // <tr> // <td colspan = "5"> // <center> //<form methods = "post" // action = "PokerFinal.php"> //<input type = "submit" // value = "Hit Me"> // <input type = "hidden" // name = "number" // value = "$serialCards"> // <input type ="hidden" // name ="statue" // value = "9"> //</form> //</center> // </td> // </tr> // </table> //HERE; print "No more HIT ME button"; print <<<HERE </tr></td> <tr> <td colspan = "5"> <center> <input type = "submit" value = "roll again"> </center> </td> </tr> </table> HERE; } function printPage(){ }//end functon //function rollDice(){ // global $die, $secondRoll, $keepIt; //print "<table border = 1><td><tr>"; //for ($i = 0; $i < 5; $i++){ //if ($keepIt[$i] == ""){ //$die[$i] = rand(1, 6); //} else { //$die[$i] = $keepIt[$i]; //} // end if //$theFile = "die" . $die[$i] . ".jpg"; //print out dice images // print <<<HERE // <td> // <img src = "$theFile" // height = 50 // width = 50><br> //HERE; //print out a checkbox on first roll only // if ($secondRoll == FALSE){ // print <<<HERE // <input type = "checkbox" // name = "keepIt[$i]" //value = $die[$i]> //</td> //HERE; // } // end if // } // end for loop //print out submit button and end of table //print <<<HERE //</tr></td> //<tr> // <td colspan = "5"> // <center> //<input type = "submit" // value = "roll again"> //</center> // </td> //</tr> //</table> //HERE; //} // end rollDice function evaluate(){ global $die, $cash; //set up payoff $payoff = 0; //subtract some money for this roll $cash -= 2; //count the dice for ($theVal = 1; $theVal <= 6; $theVal++){ for ($dieNum = 0; $dieNum < 5; $dieNum++){ if ($die[$dieNum] == $theVal){ $numVals[$theVal]++; } // end if } // end dieNum for loop } // end theVal for loop //print out results // for ($i = 1; $i <= 6; $i++){ // print "$i: $numVals[$i]<br>\n"; // } // end for loop //count how many pairs, threes, fours, fives $numPairs = 0; $numThrees = 0; $numFours = 0; $numFives = 0; for ($i = 1; $i <= 6; $i++){ switch ($numVals[$i]){ case 2: $numPairs++; break; case 3: $numThrees++; break; case 4: $numFours++; break; case 5: $numFives++; break; } // end switch } // end for loop //check for two pairs if ($numPairs == 2){ print "You have two pairs!<br>\n"; $payoff = 1; } // end if //check for three of a kind and full house if ($numThrees == 1){ if ($numPairs == 1){ //three of a kind and a pair is a full house print "You have a full house!<br>\n"; $payoff = 5; } else { print "You have three of a kind!<br>\n"; $payoff = 2; } // end 'pair' if } // end 'three' if //check for four of a kind if ($numFours == 1){ print "You have four of a kind!<br>\n"; $payoff = 5; } // end if //check for five of a kind if ($numFives == 1){ print "You got five of a kind!<br>\n"; $payoff = 10; } // end if //check for flushes if (($numVals[1] == 1) && ($numVals[2] == 1) && ($numVals[3] == 1) && ($numVals[4] == 1) && ($numVals[5] == 1)){ print "You have a flush!<br>\n"; $payoff = 10; } // end if if (($numVals[2] == 1) && ($numVals[3] == 1) && ($numVals[4] == 1) && ($numVals[5] == 1) && ($numVals[6] == 1)){ print "You have a flush!<br>\n"; $payoff = 10; } // end if print "You bet 2<br>\n"; print "Payoff is $payoff<br>\n"; $cash += $payoff; } // end evaluate function printStuff(){ global $cash, $secondRoll; print "Cash: $cash\n"; //store variables in hidden fields print <<<HERE <input type = "hidden" name = "secondRoll" value = "$secondRoll"> <input type = "hidden" name = "cash" value = "$cash"> HERE; } // end printStuff ?> </form> </center> </html> |