Sure, it's in Pascal, but is it in Abelson Pascal?
Name:
Anonymous2012-10-02 14:10
Converted to Sepples.
/* Dino - a text-based game where you try to avoid a dinosaur in a maze
while looking for some treasure and the exit.
by Kostas Michalopoulos. */
assign(f, "DINO.SAV");
/*$I-*/
rewrite(f, 1);
/*$I+*/
if (ioresult != 0) {
output << "Failed to create the DINO.SAV file." << NL;
return;
}
blockwrite(f, rooms, sizeof(rooms));
blockwrite(f, dinox, 1);
blockwrite(f, dinoy, 1);
blockwrite(f, mapx, 1);
blockwrite(f, mapy, 1);
blockwrite(f, playerx, 1);
blockwrite(f, playery, 1);
blockwrite(f, exitx, 1);
blockwrite(f, exity, 1);
blockwrite(f, score, 2);
blockwrite(f, hasmap, 1);
blockwrite(f, exitfound, 1);
close(f);
output << "The game has been saved." << NL;
}
void restoregame()
{
untyped_file f;
assign(f, "DINO.SAV");
/*$I-*/
reset(f, 1);
/*$I+*/
if (ioresult != 0) {
output << "Failed to open DINO.SAV for reading." << NL;
return;
}
blockread(f, rooms, sizeof(rooms));
blockread(f, dinox, 1);
blockread(f, dinoy, 1);
blockread(f, mapx, 1);
blockread(f, mapy, 1);
blockread(f, playerx, 1);
blockread(f, playery, 1);
blockread(f, exitx, 1);
blockread(f, exity, 1);
blockread(f, score, 2);
blockread(f, hasmap, 1);
blockread(f, exitfound, 1);
close(f);
dead=false;
output << "The game has been restored." << NL;
}
void addscore(integer newscore)
{
if (newscore > 0)
output << "You gained " << newscore << " extra treasure. ";
else if (score > 0)
output << "You lost " << -newscore << " treasure. ";
score=score + newscore;
if (score < 0) score=0;
output << "Your treasure now is " << score << '.' << NL;
}
void die()
{
output << "You are now dead." << NL;
dead=true;
}
void showhelp()
{
output << "You can use the following commands:" << NL;
output << NL;
output << " help this screen" << NL;
output << " listen listen for sounds from nearby rooms" << NL;
output << " dig dig the ground" << NL;
output << " north move north" << NL;
output << " south move south" << NL;
output << " east move east" << NL;
output << " west move west" << NL;
output << " wait wait a bit" << NL;
output << " map check your map (if you have it)" << NL;
output << " treasure show your current treasure" << NL;
output << " leave leave the maze (only if you find the exit)" << NL;
output << " save save the game to disk" << NL;
output << " restore restore the game from disk" << NL;
output << " restart restart the game in a new maze" << NL;
output << " exit exit from the game" << NL;
output << NL;
}
Name:
Anonymous2012-10-02 14:11
void listenfordino()
{
integer dist;
dist=trunc(sqrt((playerx - dinox)*(playerx - dinox) + (playery - dinoy)*(playery - dinoy)));
if (dist < 1) output << "There is a weird sensation of something heavy breathing over your neck." << NL;
else if (dist < 2) output << "There is a LOUD and HEAVY sound of steps nearby!" << NL;
else if (dist < 3) output << "There is a heavy sound of steps on dirt." << NL;
else if (dist < 4) output << "There is a distant sound of heavy steps somewhere." << NL;
}
void movetoroom(byte roomx, byte roomy)
{
if ((roomx < 1) || (roomy < 1) || (roomx > mazesize) || (roomy > mazesize)) return;
if ((roomx != playerx) || (roomy != playery)) {
switch (rooms[roomx][roomy].roomtype) {
case treasureroom: {
output << "You have found some treasure." << NL;
addscore(10 + Random(10));
rooms[roomx][roomy].roomtype=emptyroom;
}
break;
case lavaroom: {
output << "You fell in a lava pit." << NL;
die();
}
break;
case waterroom: if (score > 0) {
output << "You fell in a water pit and lost some treasure." << NL;
addscore(-(1 + Random(2)));
} else {
output << "You fell in a water pit. Thankfully you have no treasure with you" << NL;
output << "otherwise it would be lost." << NL;
}
break;
case blockedroom: {
output << "You cannot move there" << NL;
roomx=playerx;
roomy=playery;
}
break;
}
}
playerx=roomx;
playery=roomy;
rooms[playerx][playery].visited=true;
if ((mapx==playerx) && (mapy==playery) && (! dead) && (! hasmap)) {
output << "You have found a map!" << NL;
hasmap=true;
}
if ((exitx==playerx) && (exity==playery) && (! dead) && (! exitfound)) {
output << "You have found a tunnel that seems to be the exit!" << NL;
output << "Now you can leave from here at any point, or continue exploring" << NL;
output << "these cavelike rooms." << NL;
exitfound=true;
}
listenfordino();
if ((playerx==dinox) && (playery==dinoy)) {
output << "You have finally met the dinosaur that inhabits these rooms." << NL;
output << "The creature was not pleased by your visit here and decided" << NL;
output << "to make his dislike for your presense known by breaking your" << NL;
output << "skull in half." << NL;
die();
}
}
void listenaround();
static void listenin(byte x, byte y, boolean& lavasound, boolean& watersound)
{
if ((x < 1) || (y < 1) || (x > mazesize) || (y > mazesize)) return;
if ((rooms[x][y].roomtype==lavaroom) || (rooms[x][y].underground==lavaroom)) lavasound=true;
if (rooms[x][y].roomtype==waterroom) watersound=true;
}
lavasound=false;
watersound=false;
listenin(playerx, playery, lavasound, watersound);
listenin(playerx - 1, playery, lavasound, watersound);
listenin(playerx + 1, playery, lavasound, watersound);
listenin(playerx, playery - 1, lavasound, watersound);
listenin(playerx, playery + 1, lavasound, watersound);
if (lavasound) output << "You can hear the cracking of fire";
if (watersound)
if (lavasound)
output << " and water running somewhere else." << NL;
else
output << "You can hear water running." << NL;
else output << NL;
listenfordino();
}
void digabit()
{
if (rooms[playerx][playery].dug) {
output << "You already dug here." << NL;
} else {
switch (rooms[playerx][playery].underground) {
case treasureroom: {
output << "You have found some underground treasure!" << NL;
addscore(20 + Random(35));
rooms[playerx][playery].underground=emptyroom;
}
break;
case lavaroom: {
output << "You just dug to your grave. A lava pit was in a cave below." << NL;
die();
}
break;
default: output << "There is nothing to be found here." << NL;
}
rooms[playerx][playery].dug=true;
}
}
void showmap()
{
byte x, y;
output << "Your map:" << NL;
output << "=========" << NL;
for( y=1; y <= mazesize; y ++) {
output << " |";
for( x=1; x <= mazesize; x ++) {
roomrecord& with = rooms[x][y];
if ((x==playerx) && (y==playery))
output << " X |";
else if (hasmap || with.visited) {
if (with.dug) output << '>'; else output << ' ';
switch (with.roomtype) {
case emptyroom: if (exitfound && (exitx==x) && (exity==y)) output << 'E'; else output << '.'; break;
case treasureroom: output << '$'; break;
case lavaroom: output << 'v'; break;
case waterroom: output << '='; break;
case blockedroom: output << '#'; break;
}
if (with.dug) output << "<|"; else output << " |";
} else {
output << " ? |";
}
}
output << NL;
}
output << "=========" << NL;
output << "Legend: X You, . Empty, $ Treasure, v Lava, = Water, # Blocked";
if (exitfound) output << ", E Exit";
output << NL;
}
Name:
Anonymous2012-10-02 14:11
void preparemaze()
{
byte x, y;
for( y=1; y <= mazesize; y ++)
for( x=1; x <= mazesize; x ++)
{
roomrecord& with = rooms[x][y];
with.roomtype=emptyroom;
if (Random(200) > 190) with.roomtype=blockedroom;
if (Random(200) > 160) with.roomtype=treasureroom;
if (Random(200) > 180) with.roomtype=lavaroom;
if (Random(200) > 170) with.roomtype=waterroom;
with.underground=emptyroom;
if (Random(100) > 60) with.underground=treasureroom;
if (Random(100) > 70) with.underground=lavaroom;
with.visited=false;
with.dug=false;
}
}
void startgame()
{
textcolor(7);
textbackground(0);
clrscr;
output << "Dino, the game. By Kostas Michalopoulos." << NL;
showhelp();
output << NL;
nexttoken(head, len, cmd, token, tokenlen);
lowerize(token);
if (token=="help") {
showhelp();
if (dead) output << "By the way, you are dead!" << NL;
} else if (token=="exit") {
running=false;
} else if (token=="dig") {
if (dead)
output << "You are too dead to dig here..." << NL;
else {
digabit();
movedino();
listenfordino();
}
} else if (token=="listen") {
if (dead)
output << "Dead people cannot listen" << NL;
else
listenaround();
} else if (token=="north") {
if (dead)
output << "You are dead and cannot move north." << NL;
else {
movedino();
movetoroom(playerx, playery - 1);
}
} else if (token=="south") {
if (dead)
output << "You are dead and cannot move south." << NL;
else {
movedino();
movetoroom(playerx, playery + 1);
}
} else if (token=="east") {
if (dead)
output << "You are dead and cannot move east." << NL;
else {
movedino();
movetoroom(playerx + 1, playery);
}
} else if (token=="west") {
if (dead)
output << "You are dead and cannot move west." << NL;
else {
movedino();
movetoroom(playerx - 1, playery);
}
} else if (token=="wait") {
if (dead)
output << "You can wait for as long as you like, it is the only thing you can do anyway." << NL;
else {
output << "You wait a bit" << NL;
movedino();
movetoroom(playerx, playery);
}
} else if (token=="map") {
showmap();
} else if (token=="treasure") {
output << "Your current treasure is " << score << NL;
} else if (token=="restart") {
startgame();
} else if (token=="save") {
if (dead)
output << "It is not a good idea to save the game when you are dead." << NL;
else
savegame();
} else if (token=="restore") {
restoregame();
} else if (token=="leave") {
if (dead)
output << "You cannot leave the cave while you are dead." << NL;
else if (! exitfound)
output << "You need to find the exit first." << NL;
else if (! ((exitx==playerx) && (exity==playery)))
output << "You need to go back to the exit to leave the cave." << NL;
else {
output << "You have finally found the cave's exit!" << NL;
output << "Unfortunately, while you try to leave through the old tunnel," << NL;
output << "a big boulder falls on you and crushes you instantly." << NL;
output << "Well, better luck next time!" << NL;
die();
}
} else {
output << "I don't understand the command `" << token << "', could you rephase it?" << NL;
}
}
Name:
Anonymous2012-10-02 14:11
anystring prompt()
{
anystring s;
anystring prompt_result;
do {
output << "> ";
input >> s >> NL;
} while (!(s != ""));
prompt_result=s; /* GRAAAAH FUCKITFUCKITUFUCKFUFKOITUCK [oiasjdfpoaijsdfpaodifn */
return prompt_result;
}
void playgame()
{
anystring cmd;
running=true;
while (running) {
cmd=prompt();
parsecommand(cmd);
}
}