The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Games::Wumpus - Play Hunt the Wumpus

SYNOPSIS

 my $game = Games::Wumpus -> new -> init;

 while (!defined $game -> finished) {
    ($status, @messages) = $game -> move  ($someplace);
    say for @messages;
    ($status, @messages) = $game -> shoot (@somewhere);
    say for @messages;
 }

 if ($game -> finished) {say "Won!"}
 else                   {say "Lost!"}

DESCRIPTION

This class can be used to play a game of Hunt the Wumpus. It will keep state, perform action, and deduce whether a game is won or lost.

The following methods are available:

new

Class methods that returns an uninitialized object.

init

Initializes an object. Creates a Games::Wumpus::Cave object, fills the players quiver with arrows, and places the player at the start location. Returns the initialized object.

cave

Accessor returning the cave used in the current game.

item

Accessor returning the number of arrows.

lose_arrow

Accessor to reduce the number of arrows by one.

finished

Accessor returning the win/lose state of the game. If an undefined value is returned, the game isn't finished yet. A false but defined value means the player has lost the game (eaten by the Wumpus, fallen in a pit, shot by an arrow, ran out of arrows). A true value means the game was won (the Wumpus was shot).

win

Accessor setting a win for the player.

lose

Accessor setting the game lost for the player.

describe

Returns a string describing where the player is in the cave, the tunnels leading from the current location, any hints regarding nearby hazards, and the number of arrows left.

move

Takes a new location as argument. It assumes the argument is well formatted - that is, exactly one, defined, argument is parsed. Returns a status and a list of strings. If the player cannot move to the specified location 0 is returned as status, and the reason why as a string. Otherwise 1 is returned, and a (possibly empty) list of strings describing encounters with hazards. If the Wumpus or a pit is encountered, the game is declared a loss.

shoot

Takes a list (1 to 5) of locations as argument -- the path a shot arrow must follow. It assumes the argument is well formatted, 1 to 5 defined values. Returns a status and a list of strings. If the shot cannot be performed (no arrows, path goes through the same tunnel twice in succession, first location isn't connected to current location), 0 and the reason why the shot cannot be performed is returned as status and list of strings. Otherwise, 1 is returned, and list of strings describing interesting events. If the Wumpus is shot, the game is won. If the player is shot, the game is lost. Shooting an arrow may cause the Wumpus to move (and eat you).

BUGS

None known.

TODO

Configuration of the game should be possible.

SEE ALSO

Games::Wumpus::Cave, Games::Wumpus::Room, Games::Wumpus::Constants

DEVELOPMENT

The current sources of this module are found on github, git://github.com/Abigail/Games--Wumpus.git.

AUTHOR

Abigail, mailto:wumpus@abigail.be.

COPYRIGHT and LICENSE

Copyright (C) 2009 by Abigail.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

INSTALLATION

To install this module, run, after unpacking the tar-ball, the following commands:

   perl Makefile.PL
   make
   make test
   make install