mirror of
https://github.com/KarolS/millfork.git
synced 2024-11-06 06:06:31 +00:00
71 lines
1.4 KiB
Plaintext
71 lines
1.4 KiB
Plaintext
import random
|
|
import stdio
|
|
import err
|
|
|
|
#if CBM_64
|
|
import c64_basic
|
|
#endif
|
|
|
|
#if CBM_264
|
|
import c264_basic
|
|
#endif
|
|
|
|
#define READKEY = CBM_64 | CBM_VIC | CBM_264 | CBM_128 | ZX_SPECTRUM | NEC_PC_88 | ATARI_8
|
|
|
|
void main () {
|
|
init_rand_seed()
|
|
ensure_mixedcase()
|
|
putstrz("Welcome to the guessing game."z)
|
|
new_line()
|
|
while true {
|
|
play_round()
|
|
}
|
|
|
|
}
|
|
|
|
void play_round() {
|
|
word guess
|
|
word answer
|
|
word guess_count
|
|
do {
|
|
answer.hi = rand()
|
|
answer.lo = rand()
|
|
} while answer > 999
|
|
answer += 1
|
|
guess_count = 0
|
|
|
|
putstrz("I picked a number between 1 and 1000."z)
|
|
new_line()
|
|
while true {
|
|
putstrz("Your guess?"z)
|
|
new_line()
|
|
guess = readword()
|
|
while errno != err_ok {
|
|
putstrz("That wasn't a number! Try again."z)
|
|
new_line()
|
|
guess = readword()
|
|
}
|
|
guess_count += 1
|
|
if guess == answer { break }
|
|
if answer < guess {
|
|
putstrz("My number is smaller!"z)
|
|
new_line()
|
|
}
|
|
if answer > guess {
|
|
putstrz("My number is bigger!"z)
|
|
new_line()
|
|
}
|
|
}
|
|
putstrz("Congratulations! You guessed my number!"z)
|
|
new_line()
|
|
putstrz("It took you only "z)
|
|
putword(guess_count)
|
|
putstrz(" attempts!"z)
|
|
new_line()
|
|
#if READKEY
|
|
putstrz("Press any key to play again."z)
|
|
readkey()
|
|
new_line()
|
|
#endif
|
|
new_line()
|
|
} |