I think it wouldn't be too difficult to imbed this into a normal text
adventure, though there are obvious problems with out-of-context silliness. :)
Also, I bet this is dead-slow on an old 8-bit machine... it could be
sped up by not redrawing the whole screen... just erase each object and
redraw it in the new position should do.
Anyway, I thought some people might want to check this out:
!
! Cheesy Robot Game
! written by
! Greg Alt (galt@facility.cs.utah.edu)
!
Array RobotX -> 20;
Array RobotY -> 20;
Array Alive -> 20;
[ Main; PlayTheGame(); ];
[ initializeRobots i;
for(i=1:i<=20:i++)
{
Alive->i=1;
RobotX->i=random((0->33)-2)+1;
RobotY->i=random((0->32)-2)+1;
}
];
[ displayScreen x y i j;
@erase_window 1;
j=0->33;
for(i=1:i<=0->32:i++)
{
@set_cursor i 1;
@print_char ':';
@set_cursor i j;
@print_char ':';
}
j=0->32;
for(i=1:i<=0->33:i++)
{
@set_cursor 1 i;
@print_char '-';
@set_cursor j i;
@print_char '-';
}
for(i=2:i<=20:i++)
{
x=RobotX->i;
y=RobotY->i;
@set_cursor y x;
if(Alive->i==1)
@print_char '+';
else
@print_char '*';
}
x=RobotX->1;
y=RobotY->1;
@set_cursor y x;
@print_char '@';
@set_cursor 1 1;
];
[ getDir k;
@read_char 1 k;
switch(k)
{
'h': return 16; ! left
'j': return 33; ! down
'k': return 1; ! up
'l': return 18; ! right
'y': return 0; ! up-left
'u': return 2; ! up-right
'b': return 32; ! down-left
'n': return 34; ! down-right
'.': return 17; ! wait
't': { ! teleport
RobotX->1=random((0->33)-2)+1;
RobotY->1=random((0->32)-2)+1;
return 17;
}
'q': quit;
default: return -1;
}
];
[ moveStuff dir dx dy i;
dx=(dir&15)-1;
dy=(dir/16)-1;
RobotX->1=(RobotX->1)+dx;
RobotY->1=(RobotY->1)+dy;
if(RobotX->1==1) RobotX->1=2;
if(RobotY->1==1) RobotY->1=2;
if(RobotX->1==0->33) RobotX->1=0->33-1;
if(RobotY->1==0->32) RobotY->1=0->32-1;
for(i=2:i<=20:i++)
{
if(Alive->i==1)
{
if(RobotX->i<RobotX->1) RobotX->i=RobotX->i+1;
if(RobotX->i>RobotX->1) RobotX->i=RobotX->i-1;
if(RobotY->i<RobotY->1) RobotY->i=RobotY->i+1;
if(RobotY->i>RobotY->1) RobotY->i=RobotY->i-1;
}
}
];
[ collide i j;
for(i=1:i<=20:i++)
for(j=i+1:j<=20:j++)
{
if((RobotX->i==RobotX->j) && (RobotY->i==RobotY->j))
{
Alive->i=0;
Alive->j=0;
}
}
];
[ numAlive i num;
for(i=2:i<=20:i++)
if(Alive->i==1) num++;
return num;
];
[ PlayTheGame num y dir;
y=0->32;
@split_window y;
@set_window 1;
@buffer_mode 0;
initializeRobots();
num=numAlive();
displayScreen();
while(Alive->1==1 && num>0)
{
dir=getDir();
moveStuff(dir);
collide();
displayScreen();
num=numAlive();
}
@erase_window 1;
@split_window 1;
@set_window 0;
if(Alive->1==1) print "^^^You win!!!^^^";
else print "^^^You lose!!!^^^";
quit;
];
-- Videogames, Unicycling, and Anarchism: http://www.cs.utah.edu/~galt/