-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathguess.mfk
75 lines (67 loc) · 1.46 KB
/
guess.mfk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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_264 | CBM_VIC | ZX_SPECTRUM | NEC_PC_88 | APPLE_2
#if READKEY
import keyboard
#endif
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()
}