PHP - Black Jack Game Help
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> 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 guys i need some help i am trying to create a resized image with a watermark, from an uploaded image.. the image is getting uploaded and resized but the watermark doesnt appear correct. instead of a transparent watermark, there's a black square in it's place. this is my code Code: [Select] $tempfile = $_FILES['filename']['tmp_name']; $src = imagecreatefromjpeg($tempfile); list($origWidth, $origHeight) = getimagesize($tempfile); // creating png image of watermark $watermark = imagecreatefrompng('../imgs/watermark.png'); // getting dimensions of watermark image $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); // placing the watermark $dest_x = $origWidth / 2 - $watermark_width / 2; $dest_y = $origHeight / 2 - $watermark_height / 2; imagecopyresampled($src, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $origWidth, $origHeight); imagealphablending($src, true); imagealphablending($watermark, true); imagejpeg($src,$galleryPhotoLocation,100); // $galleryPhotoLocation is correct. the image gets uploaded successfully.. I'm importing a CSV using the fgetcsv() function, which is working all good. However, when I take a look at the data in the database, I see black diamonds with question marks. This isn't too much of an issue when echoing the data back out again, as they don't appear, but when I want to use one of the CSV fields as a MySQL date, it isn't recognised as a date and is stored as 0000-00-00. e.g. I think this issue is something to do with encoding of the CSV? Can anyone offer any advice? If it helps here is my import script, and the encode type is ASCII according to mb_detect_encoding Code: [Select] <?php include 'config.php'; include 'opendb.php'; ini_set("auto_detect_line_endings", true); $row = 0; $tmpName = $_FILES['csv']['tmp_name']; if (($handle = fopen($tmpName, "r")) !== FALSE) { $num = count($data); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $noQuotes = str_replace("\"", '', $data); $originalDate = $noQuotes[1]; //$delivery_date = date('Y-m-d', strtotime($originalDate)); $parts = explode('/', $originalDate); $delivery_date = $parts[2] . '-' . $parts[1] . '-' . $parts[0]; $row++; $import="INSERT into dispatch (delivery_note_number, delivery_date, dispatch_date, customer_delivery_date, delivery_line, produce, variety, quantity, pallets, count, depot, customer, grower, haulier, status) values ('$noQuotes[0]', '$delivery_date', '$noQuotes[2]', '$noQuotes[3]', '$noQuotes[4]', '$noQuotes[5]', '$noQuotes[6]', '$noQuotes[7]', '$noQuotes[8]', '$noQuotes[9]', '$noQuotes[10]', '$noQuotes[11]', '$noQuotes[12]', '$noQuotes[13]', '$noQuotes[14]')"; echo $import; mysql_query($import) or die(mysql_error()); } //header("location:list_dispatch.php?st=recordsadded"); fclose($handle); } ?> I have a picture (attached), where I find the coordinates of black points, because I do not remember any point, so you want every point at which I find coordinates with mark a red cross as watermark. At the coordinates using this script: <?php if(isset($_GET["obrazek_x"])) file_put_contents("soubor.txt",$_GET["obrazek_x"].",".$_GET["obrazek_y"]."\n",FILE_APPEND); ?> Coordinates I save to an external file in this format: Code: [Select] 602;744 Could you advise me a solution to mark black points? Hi all, can anyone see why my function is not running? im not getting the form output now. Code: [Select] <?php /* NEW.PHP Allows user to create a new entry in the database */ // creates the new record form // since this form is used multiple times in this file, I have made it a function that is easily reusable function renderForm($Name, $Rank, $error) { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>New Record</title> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <div id="wrapper"> <p> <?php // if there are any errors, display them if ($error != '') { echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>'; } ?> </p> <p> </p> <form action="" method="post"> <div> <table width="842" border="0" class="styletable" style="border: 1px solid #000000"> <tr> <td width="255"><strong>Name: *</strong></td> <td width="577"><input type="text" name="Name" value="<?php echo $Name; ?>" /></td> </tr> <tr> <td><strong>Rank:</strong></td> <td><input type="text" name="Rank" value="<?php echo $Rank; ?>" /></td> </tr> <tr> <td><strong>Contact Email: *</strong></td> <td><input type="text" name="ContactEmail" value="<?php echo $ContactEmail; ?>" /></td> </tr> <tr> <td><strong>Website: (omitting http://)</strong></td> <td><input type="text" name="Website" value="<?php echo $Website; ?>" /></td> </tr> <tr> <td><strong>Location:</strong></td> <td><select name="Location" id="Location"> <option value="East Midlands">East Midlands</option> <option value="East Of England">East Of England</option> <option value="Greater London">Greater London</option> <option value="North East England">North East England</option> <option value="North West England">North West England</option> <option value="South East England">South East England</option> <option value="South West England">Soth West England</option> <option value="West Midlands">West Midlands</option> <option value="Yorkshire And The Humber">Yorkshire And The Humber</option> </select> </td> </tr> <tr> <td><strong>Bio:</strong></td> <td><textarea name="BIO" id="BIO" cols="60" rows="5"></textarea></td> </tr> <tr> <td> </td> <td> </td> </tr> </table> <p>* required</p> <input type="submit" name="submit" value="Submit"> <a href="view.php">Cancel - View Records</a> </div> </form> </div> </body> </html> <?php } // connect to the database include('../connect-db.php'); // check if the form has been submitted. If it has, start to process the form and save it to the database if (isset($_POST['submit'])) { // get form data, making sure it is valid $Name = mysql_real_escape_string(htmlspecialchars($_POST['Name'])); $Rank = mysql_real_escape_string(htmlspecialchars($_POST['Rank'])); $ContactEmail = mysql_real_escape_string(htmlspecialchars($_POST['ContactEmail'])); $Website = mysql_real_escape_string(htmlspecialchars($_POST['Website'])); $Location = mysql_real_escape_string(htmlspecialchars($_POST['Location'])); $BIO = mysql_real_escape_string(htmlspecialchars($_POST['BIO'])); // check to make sure both fields are entered if ($Name == '' || $ContactEmail == '') { // generate error message $error = 'ERROR: Please fill in all required fields!'; // if either field is blank, display the form again renderForm($Name, $Rank, $error); } else { // save the data to the database mysql_query("INSERT members SET Name='$Name', Rank='$Rank',ContactEmail='$ContactEmail', Website='$Website', Location='$Location', BIO='$BIO'") or die(mysql_error()); // once saved, redirect back to the view page header("Location: view.php"); // if the form hasn't been submitted, display the form } renderForm('','',''); } ?> hi, i am trying to generate image gallery. but the problem is that when i upload the png files its thumbnail is generated with black background. JPEG an GIF thumbnail are generated successfully. i want to make background transparent. is there any solution that how i can get rid of it. i am using imagecreatetruecolor($thumbwidth, $thumbheight ); to generate thumbnail This is kind of weird, I've tried to figure out what is wrong for a while now, but I really can't seem to figure it out. My script does seem to work with the values I think it works with, but that might be where the error is. I've messed around a lot with it, but I still can't seem to understand what the problem is... I do realize I can just use the filledrectangle function instead of creating a new image for each background color, but the problem itself really annoys me. The black line doesn't appear anywhere but between the two first background colors and only if both background colors are visible... o.O Might be I need to use some other imagecopy function, but this is all so weird! <?php // image size $x=500; $y=100; // creating transparent image $im=imagecreatetruecolor($x,$y); $tc=imagecolorallocatealpha($im,255,255,255,0); imagefill($im,0,0,$tc); // background colors // the escaped lines is for making a background image transparent, to see where the black line appears $bgc[]=array(255,0,0,0); //$bgc[0]=array(255,0,0,127); $bgc[]=array(0,255,0,0); //$bgc[1]=array(0,255,0,127); $bgc[]=array(0,0,255,0); $bgc[]=array(0,255,255,0); // adding backgrounds // background count: $bgcq=count($bgc); // backgroundsize x,y: $bgs=array(ceil($x),($y+1)/$bgcq); // location: $bgsl=0; // last height: $bgsh=0; for($i=0;$i<$bgcq;$i++){ // start location for this background: $bgsl+=$bgsh; // calculating a round number for the background height if($bgsl+$bgs[1]<round($bgs[1]+($bgs[1]*$i))){ $bgsh=ceil($bgs[1]); }else{ $bgsh=floor($bgs[1]); } // creating background image: $bg=imagecreatetruecolor($bgs[0],$bgsh); // filling background image with set color $abgc=imagecolorallocatealpha($bg,$bgc[$i][0],$bgc[$i][1],$bgc[$i][2],$bgc[$i][3]); imagefill($bg,0,0,$abgc); // pasting background on image (imagecopy gives the same result) imagecopyresampled($im,$bg,0,$bgsl,0,0,$bgs[0],$bgsh,$bgs[0],$bgsh); // to see the values (test purpose), must escape header and imagepng functions //echo $bgsl.'-'.($bgsl+$bgsh).'<br />'.$bgsh.'<br />'; } // output, remember to escape it to echo variables header('Content-type: image/png'); imagepng($im,NULL,0); ?> I've tried to make the script as understandable and easy as possible... anyone got any ideas about what is wrong here, and how to maybe fix it? Hey all. I'm getting down the basics of the GD Library's image creation processes. I'm trying to test out creating png images. However, where there should be transparency there is a black background. Here's my code mostly based on the image tutorial found here at phpfreaks. Code: [Select] <?php // font $font = 'c:\windows\fonts\arial.ttf'; $fontsize = 12; // array of quotes $quotes = array( "I like pie.", "Surf's Up.", "Smoke em if you got em.", "Game on.", "I need TP for my bunghole."); // select quote $pos = rand(0,count($quotes)-1); $quote = $quotes[$pos]; // image $image = imagecreatefrompng('quote.png'); $white = imagecolorallocate($image, 255, 255, 255); $black = imagecolorallocate($image, 0, 0, 0); imagettftext($image, 11, 0, 107, 32, $black, $font, $quote); imagettftext($image, 11, 0, 105, 30, $white, $font, $quote); // tell the browser that the content is an image header('Content-type: image/png'); // output image to the browser imagepng($image); // delete the image resource imagedestroy($image); ?> Cheers all, thanks! function buildAvatar(array $imgArray = array()) { $img1 = imagecreatefrompng($phpbb_root_path.'images/spacer.png'); foreach($imgArray as $img) { $img2 = imagecreatefrompng($phpbb_root_path.'avatars/equip_img/'.$img); $this->imagecopymerge_alpha($img1, $img2, 0, 0, 0, 0, 210, 300, 100); } imagealphablending($img1, false); imagesavealpha($img1, true); return $img1; } The background of my PNG was transparent, I don't know what I did, but it's now black! I'm thinking it's the image! Not the code, this same code worked before, and I've tried tons of different ways of fixing it. How should I save the image to work correctly? I am trying to copy an image into another image. Code: [Select] $im = imagecreatefrompng("/oldimg.png"); //this is a semi-transparent image where I want the new image to be copied imagealphablending($im, 1); //this seems to remove the black background header('Content-type: image/png'); //outputs old image with a transparent background (YAY!) imagepng($im); imagecopy($im, $newimage, 32, 0, 0, 0, 32, 32); //I want to replace a part of the old image with a new semi-transparent image header('Content-type: image/png'); //outputs image with a black background (noooooooooo!) imagepng($im); Can anyone help me? this is the code <?php $image = imagecreatefromjpeg("9t4i_200xX.jpg"); $new_image = imagecreatetruecolor(120,90); imagecopyresampled($new_image, $image, 0, 0, 0, 0, 120, 90, imagesx($image), imagesy($image)); $image = $new_image; imagejpeg($image,"images/test.jpg"); ?> result is black jpeg image of size 120,90 I dont understand where could be the problem SimpleImage.php script doesnt work either I'm trying to convert a grayscale image to pure black and white in php using the GD library. The purpose would be to detect the cervical cells within the image. I'll leave the php code and a matlab one (i wrote this code in matlab and i'm trying to obtain the same result in php). Basically, im having troubles accessing each individual pixel's color and modifying it. MATLAB: clear all, clc, close all; I = imread('celule.jpg'); imshow(I) title('original'); a=rgb2gray(I); figure; imshow(a) title('grayscale'); s=size(a); for i=1:s(1) for j=1:s(2) if a(i,j)>190 a(i,j)=0; else a(i,j)=255; end end end figure; imshow(a) title('pure black and white'); PHP: <?php $im = imagecreatefromjpeg("celule.jpg"); function imagetograyscale($im) { if (imageistruecolor($im)) { imagetruecolortopalette($im, false, 256); } for ($c = 0; $c < imagecolorstotal($im); $c++) { $col = imagecolorsforindex($im, $c); $gray = round(0.299 * $col['red'] + 0.587 * $col['green'] + 0.114 * $col['blue']); imagecolorset($im, $c, $gray, $gray, $gray); } } imagetograyscale($im); //imagefilter($im, IMG_FILTER_CONTRAST, -255); //i'm not looking for this effect header('Content-type: image/jpeg'); imagejpeg($im); $C = imagesx($im); //width $L = imagesy($im); //height echo "Dimensiuni imagine: latime $C, inaltime $L <br>"; //scanning through the image for($x = 0; $x < $L; $x++) { //each line for($y = 0; $y < $C; $y++) { //each collumn // pixel color at (x, y) $color = imagecolorat($im, $y, $x); $color = imagecolorsforindex($im, $color); //getting rgb values $RED[$x][$y] = $color["red"]; //each rgb component $GREEN[$x][$y] = $color["green"]; $BLUE[$x][$y] = $color["blue"]; } } ?> image "celule.jpg": https://i.ibb.co/6Ffj6sc/celule.jpg Hi All, Everything is working pretty good, its just the thumbnail portion that adds a black background to every picture it converts. When the user uploads a picture, I take the original picture and then make a thumbnail, so I have 2 images in my fileroot. The original picture looks just fine, its just when I open the thumbnail. Attached is a sample of the black background picture. Below is just the thumbnail portion of the code. Code: [Select] include('uploads/image.php'); $image = $path; $thumb = new SimpleImage(); $thumb->load($image); $width = 150; $height = 95; $thumb->resize($width,$height); $thumb->save('uploads/thumbnails/'.$filename); image.php Code: [Select] class SimpleImage { var $image; var $image_type; function load($filename) { $image_info = getimagesize($filename); $this->image_type = $image_info[2]; if( $this->image_type == IMAGETYPE_JPEG ) { $this->image = imagecreatefromjpeg($filename); } elseif( $this->image_type == IMAGETYPE_GIF ) { $this->image = imagecreatefromgif($filename); } elseif( $this->image_type == IMAGETYPE_PNG ) { $this->image = imagecreatefrompng($filename); } } function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image,$filename,$compression); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image,$filename); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image,$filename); } if( $permissions != null) { chmod($filename,$permissions); } } function output($image_type=IMAGETYPE_JPEG) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image); } } function getWidth() { return imagesx($this->image); } function getHeight() { return imagesy($this->image); } function resizeToHeight($height) { $ratio = $height / $this->getHeight(); $width = $this->getWidth() * $ratio; $this->resize($width,$height); } function resizeToWidth($width) { $ratio = $width / $this->getWidth(); $height = $this->getheight() * $ratio; $this->resize($width,$height); } function scale($scale) { $width = $this->getWidth() * $scale/100; $height = $this->getheight() * $scale/100; $this->resize($width,$height); } function resize($width,$height) { $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; } } 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. 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? 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> 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); } ?> 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. 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
:-\
|