prog8/testsource/numbergame.ill

93 lines
2.4 KiB
Plaintext
Raw Normal View History

2017-12-28 22:03:59 +00:00
output prg,basic
2017-12-28 18:08:33 +00:00
;reg_preserve off ; @todo global option
2017-12-28 03:20:59 +00:00
import "c64lib"
~ main {
var .text name = '?' * 80
2017-12-28 18:08:33 +00:00
var .text guess = '?' * 80
var secretnumber
var attempts_left = 10
2017-12-28 03:20:59 +00:00
start
A = c64.VMCSB
2017-12-28 18:08:33 +00:00
A |= 2 ; @todo c64.VMCSB |= 2
2017-12-28 03:20:59 +00:00
c64.VMCSB = A
2017-12-28 18:08:33 +00:00
; greeting
2017-12-28 03:20:59 +00:00
c64util.print_string("Enter your name: ")
2017-12-28 18:08:33 +00:00
Y = c64util.input_chars(name)
c64.CHROUT('\n')
2017-12-28 03:20:59 +00:00
c64.CHROUT('\n')
2017-12-28 18:08:33 +00:00
c64util.print_string("Hello, ")
c64util.print_string(name)
c64.CHROUT('.')
c64.CHROUT('\n')
; create a secret random number from 1-100
c64.RNDA(0)
c64.MUL10()
c64.MUL10()
c64.FADDH()
c64.FADDH()
AY = c64util.GETADRAY()
secretnumber = A
c64util.print_string("I am thinking of a number from 1 to 100!You'll have to guess it!\n")
2017-12-28 03:20:59 +00:00
printloop
2017-12-28 18:08:33 +00:00
c64util.print_string("\nYou have ")
c64util.print_byte_decimal(attempts_left)
2017-12-28 22:03:59 +00:00
c64util.print_string(" guess")
2017-12-29 00:16:39 +00:00
; @todo comparison expression so we can do if attempts_left>0 ...
2017-12-28 22:03:59 +00:00
A = attempts_left
2017-12-29 00:16:39 +00:00
A --
2017-12-28 22:03:59 +00:00
if_zero A goto ask_guess
c64util.print_string("es")
ask_guess
c64util.print_string(" left.\nWhat is your next guess? ")
2017-12-28 18:08:33 +00:00
A = c64util.input_chars(guess)
c64.CHROUT('\n')
[$22.word] = guess
c64.FREADSTR(A)
AY = c64util.GETADRAY()
2017-12-29 00:16:39 +00:00
A -= secretnumber ; @todo condition so we can do if guess > secretnumber....
2017-12-28 18:08:33 +00:00
if_zero goto correct_guess
if_gt goto too_high
c64util.print_string("That is too ")
c64util.print_string("low!\n")
goto continue
correct_guess
2017-12-28 22:03:59 +00:00
c64util.print_string("\nThat's my number, impressive!\n")
goodbye()
2017-12-28 18:08:33 +00:00
return
too_high
c64util.print_string("That is too ")
c64util.print_string("high!\n")
continue
attempts_left--
if_zero attempts_left goto game_over
goto printloop
game_over
c64util.print_string("\nToo bad! It was: ")
c64util.print_byte_decimal(secretnumber)
c64.CHROUT('\n')
2017-12-28 22:03:59 +00:00
goodbye()
2017-12-28 18:08:33 +00:00
return
2017-12-28 22:03:59 +00:00
sub goodbye ()->() {
2017-12-28 18:08:33 +00:00
;var x ; @todo vars in sub
;memory y = $c000 ; @todo vars in sub
;const q = 22 ; @todo const in sub
2017-12-28 22:03:59 +00:00
c64util.print_string("\nThanks for playing. Bye!\n")
2017-12-28 03:20:59 +00:00
return
2017-12-28 18:08:33 +00:00
}
2017-12-28 03:20:59 +00:00
}