prog8/python-prototype/testsource/numbergame.ill

107 lines
2.9 KiB
Plaintext
Raw Normal View History

2018-01-11 23:55:47 +00:00
%output basic
2018-01-03 20:43:19 +00:00
%import c64lib
%import mathlib
2017-12-28 03:20:59 +00:00
~ main {
2018-04-03 14:40:24 +00:00
var .str name = '?' * 80
var .str guess = '?' * 80
2017-12-28 18:08:33 +00:00
var secretnumber
var attempts_left = 10
2017-12-28 03:20:59 +00:00
2017-12-29 01:28:59 +00:00
2018-01-03 20:43:19 +00:00
start:
2017-12-31 02:19:06 +00:00
c64.init_system()
2017-12-29 01:28:59 +00:00
2017-12-28 03:20:59 +00:00
A = c64.VMCSB
2018-01-13 22:49:57 +00:00
A |= 2
2017-12-28 03:20:59 +00:00
c64.VMCSB = A
2018-02-20 00:16:16 +00:00
c64.VMCSB |= 2 ; @todo when this works it replaces the three lines above
2017-12-28 03:20:59 +00:00
2017-12-28 18:08:33 +00:00
; greeting
2017-12-31 02:19:06 +00:00
c64scr.print_string("Enter your name: ")
Y = c64scr.input_chars(name)
2017-12-28 18:08:33 +00:00
c64.CHROUT('\n')
2017-12-28 03:20:59 +00:00
c64.CHROUT('\n')
2017-12-31 02:19:06 +00:00
c64scr.print_string("Hello, ")
c64scr.print_string(name)
2017-12-28 18:08:33 +00:00
c64.CHROUT('.')
c64.CHROUT('\n')
; create a secret random number from 1-100
2018-01-01 22:46:33 +00:00
c64.RNDA(0) ; fac = rnd(0)
c64.MUL10() ; fac *= 10
c64.MUL10() ; .. and now *100
c64.FADDH() ; add 0.5..
c64.FADDH() ; and again, so +1 total
2018-01-01 16:56:55 +00:00
AY = c64flt.GETADRAY()
2018-01-01 22:46:33 +00:00
secretnumber=A
;A=math.randbyte()
;A+=c64.RASTER
;A-=c64.TIME_LO
;X,secretnumber=math.divmod_bytes(A, 99)
2017-12-28 18:08:33 +00:00
2017-12-31 02:19:06 +00:00
c64scr.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
2018-01-03 20:43:19 +00:00
printloop:
2017-12-31 02:19:06 +00:00
c64scr.print_string("\nYou have ")
c64scr.print_byte_decimal(attempts_left)
c64scr.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 01:28:59 +00:00
A--
2017-12-28 22:03:59 +00:00
if_zero A goto ask_guess
2017-12-31 02:19:06 +00:00
c64scr.print_string("es")
2018-01-03 20:43:19 +00:00
ask_guess:
2017-12-31 02:19:06 +00:00
c64scr.print_string(" left.\nWhat is your next guess? ")
Y = c64scr.input_chars(guess)
2017-12-28 18:08:33 +00:00
c64.CHROUT('\n')
[$22.word] = guess
c64.FREADSTR(A)
2018-01-01 16:56:55 +00:00
AY = c64flt.GETADRAY()
2018-01-13 22:49:57 +00:00
A -= secretnumber ; @todo condition so we can do if guess > secretnumber.... # @todo "removed statement that has no effect" is WRONG!!
A -= secretnumber ; # @todo "removed statement that has no effect" is WRONG!!
2017-12-28 18:08:33 +00:00
if_zero goto correct_guess
if_gt goto too_high
2017-12-31 02:19:06 +00:00
c64scr.print_string("That is too ")
c64scr.print_string("low!\n")
2017-12-28 18:08:33 +00:00
goto continue
2018-01-03 20:43:19 +00:00
correct_guess:
2017-12-31 02:19:06 +00:00
c64scr.print_string("\nThat's my number, impressive!\n")
2017-12-28 22:03:59 +00:00
goodbye()
2017-12-28 18:08:33 +00:00
return
2018-01-03 20:43:19 +00:00
too_high:
2017-12-31 02:19:06 +00:00
c64scr.print_string("That is too ")
c64scr.print_string("high!\n")
2017-12-28 18:08:33 +00:00
2018-01-03 20:43:19 +00:00
continue:
2017-12-28 18:08:33 +00:00
attempts_left--
if_zero attempts_left goto game_over
goto printloop
2018-01-03 20:43:19 +00:00
game_over:
2017-12-31 02:19:06 +00:00
c64scr.print_string("\nToo bad! It was: ")
c64scr.print_byte_decimal(secretnumber)
2017-12-28 18:08:33 +00:00
c64.CHROUT('\n')
2018-01-16 00:47:55 +00:00
return goodbye()
goodbye() ; @todo fix subroutine usage tracking, it doesn't register this one
return
return
return
return
return
return
return
return
return
2017-12-28 18:08:33 +00:00
return
2017-12-28 22:03:59 +00:00
sub goodbye ()->() {
2017-12-31 02:19:06 +00:00
c64scr.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
2018-01-11 23:55:47 +00:00
}