My implementation in Scheme of the game Kinema, that was published in BASIC Computer Games in 1978.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use srfi-13 extras) | |
(printf #<<EOF | |
KINEMA | |
Adaption of BASIC computer game from 1978 | |
EOF | |
) | |
(define correct-count) | |
(define (prompt-and-evaluate-answer question answer) | |
(display question) | |
(display "? ") | |
(let ((G (read))) | |
(if (> .15 (abs (/ (- G answer) answer))) | |
(begin | |
(display "Close enough.") | |
(set! correct-count (+ correct-count 1))) | |
(display "Not even close....")) | |
(printf "Correct answer is ~A\n" answer))) | |
(define (main) | |
(newline) (newline) | |
(let* ((velocity (+ 5 (random 35))) | |
(time (/ (+ 1 (* 2 (random velocity))) 10))) | |
(set! correct-count 0) | |
(printf | |
"A ball is thrown upwars at ~A meters per second.\n\n" | |
velocity) | |
(prompt-and-evaluate-answer | |
"How high will it go (in meters)" | |
(* .05 (* velocity velocity))) | |
(prompt-and-evaluate-answer | |
"How long until it returns (in seconds)" | |
(/ velocity 5)) | |
(prompt-and-evaluate-answer | |
(sprintf "What will its velocity be after ~A seconds" time) | |
(- velocity (* 10 time))) | |
(printf "\n~A right out of 3." correct-count) | |
(when (> correct-count 2) (display " not bad!")) | |
(main))) | |
(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment