To run online, click here: RUN ONLINE
Here is the source:
Here is the source:
Code:
' PROGRAM GUESS NUMBER
' (c) 2022 by Zarsoft
' Language: ZX BASIC (BORIEL) compiled
#include <input.bas>
#define REPEAT DO
#define UNTIL LOOP UNTIL
#define ROUTINE SUB
#define PROGRAM REM
REM Variable declarations
REM VAR - Global variables
DIM secret AS INTEGER : REM number 1-1000
DIM guess AS INTEGER : REM user guess
LET tries = 0 : REM number of tries
LET GoodGame = 0 : REM user guessed on few tries
LET YouGuessed = 0 : REM User guessed it right
ROUTINE Introduction
CLS
PRINT AT 13,0
PRINT "+------------------+"
PRINT "| GUESS THE NUMBER |"
PRINT "+------------------+"
PRINT " (c) Zarsoft, 2022"
PRINT " ZX BASIC (Boriel)"
PRINT
PRINT
END ROUTINE
ROUTINE PickNumber
PRINT
PRINT "I am thinking of a Number"
PRINT "between 1 and 1000"
PAUSE 50
LET secret = 1+INT (RND*1000)
REM PRINT "secret= ";secret
END ROUTINE
ROUTINE GetUserGuess
PRINT "What is your guess? ";
guess = VAL( INPUT(9) )
LET tries = tries + 1
END ROUTINE
ROUTINE TestGuess
IF guess = secret
LET YouGuessed = 1
PRINT
PRINT "Congratulations, human!"
PRINT "The number was ";secret
PRINT "On target in ";tries;" tries."
PAUSE 50
ELSEIF guess < secret
LET YouGuessed = 0
PRINT
PRINT "Try one bigger than ";guess
PAUSE 50
ELSE
LET YouGuessed = 0
PRINT
PRINT "Try one smaller than ";guess
PAUSE 50
ENDIF
END ROUTINE
ROUTINE TestGoodGame
IF tries <= 10
LET GoodGame = 1
ELSE
PRINT
PRINT "But, it took too much time."
PRINT "Lets try again!"
PAUSE 50
ENDIF
END ROUTINE
ROUTINE GameOver
PRINT
PRINT "GAME OVER - insert another coin"
PRINT
PRINT
PRINT
PRINT
END ROUTINE
ROUTINE Game
InitVariables
PickNumber
REPEAT
GetUserGuess
TestGuess
UNTIL YouGuessed
END ROUTINE
ROUTINE MainRoutine
Introduction
REPEAT
Game
TestGoodGame
UNTIL GoodGame
GameOver
END ROUTINE
PROGRAM GuessNumber
MainRoutine
PROGRAM END