dice game

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    dice game

    Code:
    <head>
    <title>Let's roll some dice!</title>
    </head>
    <body>
    <h2><i>Let's roll some dice!</i></h2>
    <br />
    <?php
    $k = $_POST['number'];
     
    // to specify the number of dice rolls rather than allowing the user
    // to choose, change the second block to $i <= [number of rolls]
    // then remove the form unless you like frustrating people :-)
    for ($i = 1; $i <= $k; $i++) {
    $roll = mt_rand(1,6);
    echo "<img src='dice{$roll}.gif' alt='$roll' /> ";
     
    // the following 25 lines can be removed, as well as the very first line
    // of the code, if you don't care about tracking the results
    if ($roll == 1) {
            $_SESSION['one'] = $_SESSION['one'] + 1;
            } else if ($roll == 2) {
            $_SESSION['two'] = $_SESION['two'] + 1;
            } else if ($roll == 3) {
            $_SESSION['three'] = $_SESSION['three'] + 1;
            } else if ($roll == 4) {
            $_SESSION['four'] = $_SESSION['four'] + 1;
            } else if ($roll == 5) {
            $_SESSION['five'] = $_SESSION['five'] + 1;
            } else if ($roll == 6) {
            $_SESSION['six'] = $_SESSION['six'] +1;
            }
    }
    ?>
    <div style="border:2px solid red; width:160px;">
    <?php
    // these are session variables
    echo "<br />You have rolled $one ones";
    echo "<br />You have rolled $two twos";
    echo "<br />You have rolled $three threes";
    echo "<br />You have rolled $four fours";
    echo "<br />You have rolled $five fives";
    echo "<br />You have rolled $six sixes";
    ?>
    </div>
    <p><i>How many dice to roll</i></p>
    <form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
    <!-- this can only be an integer -->
    <input type="text" name='number' />
    <input type="submit" value="Roll the dice!" />
    </form>
    </body>
    </html>
    sorry if this in wrong page if in wrong please please can u move it to right place.

    can some one help me sort this out so its got a button on it to take you back to the site please its some thing i found on me pc and would like help to get it sorted please thanks

    #2
    not exactly hard really if you think about it lol
    add this if your using lava style coding
    echo "<a href=\"index.php?action=main&amp;sid=$sid\"><img src=\"../images/home.gif\" alt=\"\"/>Home</a>";
    Wapchat4u


    Topsites4u

    Comment

    Working...
    X