======================================================= "TENLINER CAVE ADVENTURE" - A ZX81 GAME BY EINAR SAUKAS ======================================================= --------- BACKSTORY --------- As a young warrior apprentice, you have been chosen by the village elders to seek out the evil menace that lurks in some nearby caves. Once found, use any means at your disposal to defeat it... Good luck on your quest! -------- COMMANDS -------- This is a very simple tiny text adventure for the ZX81, coded in 10 lines only. It recognizes the following commands: NORTH SOUTH EAST WEST INVENTORY LOOK LOOK GET OPEN KILL ----- ABOUT ----- This game was created for the "BASIC Tenliners 2016" competition organized by HOMEPUTERIUM (Das Homecomputer-Laboratorium an der Eider-Treene-Schule) in Friedrichstadt, Germany. The competition was to design games in compiled or interpreted BASIC for any 8-bit plataform (Atari, MSX, etc) restricted to 10 lines of code with limited size. It was the first ZX81 game to ever qualify for this competition, not an easy task considering the limitations of ZX81 BASIC! Each program line is under the 120 characters limit, without hidden control codes or initialization. The program only uses a machine code routine from the ZX81 ROM (accessed using "USR 3086") to scroll text on screen, because the ZX81 doesn't provide support for automatic text scrolling. ------- DETAILS ------- This game was adapted from "1 Line Cave Adventure", originally developed by Digital Prawn and myself (Einar Saukas) for the ZX-Spectrum in 2007. An almost complete solution for our original game is available here: http://www.solutionarchive.com/game/id%2C5064/ The original game was already very small. Even so, it was quite challenging to port it to the ZX81 in 10 lines of code, mainly because the ZX81 only accepts a single instruction per command line. Even worse, due to the line length restriction in this category, the instruction responsible for the main game logic had to be broken into 3 separate lines, which means the entire game had to be implemented using 8 instructions only! The main solution was concatenating the entire game state into a single string variable X$, and modeling the game logic as a finite state machine such that a single formula updates the entire game state at once, in a single instruction, based on player movement and action. This core game logic is assisted by another 2 formulas. The first formula validates and calculates player movement based on player input and current location, execute in a single instruction. The second formula validates and calculates player action based on player input, current location, and game state, executed in a single instruction although "broken" into 3 program lines because this last formula was too long. Another problem was, the full list of text responses exceeds the imposed line length limit. For this reason, the same string variable X$ is also used to store some of these responses. The complete game listing is provided here: 1 LET X$="100CANNOT DOYOU WALK OPENED CLOSED A SWORD A KEY NOTHING A CHEST A DRAGON A CORPSE " 2 PRINT TAB USR 3086+USR 3086;"YOU ARE IN A ";"CAVEPIT HALLLAKE"(VAL X$(1)*4-3 TO VAL X$(1)*4) 3 INPUT U$ 4 LET M=2*(U$="NORTH")*(X$(1)<"3")-2*(U$="SOUTH")*(X$(1)>"2")+(X$(1)+U$="2WEST")-(X$(1)+U$="3EAST") 5 LET A=(3+VAL X$(2)+2*(X$(3)="2"))*(X$(1)+U$="2LOOK CHEST")+(11+(X$(3)="2"))*(X$(1)+U$="3KILL DRAGON")+(M<>0) 6 LET A=A+(5+VAL X$(1))*(U$="LOOK")+(6-VAL X$(3))*(U$="INVENTORY")+(6-(X$(3)="0"))*(X$(1)+U$="4LOOK CORPSE") 7 LET A=A+10*(X$( TO 3)+U$="400GET KEY")+2*(X$( TO 3)+U$="201OPEN CHEST")+10*(X$( TO 3)+U$="211GET SWORD") 8 LET X$( TO 3)=STR$ (VAL X$(1)+M)+STR$ (VAL X$(2)+(A=2))+STR$ (VAL X$(3)+(A=10)) 9 PRINT TAB USR 3086;"> ";U$;TAB USR 3086;(X$+"TAKEN YOU DIED YOU WON. ")(A*9+4 TO A*9+12) 10 IF A<11 THEN GOTO 2 The complete list of variables is as follows: X$ = current game state, where: X$(1) = player location (1=cave, 2=pit, 3=hall, 4=lake) X$(2) = chest (0=closed, 1=open) X$(3) = inventory (0=nothing, 1=key, 2=sword) X$(4 TO ) = partial list of text responses U$ = player command M = player movement (from -2 to 2) A = player action (from 0 to 12) The purpose of each program line is described below: Line 1: Initialize game state (location=1, chest=0, inventory=0) Line 2: Print current player location Line 3: Input player command Line 4: Validate and calculate player movement Lines 5 to 7: Validate and calculate player action Line 8: Update game state Line 9: Print game response Line 10: Repeat until player wins or dies Easy, right? =:) ------- CREDITS ------- "TENLINER CAVE ADVENTURE" for the ZX81 by Einar Saukas (c) 2016. Based on "1 Line Cave Adventure" for the ZX-Spectrum by Digital Prawn and Einar Saukas (c) 2007.