Spinning rod animation/Text: Difference between revisions
Content deleted Content added
No edit summary |
Thundergnat (talk | contribs) →{{header|zkl}}: Remove Racket entry that was dumped in the middle of the zkl entry |
||
Line 427: | Line 427: | ||
{{trans|C Shell}} |
{{trans|C Shell}} |
||
<lang zkl>foreach n,rod in ((1).MAX, T("|", "/", "-", "\\")){ |
<lang zkl>foreach n,rod in ((1).MAX, T("|", "/", "-", "\\")){ |
||
print(" %s\r".fmt(rod)); |
print(" %s\r".fmt(rod)); |
||
(define (print-remaining tokens-remaining) |
|||
(printf "~a tokens remain.\n" tokens-remaining)) |
|||
(define (read-tokens) |
|||
(define num (read)) |
|||
(cond |
|||
[(and (natural? num) (< num 4)) num] |
|||
[else |
|||
(display "Please enter a number between 1 to 3\n") |
|||
(read-tokens)])) |
|||
(define (pturn tokens-remaining) |
|||
(cond |
|||
[(not (zero? tokens-remaining)) |
|||
(print-remaining tokens-remaining) |
|||
(display "Your turn. How many tokens? ") |
|||
(define n (read-tokens)) |
|||
(cturn (- tokens-remaining n) n)] |
|||
[else (display "Computer wins!")])) |
|||
(define (cturn tokens-remaining p-took) |
|||
(cond |
|||
[(not (zero? tokens-remaining)) |
|||
(print-remaining tokens-remaining) |
|||
(define c-take (- 4 p-took)) |
|||
(printf "Computer takes ~a tokens\n" c-take) |
|||
(pturn (- tokens-remaining c-take))] |
|||
[else (display "You win!")])) |
|||
(pturn 12) |
|||
Atomic.sleep(0.25); |
Atomic.sleep(0.25); |