README
1NAME
2 Games::GuessWord - Guess the letters in a word (ie Hangman)
3
4SYNOPSIS
5 use Games::GuessWord;
6
7 my $g = Games::GuessWord->new(file => "/path/to/wordlist");
8 print "Score: " . $g->score . "\n";
9 print "Chances: " . $g->chances . "\n";
10 print "Answer: " . $g->answer . "\n";
11 my @guesses = $g->guesses;
12 $g->guess("t");
13 # ...
14 if ($g->won) {
15 print "You won!\n";
16 $g->new_word;
17 }
18
19DESCRIPTION
20 This module is a simple wrapper around a word guessing game. You have to
21 guess the word by guessing letters in the word, and is otherwise known
22 as Hangman.
23
24METHODS
25 new
26
27 This is the constructor. You can either pass in a list of words or a
28 wordlist. A random word is picked:
29
30 my $g = Games::GuessWord->new(words => ["sleepy", "grumpy"]);
31 # or...
32 my $g = Games::GuessWord->new(file => "t/words");
33
34 You can also set the number of chances each game has with the chances
35 parameter
36
37 my $g = Games::GuessWord->new(file => "t/words",
38 chances => 5);
39
40 answer
41
42 This method returns the current word being guessed, with asterisks (*)
43 replacing letters that have not been guessed yet. For example, if trying
44 to guess "buffy" and the letters "b" and "f" have been correctly
45 guessed, this will return "b*ff*".
46
47 print "Answer: " . $g->answer . "\n";
48
49 chances
50
51 This method returns the number of chances left. You start off with six
52 chances by default and lose a chance everytime you get a guess wrong.
53
54 print "Chances: " . $g->chances . "\n";
55
56 guess
57
58 This methods guesses a letter in the word:
59
60 $g->guess("t");
61
62 guesses
63
64 This method returns the guesses taken so far this turn:
65
66 my @guesses = $g->guesses;
67
68 new_word
69
70 This method throws the current turn away and picks a new word:
71
72 $g->new_word;
73
74 secret
75
76 This method returns the secret word that the user is trying to guess:
77
78 my $secret = $g->secret;
79
80 score
81
82 This method returns the current score. You get a higher score if you
83 guess the word earlier on. The score persists over turns if you win:
84
85 print "Score: " . $g->score . "\n";
86
87 won
88
89 Returns true if and only if they have won the game, i.e. if the answer
90 equals the secret word.
91
92 lost
93
94 Returns true if and only if they have lost the game, i.e. if they have
95 no more chances left
96
97 starting_chances
98
99 Sets the number of starting chances, i.e. the number of chances the
100 player gets for each game. By default this is six.
101
102SHOWING YOUR APPRECIATION
103 There was a thread on london.pm mailing list about working in a vacumn -
104 that it was a bit depressing to keep writing modules but never get any
105 feedback. So, if you use and like this module then please send me an
106 email and make my day.
107
108 All it takes is a few little bytes.
109
110AUTHOR
111 Leon Brocard <acme@astray.com>
112
113COPYRIGHT
114 Copyright (C) 2001, Leon Brocard
115
116 This module is free software; you can redistribute it or modify it under
117 the same terms as Perl itself.
118
119