FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


How do you make categories?





Denvis
I've made a fully working hangman game and I want to add additional categories. Can anybody help?

Code:
$_SESSION['space'] = 0;
$wordlist = array ('HANGMAN');
$word = $wordlist [array_rand($wordlist)];
   for ($x=0; $x<strlen($word);$x++)
   {
      if ($_SESSION['chosenword'][$x] == " ")
         {
            $_SESSION['space']++;
         }
      if ($word[$x] !== ' ')   
      {
         $hide = $hide."-";
      }
      else
      {
         $hide = $hide." ";
      }
   }
   $_SESSION['chosenword'] = $word;
   $_SESSION['hidden'] = $hide;
Nemesis234
what do you mean by additional "catagories"

in that code snippet there is not even mention of 1 category??
jmraker
I'm guessing the categories are for different phrases. Perhaps you could use include files as in

Code:
<?php

// game init

if(is_new_game()){
    $category = mt_rand(1, 9);
    include 'category.' . $category . '.inc.php';
}

// rest of game init and stuff

?>


and make 'category.1.inc.php' through 'category.9.inc.php' which setup different phrases. Adjust the mt_rand call for more or less categories.

or if you're using a text file you can split it up into seperate files

Code:
<?php

// game init

if(is_new_game()){
    $category = mt_rand(1, 9);
    $phrases = file('category.' . $category . '.txt', FILE_IGNORE_NEW_LINES);
    // pick a random line/phrase
}

// rest of game init and stuff

?>
Related topics
New forums?
Help: SQL error after uploading new files(thread updated)
Script php about gallery
Internet Download Manager
Windows Tips&tricks!
Tutorials
10 rules of india film making
Tutorialized, 4,988 Free Tutorials in 430 categories!
PHP help: Categories > Archives
Categories
Changing Categories of a blog post
Joomla Sections and Categories
Categories versus tags
Adding Categories
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.