;This is a very, very simple adventure›;type program. There are 10 rooms›;numbered 0-9. In each room there›;are exits and maybe a treasure.››;The goal in this adventure is›;to collect the treasures in the fewest›;number of moves. When you think you›;have all the treasures, eXit the›;game and see your score.››;This is FAR from a real adventure›;game and it really isn't challenging›;at all, but it does show the use›;of ARRAYs of records.››;Here is the record for each room››TYPE room=[BYTE north,› south,› east,› west,› treasure]››››DEFINE size="5" ;5 bytes per room››BYTE ARRAY cave(50) ;save enough space› ;for 10 rooms››CARD score,› turns››room POINTER here ; our POINTER››BYTE room_num ;This holds the current› ;room number the player› ;is in.››PROC exits()››;*If a exit field in the record has›; a 255, that means there is no›; exit in that direction*›› PrintE("Exits: ")› IF here.north<>255 THEN› Print("North ")› FI› IF here.south<>255 THEN› Print("South ")› FI› IF here.east<>255 THEN› Print("East ")› FI› IF here.west<>255 THEN› Print("West ")› FI› PutE()›RETURN››PROC money()››;*Here we print how much treasure is›; in the room*›› PrintF("%EThere is $%U here.%E",here.treasure)›RETURN››PROC description()››;*What does the room look like?*›› exits()› money()›RETURN›››BYTE FUNC get_command()››;*This is the controlling routine.›; It gets a command key and executes›; it. It returns a 1 if the user›; wants to quit, 0 otherwise.›› BYTE command›› turns = turns + 1› PutE()› Print("Ãïííáîä ­¾ ")› Open(1,"K:",4,0)› command=GetD(1)› Close(1)››;*I don't know if I mentioned this ›; before or not. But when you GetD()›; a key from the keyboard, the BYTE›; returned is the ATASCII value of›; that character. Example, if the›; user press an A, command is set to›; 65. A single quote before a›; character means the ATASCII value›; of that character. So 'A = 65››› IF command='? THEN› PrintE("Help")› PutE()› PrintE(" Commands")› PrintE(" --------")› PrintE(" N - Go North")› PrintE(" S - Go South")› PrintE(" E - Go East")› PrintE(" W - Go West")› PrintE(" T - Take Treasure")› PrintE(" C - Current Score")› PrintE(" R - Room Number")› PrintE(" D - Room Description")› PrintE(" X - Exit")› PrintE(" ? - Help")› PutE()›› ELSEIF command='R THEN › PrintE("Room number")› PrintF("%EYou are in room #%U%E",room_num)›› ELSEIF command='D THEN › PrintE("Description")› description()›› ELSEIF command='T THEN› PrintE("Take Treasure")› IF here.treasure THEN› score = score + here.treasure ;add the treasure to the score› here.treasure=0 ;remove the treasure from athe room› PrintE("Treasure taken!")› ELSE› PrintE("There is no treasure to take!")› FI›› ELSEIF command='C THEN› PrintE("Current Score")› PrintF("%EYou have $%U in %U moves.%E",score,turns)›› ELSEIF command='N THEN› PrintE("North")› IF here.north<>255 THEN› room_num=here.north› here = cave + (room_num * size)› description()› ELSE › PrintE("There is no exit in that direction.")› FI›› ELSEIF command='S THEN› PrintE("South")› IF here.south<>255 THEN› room_num=here.south› here = cave + (room_num * size)› description()› ELSE › PrintE("There is no exit in that direction.")› FI›› ELSEIF command='E THEN› PrintE("East")› IF here.east <>255 THEN› room_num=here.east› here = cave + (room_num * size)› description()› ELSE › PrintE("There is no exit in that direction.")› FI›› ELSEIF command='W THEN› PrintE("West")› IF here.west<>255 THEN› room_num=here.west› here = cave + (room_num * size)› description()› ELSE › PrintE("There is no exit in that direction.")› FI›› ELSEIF command='X THEN› PrintE("Exit")› PrintF("%EYour final score is:%E $%U in %U moves.%E",score,turns)› RETURN(1)›› ELSE› Put(command)› PutE()› PrintE("I don't know that command!")› PrintE("Use ? for help.")› FI››RETURN(0)›››PROC place_treasure()››;*Put a random amout of treasure in›; a random room.››› BYTE rnd1,› rnd2,› counter›› room POINTER temp›› rnd2=Rand(6)+1 ; how many rooms will have treasure›› FOR counter=1 TO rnd2› DO› rnd1=Rand(10) ;which room?› temp = cave + (rnd1 * size)›› rnd1=Rand(240) ;how much money?› temp.treasure=rnd1› OD›RETURN›››PROC init()››;*Now we have to read in the whole›; cave in from the disk and initialize›; some variables to their starting›; values.››;When we read the cave in from the ›;data file on the disk, this is the›;order it is read in: north, south,›;east, west and the treasure amount.››;Here's an example:››; 255›; 255›; 6›; 8›; 0››;This means there is no exit north›;or south. Room 6 is to the east.›;Room 8 is to the west. There is no›;treasure. Actually, all the rooms›;have 0 treasure. We put the treasure›;in later.››› BYTE i›› turns=0› score=0› Open(2,"D:APROG12.DAT",4,0)› FOR i=0 TO 9› DO› here = cave + (i * size)› here.north=InputBD(2)› here.south=InputBD(2)› here.east=InputBD(2)› here.west=InputBD(2)› here.treasure=InputBD(2)› OD› Close(2)› place_treasure()››;Let's start in room 4›› room_num=4› here = cave + (room_num * size)››RETURN››PROC main()›› BYTE rval›› init()› description()› DO› rval=get_command()› UNTIL rval› OD›RETURN››