prog8/testsource/numbergame.ill

107 lines
2.9 KiB
Plaintext
Raw Normal View History

2018-01-12 00:55:47 +01:00
%output basic
2018-01-03 21:43:19 +01:00
%import c64lib
%import mathlib
2017-12-28 04:20:59 +01:00
~ main {
2018-04-03 16:40:24 +02:00
var .str name = '?' * 80
var .str guess = '?' * 80
2017-12-28 19:08:33 +01:00
var secretnumber
var attempts_left = 10
2017-12-28 04:20:59 +01:00
2017-12-29 02:28:59 +01:00
2018-01-03 21:43:19 +01:00
start:
2017-12-31 03:19:06 +01:00
c64.init_system()
2017-12-29 02:28:59 +01:00
2017-12-28 04:20:59 +01:00
A = c64.VMCSB
2018-01-13 23:49:57 +01:00
A |= 2
2017-12-28 04:20:59 +01:00
c64.VMCSB = A
2018-02-20 01:16:16 +01:00
c64.VMCSB |= 2 ; @todo when this works it replaces the three lines above
2017-12-28 04:20:59 +01:00
2017-12-28 19:08:33 +01:00
; greeting
2017-12-31 03:19:06 +01:00
c64scr.print_string("Enter your name: ")
Y = c64scr.input_chars(name)
2017-12-28 19:08:33 +01:00
c64.CHROUT('\n')
2017-12-28 04:20:59 +01:00
c64.CHROUT('\n')
2017-12-31 03:19:06 +01:00
c64scr.print_string("Hello, ")
c64scr.print_string(name)
2017-12-28 19:08:33 +01:00
c64.CHROUT('.')
c64.CHROUT('\n')
; create a secret random number from 1-100
2018-01-01 23:46:33 +01: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 17:56:55 +01:00
AY = c64flt.GETADRAY()
2018-01-01 23:46:33 +01:00
secretnumber=A
;A=math.randbyte()
;A+=c64.RASTER
;A-=c64.TIME_LO
;X,secretnumber=math.divmod_bytes(A, 99)
2017-12-28 19:08:33 +01:00
2017-12-31 03:19:06 +01:00
c64scr.print_string("I am thinking of a number from 1 to 100!You'll have to guess it!\n")
2017-12-28 04:20:59 +01:00
2018-01-03 21:43:19 +01:00
printloop:
2017-12-31 03:19:06 +01:00
c64scr.print_string("\nYou have ")
c64scr.print_byte_decimal(attempts_left)
c64scr.print_string(" guess")
2017-12-29 01:16:39 +01:00
; @todo comparison expression so we can do if attempts_left>0 ...
2017-12-28 23:03:59 +01:00
A = attempts_left
2017-12-29 02:28:59 +01:00
A--
2017-12-28 23:03:59 +01:00
if_zero A goto ask_guess
2017-12-31 03:19:06 +01:00
c64scr.print_string("es")
2018-01-03 21:43:19 +01:00
ask_guess:
2017-12-31 03:19:06 +01:00
c64scr.print_string(" left.\nWhat is your next guess? ")
Y = c64scr.input_chars(guess)
2017-12-28 19:08:33 +01:00
c64.CHROUT('\n')
[$22.word] = guess
c64.FREADSTR(A)
2018-01-01 17:56:55 +01:00
AY = c64flt.GETADRAY()
2018-01-13 23:49:57 +01: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 19:08:33 +01:00
if_zero goto correct_guess
if_gt goto too_high
2017-12-31 03:19:06 +01:00
c64scr.print_string("That is too ")
c64scr.print_string("low!\n")
2017-12-28 19:08:33 +01:00
goto continue
2018-01-03 21:43:19 +01:00
correct_guess:
2017-12-31 03:19:06 +01:00
c64scr.print_string("\nThat's my number, impressive!\n")
2017-12-28 23:03:59 +01:00
goodbye()
2017-12-28 19:08:33 +01:00
return
2018-01-03 21:43:19 +01:00
too_high:
2017-12-31 03:19:06 +01:00
c64scr.print_string("That is too ")
c64scr.print_string("high!\n")
2017-12-28 19:08:33 +01:00
2018-01-03 21:43:19 +01:00
continue:
2017-12-28 19:08:33 +01:00
attempts_left--
if_zero attempts_left goto game_over
goto printloop
2018-01-03 21:43:19 +01:00
game_over:
2017-12-31 03:19:06 +01:00
c64scr.print_string("\nToo bad! It was: ")
c64scr.print_byte_decimal(secretnumber)
2017-12-28 19:08:33 +01:00
c64.CHROUT('\n')
2018-01-16 01:47:55 +01: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 19:08:33 +01:00
return
2017-12-28 23:03:59 +01:00
sub goodbye ()->() {
2017-12-31 03:19:06 +01:00
c64scr.print_string("\nThanks for playing. Bye!\n")
2017-12-28 04:20:59 +01:00
return
2017-12-28 19:08:33 +01:00
}
2017-12-28 04:20:59 +01:00
2018-01-12 00:55:47 +01:00
}