PHP - Php Random Problem - Pick Your Poison Game
I developed this game and I couldn't figure how to make random only on available shot glasses but it would still random with unavailable shot glasses. I simple give up. I plan to share this php once I nailed it down but apparently, not successful. Now, I'm share with you anyway. If you can solve the problem and please let us know!
http://pastebin.com/F3N05ExK Similar TutorialsWow, 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, 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! Can someone help me create this?? Upon outside entry, a random number is chosen between 1 and 10. Use this function to generate the guess number $guessnum = rand(1,10); // you may change the variable name The user tries to guess this number by choosing from a selection list of possibilities. The user "loses" if there are three failed attempts. For reentrant activations the selection list must be sticky and the same guess number must be maintained. The guess number and the attempt number must both be propagated through hidden inputs. Here is a screen shot: Upon outside entry, or using the "Start Over" hyperlink (with the list activated): Let's suppose the number to be guessed is 6. I select 4 and guess it. Response should say "Try #1" I select 9 and guess it. Response should say "Try #2" I select 3 and guess it. Response should say "You Lose" At this point assume that we must "Start Over". This time, suppose the generated number is 8. I select 8 and guess it. Response should say "You Win" Again, assume we must "Start Over". Hello, 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. I have five names in an array and also numbers 5,2,1,3 and what i want to do is php to look at the numbers and print out the name that corresponds to the number. so for my example the name it should echo out is 'Lee'
$names = array ("Stan", "John", "Dean", "Sam", "Lee"); here are the five names. The idea is to learn php with making a little fixture list with these five names. The problem i have is to make php read the number and then look up the array for the name that corresponds to the number. I hope this explains what I would like to do?
Hi guys, I need to pick the middle five numbers from a range of numbers example $lowest number = 0; // this will allways be 0 $highest_number = 10; // this can very from 1 to 10000 $selected_number = 5; // this can also very but it will allways be between 0 and highest number the middles numbers from the above 3 varuables should be 3 4 5 6 7 --- the $selected_number number allways needs to be the middle number // some of the issue we need to watch out for is, if hughest number is 4 then it should just go 1 2 3 4 Thank you guys Hey, I have an array which stores a bunch of numbers lets say: Code: [Select] [0] = 1[1] = 6 Now a second array has: Code: [Select] [0] = 5 [1] = 6 What im trying to do - is find the first highest number from the second array that is not found in the first array.Both arrays are sorted already by the way using sort(). What is the best way to do this? I am not getting any error messages as I just think the codes are wrong. I am trying to get the $sql(s) to choose and print out the the looking_for in the database. However it is not printing anything. Any ideas of where I am need to fix this. I have tried a few ways with no luck. $sql = mysql_query("SELECT id,gender,looking_for FROM Members"); $nr = mysql_num_rows($sql); $sql2 = mysql_query("SELECT * FROM Members WHERE id='".($_POST['$looking_for'])."' LIMIT $pn, $itemsPerPage"); $outputList = ''; while($row = mysql_fetch_array($sql2)) { $id = $row["id"]; $username = $row["username"]; $firstname = $row["firstname"]; if (!$firstname) { $firstname = $username; } $gender=''; $looking_for=''; I Have the following issue and I spend my whole day looking for it. I have a database with a simple admin where I add/delete values. The database structure is the following: id, zip, email The database is called zipdatabase Here is the mailing part: Code: [Select] //headers $headers = "From: <$Email>"; $headers .= "\r\nBcc: <$Bcc>\r\n\r\n"; // send email $success = mail($EmailTo, $Subject, $Body, $headers);The variable $Bcc must come from the database. I am really ignorant so I only got to a point on how to echo the results I need (and this works): Code: [Select] $query = "SELECT email FROM zipdatabase WHERE zip = '$ZIP'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { echo "{$r['email']}, "; } ?> For a zip I get more than one result so when I tried using this Code: [Select] $query = "SELECT email FROM zipdatabase WHERE zip = '$ZIP'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { $Bcc = "{$r['email']}, "; } echo "Bcc" ?> It only gives me one result. What I noticed is I have 2 issues: - I can't extract the BCC from the database - I don't know how to add more email addresses to the bcc field, I only managed to add more addresses to the $Emailto like: Code: [Select] $EmailTo = "address1@domain.com, address2@domain.com"; $Bcc = "address3@domain.com"; All these variables are defined by a webform and it works flawlessly except the database problem: Code: [Select] $Name = Trim(stripslashes($_POST['Name'])); $Phone = Trim(stripslashes($_POST['Phone'])); $ZIP = Trim(stripslashes($_POST['ZIP'])); $Email = Trim(stripslashes($_POST['Email'])); $Message = Trim(stripslashes($_POST['Message'])); // validation $validationOK=true; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=contacterror.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Phone: "; $Body .= $Phone; $Body .= "\n"; $Body .= "ZIP: "; $Body .= $ZIP; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; Sorry for my ignorance and hope someone here can help. The webform works perfectly except the bcc from the database part. Code: [Select] function choose_numbers($number,$max) { global $ibforums,$std; srand( (double)microtime() * 1000000 ); $array = array(); $i = 0; while($i!=$number) { $array[] = mt_rand(1,$max); $i++; } $c = count($array); while($c != $number) { $array[] = mt_rand(1,$max); $c = count($array); if($c == $number) { $array = array_unique($array); $c = count($array); } } return $array; } $newnumbers = $this->choose_numbers(3,36); echo "{$newnumbers['0']}|{$newnumbers['1']}|{$newnumbers['2']}"; This echo's out my lottery balls 0|32|22 or technically RANDNuMbER|RANDNUMBER|RANDNUMBER up to 36 is the highest number. Now my issue is, I don't want 2 numbers of the same Value, EVER. Sometimes it does 2|3|2 which is BAD (for my lottery system) is there anyway I can make it so it never will echo out 2 (OR 3) of the same number? I am creating a program to simulate the Powerball Lottery game, I have everything working but i forgot to add the Quick Pick Option, having alittle bit of an issue with my "if" statement I believe. My confusion is whether it should be a nested "if", or should it be it's own entity? Here's what i have so far: Code: [Select] <?php $intGrandPize = 10000000; $intRegCount = 5; $intMaxReg = 59; $intMaxPB = 39; //$quick = rand(1, 59); //$quickPB = rand(1, 49); if (isset($_POST['Quick Pick'])){ if (count($_POST)>0) { $aryPick = array(); $intPower = 0; for($t=1;$t<=$intRegCount;$t++) { if (isset($_POST['num'.$t])) { $intPick = (int)$_POST['num'.$t]; if ($intPick > 0 && $intPick <= $intMaxReg && !in_array($intPick,$aryPick)) { $aryPick[] = $intPick; } } } if (isset($_POST['Power']) && (int)$_POST['Power'] > 0 && $_POST['Power'] <= $intMaxPB) { $intPower = (int)$_POST['Power']; } if (count($aryPick) < 5 || $intPower == 0) { echo "<font color='red'>'*Five unique numbers and a PowerBall selection are Required*'</font>";; } else { // Have valid numbers... sort($aryPick); // For if you are going to display them, they will be in order... // Pick your winners $aryAllBalls = range(1,$intMaxReg); // array of numbers 1 - 59 shuffle($aryAllBalls); // Randomize their order $aryAllBalls = array_chunk($aryAllBalls,$intRegCount); // The above breaks up into an array with 5 numbers each // [0] contains the first 5 balls of all balls randomized, these are what are "picked" $aryPickedBalls = $aryAllBalls[0]; sort($aryPickedBalls); // Sort them for display $intPowerBall = rand(1,$intMaxPB); echo "YOUR WINNING NUMBERS A <br>",implode(' ',$aryPickedBalls),' PB: ',$intPowerBall,"<br>\n<br>\n"; echo "You Picked: "; foreach($aryPick as $key=>$val) { if (in_array($val,$aryPickedBalls)) { echo '<strong>',$val,'</strong> '; } else { echo $val,' '; unset($aryPick[$key]); // Remove it since it didn't match } } $bMatchPB = ($intPower == $intPowerBall); // Set here since checked in 3 places... if ($bMatchPB) { echo 'PB: <strong>',$intPower,"</strong><br>\n<br>\n"; } else { echo 'PB: '.$intPower,"<br>\n<br>\n"; } // At this point, $aryPick will only contain matching numbers... $intMatches = count($aryPick); echo 'You matched '.$intMatches,' numbers and did '; if (!$bMatchPB) { echo 'not '; } echo "match the PowerBall number.<br><br>\n\n"; // HERE YOU WOULD DO SOMETHING TO SAY HOW MUCH THEY WON if ($intMatches>=3 || $bMatchPB) { $intWinnings = 0; switch ($intMatches) { case 0: if ($bMatchPB) { $intWinnings = 3; } break; case 1: if ($bMatchPB) { $intWinnings = 4; } break; case 2: if ($bMatchPB) { $intWinnings = 7; } break; case 3: if ($bMatchPB) { $intWinnings = 100; } else { $intWinnings = 7; } break; case 4: if ($bMatchPB) { $intWinnings = 10000; } else { $intWinnings = 100; } break; case 5: if ($bMatchPB) { $intWinnings = $intGrandPize; } else { $intWinnings = 200000; } break; default: echo "ERROR: Winning Combination not defined in systen!!!<br>\n"; } echo "<strong>YOU ARE A WINNER!!!!</strong><br>\n"; echo 'You Won: $'.number_format($intWinnings,0),"<br>\n"; } else { echo "Sorry, you didn't win. Try again!<br>\n"; } } // END: if (had valid numbers picked) } // END: There was data posted (ie. Form submitted) ?> Hi, I need to write some code for this but unsure where to start. Basically i have a database of say 10 rows. I need to be able to input a number and some sort of fair algorithm will choose one of the rows. The number will be from 6 to 10 numbers long, and will need to pick the same result each time based on that number. Its for a lotto game i'm creating a ticketing system and i need some assistance. The code directly below displays the database records and the delete works fine. The edit however isn't picking the values in the various fields.
<?Php require "config.php"; $page_name="currentout.php"; $start=$_GET['start']; if(strlen($start) > 0 and !is_numeric($start)){ echo "Data Error"; exit; } $eu = ($start - 0); $limit = 10; $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; $nume = $dbo->query("select count(id) from receipt")->fetchColumn(); echo "<TABLE class='t1'>"; echo "<tr><th>ID</th><th>Name</th><th>Pass</th><th>Amount</th><th>Action</th></tr>"; $query=" SELECT * FROM receipt limit $eu, $limit "; foreach ($dbo->query($query) as $row) { @$m=$i%2; @$i=$i+1; echo "<tr class='r$m'><td>$row[id]</td><td>$row[name]</td><td>$row[phone_num]</td><td>$row[Amount]</td><td><a href='delete.php?id=$row[id]'>delete</a></td><td><a href='edit.php?id=$row[id]'>Edit</a></td></tr>"; } echo "</table>"; if($nume > $limit ){ echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>"; if($back >=0) { print "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>"; } echo "</td><td align=center width='30%'>"; $i=0; $l=1; for($i=0;$i < $nume;$i=$i+$limit){ if($i <> $eu){ echo " <a href='$page_name?start=$i'><font face='Verdana' size='2'>$l</font></a> "; } else { echo "<font face='Verdana' size='4' color=red>$l</font>";} $l=$l+1; } echo "</td><td align='right' width='30%'>"; if($this1 < $nume) { print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";} echo "</td></tr></table>"; } ?>The code below is edit.php. It's supposed to display the various fields when clicked to allow for editing but it isn't picking any field, PLEASE assist. <?Php require "config.php"; $sql = "SELECT FROM receipt WHERE ID= :ID"; $stmt = $dbo->prepare($sql); $stmt->bindParam(':ID', $_GET['id'], PDO::PARAM_INT); $stmt->execute(); ?> <form action="update.php" method="post" enctype="multipart/form-data"> <table align="center"> <tr> <td> <label><strong>Full Names</strong></label></td> <td> <input type='text' name='name' value=" <?php echo $row['name']; ?>" /> <input type="hidden" name="id" value="<?php echo $id; ?> " /> <br /></td> </tr> <tr> <td><label><strong>ID/Passport No. </strong></label></td> <td> <input type="text" name="pass" value="<?php echo $row['id_passno']; ?> " /><br /></td> </tr> <tr> <td> <label><strong>Phone No. </strong></label></td> <td><input type="text" name="phone" value="<?php echo $row['phone_num']; ?>" /> <br /></td> </tr> <tr> <td> <label><strong>Amount (KShs.) </strong></label></td> <td><input type="text" name="amount" value="<?php echo $row['Amount']; ?> "/> <br /></td> </tr> <tr> <td> <input type="reset" name="Reset" value="CANCEL" onClick="return confirm('Discard changes?');" /> <br></td> <td> <input type="submit" name="Submit2" value="SUBMIT" /> </td> </tr> </table> </form> i'm creating a ticketing system and i need some assistance. The code directly below displays the database records and the delete works fine. The edit however isn't picking the values in the various fields.
<?Php require "config.php"; $page_name="currentout.php"; $start=$_GET['start']; if(strlen($start) > 0 and !is_numeric($start)){ echo "Data Error"; exit; } $eu = ($start - 0); $limit = 10; $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; $nume = $dbo->query("select count(id) from receipt")->fetchColumn(); echo "<TABLE class='t1'>"; echo "<tr><th>ID</th><th>Name</th><th>Pass</th><th>Amount</th><th>Action</th></tr>"; $query=" SELECT * FROM receipt limit $eu, $limit "; foreach ($dbo->query($query) as $row) { @$m=$i%2; @$i=$i+1; echo "<tr class='r$m'><td>$row[id]</td><td>$row[name]</td><td>$row[phone_num]</td><td>$row[Amount]</td><td><a href='delete.php?id=$row[id]'>delete</a></td><td><a href='edit.php?id=$row[id]'>Edit</a></td></tr>"; } echo "</table>"; if($nume > $limit ){ echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>"; if($back >=0) { print "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>"; } echo "</td><td align=center width='30%'>"; $i=0; $l=1; for($i=0;$i < $nume;$i=$i+$limit){ if($i <> $eu){ echo " <a href='$page_name?start=$i'><font face='Verdana' size='2'>$l</font></a> "; } else { echo "<font face='Verdana' size='4' color=red>$l</font>";} $l=$l+1; } echo "</td><td align='right' width='30%'>"; if($this1 < $nume) { print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";} echo "</td></tr></table>"; } ?>The code below is edit.php. It's supposed to display the various fields when clicked to allow for editing but it isn't picking any field, PLEASE assist. <?Php require "config.php"; $sql = "SELECT FROM receipt WHERE ID= :ID"; $stmt = $dbo->prepare($sql); $stmt->bindParam(':ID', $_GET['id'], PDO::PARAM_INT); $stmt->execute(); ?> <form action="update.php" method="post" enctype="multipart/form-data"> <table align="center"> <tr> <td> <label><strong>Full Names</strong></label></td> <td> <input type='text' name='name' value=" <?php echo $row['name']; ?>" /> <input type="hidden" name="id" value="<?php echo $id; ?> " /> <br /></td> </tr> <tr> <td><label><strong>ID/Passport No. </strong></label></td> <td> <input type="text" name="pass" value="<?php echo $row['id_passno']; ?> " /><br /></td> </tr> <tr> <td> <label><strong>Phone No. </strong></label></td> <td><input type="text" name="phone" value="<?php echo $row['phone_num']; ?>" /> <br /></td> </tr> <tr> <td> <label><strong>Amount (KShs.) </strong></label></td> <td><input type="text" name="amount" value="<?php echo $row['Amount']; ?> "/> <br /></td> </tr> <tr> <td> <input type="reset" name="Reset" value="CANCEL" onClick="return confirm('Discard changes?');" /> <br></td> <td> <input type="submit" name="Submit2" value="SUBMIT" /> </td> </tr> </table> </form> I am using extra fees extension, if customer chooses shipping method: Pick from the store how to remove Handling fees(extra fees extension).
How to solve by using observer? Edited August 12, 2019 by aveevaAs above, I have a lottery style site that picks a random number between 1-8 but my users complain for some reason that this is not enough. So i was told to look into using fopen and random.org to generate a random number. Anyone have experience of this and perhaps a code snippet for me to look at and possibly use? help will be appreciated. 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> 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. 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? 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? |