2018-11-28 00:12:23 +00:00
|
|
|
%import c64utils
|
2019-01-20 16:45:57 +00:00
|
|
|
%import c64lib
|
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.
|
2018-11-28 00:12:23 +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 = "??????????"
|
|
|
|
ubyte secretnumber = rnd() % 99 + 1 ; random number 1..100
|
2018-11-28 00:12:23 +00:00
|
|
|
|
2018-12-07 23:27:12 +00:00
|
|
|
c64.VMCSB |= 2 ; switch lowercase chars
|
2018-12-21 00:06:01 +00:00
|
|
|
c64scr.print("Please introduce yourself: ")
|
2018-12-07 23:27:12 +00:00
|
|
|
c64scr.input_chars(name)
|
2018-12-21 00:06:01 +00:00
|
|
|
c64scr.print("\n\nHello, ")
|
|
|
|
c64scr.print(name)
|
|
|
|
c64scr.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
|
|
|
|
|
|
|
for ubyte attempts_left in 10 to 1 step -1 {
|
2018-12-10 08:25:38 +00:00
|
|
|
|
2018-12-21 00:06:01 +00:00
|
|
|
c64scr.print("\nYou have ")
|
|
|
|
c64scr.print_ub(attempts_left)
|
|
|
|
c64scr.print(" guess")
|
2018-12-10 23:09:37 +00:00
|
|
|
if attempts_left>1
|
2018-12-21 00:06:01 +00:00
|
|
|
c64scr.print("es")
|
|
|
|
c64scr.print(" left.\nWhat is your next guess? ")
|
2018-12-10 23:09:37 +00:00
|
|
|
c64scr.input_chars(input)
|
2019-03-16 16:50:59 +00:00
|
|
|
ubyte guess = lsb(c64utils.str2uword(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 {
|
2018-12-21 00:06:01 +00:00
|
|
|
c64scr.print("\n\nThat is too ")
|
2019-01-15 23:28:30 +00:00
|
|
|
if guess<secretnumber
|
2018-12-21 00:06:01 +00:00
|
|
|
c64scr.print("low!\n")
|
2018-11-28 00:12:23 +00:00
|
|
|
else
|
2018-12-21 00:06:01 +00:00
|
|
|
c64scr.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
|
|
|
|
|
|
|
|
2018-12-19 01:51:22 +00:00
|
|
|
sub ending(ubyte success) {
|
2018-12-10 23:09:37 +00:00
|
|
|
if success
|
2018-12-21 00:06:01 +00:00
|
|
|
c64scr.print("\n\nYou guessed it, impressive!\n")
|
2018-12-10 23:09:37 +00:00
|
|
|
else {
|
2018-12-21 00:06:01 +00:00
|
|
|
c64scr.print("\nToo bad! My number was: ")
|
|
|
|
c64scr.print_ub(secretnumber)
|
|
|
|
c64scr.print(".\n")
|
2018-12-10 23:09:37 +00:00
|
|
|
}
|
2018-12-21 00:06:01 +00:00
|
|
|
c64scr.print("Thanks for playing, ")
|
|
|
|
c64scr.print(name)
|
|
|
|
c64scr.print(".\n")
|
2018-12-10 23:09:37 +00:00
|
|
|
}
|
2018-11-28 00:12:23 +00:00
|
|
|
}
|
|
|
|
}
|