Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 9 of 9

Thread: Hang-man #2

  1. #1
    Join Date
    Aug 2004
    Location
    bristol
    Posts
    3,799
    Tokens
    0

    Latest Awards:

    Default Hang-man #2

    This was posted ages ago but was lost when the forum went down, so I've decided to post it again.
    This isn't the version which Mentor made changes to, as I have lost my copy of it.

    PHP Code:
    <?php
    /*
    -------------------------------
    To customize the file name of the text
    document and the character separating
    the words, modify the code just bellow
    this sentence.
    -------------------------------  */

    $word_list_location 'word_list.txt'// Location of file containing the words
    $word_separator '|'// Character used to separate the words
    $file_name 'hang_man.php'// The name of this file

    /* Don't edit bellow this line unless you know what you're doing */

    session_start();
    $users_guess $_GET['guess'];

    // If game hasn't started
    if(!isset($_SESSION['hangman_word']))
    {
     unset(
    $users_guess);

     
    // Choose a random word
     
    $handle fopen($word_list_location'r');
      
    $word_list fread($handlefilesize($word_list_location));
      
    $word_list explode($word_separator$word_list);
     
    fclose($handle);
     
    $word_list_count = (count($word_list) - 1);
     
    $choosen_word $word_list[rand(0$word_list_count)];

     
    // Put word into session
     
    $_SESSION['hangman_word'] = $choosen_word;
    }

    // Check guess length
    if(isset($users_guess) && strlen($users_guess) != 1)
    {
     
    session_destroy();
      die(
    "<script language=\"JavaScript\">
    alert(\"Only enter one letter!\");
    document.location.href=\"
    $file_name\";
    </script>"
    );
    }

    // Check if max loses has been met
    if($_SESSION['hangman_loses'] > 9)
    {
     
    session_destroy();
      die(
    "<script language=\"JavaScript\">
    alert(\"All lifes used up!\");
    document.location.href=\"
    $file_name\";
    </script>"
    );
    }

    // Switches guessed letters to upper case
    $correct_word $_SESSION['hangman_word'];
    $guess_check str_replace($users_guessstrtoupper($users_guess), $correct_word);

    // Checks if user guessed an incorrect letter
    if (isset($users_guess) && $guess_check == $correct_word)
    {
     
    $_SESSION['hangman_loses']++;
    }
    else
    {
     
    $_SESSION['hangman_word'] = $guess_check;

     
    // Check for win
     
    if($_SESSION['hangman_word'] == strtoupper($_SESSION['hangman_word']))
     {
      
    session_destroy();
      die(
    "<script language=\"JavaScript\">
    alert(\"You have won!\");
    document.location.href=\"
    $file_name\";
    </script>"
    );
     }
    }
    ?>
    <html>
    <head>
    <title>Hang-man</title>
    </head>
    <body>
    <form>
    <input type="text" name="guess" size="1" maxlength="1" value="" />
    <input type="submit" value="Go" />
    <br />
    Word:

    <?php
    // Print word, with lower caps (non-guessed) hidden
    print ereg_replace('[a-z]','_ '$_SESSION['hangman_word']);
    ?>

    <br />
    Lifes:

    <?php
    // Put loses as zero if unset
    if(!isset($_SESSION['hangman_loses'])) $_SESSION['hangman_loses'] = 0;

    print 
    $_SESSION['hangman_loses'].'/10';
    ?>
    </form>
    </body>
    </html>
    You can play it at (It is another version, but is pretty similar):
    http://www.thybag.co.uk/test/hangyman.php

  2. #2
    Join Date
    Feb 2006
    Location
    Befordshire, England
    Posts
    672
    Tokens
    0

    Default

    Yeh i was getting bored and wondered where this went thanks for re-posting.
    Once again Nets has done it.


    -Daza

  3. #3
    Join Date
    Nov 2004
    Location
    HabboWeb FM Offices
    Posts
    3,019
    Tokens
    0

    Latest Awards:

    Default

    You've won!
    The word was rich!


    How hard!

  4. #4
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    3,285
    Tokens
    0

    Latest Awards:

    Default

    I won on my last chance The word was morning



    i used to be NintendoNews. visit my blog or add me on twitter.
    need help with vista? i am a microsoft certified technology specialist in configuring windows vista and connected home integrator.. pm me for help!


    "I am the way, the truth, and the life. No one comes to the Father except through me"
    John 14:6 (NIV)


  5. #5
    Join Date
    Mar 2005
    Location
    Leeds
    Posts
    3,423
    Tokens
    0

    Latest Awards:

    Default

    Ah you helped me

    I needed something like strlen, very helpful I will read it more and see if there is anything else I may help me with my system.

    Thanks Nets

  6. #6
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default

    Nets could u IM me, as css is driveing me mad and your the only one i know who can actaly use the stuff, without exsploaions and death "/

    Plus, The updated script is here.

    PHP Code:

    <?php
    /*
    -------------------------------
    To customize the file name of the text
    document and the character separating
    the words, modify the code just bellow
    this sentence.
    -------------------------------  */

    $word_list_location 'word_list.txt'// Location of file containing the words
    $word_separator '|'// Character used to separate the words
    $file_name  'hangyman.php'// Name of this file
    $Game_lifes  '10'// How many lifes a use has
    $use_images true //if you dont want to use images set to false.

    //if you want to use images
    $image_locations =""//images must have names 0 to the maximum number of lives allowed, the top number is the hanging.
    $image_type "gif" //file exstention

    /* Don't edit bellow this line unless you know what you're doing */



    //As suggested by luckyrare, do we want to reset?
    if($_GET['reset'] == "yes"){

    session_start();
    session_destroy();
    header("Location: ".$file_name);

            }


    session_start();
    $users_guess $_GET['guess'];

    // If game hasn't started
    if(!isset($_SESSION['hangman_word']))
    {
     unset(
    $users_guess);

     
    // Choose a random word
     
    $handle fopen($word_list_location'r');
      
    $word_list fread($handlefilesize($word_list_location));
      
    $word_list explode($word_separator$word_list);
     
    fclose($handle);
     
    $word_list_count = (count($word_list) - 1);
     
    $choosen_word $word_list[rand(0$word_list_count)];

     
    // Put word into session
     
    $_SESSION['hangman_word'] = $choosen_word;
     
    //Create alphabet
     
    $_SESSION['letters'] = "abcdefghijklmnopqrstuvwxyz";
    }

    // Check guess length
    if(isset($users_guess) && strlen($users_guess) != 1)
    {
    die(
    'You must enter only one letter. <a href="'.$file_name.'">Return</a>');
    }

    // Check there letters
    if (ereg('[^A-Za-z]'$users_guess))
    {
    die(
    'You may only use letters. <a href="'.$file_name.'">Return</a>');
    }

    // Make sure havent already guessed letter
    if(preg_match(strtoupper("/".$users_guess."/"),  $_SESSION['letters']) && isset($users_guess))
    {
     
    $Letter_Twice="1"  ;
    }



    // Switches guessed letters to upper case
    $correct_word $_SESSION['hangman_word'];
    $guess_check str_replace($users_guessstrtoupper($users_guess), $correct_word);

    //Updates Alphabet with letter guessed
    $_SESSION['letters']   = str_replace($users_guessstrtoupper($users_guess), $_SESSION['letters']);



    // Checks if user guessed an incorrect letter
    if (isset($users_guess) && $guess_check == $correct_word AND $Letter_Twice !=="1")
    {
     
    $_SESSION['hangman_loses']++;

    // Check if max loses has been met
    if($_SESSION['hangman_loses'] > $Game_lifes-1)
    {
     
    session_destroy();

      echo 
    ' All lifes used up :(<br> The word was <b>'.strtolower($_SESSION['hangman_word']).'</b><br>';

     if(
    $use_images == true){

     echo 
    "<img src='".$image_locations."".$Game_lifes.".".$image_type."'>";
                }

     echo 
    '<a href="'.$file_name.'">Start New Game?</a>  ' ;
     die();
    }

    }
    else
    {
     
    $_SESSION['hangman_word'] = $guess_check;

     
    // Check for win
     
    if($_SESSION['hangman_word'] == strtoupper($_SESSION['hangman_word']))
     {
      
    session_destroy();
      die(
    'You\'ve won!<br> The word was <b>'.strtolower($_SESSION['hangman_word']).'!</b><br> <a href="'.$file_name.'">Start New Game?</a>');
     }
    }
    ?>
    <html>
    <head>
    <title>Hang-man</title>
    <style>
     a:visited {color:0000ff;}
     a:link {color:0000ff;}
    </style>
    </head>
    <body>
    <?php

    //Choose Whether to Link or Not link Letter
    function buttons($let){
    if(
    preg_match(strtoupper("/".$let."/"),  $_SESSION['letters'])){
    $let $let." ";
    } else {
     
    $let "<b><a href='".$file_name."?guess=".$let."'>".$let."</a> ";
    }
    return 
    $let;
    }

     
    //Letters
    echo buttons("a");
    echo 
    buttons("b");
    echo 
    buttons("c");
    echo 
    buttons("d");
    echo 
    buttons("e");
    echo 
    buttons("f");
    echo 
    buttons("g");
    echo 
    buttons("h");
    echo 
    buttons("i");
    echo 
    buttons("j");
    echo 
    buttons("k");
    echo 
    buttons("l");
    echo 
    buttons("m");
    echo 
    buttons("n");
    echo 
    buttons("o");
    echo 
    buttons("p");
    echo 
    buttons("q");
    echo 
    buttons("r");
    echo 
    buttons("s");
    echo 
    buttons("t");
    echo 
    buttons("u");
    echo 
    buttons("v");
    echo 
    buttons("w");
    echo 
    buttons("x");
    echo 
    buttons("y");
    echo 
    buttons("z");

    ?>

    <br />
    <?php
    //do we want images?
    if($use_images == true){

     if(isset(
    $_SESSION['hangman_loses'])){
     echo 
    "<img src='".$image_locations."".$_SESSION['hangman_loses'].".".$image_type."'>";
            }else{
     echo 
    "<img src='".$image_locations."0.".$image_type."'>";
                                            }
                                             }
    ?>
    <br />
    Word:

    <?php

    // Print word, with lower caps (non-guessed) hidden
    print ereg_replace('[a-z]','_ '$_SESSION['hangman_word']);

    if(
    $Letter_Twice =="1"){echo"<br><br>Sorry. You Cannot Enter the Same Letter twice.";}
    ?>




    <br />
    Lifes:

    <?php
    // Put loses as zero if unset
    if(!isset($_SESSION['hangman_loses'])) $_SESSION['hangman_loses'] = 0;

    print 
    $_SESSION['hangman_loses'].'/'.$Game_lifes;
    ?>
    <div style="position:absolute; width: 80px; height: 30px; right: 0px; top: 0px;">
      <div align="center"><strong><a href="<?php echo $file_name?>?reset=yes"> Reset</a> </strong></div>
    </div>
    </body>
    </html>
    And the bigger word list, off wiki pedia with 2 letter words removed.

    Code:
    about|above|across|act|active|activity|add|afraid|after|again|age|ago|agree|air|all|alone|along|already|always|amount|and|angry|another|answer|anyone|anything|anytime|appear|apple|area|arm|army|around|arrive|art|ask|attack|aunt|autumn|away|baby|base|back|bad|bag|ball|bank|basket|bath|bean|bear|beautiful|beer|bed|bedroom|behave|before|begin|behind|bell|below|besides|best|better|between|big|bird|birth|birthday|bit|bite|black|bleed|block|blood|blow|blue|board|boat|body|boil|bone|book|border|born|borrow|both|bottle|bottom|bowl|box|boy|branch|brave|bread|break|breakfast|breathe|bridge|bright|bring|brother|brown|brush|build|burn|business|bus|busy|but|buy|cake|call|can|candle|cap|car|card|care|careful|careless|carry|case|cat|catch|central|century|certain|chair|chance|change|chase|cheap|cheese|chicken|child|children|chocolate|choice|choose|circle|city|class|clever|clean|clear|climb|clock|cloth|clothes|cloud|cloudy|close|coffee|coat|coin|cold|collect|colour|comb|comfortable|common|compare|come|complete|computer|condition|continue|control|cook|cool|copper|corn|corner|correct|cost|contain|count|country|course|cover|crash|cross|cry|cup|cupboard|cut|dance|dangerous|dark|daughter|day|dead|decide|decrease|deep|deer|depend|desk|destroy|develop|die|different|difficult|dinner|direction|dirty|discover|dish|direction|dog|door|double|down|draw|dream|dress|drink|drive|drop|dry|duck|dust|duty|each|ear|early|earn|earth|east|easy|eat|education|effect|egg|eight|either|electric|elephant|else|empty|end|enemy|enjoy|enough|enter|equal|entrance|escape|even|evening|event|ever|every|everyone|exact|everybody|examination|example|except|excited|exercise|expect|expensive|explain|extremely|eye|face|fact|fail|fall|false|family|famous|far|farm|father|fast|fat|fault|fear|feed|feel|female|fever|few|fight|fill|film|find|fine|finger|finish|fire|first|fit|five|fix|flag|flat|float|floor|flour|flower|fly|fold|food|fool|foot|football|for|force|foreign|forest|forget|forgive|fork|form|fox|four|free|freedom|freeze|fresh|friend|friendly|from|front|fruit|full|fun|funny|furniture|further|future|game|garden|gate|general|gentleman|get|gift|give|glad|glass|goat|god|gold|good|goodbye|grandfather|grandmother|grass|grave|great|green|grey|ground|group|grow|gun|hair|half|hall|hammer|hand|happen|happy|hard|hat|hate|have|he|head|healthy|hear|heavy|hello|help|heart|heaven|height|help|hen|her|here|hers|hide|high|hill|him|his|hit|hobby|hold|hole|holiday|home|hope|horse|hospital|hot|hotel|house|how|hundred|hungry|hour|hurry|husband|hurt|ice|idea|important|increase|inside|into|introduce|invent|iron|invite|island|jelly|job|join|juice|jump|just|keep|key|kill|kind|king|kitchen|knee|knife|knock|know|ladder|lady|lamp|land|large|last|late|lately|laugh|lazy|lead|leaf|learn|leave|leg|left|lend|length|less|lesson|let|letter|library|lie|life|light|like|lion|lip|list|listen|little|live|lock|lonely|long|look|lose|lot|love|low|lower|luck|machine|main|make|male|man|many|map|mark|market|marry|matter|may|meal|mean|measure|meat|medicine|meet|member|mention|method|middle|milk|million|mind|minute|miss|mistake|mix|model|modern|moment|money|monkey|month|moon|more|morning|most|mother|mountain|mouth|move|much|music|must|name|narrow|nation|nature|near|nearly|neck|need|needle|neighbour|neither|net|never|new|news|newspaper|next|nice|night|nine|noble|noise|none|nor|north|nose|not|nothing|notice|now|number|obey|object|ocean|of|off|offer|office|often|oil|old|one|only|open|opposite|orange|order|other|our|out|outside|over|own|page|pain|paint|pair|pan|paper|parent|park|part|partner|party|pass|past|path|pay|peace|pen|pencil|people|pepper|per|perfect|period|person|petrol|photograph|piano|pick|picture|piece|pig|pin|pink|place|plane|plant|plastic|plate|play|please|pleased|plenty|pocket|point|poison|police|polite|pool|poor|popular|position|possible|potato|pour|power|present|press|pretty|prevent|price|prince|prison|private|prize|probably|problem|produce|promise|proper|protect|provide|public|pull|punish|pupil|push|put|queen|question|quick|quiet|quite|radio|rain|rainy|raise|reach|read|ready|real|really|receive|record|red|remember|remind|remove|rent|repair|repeat|reply|report|rest|restaurant|result|return|rice|rich|ride|right|ring|rise|road|rob|rock|room|round|rubber|rude|rule|ruler|run|rush|sad|safe|sail|salt|same|sand|save|say|school|science|scissors|search|seat|second|see|seem|sellsend|sentence|serve|seven|several|***|shade|shadow|shake|shape|share|sharp|she|sheep|sheet|shelf|shine|ship|shirt|shoe|shoot|shop|short|should|shoulder|shout|show|sick|side|signal|silence|silly|silver|similar|simple|single|since|sing|sink|sister|sit|six|size|skill|skin|skirt|sky|sleep|slip|slow|smoke|small|smell|smile|smoke|snow|soap|sock|soft|some|someone|something|sometimes|son|soon|sorry|sound|soup|south|space|speak|special|speed|spell|spend|spoon|sport|spread|spring|square|stamp|stand|star|start|station|stay|steal|steam|step|still|stomach|stone|stop|store|storm|story|strange|street|strong|structure|student|study|stupid|subject|substance|successful|such|sudden|sugar|suitable|summer|sun|sunny|support|sure|surprise|sweet|swim|sword|table|take|talk|tall|taste|taxi|tea|teach|team|tear|telephone|television|tell|ten|tennis|terrible|test|than|that|the|their|then|there|therefore|these|thick|thin|thing|think|third|this|though|threat|three|tidy|tie|title|today|toe|together|tomorrow|tonight|too|tool|tooth|top|total|touch|town|train|tram|travel|tree|trouble|true|trust|twice|try|turn|type|uncle|under|understand|unit|until|up|use|useful|usual|usually|vegetable|very|village|voice|visit|wait|wake|walk|want|warm|wash|waste|watch|water|way|weak|wear|weather|wedding|week|weight|welcome|well|west|wet|what|wheel|when|where|which|while|white|who|why|wide|wife|wild|will|win|wind|window|wine|winter|wire|wise|wish|with|without|woman|wonder|word|work|world|worry|worry|worst|write|wrong|year|yes|yesterday|yet|you|young|your|zero|zebra
    Last edited by Mentor; 23-02-2006 at 09:06 PM.

  7. #7
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    3,285
    Tokens
    0

    Latest Awards:

    Default

    Tomorrow I might do a version of this with AJAX



    i used to be NintendoNews. visit my blog or add me on twitter.
    need help with vista? i am a microsoft certified technology specialist in configuring windows vista and connected home integrator.. pm me for help!


    "I am the way, the truth, and the life. No one comes to the Father except through me"
    John 14:6 (NIV)


  8. #8
    Join Date
    Aug 2004
    Location
    bristol
    Posts
    3,799
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by NintendoNews
    Tomorrow I might do a version of this with AJAX
    Wouldn't it be easier and more effective just to rewrite it in 100% JavaScript? As not only would it not "reload" the page, but no loading after you've initially loaded it would be necessary.

  9. #9
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default

    Quote Originally Posted by Nets
    Wouldn't it be easier and more effective just to rewrite it in 100% JavaScript? As not only would it not "reload" the page, but no loading after you've initially loaded it would be necessary.
    Writing compleaty in JS would do my head in lol. But you have a point, shoudl add some php value, i may add a score board etc
    (btw about the css bit, i figured it out, the doctype was forcing it in to a strct mode in firefox, while the test version i was working wasnt, so my less than standard css useage wasnt working to well )

Posting Permissions

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