2020-09-20 23:49:36 +02:00
|
|
|
%import textio
|
2020-08-26 20:52:38 +02:00
|
|
|
%import conv
|
2022-10-22 16:35:57 +02:00
|
|
|
%import math
|
2019-02-03 00:14:56 +01:00
|
|
|
%zeropage basicsafe
|
2018-12-07 00:08:22 +01:00
|
|
|
|
2018-12-11 00:09:37 +01:00
|
|
|
; The classic number guessing game.
|
2023-06-03 19:14:45 +02:00
|
|
|
; Note: this program can be compiled for multiple target systems.
|
2020-09-20 01:14:53 +02:00
|
|
|
|
|
|
|
|
2019-07-29 23:11:13 +02:00
|
|
|
main {
|
2018-12-11 00:09:37 +01:00
|
|
|
|
2018-11-28 01:12:23 +01:00
|
|
|
sub start() {
|
2018-12-08 00:27:12 +01:00
|
|
|
str name = "????????????????????????????????????????"
|
2018-12-11 00:09:37 +01:00
|
|
|
str input = "??????????"
|
2022-10-22 16:35:57 +02:00
|
|
|
ubyte secretnumber = math.rnd() % 99 + 1 ; random number 1..100
|
2019-08-18 03:16:23 +02:00
|
|
|
ubyte attempts_left
|
2018-11-28 01:12:23 +01:00
|
|
|
|
2020-09-19 22:37:24 +02:00
|
|
|
txt.lowercase()
|
2020-08-27 18:10:22 +02:00
|
|
|
txt.print("Please introduce yourself: ")
|
|
|
|
void txt.input_chars(name)
|
|
|
|
txt.print("\n\nHello, ")
|
|
|
|
txt.print(name)
|
|
|
|
txt.print(".\nLet's play a number guessing game.\nI am thinking of a number from 1 to 100!You'll have to guess it!\n")
|
2018-11-28 01:12:23 +01:00
|
|
|
|
2020-03-11 20:47:42 +01:00
|
|
|
for attempts_left in 10 downto 1 {
|
2018-12-10 09:25:38 +01:00
|
|
|
|
2020-08-27 18:10:22 +02:00
|
|
|
txt.print("\nYou have ")
|
|
|
|
txt.print_ub(attempts_left)
|
|
|
|
txt.print(" guess")
|
2018-12-11 00:09:37 +01:00
|
|
|
if attempts_left>1
|
2020-08-27 18:10:22 +02:00
|
|
|
txt.print("es")
|
|
|
|
txt.print(" left.\nWhat is your next guess? ")
|
|
|
|
void txt.input_chars(input)
|
2020-10-11 18:36:20 +02:00
|
|
|
ubyte guess = conv.str2ubyte(input)
|
2018-12-10 09:25:38 +01:00
|
|
|
|
2018-12-11 00:09:37 +01:00
|
|
|
if guess==secretnumber {
|
2019-07-10 19:14:41 +02:00
|
|
|
ending(true)
|
|
|
|
return
|
2018-11-28 01:12:23 +01:00
|
|
|
} else {
|
2020-08-27 18:10:22 +02:00
|
|
|
txt.print("\n\nThat is too ")
|
2019-01-16 00:28:30 +01:00
|
|
|
if guess<secretnumber
|
2020-08-27 18:10:22 +02:00
|
|
|
txt.print("low!\n")
|
2018-11-28 01:12:23 +01:00
|
|
|
else
|
2020-08-27 18:10:22 +02:00
|
|
|
txt.print("high!\n")
|
2018-11-28 01:12:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-10 19:14:41 +02:00
|
|
|
ending(false)
|
|
|
|
return
|
2018-12-11 00:09:37 +01:00
|
|
|
|
|
|
|
|
2018-12-19 02:51:22 +01:00
|
|
|
sub ending(ubyte success) {
|
2018-12-11 00:09:37 +01:00
|
|
|
if success
|
2020-08-27 18:10:22 +02:00
|
|
|
txt.print("\n\nYou guessed it, impressive!\n")
|
2018-12-11 00:09:37 +01:00
|
|
|
else {
|
2020-08-27 18:10:22 +02:00
|
|
|
txt.print("\nToo bad! My number was: ")
|
|
|
|
txt.print_ub(secretnumber)
|
|
|
|
txt.print(".\n")
|
2018-12-11 00:09:37 +01:00
|
|
|
}
|
2020-08-27 18:10:22 +02:00
|
|
|
txt.print("Thanks for playing, ")
|
|
|
|
txt.print(name)
|
|
|
|
txt.print(".\n")
|
2018-12-11 00:09:37 +01:00
|
|
|
}
|
2018-11-28 01:12:23 +01:00
|
|
|
}
|
|
|
|
}
|