Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
31
Task/21-game/BASIC256/21-game.basic
Normal file
31
Task/21-game/BASIC256/21-game.basic
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
PLAYER = 1
|
||||
COMP = 0
|
||||
|
||||
sum = 0
|
||||
total = 0
|
||||
turn = int(rand + 0.5)
|
||||
dim precomp = {1, 1, 3, 2}
|
||||
|
||||
while sum < 21
|
||||
turn = 1 - turn
|
||||
print "The sum is "; sum
|
||||
if turn = PLAYER then
|
||||
print "It is your turn."
|
||||
while total < 1 or total > 3 or total + sum > 21
|
||||
input "How many would you like to total? ", total
|
||||
end while
|
||||
else
|
||||
print "It is the computer's turn."
|
||||
total = precomp[sum mod 4]
|
||||
print "The computer totals ", total, "."
|
||||
end if
|
||||
print
|
||||
sum += total
|
||||
total = 0
|
||||
end while
|
||||
|
||||
if turn = PLAYER then
|
||||
print "Congratulations. You win."
|
||||
else
|
||||
print "Bad luck. The computer wins."
|
||||
end if
|
||||
133
Task/21-game/Chipmunk-Basic/21-game.basic
Normal file
133
Task/21-game/Chipmunk-Basic/21-game.basic
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
100 rem 21 game
|
||||
110 rem for rosetta code
|
||||
120 '
|
||||
130 rem initialization
|
||||
140 l$ = chr$(157) : rem left cursor
|
||||
150 dim p$(2),hc(2),ca(4) : hc(1) = 0 : hc(2) = 0 : rem players
|
||||
160 ca(0) = 1 : ca(1) = 1 : ca(2) = 3 : ca(3) = 2 : rem computer answers
|
||||
170 dim cn$(6) : for i = 1 to 6 : read cn$(i) : next i : rem computer names
|
||||
180 def fnm(X)=(X-(INT(X/4))*4):REM modulo function
|
||||
190 '
|
||||
200 rem optionally set screen colors here
|
||||
210 cls
|
||||
220 print " 21 GAME"
|
||||
230 print : print " The goal of this game is to take turns"
|
||||
240 print " adding the value of either 1, 2, or 3"
|
||||
250 print " to a running total. The first player"
|
||||
260 print " to bring the total to 21..."
|
||||
270 print : print " ... WINS THE GAME!"
|
||||
280 print : gosub 1110
|
||||
290 for p = 1 to 2
|
||||
300 '
|
||||
310 rem game setup and get players
|
||||
320 for p = 1 to 2
|
||||
330 print : print "Player ";p;l$;", [H]uman or [C]omputer? ";
|
||||
340 k$ = inkey$ : if k$ <> "c" and k$ <> "h" then 340
|
||||
350 print k$ : hc(p) = (k$ = "c")
|
||||
360 print : print "Player";p;l$ "," : print "Enter your name"; : if hc(p) then goto 400
|
||||
370 input p$(p)
|
||||
380 next p
|
||||
390 goto 420
|
||||
400 gosub 1340 : print "? ";p$(p)
|
||||
410 next p
|
||||
420 print
|
||||
430 for p = 1 to 2 : print p;l$;". ";p$(p) : next p
|
||||
440 print : print "Is this correct (y/n)? ";
|
||||
450 k$ = inkey$ : if k$ <> "y" and k$ <> "n" then 450
|
||||
460 print k$ : if k$ = "n" then goto 290
|
||||
470 print : print "Who will play first (1 or 2)? ";
|
||||
480 k$ = inkey$ : if k$ < "1" or k$ > "2" then 480
|
||||
490 fp = asc(k$)-48 : print k$ : print
|
||||
500 print "Okay, ";p$(fp);" will play first." : print : gosub 1110
|
||||
510 cls
|
||||
520 '
|
||||
530 rem start main game loop
|
||||
540 pi = fp : rt = 0
|
||||
550 print "Total so far:";rt
|
||||
560 print : print p$(pi);"'s turn."
|
||||
570 if hc(pi) then gosub 1240
|
||||
580 if not hc(pi) then gosub 1170
|
||||
590 rt = rt+ad
|
||||
600 if rt = 21 then goto 680
|
||||
610 if rt > 21 then print : print p$(pi);" loses by going over 21!!" : goto 700
|
||||
620 pi = pi+1 : if pi > 2 then pi = 1
|
||||
630 goto 550
|
||||
640 print : print " ... WINS THE GAME!"
|
||||
650 print : gosub 1110
|
||||
660 '
|
||||
670 for p = 1 to 2
|
||||
680 rem winner winner chicken dinner
|
||||
690 print : print "21! ";p$(pi);" wins the game!!!"
|
||||
700 print : print "Would you like to play again? ";
|
||||
710 k$ = inkey$ : if k$ <> "n" and k$ <> "y" then 710
|
||||
720 print k$
|
||||
730 if k$ = "n" then print : print "Okay, maybe another time. Bye!" : end
|
||||
740 goto 200
|
||||
750 print k$ : hc(p) = (k$ = "c")
|
||||
760 print : print "Player";p;l$ "," : print "Enter your name"; : if hc(p) then goto 800
|
||||
770 input p$(p)
|
||||
780 next p
|
||||
790 goto 820
|
||||
800 gosub 1340 : print "? ";p$(p)
|
||||
810 next p
|
||||
820 print : for p = 1 to 2 : print p;l$;". ";p$(p) : next p
|
||||
830 print : print "Is this correct (y/n)? ";
|
||||
840 k$ = inkey$ : if k$ <> "y" and k$ <> "n" then 840
|
||||
850 print k$ : if k$ = "n" then goto 660
|
||||
860 print : print "Who will play first (1 or 2)? ";
|
||||
870 k$ = inkey$ : if k$ < "1" or k$ > "2" then 870
|
||||
880 fp = asc(k$)-48 : print k$ : print
|
||||
890 print "Okay, ";p$(fp);" will play first." : print : gosub 1110
|
||||
900 '
|
||||
910 rem start main game loop
|
||||
920 pi = fp : rt = 0
|
||||
930 print chr$(147);"Total so far: ";rt
|
||||
940 print : print p$(pi);"'s turn."
|
||||
950 if hc(pi) then gosub 1240
|
||||
960 if not hc(pi) then gosub 1170
|
||||
970 rt = rt+ad
|
||||
980 if rt = 21 then goto 1030
|
||||
990 if rt > 21 then print : print p$(pi);" loses by going over 21!!" : goto 1050
|
||||
1000 pi = pi+1 : if pi > 2 then pi = 1
|
||||
1010 goto 930
|
||||
1020 '
|
||||
1030 rem winner winner chicken dinner
|
||||
1040 print : print "21! ";p$(pi);" wins the game!!!"
|
||||
1050 print : print "Would you like to play again? ";
|
||||
1060 k$ = inkey$ : if k$ <> "n" and k$ <> "y" then 1060
|
||||
1070 print k$
|
||||
1080 if k$ = "n" then print : print "Okay, maybe another time. Bye!" : end
|
||||
1090 goto 490
|
||||
1100 '
|
||||
1110 rem pause for keypress
|
||||
1120 z$ = " Press a key to continue. "
|
||||
1130 print z$
|
||||
1140 k$ = inkey$ : if k$ = "" then 1140
|
||||
1150 return
|
||||
1160 '
|
||||
1170 rem human player move
|
||||
1180 print : print "How much to add,"
|
||||
1190 print "1, 2, or 3 (0 to quit)"; : input ad
|
||||
1200 if ad < 0 or ad > 3 then print : print "Illegal amount. Try again." : goto 1180
|
||||
1210 if ad = 0 then print : print "Game was ended by ";p$(pi);"." : end
|
||||
1220 return
|
||||
1230 '
|
||||
1240 rem computer player move
|
||||
1250 print : print "Thinking...";
|
||||
1260 tt = int(rnd(1)*10)
|
||||
1270 for t = 1 to tt : print "."; : for i = 1 to 250 : next i : next t : print
|
||||
1280 rm = fn m(rt)
|
||||
1290 ad = ca(rm)
|
||||
1300 print : print p$(pi);" adds ";ca(rm);l$;"."
|
||||
1310 for t = 1 to 1000 : next t
|
||||
1320 return
|
||||
1330 '
|
||||
1340 rem pick a computer name
|
||||
1350 pn = int(rnd(1)*6)+1 : t$ = cn$(pn)
|
||||
1360 if t$ = p$(p-1) then goto 1350
|
||||
1370 p$(p) = t$
|
||||
1380 return
|
||||
1390 '
|
||||
1400 rem some computer names to pick from
|
||||
1410 data "Commodore 64","VIC-20","Commodore 128"
|
||||
1420 data "PET","Plus/4","Commodore 16"
|
||||
40
Task/21-game/PureBasic/21-game.basic
Normal file
40
Task/21-game/PureBasic/21-game.basic
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
If OpenConsole()
|
||||
PLAYER.i = 1
|
||||
COMP.i = 0
|
||||
|
||||
sum.i = 0
|
||||
total.i = 0
|
||||
turn.i = Random(1) + 0.5
|
||||
Dim precomp.i(3)
|
||||
precomp(0) = 1
|
||||
precomp(1) = 1
|
||||
precomp(2) = 3
|
||||
precomp(3) = 2
|
||||
|
||||
While sum < 21
|
||||
turn = 1 - turn
|
||||
PrintN("The sum is " + Str(sum))
|
||||
If turn = PLAYER
|
||||
PrintN("It is your turn.")
|
||||
While total < 1 Or total > 3 Or total + sum > 21
|
||||
Print("How many would you like to total? ")
|
||||
total = Val(Input())
|
||||
Wend
|
||||
Else
|
||||
PrintN("It is the computer's turn.")
|
||||
total = precomp(sum % 4)
|
||||
PrintN("The computer totals " + Str(total) + ".")
|
||||
EndIf
|
||||
PrintN("")
|
||||
sum + total
|
||||
total = 0
|
||||
Wend
|
||||
|
||||
If turn = PLAYER
|
||||
PrintN("Congratulations. You win.")
|
||||
Else
|
||||
PrintN("Bad luck. The computer wins.")
|
||||
EndIf
|
||||
|
||||
Input()
|
||||
EndIf
|
||||
34
Task/21-game/QBasic/21-game.basic
Normal file
34
Task/21-game/QBasic/21-game.basic
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
PLAYER = 1
|
||||
COMP = 0
|
||||
RANDOMIZE TIMER
|
||||
|
||||
sum = 0
|
||||
total = 0
|
||||
turn = INT(RND + 0.5)
|
||||
DIM precomp(0 TO 3)
|
||||
precomp(0) = 1 : precomp(1) = 1
|
||||
precomp(2) = 3 : precomp(3) = 2
|
||||
|
||||
WHILE sum < 21
|
||||
turn = 1 - turn
|
||||
PRINT "The sum is "; sum
|
||||
IF turn = PLAYER THEN
|
||||
PRINT "It is your turn."
|
||||
WHILE total < 1 OR total > 3 OR total + sum > 21
|
||||
INPUT "How many would you like to total? ", total
|
||||
WEND
|
||||
ELSE
|
||||
PRINT "It is the computer's turn."
|
||||
total = precomp(sum MOD 4)
|
||||
PRINT "The computer totals"; total; "."
|
||||
END IF
|
||||
PRINT
|
||||
sum = sum + total
|
||||
total = 0
|
||||
WEND
|
||||
|
||||
IF turn = PLAYER THEN
|
||||
PRINT "Congratulations. You win."
|
||||
ELSE
|
||||
PRINT "Bad luck. The computer wins."
|
||||
END IF
|
||||
30
Task/21-game/True-BASIC/21-game.basic
Normal file
30
Task/21-game/True-BASIC/21-game.basic
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
LET player = 1
|
||||
LET comp = 0
|
||||
RANDOMIZE
|
||||
LET sum = 0
|
||||
LET total = 0
|
||||
LET turn = INT(RND+0.5)
|
||||
DIM precomp(0 TO 3)
|
||||
LET precomp(0) = 1
|
||||
LET precomp(1) = 1
|
||||
LET precomp(2) = 3
|
||||
LET precomp(3) = 2
|
||||
DO WHILE sum < 21
|
||||
LET turn = 1-turn
|
||||
PRINT "The sum is "; sum
|
||||
IF turn = player THEN
|
||||
PRINT "It is your turn."
|
||||
DO WHILE total < 1 OR total > 3 OR total+sum > 21
|
||||
INPUT prompt "How many would you like to total? ": total
|
||||
LOOP
|
||||
ELSE
|
||||
PRINT "It is the computer's turn."
|
||||
LET total = precomp(remainder(round(sum),4))
|
||||
PRINT USING "The computer totals #.": total
|
||||
END IF
|
||||
PRINT
|
||||
LET sum = sum+total
|
||||
LET total = 0
|
||||
LOOP
|
||||
IF turn = player THEN PRINT "Congratulations. You win." ELSE PRINT "Bad luck. The computer wins."
|
||||
END
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import "/fmt" for Conv
|
||||
import "/ioutil" for Input
|
||||
import "./fmt" for Conv
|
||||
import "./ioutil" for Input
|
||||
import "random" for Random
|
||||
|
||||
var total = 0
|
||||
|
|
|
|||
33
Task/21-game/Yabasic/21-game.basic
Normal file
33
Task/21-game/Yabasic/21-game.basic
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
PLAYER = 1
|
||||
COMP = 0
|
||||
|
||||
sum = 0
|
||||
total = 0
|
||||
turn = int(ran() + 0.5)
|
||||
dim precomp(3)
|
||||
precomp(0) = 1 : precomp(1) = 1
|
||||
precomp(2) = 3 : precomp(3) = 2
|
||||
|
||||
while sum < 21
|
||||
turn = 1 - turn
|
||||
print "The sum is ", sum
|
||||
if turn = PLAYER then
|
||||
print "It is your turn."
|
||||
while total < 1 or total > 3 or total + sum > 21
|
||||
input "How many would you like to total? " total
|
||||
wend
|
||||
else
|
||||
print "It is the computer's turn."
|
||||
total = precomp(mod(sum, 4))
|
||||
print "The computer totals ", total, "."
|
||||
fi
|
||||
print
|
||||
sum = sum + total
|
||||
total = 0
|
||||
wend
|
||||
|
||||
if turn = PLAYER then
|
||||
print "Congratulations. You win."
|
||||
else
|
||||
print "Bad luck. The computer wins."
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue