GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Games::GuessWord(3) User Contributed Perl Documentation Games::GuessWord(3)

Games::GuessWord - Guess the letters in a word (ie Hangman)

  use Games::GuessWord;

  my $g = Games::GuessWord->new(file => "/path/to/wordlist");
  print   "Score: " . $g->score . "\n";
  print "Chances: " . $g->chances . "\n";
  print  "Answer: " . $g->answer . "\n";
  my @guesses = $g->guesses;
  $g->guess("t");
  # ...
  if ($g->won) {
    print "You won!\n";
    $g->new_word;
  }

This module is a simple wrapper around a word guessing game. You have to guess the word by guessing letters in the word, and is otherwise known as Hangman.

This is the constructor. You can either pass in a list of words or a wordlist. A random word is picked:

  my $g = Games::GuessWord->new(words => ["sleepy", "grumpy"]);
  # or...
  my $g = Games::GuessWord->new(file => "t/words");

You can also set the number of chances each game has with the chances parameter

  my $g = Games::GuessWord->new(file    => "t/words",
                                chances => 5);

This method returns the current word being guessed, with asterisks (*) replacing letters that have not been guessed yet. For example, if trying to guess "buffy" and the letters "b" and "f" have been correctly guessed, this will return "b*ff*".

  print  "Answer: " . $g->answer . "\n";

This method returns the number of chances left. You start off with six chances by default and lose a chance everytime you get a guess wrong.

  print "Chances: " . $g->chances . "\n";

This methods guesses a letter in the word:

  $g->guess("t");

This method returns the guesses taken so far this turn:

  my @guesses = $g->guesses;

This method throws the current turn away and picks a new word:

    $g->new_word;

This method returns the secret word that the user is trying to guess:

  my $secret = $g->secret;

This method returns the current score. You get a higher score if you guess the word earlier on. The score persists over turns if you win:

  print   "Score: " . $g->score . "\n";

Returns true if and only if they have won the game, i.e. if the answer equals the secret word.

Returns true if and only if they have lost the game, i.e. if they have no more chances left

Sets the number of starting chances, i.e. the number of chances the player gets for each game. By default this is six.

There was a thread on london.pm mailing list about working in a vacumn - that it was a bit depressing to keep writing modules but never get any feedback. So, if you use and like this module then please send me an email and make my day.

All it takes is a few little bytes.

Leon Brocard <acme@astray.com>

Copyright (C) 2001-8, Leon Brocard

This module is free software; you can redistribute it or modify it under the same terms as Perl itself.
2008-12-12 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.