|
Post by tsh73 on Feb 28, 2023 20:49:55 GMT
There was a thread in 2020 at LB forum libertybasiccom.proboards.com/thread/957/contest-line-atari-basic-gameThere is an ATARI BASIC code in first post (it is contest code with goal to fit in 10 lines - so line numbers are just for that. Only GOTO is GOTO 3) With minimal changes, runnable JB/ LB code is 1 X$="CANNOT DOYOU WALK OPENED CLOSED A SWORD A KEY NOTHING A CHEST A DRAGON A CORPSE " 2 R=1: C=0: I=0: X$=X$+"TAKEN YOU DIED YOU WON. " 3 'PRINT "R=";R, "C=";C, "I=";I LET L$="CAVEPIT HALLLAKE":PRINT "YOU ARE IN A ";mid$(L$,R*4-3,4):INPUT U$:U$=UPPER$(U$) 4 M=2*(U$="NORTH")*(R<3)-2*(U$="SOUTH")*(R>2)+(R=2 AND U$="WEST")-(R=3 AND U$="EAST") 5 LET A=(3+C+2*(I=2))*(R=2 AND U$="LOOK CHEST")+(11+(I=2))*(R=3 AND U$="KILL DRAGON")+(M<>0) 6 LET A=A+(5+R)*(U$="LOOK")+(6-I)*(U$="INVENTORY")+(6-(I=0))*(R=4 AND U$="LOOK CORPSE") 7 LET B=100*R+10*C+I:A=A+10*(B=400 AND U$="GET KEY")+2*(B=201 AND U$="OPEN CHEST")+10*(B=211 AND U$="GET SWORD") 8 LET R=R+M:C=C+(A=2):I=I+(A=10) 9 PRINT "> ";U$:print mid$(X$,A*9+1,9) 10 IF A<11 THEN GOTO 3
You can try it and ponder how in works inside. ;) Actually I tried to recreate it in readable / more useful/expandable form libertybasiccom.proboards.com/thread/985/10-lines-adventure-rewritten(but it was another story) Recently I recalled it and tried to explain how it works and THERE THEY HID THE MAZE (next post ;) )
|
|
|
Post by tsh73 on Feb 28, 2023 20:50:25 GMT
So. Each line commented out, explained and re-created with ordinary JB commands. Still works the same (or so it seems to me).
'10 lines adventure 'explained '1 X$="CANNOT DOYOU WALK OPENED CLOSED A SWORD A KEY NOTHING A CHEST A DRAGON A CORPSE " ' ... X$=X$+"TAKEN YOU DIED YOU WON. " 'so A is the answer - index in X$. Let's use WORD$() X$="CANNOT DO,YOU WALK, OPENED, CLOSED, A SWORD, A KEY, NOTHING, A CHEST, A DRAGON, A CORPSE, TAKEN ,YOU DIED,YOU WON. " 'A= 0 1 2 3 4 5 6 7 8 9 10 11 12
2 R=1: C=0: I=0
3 'PRINT "R=";R, "C=";C, "I=";I 'L$="CAVEPIT HALLLAKE" 'alike, R is room number, index in L$. . Let's use WORD$() too L$="CAVE PIT HALL LAKE" 'R= 1 2 3 4 'so we start from room R=1 (CAVE)
'this is start of the loop DO 'PRINT "YOU ARE IN A ";mid$(L$,R*4-3,4) PRINT "YOU ARE IN A ";word$(L$,R) INPUT U$:U$=UPPER$(U$)
'4 M=2*(U$="NORTH")*(R<3)-2*(U$="SOUTH")*(R>2)+(R=2 AND U$="WEST")-(R=3 AND U$="EAST") 'this is actually there maze is stored 'lake(4) 'pit(2) hall(3) ' cave(1) 'M is change between rooms, 0 means no change select case case U$="NORTH" and R<3 '(pit, cave) then move is 2 (to lake, hall) M=2 case U$="SOUTH" and R>2 '(lake, hall) then move is -2 (pit, cave) M=-2 case R=2 AND U$="WEST" '(pit) move is 1 (to hall) M=1 case R=3 AND U$="EAST" '(hall) move is -1 (to pit) M=-1 case else M=0 end select 'That's all maze it had. 6 possible moves. But it is all packed in a single line (!) 'next line has LET A=...+(M<>0), which results in "YOU WALK" if M<>0 or "CANNOT DO" if you can't walk there
'5 LET A=(3+C+2*(I=2))*(R=2 AND U$="LOOK CHEST")+(11+(I=2))*(R=3 AND U$="KILL DRAGON")+(M<>0) ' A is the answer - index in X$ A=0 'default is CANNOT DO select case case M<>0 A=1 'YOU WALK case R=3 AND U$="KILL DRAGON" 'dragon is in the hall A=11 'you are probably dead if I=2 then A=A+1'inless you got sword, then you won. case R=2 AND U$="LOOK CHEST" 'chest is in the pit A=3 'CLOSED if C=1 then A=A+C 'if OPENED then you see (4) A SWORD if I=2 then A=A+2 'if sword taken then you see (6) NOTHING end select '6 LET A=A+(5+R)*(U$="LOOK")+(6-I)*(U$="INVENTORY")+(6-(I=0))*(R=4 AND U$="LOOK CORPSE") select case case U$="LOOK" A=5+R 'for rooms 1,2,3,4 (CAVE PIT HALL LAKE) 'get responces 6,7,8,9 (NOTHING, A CHEST, A DRAGON, A CORPSE) case U$="INVENTORY" A=6-I 'I=2 (4) A SWORD, I=1 (5) A KEY, I=0 (6) NOTHING case R=4 AND U$="LOOK CORPSE" 'corpse is at the LAKE A=6 'NOTHING if I=0 then A=A-1 'if key is not taken then we see (5) A KEY end select '7 LET B=100*R+10*C+I:A=A+10*(B=400 AND U$="GET KEY")+2*(B=201 AND U$="OPEN CHEST")+10*(B=211 AND U$="GET SWORD") 'B actually is game state in a single number: room*100+chest_is_open*10+inventory B=100*R+10*C+I select case case B=400 AND U$="GET KEY" 'at the LAKE without key (I=0) A=10 'you can GET KEY -> (10) TAKEN case B=201 AND U$="OPEN CHEST" 'in the PIT with a KEY (I=1) A=2 'you can OPEN CHEST -> (2) OPENED case B=211 AND U$="GET SWORD" 'in the PIT with opened chest (C=1) and a KEY (I=1) A=10 'you can GET SWORD -> (10) TAKEN end select 8 LET R=R+M:C=C+(A=2):I=I+(A=10) 'so M is change between rooms 'C is state of the chest, (A=2) is (OPENED) so C 0/1 is closed/opened 'I is inventory, starts 0, increments on (A=10) that is (TAKEN) 'so 0 is empty, then we could take key (I=1), and at last we take sword (I=2) '9 PRINT "> ";U$:print mid$(X$,A*9+1,9) ' A is the answer - index in X$ PRINT "> ";U$:print word$(X$,A+1,",") '10 IF A<11 THEN GOTO 3 LOOP while A<11 'A=11,12 is end of the game
|
|
|
Post by cundo on Feb 28, 2023 21:25:24 GMT
I made it! (I was playing it haha)
|
|
|
Post by cundo on Feb 28, 2023 21:30:22 GMT
Random starting room
2 R=INT(rnd(1)*4 +1): C=0: I=0
Now I need a random objects placement, and random weapon.
|
|
|
Post by plus on Mar 1, 2023 16:16:10 GMT
Very impressive to do this in 10 lines.
Even with tsh73 notes, it took a long time to figure how to get out of lake...try everything and then wind up in a pit. I think I want a map LOL!
|
|