Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
31
Task/21-game/YAMLScript/21-game.ys
Normal file
31
Task/21-game/YAMLScript/21-game.ys
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
!YS-v0
|
||||
|
||||
players =: qw(A B):cycle.drop(rand-int(2))
|
||||
|
||||
defn main():
|
||||
say: |
|
||||
--------------------
|
||||
Welcome to 21 Game
|
||||
--------------------
|
||||
|
||||
loop turn 0 total 0:
|
||||
say: "Running total: $total"
|
||||
say: "Player $(players.$turn)'s turn"
|
||||
total +=: get-num(total)
|
||||
say:
|
||||
when total == 21:
|
||||
say: |
|
||||
Running total is 21. Player $(players.$turn) won!
|
||||
exit: 0
|
||||
recur: turn.++ total
|
||||
|
||||
defn get-num(total):
|
||||
print: 'Enter a number (1,2,3): '
|
||||
val =: read-line()
|
||||
condf val:
|
||||
nil?: exit()
|
||||
\(/[1-3]/):
|
||||
if (total + val:N) > 21:
|
||||
recur()
|
||||
val
|
||||
else: recur()
|
||||
Loading…
Add table
Add a link
Reference in a new issue