Recently,
Jeffa and I were discussing a flame by
anonymous monk and I mentioned that I thought I knew the identity of the person posting....
Jeff said he thought he knew as well and asked if my guess began with an "a".
My reply was that it began with a "d" but there wasn't any point in playing hangmonk over something so trivial and thus the idea of Hangmonk came about.
The following grabs a list of the monks lurking in the Monastery and implements a game of hangman based on the name of one of the monks online at the time.
So, the next time you get flamed by
anonymous monk you can play a quick game of Hangmonk to see if you can guess who it is ;-)
Special thanks go out to
DrManhattan for his patient assistance and the recommendation to use map as well as to
Jeffa for helping conceive the idea in the first place and also recommending I use map...you don't want to know how I was doing it before...also, to
ybiC for reminding me to use -w.
Enjoy
#!/usr/bin/perl -w
use strict;
use XML::Simple;
use LWP::UserAgent;
use Games::GuessWord;
my $ua = LWP::UserAgent->new();
my $response = $ua->get("http://www.perlmonks.org/index.pl?node_id=158
+51");
die $response->code() if $response->code() != 200;
my $content = $response->content();
my $cblist = XMLin($content);
my @user = map $_->{username}, @{$cblist->{user}};
my $monk = $user[rand @user];
my $g = Games::GuessWord->new(words => [$monk]);
# Uncomment out the following for testing
# print "Secret: " . $g->secret . "\n";
my @guesses = $g->guesses;
do{
print "Guesses Remaining:" . $g->chances . "\n";
print "The Monk is: " . $g->answer . "\n";
print "What is your Guess?: ";
my $response = <>;
$g->guess($response);
if ($g->won) {
print "Yep, it was " . $g->secret . "...Great
+Guess!\n";
exit;
}
}until($g->chances<=0);
print "Sorry, the monk was: " . $g->secret . "\n";
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.