mirror of
https://github.com/KarolS/millfork.git
synced 2024-10-31 14:04:58 +00:00
Guess-a-number example; make echo run on PC-88
This commit is contained in:
parent
c438152f1d
commit
2f63eafc3a
@ -2,14 +2,16 @@
|
||||
|
||||
## Cross-platform examples
|
||||
|
||||
* [Hello world](crossplatform/hello_world.mfk) (C64/C16/PET/VIC-20/Atari/Apple II/BBC Micro/ZX Spectrum/PC-88/Armstrad CPC) – simple text output
|
||||
* [Hello world](crossplatform/hello_world.mfk) (C64/C16/PET/VIC-20/PET/Atari/Apple II/BBC Micro/ZX Spectrum/PC-88/Armstrad CPC) – simple text output
|
||||
|
||||
* [Text encodings](crossplatform/text_encodings.mfk) (C64/ZX Spectrum) – examples of text encoding features
|
||||
|
||||
* [Echo](crossplatform/echo.mfk) (C64/C16/ZX Spectrum)– simple text input and output
|
||||
* [Echo](crossplatform/echo.mfk) (C64/C16/ZX Spectrum/PC-88)– simple text input and output
|
||||
|
||||
* [Calculator](crossplatform/calculator.mfk) (C64/C16/ZX Spectrum/PC-88) – simple numeric input and output
|
||||
|
||||
* [Guessing game](crossplatform/guess.mfk) (C64/C16/ZX Spectrum/PC-88) – a guess-a-number game
|
||||
|
||||
* [Fire effect](crossplatform/fire.mfk) (C64/C16/ZX Spectrum) – a simple fire effect
|
||||
|
||||
* [Bell](crossplatform/bell.mfk) (Apple II/ZX Spectrum) – a program that goes \*ding!\*
|
||||
|
@ -3,7 +3,7 @@
|
||||
import c64_basic
|
||||
#elseif CBM_264
|
||||
import c264_basic
|
||||
#elseif ZX_SPECTRUM
|
||||
#elseif ZX_SPECTRUM || NEC_PC_88
|
||||
// no imports needed
|
||||
#else
|
||||
#error Unsupported platform
|
||||
@ -12,11 +12,12 @@
|
||||
import stdio
|
||||
|
||||
void main() {
|
||||
pointer line
|
||||
while true {
|
||||
readline()
|
||||
line = readline()
|
||||
// empty line is read as a single space
|
||||
if readline_out[0] == 32 && readline_out[1] == 0 { return }
|
||||
putstrz(readline_out)
|
||||
putchar(13)
|
||||
if line[0] == 32 && line[1] == 0 { return }
|
||||
putstrz(line)
|
||||
new_line()
|
||||
}
|
||||
}
|
||||
|
64
examples/crossplatform/guess.mfk
Normal file
64
examples/crossplatform/guess.mfk
Normal file
@ -0,0 +1,64 @@
|
||||
import random
|
||||
import stdio
|
||||
import err
|
||||
|
||||
#if CBM_64
|
||||
import c64_basic
|
||||
#endif
|
||||
|
||||
#if CBM_264
|
||||
import c264_basic
|
||||
#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()
|
||||
new_line()
|
||||
}
|
Loading…
Reference in New Issue
Block a user