Results 1 to 10 of 17

Thread: Day 9 - Lets Make A Game - Part 2 - Become PHP Expert in 30 days

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2003
    Location
    india
    Posts
    11,527

    Default

    http://php.flashwebhost.com/annie/9day_number_game.php
    Code:
    <html>
    <body>
    
    <h1>Guess the Secret Number - Numbers up to 1 to 20 </h1>
    
    <?php
    
    if (isset($_POST['secretNumber'])) {
    $secretNumber = $_POST['secretNumber'];
    } else {
    $secretNumber = rand(1,20);
    }
    if (isset($_POST['userNumber'])) {
    $userNumber = $_POST['userNumber'];
    if ($secretNumber > $userNumber) {
    echo '<h1 style ="color:Blue"> Your number is too Small >/h1>';
    } else if ($secretNumber < $userNumber) {
    echo '<h1 style ="color:Red"> Your number is too BIG <h1>';
    }  else {
    echo '<h1 style="color:green">You win the game.</h1>';
    }
    } 
    ?> 
    
    <form method = "POST" action="">
    Enter Number: <input name="userNumber" type="text">
    <button type = "submit"> Check</button>
    <input type="hidden" name="secretNumber" value"<?php echo $secretNumber; ?>">
    </form>

  2. #2
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    http://php.flashwebhost.com/sherly/9...essinggame.php

    Code:
    <html>
    <body>
    
    <h1>Guessing Game</h1>
    
    <?php
    
    if (isset($_POST['guessNumber'])) {
        $guessNumber = $_POST['guessNumber'];
    } else {
        $guessNumber = rand(1,50);
    }
    
    if (isset($_POST['userNumber'])) {
        $userNumber = $_POST['userNumber'];
    if ($guessNumber > $userNumber) {
            echo '<h1 style="color:green">Your number is too SMALL.</h1>';
        } else if ($guessNumber < $userNumber) {
            echo '<h1 style="color:brown">Your number is too BIG.</h1>';
        } else {
            echo '<h1 style="color:orange">You win the game.</h1>';
        }
    }
    
    ?>
    
    <form method="POST" action="">
    Enter Number: <input name="userNumber" type="text">
    <button type="submit">Check</button>
    <input type="hidden" name="guessNumber" value="<?php echo $guessNumber; ?>">
    </form>
    
    <h2>How to Play:</h2>
    
    <pre>
    * Server will pick a guess number between 1 and 50.
    * You guess what number it is.
    * If your guess is too high or too low, Server will give you a hint.
    * See how many turns it takes you to win!
    </pre>
    
    </body>
    </html>

  3. #3
    Join Date
    Feb 2005
    Location
    India
    Posts
    11,004

    Default

    http://php.flashwebhost.com/melbin/number_game_post.php

    PHP Code:
    <html>
    <body>

    <h1>Guess the Number</h1>

    <?php

    if (isset($_POST['secretNumber'])) {
        
    $secretNumber $_POST['secretNumber'];
    } else {
        
    $secretNumber rand(1,100);
    }

    if (isset(
    $_POST['userNumber'])) {
        
    $userNumber $_POST['userNumber'];

        if (
    $secretNumber == $userNumber) {
            echo 
    '<h1 style="color:green">You are right...!!!!</h1>';
            echo 
    '<h1 style="color:green">Secret Number is ' $secretNumber '</h1><br>';

        } else {
            echo 
    '<h1 style="color:red">You are Wrong</h1>';
            echo 
    '<h1 style="color:#FFF">Secret Number was ' $secretNumber '</h1><br>';
            echo 
    '<h3 style="color:blue">Press Ctrl + A to see the secret number</h3><br>';
        }
    }

    ?>

    <form method="POST" action="">
        Enter Number: <input name="userNumber" type="text">
        <button type="submit">Check</button>
        <input type="hidden" name="secretNumber" value="<?php echo $secretNumber?>">
    </form>
    VIDEO WORLD : LATEST HOLLYWOOD || BOLLYWOOD || SOUTH INDIAN VIDEOS || TRAILERS

  4. #4
    Join Date
    Nov 2004
    Location
    India
    Posts
    65

    Default

    http://php.flashwebhost.com/stefin/games_10.php

    Code:
    <html>
    <body>
    <h1>Number Guessing Game.</h1>
    
    <?php
    
    if (isset($_POST['secretNumber'])) {
    $secretNumber = $_POST['secretNumber'];
    } else {
     $secretNumber = rand(1,500);
    }
    if (isset($_POST['userNumber'])) {
    $userNumber = $_POST['userNumber'];
    if ($secretNumber > $userNumber) {
    echo '<h1 style="color:BLACK">Think Greater.</h1>';
    } else if ($secretNumber < $userNumber) {
    echo '<h1 style="color:GREEN">Think Smaller.</h1>';
    } else {
    echo '<h1 style="color:RED">Good Job, You win the game.</h1>';
    }
    }
    ?>
    
    <form method="POST" action="">
    Enter Number: <input name="userNumber" type="text">
    <button type="submit">Check</button>
    <input type="hidden" name="secretNumber" value="<?php echo $secretNumber; ?>">
    </form>

  5. #5
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by stefin View Post
    http://php.flashwebhost.com/stefin/games_10.php

    Code:
    <html>
    <body>
    <h1>Number Guessing Game.</h1>
    
    <?php
    
    if (isset($_POST['secretNumber'])) {
    $secretNumber = $_POST['secretNumber'];
    } else {
     $secretNumber = rand(1,500);
    }
    if (isset($_POST['userNumber'])) {
    $userNumber = $_POST['userNumber'];
    if ($secretNumber > $userNumber) {
    echo '<h1 style="color:BLACK">Think Greater.</h1>';
    } else if ($secretNumber < $userNumber) {
    echo '<h1 style="color:GREEN">Think Smaller.</h1>';
    } else {
    echo '<h1 style="color:RED">Good Job, You win the game.</h1>';
    }
    }
    ?>
    
    <form method="POST" action="">
    Enter Number: <input name="userNumber" type="text">
    <button type="submit">Check</button>
    <input type="hidden" name="secretNumber" value="<?php echo $secretNumber; ?>">
    </form>
    Good script.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  6. #6
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by annie View Post
    http://php.flashwebhost.com/annie/9day_number_game.php
    Code:
    <html>
    <body>
    
    <h1>Guess the Secret Number - Numbers up to 1 to 20 </h1>
    
    <?php
    
    if (isset($_POST['secretNumber'])) {
    $secretNumber = $_POST['secretNumber'];
    } else {
    $secretNumber = rand(1,20);
    }
    if (isset($_POST['userNumber'])) {
    $userNumber = $_POST['userNumber'];
    if ($secretNumber > $userNumber) {
    echo '<h1 style ="color:Blue"> Your number is too Small >/h1>';
    } else if ($secretNumber < $userNumber) {
    echo '<h1 style ="color:Red"> Your number is too BIG <h1>';
    }  else {
    echo '<h1 style="color:green">You win the game.</h1>';
    }
    } 
    ?> 
    
    <form method = "POST" action="">
    Enter Number: <input name="userNumber" type="text">
    <button type = "submit"> Check</button>
    <input type="hidden" name="secretNumber" value"<?php echo $secretNumber; ?>">
    </form>
    This script have bugs.

    bug 1

    Code:
    echo '<h1 style ="color:Blue"> Your number is too Small >/h1>';
    >/h1> instead of </h1>

    bug 2

    Code:
    echo '<h1 style ="color:Red"> Your number is too BIG <h1>';
    <h1> instead of </h1>
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •