Here is a chance to have some fun.
This is a very simple arcade game. Type it in and play it with your friends. Later in this chapter, you may want to improve it.
/* CATMOUSE EXEC */
/* The user says where the mouse is to go. But where */
/* will the cat jump? */
say "This is the mouse ----------> @"
say "These are the cat's paws ---> ( )"
say "This is the mousehole ------> O"
say "This is a wall -------------> |"
say
say "You are the mouse. You win if you reach",
"the mousehole. You cannot go past"
say "the cat. Wait for him to jump over you.",
"If you bump into him you're caught!"
say
say "The cat always jumps towards you, but he's not",
"very good at judging distances."
say "If either player hits the wall he misses a turn."
say
say "Enter a number between 0 and 2 to say how far to",
"the right you want to run."
say "Be careful, if you enter a number greater than 2 then",
"the mouse will freeze and the cat will move!"
say
/*------------------------------------------------------*/
/* Parameters that can be changed to make a different */
/* game */
/*------------------------------------------------------*/
len = 14 /* length of corridor */
hole = 14 /* position of hole */
spring = 5 /* maximum distance cat can jump */
mouse = 1 /* mouse starts on left */
cat = len /* cat starts on right */
/*------------------------------------------------------*/
/* Main program */
/*------------------------------------------------------*/
do forever
call display
/*---------------------------------------------------*/
/* Mouse's turn */
/*---------------------------------------------------*/
pull move
if datatype(move,whole) & move >= 0 & move <= 2
then select
when mouse + move > len then nop /* hits wall */
when cat > mouse,
& mouse + move >= cat /* hits cat */
/* continued ... */
then mouse = cat
otherwise /* moves */
mouse = mouse + move
end
if mouse = hole then leave /* reaches hole */
if mouse = cat then leave /* hits cat */
/*---------------------------------------------------*/
/* Cat turn */
/*---------------------------------------------------*/
jump = random(1,spring)
if cat > mouse then do /* cat tries to jump left */
Temp = cat - jump
if Temp < 1 then nop /* hits wall */
else cat = Temp
end
else do /* cat tries to jump right */
if cat + jump > len then nop /* hits wall */
else cat = cat + jump
end
if cat = mouse then leave
end
/*------------------------------------------------------*/
/* Conclusion */
/*------------------------------------------------------*/
call display
if cat = mouse then say "Cat wins"
else say "Mouse wins"
exit
/*------------------------------------------------------*/
/* Subroutine to display the state of play */
/* */
/* Input: CAT and MOUSE */
/* */
/* Design note: each position in the corridor occupies */
/* three character positions on the screen. */
/*------------------------------------------------------*/
corridor = copies(" ",3*len) /* corridor */
corridor = overlay("O",corridor,3*hole-1) /* hole */
if mouse ¬= len /* mouse in hole? */
then corridor = overlay("@",corridor,3*mouse-1)/* mouse */
corridor = overlay("(",corridor,3*cat-2) /* cat */
corridor = overlay(")",corridor,3*cat)
say " |"corridor"|"
return
Good job! Now, take a while to put your new skills into action, or continue reading.