Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
|
|
@ -17,7 +17,7 @@ repeat
|
|||
else
|
||||
sleep 1
|
||||
if sum mod 4 = 1
|
||||
n = random 3
|
||||
n = randint 3
|
||||
else
|
||||
n = 4 - (sum + 3) mod 4
|
||||
.
|
||||
|
|
|
|||
32
Task/21-game/Forth/21-game.fth
Normal file
32
Task/21-game/Forth/21-game.fth
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
: READKEY
|
||||
1+ BEGIN
|
||||
KEY DUP 27 = ABORT" Bye!"
|
||||
48 - 2DUP > OVER 0 > AND IF
|
||||
DUP 48 + EMIT CR SWAP DROP EXIT
|
||||
THEN DROP
|
||||
REPEAT
|
||||
;
|
||||
: 21GAME CLS
|
||||
0 2 RND 1-
|
||||
." 21 is a two player game." CR
|
||||
." The game is played by choosing a number (1, 2 or 3) to be added to the running total. "
|
||||
." The game is won by the player whose chosen number causes the running total to reach exactly 21."
|
||||
." The running total starts at zero. One player will be the computer."
|
||||
BEGIN
|
||||
NOT
|
||||
CR ." The sum is " OVER . CR
|
||||
SWAP OVER IF
|
||||
." How many would you like add?"
|
||||
." (1-3) " 3 READKEY
|
||||
ELSE
|
||||
." It is the computer's turn."
|
||||
4 OVER 1- 4 MOD -
|
||||
DUP 4 = IF 3 RND 1+ MIN THEN
|
||||
DUP CR ." Computer adds " . CR
|
||||
THEN + SWAP
|
||||
OVER 21 < NOT UNTIL
|
||||
CR
|
||||
IF ." Congratulations. You win."
|
||||
ELSE ." Bad Luck. Computer wins."
|
||||
THEN CR DROP
|
||||
;
|
||||
|
|
@ -1,25 +1,25 @@
|
|||
100 PROGRAM "21Game.bas"
|
||||
110 RANDOMIZE
|
||||
120 LET SUM,ADD=0
|
||||
130 LET TURN=RND(2)
|
||||
130 LET TURN=RND(2)-1
|
||||
140 CLEAR SCREEN
|
||||
150 PRINT "21 is a two player game, the game is played by choosing a number (1, 2, or 3) to be added to the running total. The game is won by the player whose chosen number causes the running total to reach exactly 21."
|
||||
160 PRINT "The running total starts at zero. One player will be the computer.":PRINT
|
||||
170 DO
|
||||
180 LET TURN=1-TURN
|
||||
180 LET TURN=NOT TURN
|
||||
190 SET #102:INK 3:PRINT "The sum is";SUM:SET #102:INK 1
|
||||
200 IF TURN=1 THEN
|
||||
200 IF TURN THEN
|
||||
210 PRINT "It is your turn.":PRINT "How many would you like to add? (1-3): ";
|
||||
220 LET ADD=READKEY
|
||||
230 IF ADD>21-SUM THEN PRINT "You can only add";21-SUM
|
||||
240 ELSE
|
||||
250 LET ADD=4-MOD((SUM-1),4)
|
||||
260 IF ADD=4 THEN LET ADD=MIN(RND(3)+1,SUM)
|
||||
250 LET ADD=4-MOD(SUM-1,4)
|
||||
260 IF ADD=4 THEN LET ADD=RND(3)+1
|
||||
270 PRINT "It is the computer's turn.":PRINT "The computer adds";ADD
|
||||
280 END IF
|
||||
290 PRINT :LET SUM=SUM+ADD
|
||||
300 LOOP WHILE SUM<21
|
||||
310 IF TURN=1 THEN
|
||||
310 IF TURN THEN
|
||||
320 PRINT "Congratulations. You win."
|
||||
330 ELSE
|
||||
340 PRINT "Bad luck. The computer wins."
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue