Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > funny game

Reply
Thread Tools

funny game

 
 
robin
Guest
Posts: n/a
 
      08-15-2005
this is some basic stuff, but I think some of you might have fun with
it,
--


#!/perl
use strict;
my @compresponses=('Yes.', ' No.', 'Maybe.', 'Nothing doing.', 'You
might be
crazy to ask that.', 'You are so cool.', 'The magic 8 box likes you',
'Cool!', 'Hmmm.',
'2$#@(&*#&*(*&#$$&(*', 'No way in heck.',, 'Good luck.', 'I like what
you\'re doing with yourself', 'This game sucks.', 'Better luck next
time.',
'Try again.', 'Maybe so.', 'Forever.', 'Difficult to tell.', 'You
really
crack me up.',
'Good, but no cigar.', 'Have a cold beer.', 'Having fun?', 'Good
thinking.',
'Whatever.','Are you implying I am fat?','Go and put the kettle on.','I
want
you to think about what you just asked.','Fourty Two.','It will all end
in
tears.',
'A long time ago in a galaxy far far away...','I\'m late for a very
important date.','That\'s hard to say - I\'ll have to get back to
you.','Such things are not for me to decide.','I have a
dream!','Vanity,
Vanity, All is vanity!',
'Are you always this tenecious?','I could tell you, but then I\'d have
to
kill you.','What do I look like - a fortune teller!?');

my $in;
my $answer;
while ()
{
srand;
print "Ask the magic 8 ball a question: (\"q\" to quit)\n";
$in = <STDIN>;
chomp ($in);
print "\n\n--Mail me at webmaster\@infusedlight.net!--\n\n" and
exit
if $in eq "q";
next if ! $in or $in =~ /^\s*$/;
$answer = $compresponses[int rand @compresponses];
print "ANSWER: $answer\n\n";
sleep 2;
}


--
Robin
--
http://www.velocityreviews.com/forums/(E-Mail Removed)
--

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      08-15-2005
robin wrote:
> this is some basic stuff, but I think some of you might have fun with
> it,
> --
>
>
> #!/perl
> use strict;


After $deity knows how many years, you *still* refuse to use warnings?!

> my @compresponses=('Yes.', ' No.', 'Maybe.', 'Nothing doing.', 'You
> might be
> crazy to ask that.', 'You are so cool.', 'The magic 8 box likes you',
> 'Cool!', 'Hmmm.',
> '2$#@(&*#&*(*&#$$&(*', 'No way in heck.',, 'Good luck.', 'I like what
> you\'re doing with yourself', 'This game sucks.', 'Better luck next
> time.',
> 'Try again.', 'Maybe so.', 'Forever.', 'Difficult to tell.', 'You
> really
> crack me up.',
> 'Good, but no cigar.', 'Have a cold beer.', 'Having fun?', 'Good
> thinking.',
> 'Whatever.','Are you implying I am fat?','Go and put the kettle on.','I
> want
> you to think about what you just asked.','Fourty Two.','It will all end
> in
> tears.',
> 'A long time ago in a galaxy far far away...','I\'m late for a very
> important date.','That\'s hard to say - I\'ll have to get back to
> you.','Such things are not for me to decide.','I have a
> dream!','Vanity,
> Vanity, All is vanity!',
> 'Are you always this tenecious?','I could tell you, but then I\'d have
> to
> kill you.','What do I look like - a fortune teller!?');
>


Gaahhhhh! What do you have against legible code? And *why* are you
mixing logic with data?!

> my $in;
> my $answer;


Neither of these are used outside the following block. They should be
declared in the smallest scope possible.

> while ()


Personal preference - that looks yucky. Like you forgot something.
while (1) at least makes it explicit you're writing an infinite loop.

> {
> srand;


Wholly unnecessary. Please read:
perldoc -f rand

> print "Ask the magic 8 ball a question: (\"q\" to quit)\n";
> $in = <STDIN>;
> chomp ($in);


chomp (my $in = <STDIN>);

> print "\n\n--Mail me at webmaster\@infusedlight.net!--\n\n" and
> exit
> if $in eq "q";


but not if $in is 'Q'?

> next if ! $in or $in =~ /^\s*$/;


So that the question can't consist of a single 0? Because an empty
string is already taken care of by the regexp.

> $answer = $compresponses[int rand @compresponses];
> print "ANSWER: $answer\n\n";
> sleep 2;
> }


IMHO, this looks rather cleaner:
#!/usr/bin/perl
use strict;
use warnings;
chomp (my @compresponses=<DATA>);

my $in;
do {
print qq/Ask the magic 8 ball a question: ("q" to quit)\n/;
chomp ($in = <STDIN>);
unless ($in =~ /^\s*$/ or lc $in eq 'q'){
my $answer = $compresponses[int rand @compresponses];
print "ANSWER: $answer\n\n";
sleep 2;
}
} until lc $in eq 'q';

print "\n\n--Mail me at webmaster\@infusedlight.net!--\n\n";

__DATA__
Yes.
No.
Maybe.
Nothing doing.
You might be crazy to ask that.
You are so cool.
The magic 8 box likes you
Cool!
Hmmm.
2$#@(&*#&*(*&#$$&(*
No way in heck.
Good luck.
I like what you're doing with yourself
This game sucks.
Better luck next time.
Try again.
<etc...>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Game programming for kids: looking for open source 2D game developmentkit Max Kubierschky Python 10 03-31-2007 07:18 PM
I need help with card game game of war in GUI enviroment judith Java 0 11-01-2006 06:11 AM
Funny Pictures ! Funny Jokes ! Drink Recipes, Reviews & More ! joevan Computer Support 0 06-29-2006 06:00 PM
OT: The Interview - Real, Funny...Real Funny The Rev [MCT] MCSE 42 05-31-2005 10:42 PM
Java Game- Game can't find it's graphics jar file BlackHawke Java 12 01-26-2004 06:14 AM



Advertisments