mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
96 lines
2.5 KiB
Plaintext
96 lines
2.5 KiB
Plaintext
output prg,basic
|
|
;reg_preserve off ; @todo global option off/on default off?
|
|
|
|
import "c64lib"
|
|
|
|
|
|
~ main {
|
|
var .text name = '?' * 80
|
|
var .text guess = '?' * 80
|
|
var secretnumber
|
|
var attempts_left = 10
|
|
|
|
|
|
start
|
|
c64util.init_system()
|
|
|
|
A = c64.VMCSB
|
|
A |= 2 ; @todo c64.VMCSB |= 2
|
|
c64.VMCSB = A
|
|
|
|
; greeting
|
|
c64util.print_string("Enter your name: ")
|
|
Y = c64util.input_chars(name)
|
|
c64.CHROUT('\n')
|
|
c64.CHROUT('\n')
|
|
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")
|
|
|
|
printloop
|
|
c64util.print_string("\nYou have ")
|
|
c64util.print_byte_decimal(attempts_left)
|
|
c64util.print_string(" guess")
|
|
|
|
; @todo comparison expression so we can do if attempts_left>0 ...
|
|
A = attempts_left
|
|
A--
|
|
if_zero A goto ask_guess
|
|
c64util.print_string("es")
|
|
ask_guess
|
|
c64util.print_string(" left.\nWhat is your next guess? ")
|
|
Y = c64util.input_chars(guess)
|
|
c64.CHROUT('\n')
|
|
[$22.word] = guess
|
|
c64.FREADSTR(A)
|
|
AY = c64util.GETADRAY()
|
|
A -= secretnumber ; @todo condition so we can do if guess > secretnumber....
|
|
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
|
|
c64util.print_string("\nThat's my number, impressive!\n")
|
|
goodbye()
|
|
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')
|
|
goodbye()
|
|
return
|
|
|
|
sub goodbye ()->() {
|
|
;var x ; @todo vars in sub
|
|
;memory y = $c000 ; @todo vars in sub
|
|
;const q = 22 ; @todo const in sub
|
|
|
|
c64util.print_string("\nThanks for playing. Bye!\n")
|
|
return
|
|
}
|
|
|
|
} |