2018-10-21 21:03:15 +00:00
|
|
|
%import c64utils
|
|
|
|
|
2018-08-14 00:22:59 +00:00
|
|
|
~ main {
|
2018-09-30 20:43:34 +00:00
|
|
|
sub start() {
|
2018-09-30 12:19:41 +00:00
|
|
|
str name = " "
|
2018-09-30 20:43:34 +00:00
|
|
|
str guess = "000000"
|
2018-10-10 07:21:20 +00:00
|
|
|
ubyte secretnumber = rnd() % 100
|
2018-08-14 00:22:59 +00:00
|
|
|
|
2018-10-20 21:45:03 +00:00
|
|
|
vm_write_str("Let's play a number guessing game!\n")
|
|
|
|
vm_write_str("Enter your name: ")
|
|
|
|
vm_input_str(name)
|
|
|
|
vm_write_str("\nHello, ")
|
|
|
|
vm_write_str(name)
|
|
|
|
vm_write_str(".\nI am thinking of a number from 1 to 100! You'll have to guess it!\n")
|
2018-08-14 00:22:59 +00:00
|
|
|
|
2018-10-10 07:21:20 +00:00
|
|
|
for ubyte attempts_left in 10 to 1 step -1 {
|
2018-10-20 21:45:03 +00:00
|
|
|
vm_write_str("\nYou have ")
|
|
|
|
vm_write_num(attempts_left)
|
|
|
|
vm_write_str(" guess")
|
|
|
|
if attempts_left>1 vm_write_str("es")
|
|
|
|
vm_write_str(" left. What is your next guess? ")
|
|
|
|
vm_input_str(guess)
|
2018-10-12 12:01:29 +00:00
|
|
|
ubyte guessednumber = str2ubyte(guess)
|
2018-09-30 20:43:34 +00:00
|
|
|
if guessednumber==secretnumber {
|
2018-10-20 21:45:03 +00:00
|
|
|
vm_write_str("\nYou guessed it, impressive!\n")
|
|
|
|
vm_write_str("Thanks for playing.\n")
|
2018-09-30 20:43:34 +00:00
|
|
|
return
|
|
|
|
} else {
|
2018-10-20 21:45:03 +00:00
|
|
|
vm_write_str("That is too ")
|
2018-09-30 20:43:34 +00:00
|
|
|
if guessednumber<secretnumber
|
2018-10-20 21:45:03 +00:00
|
|
|
vm_write_str("low!\n")
|
2018-09-30 20:43:34 +00:00
|
|
|
else
|
2018-10-20 21:45:03 +00:00
|
|
|
vm_write_str("high!\n")
|
2018-09-30 20:43:34 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-30 12:19:41 +00:00
|
|
|
|
2018-10-20 21:45:03 +00:00
|
|
|
vm_write_str("\nToo bad! My number was: ")
|
|
|
|
vm_write_num(secretnumber)
|
|
|
|
vm_write_str(".\n")
|
2018-09-30 20:43:34 +00:00
|
|
|
return
|
2018-09-06 19:13:49 +00:00
|
|
|
}
|
2018-08-14 00:22:59 +00:00
|
|
|
}
|