REM REM --- Tiny BASIC Interpreter and Compiler Project REM --- Mugwump Demonstration Game REM REM --- Released as Public Domain by Damian Gareth Walker 2019 REM --- Created: 13-Aug-2019 REM REM --- Variables REM C: axis diff between player guess and mugwump position REM D: distance between player guess and mugwump position REM G: mugwump column REM H: mugwump row REM M: moves taken REM R: random number generator seed REM X: player guess column REM Y: player guess row REM --- Initialise the random number generator 1 PRINT "Think of a number." 2 INPUT R 3 IF R<0 THEN LET R=0 4 IF R>4095 THEN LET R=4095 REM --- Initialise the game 5 GOSUB 200 6 LET G=R-(R/10*10) 6 GOSUB 200 7 LET H=R-(R/10*10) 8 LET M=0 REM --- Input player guess 10 PRINT "Where is the mugwump? Enter column then row." 11 INPUT X,Y 12 IF X>=0 THEN IF X<=9 THEN IF Y>=0 THEN IF Y<=9 THEN GOTO 20 13 PRINT "That location is off the grid!" 14 GOTO 10 REM --- Process player guess 20 LET M=M+1 21 PRINT "The mugwump is..." 22 LET D=0 23 LET C=G-X 24 GOSUB 60 25 LET C=H-Y 26 GOSUB 60 27 IF D=0 THEN GOTO 40 28 PRINT "...",D," cells away." 29 IF M>10 THEN GOTO 50 30 PRINT "You have taken ",M," turns so far." 35 GOTO 10 REM --- Player has won 40 PRINT "...RIGHT HERE!" 45 PRINT "You took ",M," turns to find it." 47 END REM --- Player has lost 50 PRINT "You have taken too long over this. You lose!" END REM --- Helper subroutine to calculate distance from player to mugwump REM Inputs: C - difference in rows or columns REM D - running total distance REM Output: D - running total distance, updated 60 IF C<0 THEN LET C=-C 65 LET D=D+C 70 RETURN REM --- Random number generator REM Input: R - current seed REM Outputs: R - updated seed 200 LET R=5*R+35 210 LET R=R-R/4096*4096 220 RETURN