Results 1 to 10 of 16

Thread: Day 8 - Lets Make A Game - Part 1 - Become PHP Expert in 30 days

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2004
    Location
    India
    Posts
    65

    Default

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

    Code:
    <html>
    <body>
    
    
    <h1>Guess My Number!</h1>
    
    
    <?php
    
    
    if (isset($_GET['secretNumber'])) {
    $secretNumber = $_GET['secretNumber'];
    } else {
    $secretNumber = rand(10,800);
    }
    
    
    if (isset($_GET['userNumber'])) {
    $userNumber = $_GET['userNumber'];
    
    
    if ($secretNumber > $userNumber) {
    echo '<h1 style="color:LimeGreen">Your guess is too low.</h1>';
    } else if ($secretNumber < $userNumber) {
    echo '<h1 style="color:red ">Your guess is too high.</h1>';
    } else {
    echo '<h1 style="color:green">You win the game.</h1>';
    }
    }
    
    
    ?>
    
    
    <form method="GET" action="">
    Enter letter: <input name="userNumber" type="text">
    <button type="submit">Check</button>
    <input type="hidden" name="secretNumber" value="<?php echo $letter; ?>">
    </form>
    
    
    <h2>Tips for Playing Game:</h2>
    
    
    <pre>
    * Server will pick a secret letter between 10 and 800.
    * You guess what letter it is.
    * If your guess is too high or too low, Server will give you a hint.
    </pre>
    
    
    </body>
    </html>
    Last edited by stefin; 05-19-2014 at 03:53 PM.

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

    Default

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

    Code:
    <html>
    <body>
    
    
    <h1>Guess My Number!</h1>
    
    
    <?php
    
    
    if (isset($_GET['secretNumber'])) {
    $secretNumber = $_GET['secretNumber'];
    } else {
    $secretNumber = rand(10,800);
    }
    
    
    if (isset($_GET['userNumber'])) {
    $userNumber = $_GET['userNumber'];
    
    
    if ($secretNumber > $userNumber) {
    echo '<h1 style="color:LimeGreen">Your guess is too low.</h1>';
    } else if ($secretNumber < $userNumber) {
    echo '<h1 style="color:red ">Your guess is too high.</h1>';
    } else {
    echo '<h1 style="color:green">You win the game.</h1>';
    }
    }
    
    
    ?>
    
    
    <form method="GET" action="">
    Enter letter: <input name="userNumber" type="text">
    <button type="submit">Check</button>
    <input type="hidden" name="secretNumber" value="<?php echo $letter; ?>">
    </form>
    
    
    <h2>Tips for Playing Game:</h2>
    
    
    <pre>
    * Server will pick a secret letter between 10 and 800.
    * You guess what letter it is.
    * If your guess is too high or too low, Server will give you a hint.
    </pre>
    
    
    </body>
    </html>

    @stefin, in this code

    Code:
    <input type="hidden" name="secretNumber" value="<?php echo $letter; ?>">
    Should be

    Code:
    <input type="hidden" name="secretNumber" value="<?php echo $secretNumber; ?>">
    This is the number visitor need to guess.

    We generate it with rand() function if that number on first visit to the page using following code.


    Code:
    if (isset($_GET['secretNumber'])) {
        $secretNumber = $_GET['secretNumber'];
    } else {
        $secretNumber = rand(10,800);
    }
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  3. #3
    Join Date
    Apr 2005
    Posts
    46,704

    Default

    Code:
    <html>
    <body>
    
    <h1>Number Guessing Game.</h1>
    
    <?php
    
    if (isset($_GET['secretNumber'])) {
        $secretNumber = $_GET['secretNumber'];
    } else {
        $secretNumber = rand(1,20);
    }
    
    if (isset($_GET['userNumber'])) {
        $userNumber = $_GET['userNumber'];
    
        if ($secretNumber > $userNumber) {
            echo '<h1 style="color:blue">Your Guess is too Low.</h1>';
        } else if ($secretNumber < $userNumber) {
            echo '<h1 style="color:Red">Your Guess is too High.</h1>';
        } else {
            echo '<h1 style="color:green">You win the game.</h1>';
        }
    }
    
    ?>
    
    <form method="GET" action="">
        Guess A Number: <input name="userNumber" type="text">
        <button type="submit">Check</button>
        <input type="hidden" name="secretNumber" value="<?php echo $secretNumber; ?>">
    </form>
    
    <h2>How to Play:</h2>
    
    <pre>
    * Server will pick a secret number between 1 and 20.
    * 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>
    http://php.flashwebhost.com/mini/game.php

  4. #4
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 8 PHP PROGRAMMING

    http://php.flashwebhost.com/tom/day_8_ex_1.php

    Code:
    <?php
    
    
    echo 'My Random Number is ' . rand(1,1000);

  5. #5
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 8 PHP PROGRAMMING

    http://php.flashwebhost.com/tom/day_8_ex_1_new.php

    Code:
    <?php
    
    
    echo '<h1>Computer as Dice</h1>';
    echo '<p>Use it when your Dice broken.</p>';
    
    
    echo 'Your number is: ' . rand(1,6);

  6. #6
    Join Date
    Oct 2003
    Location
    Kochi, Kerala, India
    Posts
    21,389

    Default

    http://php.flashwebhost.com/vineesh/day8/day_8_ex_5.php

    PHP Code:
    <html>
    <body>

    <h1 style="color:blue">HI..LETS PLAY A NUMBER GUESSING GAME<h1>

    <?php

    if (isset($_GET['serverNumber'])) {
    $serverNumber $_GET['serverNumber'];
    } else {
    $serverNumber rand(1,6);
    }

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

    if (
    $serverNumber $userNumber) {
    echo 
    '<h2 style="color:red">Number you entered is small</h2>';
    } else if (
    $serverNumber $userNumber) {
    echo 
    '<h2 style="color:red">Number you entered is big</h2>'
    } else {
    echo 
    '<h2 style="color:green">Hey..congratulations!, you win.</h2>';
    }
    }


    ?>

    <form method="GET" action="">

    <font style="color:green">Enter your Number</font>
    <input type="text" name='userNumber'>
    <button type="submit">Check now!!!</button>
    <input type="hidden" name="serverNumber" value="<?php echo $serverNumber ?>">

    </form>

    <h2 style="color:orange"><u>Instructions for players:</u></h2>

    <pre style="color:green">
    1. The game will automatically pick a number between 1 and 7.
    2. You need to guess the number and enter into the box, then click on 'check now' button.
    3. If you are wrong, the game will give you a hint.
    4. Try to win the game within 3 attempts.

       and finally, all the best..! 
    </pre>


    </body>
    </html>

  7. #7
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 8 PHP PROGRAMMING

    http://php.flashwebhost.com/tom/day_8_ex_2.php

    PHP Code:

    <html><body>
    <h1>NUMBER GUESSING GAME</h1>
    <?php
    if (isset($_GET['secretNumber'])) {
    $secretNumber $_GET['secretNumber'];
    } else {
    $secretNumber rand(90,100);
    }
    if (isset(
    $_GET['userNumber'])) {
    $userNumber $_GET['userNumber'];
    if (
    $secretNumber $userNumber) {
    echo 
    '<h1 style="color:blue">Your number is too SMALL.</h1>';
    } else if (
    $secretNumber $userNumber) {
    echo 
    '<h1 style="color:green">Your number is too BIG.</h1>';
    } else {
    echo 
    '<h1 style="color:red">You Win The Game</h1>';
    }
    }
    ?>
    <form method="GET" action="">
    Enter Number: <input name="userNumber" type="text">
    <button type="Submit">Check</button>
    <input type="hidden" name="secretNumber" value="<?php echo $secretNumber?>">
    </form>
    <h2>How to Play:</h2>
    <pre>* Server will pick a secret number between 90 and 100.* 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>

  8. #8
    Join Date
    Jan 2008
    Location
    india,kerala-god's own country
    Posts
    14,007

    Default

    DAY 8 PHP PROGRAMMING

    http://php.flashwebhost.com/ramesh/day-8/game_3.php

    PHP Code:
    <html>
    <body>

    <h1 style="color:red">Number Guessing Game.</h1>

    <?php

    if (isset($_GET['secretNumber'])) {
        
    $secretNumber $_GET['secretNumber'];
    } else {
        
    $secretNumber rand(5,15);
    }

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

        if (
    $secretNumber $userNumber) {
            echo 
    '<h1 style="color:red">Your number is too SMALL.</h1>';
        } else if (
    $secretNumber $userNumber) {
            echo 
    '<h1 style="color:blue">Your number is too BIG.</h1>';
        } else {
            echo 
    '<h1 style="color:green">You win the game.</h1>';
        }
    }

    ?>

    <form method="GET" action="">
        <font style="color:green">Enter Number:</font>
        <input name="userNumber" type="text">
        <button type="submit">Check</button>
        <input type="hidden" name="secretNumber" value="<?php echo $secretNumber?>">
    </form>
    </body>
    </html>

  9. #9
    Join Date
    Feb 2010
    Posts
    35

    Red face between 1 and 3

    PHP Code:
    <html>
    <body>

    <h1>Number Guessing Game.</h1>

    <?php

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

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

        if (
    $secretNumber $userNumber) {
            echo 
    '<h1 style="color:red">Your number is too SMALL.</h1>';
        } else if (
    $secretNumber $userNumber) {
            echo 
    '<h1 style="color:blue">Your number is too BIG.</h1>';
        } else {
            echo 
    '<h1 style="color:green">You win the game.</h1>';
        }
    }

    ?>

    <form method="GET" action="">
        Enter Number: <input name="userNumber" type="text">
        <button type="submit">Check</button>
        <input type="hidden" name="secretNumber" value="<?php echo $secretNumber?>">
    </form>

    <h2>How to Play:</h2>

    <pre>
    * Server will pick a secret number between 1 and 3.
    * 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>
    Last edited by betheman; 09-08-2015 at 05:38 AM.

Tags for this Thread

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
  •