mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-26 20:54:07 -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
26_Chomp/README.md
Normal file
7
26_Chomp/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
### Chomp
|
||||
|
||||
As published in Basic Computer Games (1978)
|
||||
https://www.atariarchives.org/basicgames/showpage.php?page=44
|
||||
|
||||
Downloaded from Vintage Basic at
|
||||
http://www.vintage-basic.net/games.html
|
||||
104
26_Chomp/chomp.bas
Normal file
104
26_Chomp/chomp.bas
Normal file
@@ -0,0 +1,104 @@
|
||||
10 PRINT TAB(33);"CHOMP"
|
||||
20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
|
||||
30 PRINT:PRINT:PRINT
|
||||
40 DIM A(10,10)
|
||||
100 REM *** THE GAME OF CHOMP *** COPYRIGHT PCC 1973 ***
|
||||
110 PRINT
|
||||
120 PRINT "THIS IS THE GAME OF CHOMP (SCIENTIFIC AMERICAN, JAN 1973)"
|
||||
130 PRINT "DO YOU WANT THE RULES (1=YES, 0=NO!)";
|
||||
140 INPUT R
|
||||
150 IF R=0 THEN 340
|
||||
160 F=1
|
||||
170 R=5
|
||||
180 C=7
|
||||
190 PRINT "CHOMP IS FOR 1 OR MORE PLAYERS (HUMANS ONLY)."
|
||||
200 PRINT
|
||||
210 PRINT "HERE'S HOW A BOARD LOOKS (THIS ONE IS 5 BY 7):"
|
||||
220 GOSUB 540
|
||||
230 PRINT
|
||||
240 PRINT "THE BOARD IS A BIG COOKIE - R ROWS HIGH AND C COLUMNS"
|
||||
250 PRINT "WIDE. YOU INPUT R AND C AT THE START. IN THE UPPER LEFT"
|
||||
260 PRINT "CORNER OF THE COOKIE IS A POISON SQUARE (P). THE ONE WHO"
|
||||
270 PRINT "CHOMPS THE POISON SQUARE LOSES. TO TAKE A CHOMP, TYPE THE"
|
||||
280 PRINT "ROW AND COLUMN OF ONE OF THE SQUARES ON THE COOKIE."
|
||||
290 PRINT "ALL OF THE SQUARES BELOW AND TO THE RIGHT OF THAT SQUARE"
|
||||
300 PRINT "(INCLUDING THAT SQUARE, TOO) DISAPPEAR -- CHOMP!!"
|
||||
310 PRINT "NO FAIR CHOMPING SQUARES THAT HAVE ALREADY BEEN CHOMPED,"
|
||||
320 PRINT "OR THAT ARE OUTSIDE THE ORIGINAL DIMENSIONS OF THE COOKIE."
|
||||
330 PRINT
|
||||
340 PRINT "HERE WE GO..."
|
||||
350 REM
|
||||
360 F=0
|
||||
370 FOR I=1 TO 10
|
||||
372 FOR J=1 TO 10
|
||||
375 A(I,J)=0
|
||||
377 NEXT J
|
||||
379 NEXT I
|
||||
380 PRINT
|
||||
390 PRINT "HOW MANY PLAYERS";
|
||||
400 INPUT P
|
||||
410 I1=0
|
||||
420 PRINT "HOW MANY ROWS";
|
||||
430 INPUT R
|
||||
440 IF R <= 9 THEN 470
|
||||
450 PRINT "TOO MANY ROWS (9 IS MAXIMUM). NOW, ";
|
||||
460 GOTO 420
|
||||
470 PRINT "HOW MANY COLUMNS";
|
||||
480 INPUT C
|
||||
490 IF C <= 9 THEN 530
|
||||
500 PRINT "TOO MANY COLUMNS (9 IS MAXIMUM). NOW, ";
|
||||
510 GOTO 470
|
||||
530 PRINT
|
||||
540 FOR I=1 TO R
|
||||
550 FOR J=1 TO C
|
||||
560 A(I,J)=1
|
||||
570 NEXT J
|
||||
580 NEXT I
|
||||
590 A(1,1)=-1
|
||||
600 REM PRINT THE BOARD
|
||||
610 PRINT
|
||||
620 PRINT TAB(7);"1 2 3 4 5 6 7 8 9"
|
||||
630 FOR I=1 TO R
|
||||
640 PRINT I;TAB(7);
|
||||
650 FOR J=1 TO C
|
||||
660 IF A(I,J)=-1 THEN 700
|
||||
670 IF A(I,J)=0 THEN 720
|
||||
680 PRINT "* ";
|
||||
690 GOTO 710
|
||||
700 PRINT "P ";
|
||||
710 NEXT J
|
||||
720 PRINT
|
||||
730 NEXT I
|
||||
740 PRINT
|
||||
750 IF F=0 THEN 770
|
||||
760 RETURN
|
||||
770 REM GET CHOMPS FOR EACH PLAYER IN TURN
|
||||
780 LET I1=I1+1
|
||||
790 LET P1=I1-INT(I1/P)*P
|
||||
800 IF P1 <> 0 THEN 820
|
||||
810 P1=P
|
||||
820 PRINT "PLAYER";P1
|
||||
830 PRINT "COORDINATES OF CHOMP (ROW,COLUMN)";
|
||||
840 INPUT R1,C1
|
||||
850 IF R1<1 THEN 920
|
||||
860 IF R1>R THEN 920
|
||||
870 IF C1<1 THEN 920
|
||||
880 IF C1>C THEN 920
|
||||
890 IF A(R1,C1)=0 THEN 920
|
||||
900 IF A(R1,C1)=-1 THEN 1010
|
||||
910 GOTO 940
|
||||
920 PRINT "NO FAIR. YOU'RE TRYING TO CHOMP ON EMPTY SPACE!"
|
||||
930 GOTO 820
|
||||
940 FOR I=R1 TO R
|
||||
950 FOR J=C1 TO C
|
||||
960 A(I,J)=0
|
||||
970 NEXT J
|
||||
980 NEXT I
|
||||
990 GOTO 610
|
||||
1000 REM END OF GAME DETECTED IN LINE 900
|
||||
1010 PRINT "YOU LOSE, PLAYER";P1
|
||||
1020 PRINT
|
||||
1030 PRINT "AGAIN (1=YES, 0=NO!)";
|
||||
1040 INPUT R
|
||||
1050 IF R=1 THEN 340
|
||||
1060 END
|
||||
3
26_Chomp/csharp/README.md
Normal file
3
26_Chomp/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/)
|
||||
157
26_Chomp/java/Chomp.java
Normal file
157
26_Chomp/java/Chomp.java
Normal file
@@ -0,0 +1,157 @@
|
||||
import java.util.Scanner;
|
||||
public class Chomp{
|
||||
int rows;
|
||||
int cols;
|
||||
int numberOfPlayers;
|
||||
int []board;
|
||||
Scanner scanner;
|
||||
Chomp(){
|
||||
System.out.println("\t\t\t\tCHOMP");
|
||||
System.out.println("\t\tCREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
|
||||
System.out.println("THIS IS THE GAME OF CHOMP (SCIENTIFIC AMERICAN, JAN 1973)");
|
||||
System.out.print("Do you want the rules (1=Yes, 0=No!) ");
|
||||
|
||||
scanner = new Scanner(System.in);
|
||||
int choice = scanner.nextInt();
|
||||
if(choice != 0){
|
||||
System.out.println("Chomp is for 1 or more players (Humans only).\n");
|
||||
System.out.println("Here's how a board looks (This one is 5 by 7):");
|
||||
System.out.println("\t1 2 3 4 5 6 7");
|
||||
System.out.println(" 1 P * * * * * *\n 2 * * * * * * *\n 3 * * * * * * *\n 4 * * * * * * *\n 5 * * * * * * *");
|
||||
System.out.println("\nThe board is a big cookie - R rows high and C columns \nwide. You input R and C at the start. In the upper left\ncorner of the cookie is a poison square (P). The one who\nchomps the poison square loses. To take a chomp, type the\nrow and column of one of the squares on the cookie.\nAll of the squares below and to the right of that square\n(Including that square, too) disappear -- CHOMP!!\nNo fair chomping squares that have already been chomped,\nor that are outside the original dimensions of the cookie.\n");
|
||||
System.out.println("Here we go...\n");
|
||||
}
|
||||
startGame();
|
||||
}
|
||||
|
||||
private void startGame(){
|
||||
System.out.print("How many players ");
|
||||
numberOfPlayers = scanner.nextInt();
|
||||
while(numberOfPlayers < 2){
|
||||
System.out.print("How many players ");
|
||||
numberOfPlayers = scanner.nextInt();
|
||||
}
|
||||
System.out.print("How many rows ");
|
||||
rows = scanner.nextInt();
|
||||
while(rows<=0 || rows >9){
|
||||
if(rows <= 0){
|
||||
System.out.println("Minimun 1 row is required !!");
|
||||
}
|
||||
else{
|
||||
System.out.println("Too many rows(9 is maximum). ");
|
||||
}
|
||||
System.out.print("How many rows ");
|
||||
rows = scanner.nextInt();
|
||||
}
|
||||
System.out.print("How many columns ");
|
||||
cols = scanner.nextInt();
|
||||
while(cols<=0 || cols >9){
|
||||
if(cols <= 0){
|
||||
System.out.println("Minimun 1 column is required !!");
|
||||
}
|
||||
else{
|
||||
System.out.println("Too many columns(9 is maximum). ");
|
||||
}
|
||||
System.out.print("How many columns ");
|
||||
cols = scanner.nextInt();
|
||||
}
|
||||
board = new int[rows];
|
||||
for(int i=0;i<rows;i++){
|
||||
board[i]=cols;
|
||||
}
|
||||
printBoard();
|
||||
scanner.nextLine();
|
||||
move(0);
|
||||
}
|
||||
|
||||
private void printBoard(){
|
||||
System.out.print(" ");
|
||||
for(int i=0;i<cols;i++){
|
||||
System.out.print(i+1);
|
||||
System.out.print(" ");
|
||||
}
|
||||
for(int i=0;i<rows;i++){
|
||||
System.out.print("\n ");
|
||||
System.out.print(i+1);
|
||||
System.out.print(" ");
|
||||
for(int j=0;j<board[i];j++){
|
||||
if(i == 0 && j == 0){
|
||||
System.out.print("P ");
|
||||
}
|
||||
else{
|
||||
System.out.print("* ");
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
private void move(int player){
|
||||
System.out.println(String.format("Player %d",(player+1)));
|
||||
|
||||
String input;
|
||||
String [] coordinates;
|
||||
int x=-1,y=-1;
|
||||
while(true){
|
||||
try{
|
||||
System.out.print("Coordinates of chomp (Row, Column) ");
|
||||
input = scanner.nextLine();
|
||||
coordinates = input.split(",");
|
||||
x = Integer.parseInt(coordinates[0]);
|
||||
y = Integer.parseInt(coordinates[1]);
|
||||
break;
|
||||
}
|
||||
catch(Exception e){
|
||||
System.out.println("Please enter valid coordinates.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
while(x>rows || x <1 || y>cols || y<1 || board[x-1]<y){
|
||||
System.out.println("No fair. You're trying to chomp on empty space!");
|
||||
while(true){
|
||||
try{
|
||||
System.out.print("Coordinates of chomp (Row, Column) ");
|
||||
input = scanner.nextLine();
|
||||
coordinates = input.split(",");
|
||||
x = Integer.parseInt(coordinates[0]);
|
||||
y = Integer.parseInt(coordinates[1]);
|
||||
break;
|
||||
}
|
||||
catch(Exception e){
|
||||
System.out.println("Please enter valid coordinates.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(x == 1 && y == 1){
|
||||
System.out.println("You lose player "+(player+1));
|
||||
int choice = -1 ;
|
||||
while(choice != 0 && choice != 1){
|
||||
System.out.print("Again (1=Yes, 0=No!) ");
|
||||
choice = scanner.nextInt();
|
||||
}
|
||||
if(choice == 1){
|
||||
startGame();
|
||||
}
|
||||
else{
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
else{
|
||||
for(int i=x-1;i<rows;i++){
|
||||
if(board[i] >= y){
|
||||
board[i] = y-1;
|
||||
}
|
||||
}
|
||||
printBoard();
|
||||
move((player+1)%numberOfPlayers);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String []args){
|
||||
new Chomp();
|
||||
}
|
||||
}
|
||||
3
26_Chomp/java/README.md
Normal file
3
26_Chomp/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
26_Chomp/javascript/README.md
Normal file
3
26_Chomp/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
26_Chomp/javascript/chomp.html
Normal file
9
26_Chomp/javascript/chomp.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>CHOMP</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="output" style="font-size: 12pt;"></pre>
|
||||
<script src="chomp.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
175
26_Chomp/javascript/chomp.js
Normal file
175
26_Chomp/javascript/chomp.js
Normal file
@@ -0,0 +1,175 @@
|
||||
// CHOMP
|
||||
//
|
||||
// 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 a = [];
|
||||
var r;
|
||||
var c;
|
||||
|
||||
function init_board()
|
||||
{
|
||||
for (i = 1; i <= r; i++)
|
||||
for (j = 1; j <= c; j++)
|
||||
a[i][j] = 1;
|
||||
a[1][1] = -1;
|
||||
}
|
||||
|
||||
function show_board()
|
||||
{
|
||||
print("\n");
|
||||
print(tab(7) + "1 2 3 4 5 6 7 8 9\n");
|
||||
for (i = 1; i <= r; i++) {
|
||||
str = i + tab(6);
|
||||
for (j = 1; j <= c; j++) {
|
||||
if (a[i][j] == -1)
|
||||
str += "P ";
|
||||
else if (a[i][j] == 0)
|
||||
break;
|
||||
else
|
||||
str += "* ";
|
||||
}
|
||||
print(str + "\n");
|
||||
}
|
||||
print("\n");
|
||||
}
|
||||
|
||||
// Main program
|
||||
async function main()
|
||||
{
|
||||
print(tab(33) + "CHOMP\n");
|
||||
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
for (i = 1; i <= 10; i++)
|
||||
a[i] = [];
|
||||
// *** THE GAME OF CHOMP *** COPYRIGHT PCC 1973 ***
|
||||
print("\n");
|
||||
print("THIS IS THE GAME OF CHOMP (SCIENTIFIC AMERICAN, JAN 1973)\n");
|
||||
print("DO YOU WANT THE RULES (1=YES, 0=NO!)");
|
||||
r = parseInt(await input());
|
||||
if (r != 0) {
|
||||
f = 1;
|
||||
r = 5;
|
||||
c = 7;
|
||||
print("CHOMP IS FOR 1 OR MORE PLAYERS (HUMANS ONLY).\n");
|
||||
print("\n");
|
||||
print("HERE'S HOW A BOARD LOOKS (THIS ONE IS 5 BY 7):\n");
|
||||
init_board();
|
||||
show_board();
|
||||
print("\n");
|
||||
print("THE BOARD IS A BIG COOKIE - R ROWS HIGH AND C COLUMNS\n");
|
||||
print("WIDE. YOU INPUT R AND C AT THE START. IN THE UPPER LEFT\n");
|
||||
print("CORNER OF THE COOKIE IS A POISON SQUARE (P). THE ONE WHO\n");
|
||||
print("CHOMPS THE POISON SQUARE LOSES. TO TAKE A CHOMP, TYPE THE\n");
|
||||
print("ROW AND COLUMN OF ONE OF THE SQUARES ON THE COOKIE.\n");
|
||||
print("ALL OF THE SQUARES BELOW AND TO THE RIGHT OF THAT SQUARE\n");
|
||||
print("INCLUDING THAT SQUARE, TOO) DISAPPEAR -- CHOMP!!\n");
|
||||
print("NO FAIR CHOMPING SQUARES THAT HAVE ALREADY BEEN CHOMPED,\n");
|
||||
print("OR THAT ARE OUTSIDE THE ORIGINAL DIMENSIONS OF THE COOKIE.\n");
|
||||
print("\n");
|
||||
}
|
||||
while (1) {
|
||||
print("HERE WE GO...\n");
|
||||
f = 0;
|
||||
for (i = 1; i <= 10; i++) {
|
||||
a[i] = [];
|
||||
for (j = 1; j <= 10; j++) {
|
||||
a[i][j] = 0;
|
||||
}
|
||||
}
|
||||
print("\n");
|
||||
print("HOW MANY PLAYERS");
|
||||
p = parseInt(await input());
|
||||
i1 = 0;
|
||||
while (1) {
|
||||
print("HOW MANY ROWS");
|
||||
r = parseInt(await input());
|
||||
if (r <= 9)
|
||||
break;
|
||||
print("TOO MANY ROWS (9 IS MAXIMUM). NOW ");
|
||||
}
|
||||
while (1) {
|
||||
print("HOW MANY COLUMNS");
|
||||
c = parseInt(await input());
|
||||
if (c <= 9)
|
||||
break;
|
||||
print("TOO MANY COLUMNS (9 IS MAXIMUM). NOW ");
|
||||
}
|
||||
print("\n");
|
||||
init_board();
|
||||
while (1) {
|
||||
// Print the board
|
||||
show_board();
|
||||
// Get chomps for each player in turn
|
||||
i1++;
|
||||
p1 = i1 - Math.floor(i1 / p) * p;
|
||||
if (p1 == 0)
|
||||
p1 = p;
|
||||
while (1) {
|
||||
print("PLAYER " + p1 + "\n");
|
||||
print("COORDINATES OF CHOMP (ROW,COLUMN)");
|
||||
str = await input();
|
||||
r1 = parseInt(str);
|
||||
c1 = parseInt(str.substr(str.indexOf(",") + 1));
|
||||
if (r1 >= 1 && r1 <= r && c1 >= 1 && c1 <= c && a[r1][c1] != 0)
|
||||
break;
|
||||
print("NO FAIR. YOU'RE TRYING TO CHOMP ON EMPTY SPACE!\n");
|
||||
}
|
||||
if (a[r1][c1] == -1)
|
||||
break;
|
||||
for (i = r1; i <= r; i++)
|
||||
for (j = c1; j <= c; j++)
|
||||
a[i][j] = 0;
|
||||
}
|
||||
// End of game detected
|
||||
print("YOU LOSE, PLAYER " + p1 + "\n");
|
||||
print("\n");
|
||||
print("AGAIN (1=YES, 0=NO!)");
|
||||
r = parseInt(await input());
|
||||
if (r != 1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
3
26_Chomp/pascal/README.md
Normal file
3
26_Chomp/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
26_Chomp/perl/README.md
Normal file
3
26_Chomp/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
26_Chomp/python/README.md
Normal file
3
26_Chomp/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/)
|
||||
132
26_Chomp/python/chomp.py
Executable file
132
26_Chomp/python/chomp.py
Executable file
@@ -0,0 +1,132 @@
|
||||
#!/usr/bin/env python3
|
||||
# CHOMP
|
||||
#
|
||||
# Converted from BASIC to Python by Trevor Hobson
|
||||
|
||||
|
||||
class Canvas:
|
||||
""" For drawing the cookie """
|
||||
|
||||
def __init__(self, width=9, height=9, fill="*"):
|
||||
self._buffer = []
|
||||
for _ in range(height):
|
||||
line = []
|
||||
for _ in range(width):
|
||||
line.append(fill)
|
||||
self._buffer.append(line)
|
||||
self._buffer[0][0] = "P"
|
||||
|
||||
def render(self):
|
||||
lines = [" 1 2 3 4 5 6 7 8 9"]
|
||||
row = 0
|
||||
for line in self._buffer:
|
||||
row += 1
|
||||
lines.append(" " + str(row) + " " * 5 + " ".join(line))
|
||||
return "\n".join(lines)
|
||||
|
||||
def chomp(self, r, c):
|
||||
if not 1 <= r <= len(self._buffer) or not 1 <= c <= len(self._buffer[0]):
|
||||
return "Empty"
|
||||
elif self._buffer[r - 1][c - 1] == " ":
|
||||
return "Empty"
|
||||
elif self._buffer[r - 1][c - 1] == "P":
|
||||
return "Poison"
|
||||
else:
|
||||
for row in range(r - 1, len(self._buffer)):
|
||||
for column in range(c - 1, len(self._buffer[row])):
|
||||
self._buffer[row][column] = " "
|
||||
return "Chomp"
|
||||
|
||||
|
||||
def play_game():
|
||||
"""Play one round of the game"""
|
||||
players = 0
|
||||
while players == 0:
|
||||
try:
|
||||
players = int(input("How many players "))
|
||||
|
||||
except ValueError:
|
||||
print("Please enter a number.")
|
||||
rows = 0
|
||||
while rows == 0:
|
||||
try:
|
||||
rows = int(input("How many rows "))
|
||||
if rows > 9 or rows < 1:
|
||||
rows = 0
|
||||
print("Too many rows (9 is maximum).")
|
||||
|
||||
except ValueError:
|
||||
print("Please enter a number.")
|
||||
columns = 0
|
||||
while columns == 0:
|
||||
try:
|
||||
columns = int(input("How many columns "))
|
||||
if columns > 9 or columns < 1:
|
||||
columns = 0
|
||||
print("Too many columns (9 is maximum).")
|
||||
|
||||
except ValueError:
|
||||
print("Please enter a number.")
|
||||
cookie = Canvas(width=columns, height=rows)
|
||||
player = 0
|
||||
alive = True
|
||||
while alive:
|
||||
print("")
|
||||
print(cookie.render())
|
||||
print("")
|
||||
player += 1
|
||||
if player > players:
|
||||
player = 1
|
||||
while True:
|
||||
print("Player", player)
|
||||
player_row = -1
|
||||
player_column = -1
|
||||
while player_row == -1 or player_column == -1:
|
||||
try:
|
||||
coordinates = [int(item) for item in input(
|
||||
"Coordinates of chomp (Row, Column) ").split(",")]
|
||||
player_row = coordinates[0]
|
||||
player_column = coordinates[1]
|
||||
|
||||
except (ValueError, IndexError):
|
||||
print("Please enter valid coordinates.")
|
||||
result = cookie.chomp(player_row, player_column)
|
||||
if result == "Empty":
|
||||
print("No fair. You're trying to chomp on empty space!")
|
||||
elif result == "Poison":
|
||||
print("\nYou lose player", player)
|
||||
alive = False
|
||||
break
|
||||
else:
|
||||
break
|
||||
|
||||
|
||||
def main():
|
||||
print(" " * 33 + "CHOMP")
|
||||
print(" " * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n")
|
||||
print("THIS IS THE GAME OF CHOMP (SCIENTIFIC AMERICAN, JAN 1973)")
|
||||
if input("Do you want the rules (1=Yes, 0=No!) ") != "0":
|
||||
print("Chomp is for 1 or more players (Humans only).\n")
|
||||
print("Here's how a board looks (This one is 5 by 7):")
|
||||
example = Canvas(width=7, height=5)
|
||||
print(example.render())
|
||||
print("\nThe board is a big cookie - R rows high and C columns")
|
||||
print("wide. You input R and C at the start. In the upper left")
|
||||
print("corner of the cookie is a poison square (P). The one who")
|
||||
print("chomps the poison square loses. To take a chomp, type the")
|
||||
print("row and column of one of the squares on the cookie.")
|
||||
print("All of the squares below and to the right of that square")
|
||||
print("(Including that square, too) disappear -- CHOMP!!")
|
||||
print("No fair chomping squares that have already been chomped,")
|
||||
print("or that are outside the original dimensions of the cookie.\n")
|
||||
print("Here we go...")
|
||||
|
||||
keep_playing = True
|
||||
while keep_playing:
|
||||
|
||||
play_game()
|
||||
keep_playing = input("\nAgain (1=Yes, 0=No!) ") == "1"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
3
26_Chomp/ruby/README.md
Normal file
3
26_Chomp/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
26_Chomp/vbnet/README.md
Normal file
3
26_Chomp/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