mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-04 09:07:41 -08:00
Removed spaces from top-level directory names.
Spaces tend to cause annoyances in a Unix-style shell environment. This change fixes that.
This commit is contained in:
7
56_Life_for_Two/README.md
Normal file
7
56_Life_for_Two/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
### Life for Two
|
||||
|
||||
As published in Basic Computer Games (1978)
|
||||
https://www.atariarchives.org/basicgames/showpage.php?page=102
|
||||
|
||||
Downloaded from Vintage Basic at
|
||||
http://www.vintage-basic.net/games.html
|
||||
3
56_Life_for_Two/csharp/README.md
Normal file
3
56_Life_for_Two/csharp/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Microsoft C#](https://docs.microsoft.com/en-us/dotnet/csharp/)
|
||||
3
56_Life_for_Two/java/README.md
Normal file
3
56_Life_for_Two/java/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Oracle Java](https://openjdk.java.net/)
|
||||
3
56_Life_for_Two/javascript/README.md
Normal file
3
56_Life_for_Two/javascript/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Shells)
|
||||
9
56_Life_for_Two/javascript/lifefortwo.html
Normal file
9
56_Life_for_Two/javascript/lifefortwo.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>LIFE FOR TWO</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="output" style="font-size: 12pt;"></pre>
|
||||
<script src="lifefortwo.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
209
56_Life_for_Two/javascript/lifefortwo.js
Normal file
209
56_Life_for_Two/javascript/lifefortwo.js
Normal file
@@ -0,0 +1,209 @@
|
||||
// LIFE FOR TWO
|
||||
//
|
||||
// Converted from BASIC to Javascript by Oscar Toledo G. (nanochess)
|
||||
//
|
||||
|
||||
function print(str)
|
||||
{
|
||||
document.getElementById("output").appendChild(document.createTextNode(str));
|
||||
}
|
||||
|
||||
function input()
|
||||
{
|
||||
var input_element;
|
||||
var input_str;
|
||||
|
||||
return new Promise(function (resolve) {
|
||||
input_element = document.createElement("INPUT");
|
||||
|
||||
print("? ");
|
||||
input_element.setAttribute("type", "text");
|
||||
input_element.setAttribute("length", "50");
|
||||
document.getElementById("output").appendChild(input_element);
|
||||
input_element.focus();
|
||||
input_str = undefined;
|
||||
input_element.addEventListener("keydown", function (event) {
|
||||
if (event.keyCode == 13) {
|
||||
input_str = input_element.value;
|
||||
document.getElementById("output").removeChild(input_element);
|
||||
print(input_str);
|
||||
print("\n");
|
||||
resolve(input_str);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function tab(space)
|
||||
{
|
||||
var str = "";
|
||||
while (space-- > 0)
|
||||
str += " ";
|
||||
return str;
|
||||
}
|
||||
|
||||
var na = [];
|
||||
var ka = [, 3,102,103,120,130,121,112,111,12,
|
||||
21,30,1020,1030,1011,1021,1003,1002,1012];
|
||||
var aa = [,-1,0,1,0,0,-1,0,1,-1,-1,1,-1,-1,1,1,1];
|
||||
var xa = [];
|
||||
var ya = [];
|
||||
var j;
|
||||
var k;
|
||||
var m2;
|
||||
var m3;
|
||||
|
||||
function show_data()
|
||||
{
|
||||
k = 0;
|
||||
m2 = 0;
|
||||
m3 = 0;
|
||||
for (j = 0; j <= 6; j++) {
|
||||
print("\n");
|
||||
for (k = 0; k <= 6; k++) {
|
||||
if (j == 0 || j == 6) {
|
||||
if (k == 6)
|
||||
print(" 0 ");
|
||||
else
|
||||
print(" " + k + " ");
|
||||
} else if (k == 0 || k == 6) {
|
||||
if (j == 6)
|
||||
print(" 0\n");
|
||||
else
|
||||
print(" " + j + " ");
|
||||
} else {
|
||||
if (na[j][k] >= 3) {
|
||||
for (o1 = 1; o1 <= 18; o1++) {
|
||||
if (na[j][k] == ka[o1])
|
||||
break;
|
||||
}
|
||||
if (o1 <= 18) {
|
||||
if (o1 <= 9) {
|
||||
na[j][k] = 100;
|
||||
m2++;
|
||||
print(" * ");
|
||||
} else {
|
||||
na[j][k] = 1000;
|
||||
m3++;
|
||||
print(" # ");
|
||||
}
|
||||
} else {
|
||||
na[j][k] = 0;
|
||||
print(" ");
|
||||
}
|
||||
} else {
|
||||
na[j][k] = 0;
|
||||
print(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function process_board()
|
||||
{
|
||||
for (j = 1; j <= 5; j++) {
|
||||
for (k = 1; k <= 5; k++) {
|
||||
if (na[j][k] > 99) {
|
||||
b = 1;
|
||||
if (na[j][k] > 999)
|
||||
b = 10;
|
||||
for (o1 = 1; o1 <= 15; o1 += 2) {
|
||||
na[j + aa[o1]][k + aa[o1 + 1]] = na[j + aa[o1]][k + aa[o1 + 1]] + b;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
show_data();
|
||||
}
|
||||
|
||||
// Main program
|
||||
async function main()
|
||||
{
|
||||
print(tab(33) + "LIFE2\n");
|
||||
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print(tab(10) + "U.B. LIFE GAME\n");
|
||||
m2 = 0;
|
||||
m3 = 0;
|
||||
for (j = 0; j <= 6; j++) {
|
||||
na[j] = [];
|
||||
for (k = 0; k <= 6; k++)
|
||||
na[j][k] = 0;
|
||||
}
|
||||
for (b = 1; b <= 2; b++) {
|
||||
p1 = (b == 2) ? 30 : 3;
|
||||
print("\n");
|
||||
print("PLAYER " + b + " - 3 LIVE PIECES.\n");
|
||||
for (k1 = 1; k1 <= 3; k1++) {
|
||||
while (1) {
|
||||
print("X,Y\n");
|
||||
str = await input();
|
||||
ya[b] = parseInt(str);
|
||||
xa[b] = parseInt(str.substr(str.indexOf(",") + 1));
|
||||
if (xa[b] > 0 && xa[b] < 6 && ya[b] > 0 && ya[b] < 5 && na[xa[b]][ya[b]] == 0)
|
||||
break;
|
||||
print("ILLEGAL COORDS. RETYPE\n");
|
||||
}
|
||||
if (b != 1) {
|
||||
if (xa[1] == xa[2] && ya[1] == ya[2]) {
|
||||
print("SAME COORD. SET TO 0\n");
|
||||
na[xa[b] + 1][ya[b] + 1] = 0;
|
||||
b = 99;
|
||||
}
|
||||
}
|
||||
na[xa[b]][ya[b]] = p1;
|
||||
}
|
||||
}
|
||||
show_data();
|
||||
while (1) {
|
||||
print("\n");
|
||||
process_board();
|
||||
if (m2 == 0 && m3 == 0) {
|
||||
print("\n");
|
||||
print("A DRAW\n");
|
||||
break;
|
||||
}
|
||||
if (m3 == 0) {
|
||||
print("\n");
|
||||
print("PLAYER 1 IS THE WINNER\n");
|
||||
break;
|
||||
}
|
||||
if (m2 == 0) {
|
||||
print("\n");
|
||||
print("PLAYER 2 IS THE WINNER\n");
|
||||
break;
|
||||
}
|
||||
for (b = 1; b <= 2; b++) {
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("PLAYER " + b + " ");
|
||||
while (1) {
|
||||
print("X,Y\n");
|
||||
str = await input();
|
||||
ya[b] = parseInt(str);
|
||||
xa[b] = parseInt(str.substr(str.indexOf(",") + 1));
|
||||
if (xa[b] > 0 && xa[b] < 6 && ya[b] > 0 && ya[b] < 5 && na[xa[b]][ya[b]] == 0)
|
||||
break;
|
||||
print("ILLEGAL COORDS. RETYPE\n");
|
||||
}
|
||||
if (b != 1) {
|
||||
if (xa[1] == xa[2] && ya[1] == ya[2]) {
|
||||
print("SAME COORD. SET TO 0\n");
|
||||
na[xa[b] + 1][ya[b] + 1] = 0;
|
||||
b = 99;
|
||||
}
|
||||
}
|
||||
if (b == 99)
|
||||
break;
|
||||
}
|
||||
if (b <= 2) {
|
||||
na[x[1]][y[1]] = 100;
|
||||
na[x[2]][y[2]] = 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
83
56_Life_for_Two/lifefortwo.bas
Normal file
83
56_Life_for_Two/lifefortwo.bas
Normal file
@@ -0,0 +1,83 @@
|
||||
2 PRINT TAB(33);"LIFE2"
|
||||
4 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
|
||||
6 PRINT: PRINT: PRINT
|
||||
7 DIM N(6,6),K(18),A(16),X(2),Y(2)
|
||||
8 DATA 3,102,103,120,130,121,112,111,12
|
||||
9 DATA 21,30,1020,1030,1011,1021,1003,1002,1012
|
||||
10 FOR M=1 TO 18: READ K(M): NEXT M
|
||||
13 DATA -1,0,1,0,0,-1,0,1,-1,-1,1,-1,-1,1,1,1
|
||||
14 FOR O1= 1 TO 16: READ A(O1): NEXT O1
|
||||
20 GOTO 500
|
||||
50 FOR J=1 TO 5
|
||||
51 FOR K=1 TO 5
|
||||
55 IF N(J,K)>99 THEN GOSUB 200
|
||||
60 NEXT K
|
||||
65 NEXT J
|
||||
90 K=0: M2=0: M3=0
|
||||
99 FOR J=0 TO 6: PRINT
|
||||
100 FOR K=0 TO 6
|
||||
101 IF J<>0 THEN IF J<>6 THEN 105
|
||||
102 IF K=6 THEN PRINT 0;: GOTO 125
|
||||
103 PRINT K;: GOTO 120
|
||||
105 IF K<>0 THEN IF K<>6 THEN 110
|
||||
106 IF J=6 THEN PRINT 0: GOTO 126
|
||||
107 PRINT J;: GOTO 120
|
||||
110 GOSUB 300
|
||||
120 NEXT K
|
||||
125 NEXT J
|
||||
126 RETURN
|
||||
200 B=1: IF N(J,K)>999 THEN B=10
|
||||
220 FOR O1= 1 TO 15 STEP 2
|
||||
230 N(J+A(O1),K+A(O1+1))=N(J+A(O1),K+A(O1+1))+B
|
||||
231 NEXT O1
|
||||
239 RETURN
|
||||
300 IF N(J,K)<3 THEN 399
|
||||
305 FOR O1=1 TO 18
|
||||
310 IF N(J,K)=K(O1) THEN 350
|
||||
315 NEXT O1
|
||||
320 GOTO 399
|
||||
350 IF O1>9 THEN 360
|
||||
351 N(J,K)=100: M2=M2+1: PRINT " * ";
|
||||
355 RETURN
|
||||
360 N(J,K)=1000: M3=M3+1: PRINT " # ";
|
||||
365 RETURN
|
||||
399 N(J,K)=0: PRINT " ";: RETURN
|
||||
500 PRINT TAB(10);"U.B. LIFE GAME"
|
||||
505 M2=0: M3=0
|
||||
510 FOR J=1 TO 5
|
||||
511 FOR K=1 TO 5
|
||||
515 N(J,K)=0
|
||||
516 NEXT K
|
||||
517 NEXT J
|
||||
519 FOR B=1 TO 2: P1=3: IF B=2 THEN P1=30
|
||||
520 PRINT:PRINT "PLAYER";B;" - 3 LIVE PIECES."
|
||||
535 FOR K1=1 TO 3: GOSUB 700
|
||||
540 N(X(B),Y(B))=P1: NEXT K1
|
||||
542 NEXT B
|
||||
559 GOSUB 90
|
||||
560 PRINT: GOSUB 50
|
||||
570 IF M2=0 THEN IF M3=0 THEN 574
|
||||
571 IF M3=0 THEN B=1: GOTO 575
|
||||
572 IF M2=0 THEN B=2: GOTO 575
|
||||
573 GOTO 580
|
||||
574 PRINT: PRINT "A DRAW":GOTO 800
|
||||
575 PRINT: PRINT "PLAYER";B;"IS THE WINNER":GOTO 800
|
||||
580 FOR B=1 TO 2: PRINT: PRINT: PRINT "PLAYER";B;: GOSUB 700
|
||||
581 IF B=99 THEN 560
|
||||
582 NEXT B
|
||||
586 N(X(1),Y(1))=100: N(X(2),Y(2))=1000
|
||||
596 GOTO 560
|
||||
700 PRINT "X,Y":PRINT"XXXXXX";CHR$(13);"$$$$$$";CHR$(13);"&&&&&&";
|
||||
701 PRINT CHR$(13);: INPUT Y(B),X(B)
|
||||
705 IF X(B)<=5 THEN IF X(B)>0 THEN 708
|
||||
706 GOTO 750
|
||||
708 IF Y(B)<=5 THEN IF Y(B)>0 THEN 715
|
||||
710 GOTO 750
|
||||
715 IF N(X(B),Y(B))<>0 THEN 750
|
||||
720 IF B=1 THEN RETURN
|
||||
725 IF X(1)=X(2) THEN IF Y(1)=Y(2) THEN 740
|
||||
730 RETURN
|
||||
740 PRINT "SAME COORD. SET TO 0"
|
||||
741 N(X(B)+1,Y(B)+1)=0: B=99: RETURN
|
||||
750 PRINT "ILLEGAL COORDS. RETYPE": GOTO 700
|
||||
999 END
|
||||
3
56_Life_for_Two/pascal/README.md
Normal file
3
56_Life_for_Two/pascal/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Pascal](https://en.wikipedia.org/wiki/Pascal_(programming_language))
|
||||
3
56_Life_for_Two/perl/README.md
Normal file
3
56_Life_for_Two/perl/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Perl](https://www.perl.org/)
|
||||
3
56_Life_for_Two/python/README.md
Normal file
3
56_Life_for_Two/python/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Python](https://www.python.org/about/)
|
||||
3
56_Life_for_Two/ruby/README.md
Normal file
3
56_Life_for_Two/ruby/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Ruby](https://www.ruby-lang.org/en/)
|
||||
3
56_Life_for_Two/vbnet/README.md
Normal file
3
56_Life_for_Two/vbnet/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original BASIC source [downloaded from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Visual Basic .NET](https://en.wikipedia.org/wiki/Visual_Basic_.NET)
|
||||
Reference in New Issue
Block a user