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