prog8/compiler/examples/numbergame-novm.p8

47 lines
1.7 KiB
Plaintext
Raw Normal View History

2018-11-28 00:12:23 +00:00
%import c64utils
2018-12-06 23:08:22 +00:00
%import mathlib
2018-11-28 00:12:23 +00:00
~ main {
sub start() {
2018-12-07 23:27:12 +00:00
str name = "????????????????????????????????????????"
str guess = "??????????"
2018-11-28 00:12:23 +00:00
ubyte secretnumber = rnd() % 100
2018-12-07 23:27:12 +00:00
c64.VMCSB |= 2 ; switch lowercase chars
2018-12-06 23:08:22 +00:00
c64scr.print_string("Please introduce yourself: ")
2018-12-07 23:27:12 +00:00
c64scr.input_chars(name)
2018-12-06 23:08:22 +00:00
c64scr.print_string("\n\nHello, ")
2018-11-28 00:12:23 +00:00
c64scr.print_string(name)
2018-12-06 23:08:22 +00:00
c64scr.print_string(".\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 {
c64scr.print_string("\nYou have ")
c64scr.print_byte_decimal(attempts_left)
2018-11-28 00:12:23 +00:00
c64scr.print_string(" guess")
if attempts_left>1 c64scr.print_string("es")
2018-12-06 23:08:22 +00:00
c64scr.print_string(" left.\nWhat is your next guess? ")
2018-12-07 23:27:12 +00:00
c64scr.input_chars(guess)
2018-11-28 00:12:23 +00:00
ubyte guessednumber = str2ubyte(guess)
if guessednumber==secretnumber {
2018-12-06 23:08:22 +00:00
c64scr.print_string("\n\nYou guessed it, impressive!\n")
c64scr.print_string("Thanks for playing, ")
c64scr.print_string(name)
c64scr.print_string(".\n")
2018-11-28 00:12:23 +00:00
return
} else {
2018-12-06 23:08:22 +00:00
c64scr.print_string("\n\nThat is too ")
2018-11-28 00:12:23 +00:00
if guessednumber<secretnumber
c64scr.print_string("low!\n")
else
c64scr.print_string("high!\n")
}
}
c64scr.print_string("\nToo bad! My number was: ")
c64scr.print_byte_decimal(secretnumber)
2018-11-28 00:12:23 +00:00
c64scr.print_string(".\n")
return
}
}