From fd326d45fe7c500370ac22b65a74693bf56aaf8d Mon Sep 17 00:00:00 2001
From: Tim <70119791+journich@users.noreply.github.com>
Date: Sun, 21 Feb 2021 12:15:00 +1030
Subject: [PATCH 01/15] Removed package and general cleanup
---
.gitignore | 2 +
.../java/src/{aceyducey => }/AceyDucey.java | 47 ++++++++-----------
.../Game.java => AceyDuceyGame.java} | 10 ++--
.../java/src/{aceyducey => }/Card.java | 2 -
4 files changed, 25 insertions(+), 36 deletions(-)
create mode 100644 .gitignore
rename 01 Acey Ducey/java/src/{aceyducey => }/AceyDucey.java (79%)
rename 01 Acey Ducey/java/src/{aceyducey/Game.java => AceyDuceyGame.java} (72%)
rename 01 Acey Ducey/java/src/{aceyducey => }/Card.java (98%)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..9bea4330
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+
+.DS_Store
diff --git a/01 Acey Ducey/java/src/aceyducey/AceyDucey.java b/01 Acey Ducey/java/src/AceyDucey.java
similarity index 79%
rename from 01 Acey Ducey/java/src/aceyducey/AceyDucey.java
rename to 01 Acey Ducey/java/src/AceyDucey.java
index 37dcc57c..5320c8e0 100644
--- a/01 Acey Ducey/java/src/aceyducey/AceyDucey.java
+++ b/01 Acey Ducey/java/src/AceyDucey.java
@@ -1,5 +1,3 @@
-package aceyducey;
-
import java.util.Scanner;
/**
@@ -7,7 +5,7 @@ import java.util.Scanner;
*
* Based on the Basic game of AceyDucey here
* https://github.com/coding-horror/basic-computer-games/blob/main/01%20Acey%20Ducey/aceyducey.bas
- * Note: The idea was to create a version of this 1970's Basic game in Java, without introducing
+ * Note: The idea was to create a version of 1970's Basic game in Java, without introducing
* new features - no additional text, error checking, etc has been added.
*
*/
@@ -32,7 +30,7 @@ public class AceyDucey {
private boolean gameOver = false;
// Used for keyboard input
- private Scanner kbScanner;
+ private final Scanner kbScanner;
// Constant value for cards from a deck - 2 lowest, 14 (Ace) highest
public static final int LOW_CARD_RANGE =2;
@@ -71,7 +69,6 @@ public class AceyDucey {
public void play() {
// Keep playing hands until player runs out of cash
- // which sets gameover to true
do {
if(firstTimePlaying) {
intro();
@@ -81,17 +78,17 @@ public class AceyDucey {
drawCards();
displayCards();
int betAmount = getBet();
- this.playersCard = randomCard();
+ playersCard = randomCard();
displayPlayerCard();
if(playerWon()) {
System.out.println("YOU WIN!!");
- this.playerAmount += betAmount;
+ playerAmount += betAmount;
} else {
System.out.println("SORRY, YOU LOSE");
- this.playerAmount -= betAmount;
+ playerAmount -= betAmount;
// Player run out of money?
- if(this.playerAmount <=0) {
- this.gameOver = true;
+ if(playerAmount <=0) {
+ gameOver = true;
}
}
@@ -102,18 +99,14 @@ public class AceyDucey {
// to win a players card has to be in the range of the first and second dealer
// drawn cards inclusive of first and second cards.
private boolean playerWon() {
- if((this.playersCard.getValue() >= this.firstCard.getValue())
- && this.playersCard.getValue() <= this.secondCard.getValue()) {
- // winner
- return true;
- }
-
- return false;
+ // winner
+ return (playersCard.getValue() >= firstCard.getValue())
+ && playersCard.getValue() <= secondCard.getValue();
}
private void displayPlayerCard() {
- System.out.println(this.playersCard.getName());
+ System.out.println(playersCard.getName());
}
// Get the players bet, and return the amount
@@ -121,16 +114,16 @@ public class AceyDucey {
// method will loop until a valid bet is entered.
private int getBet() {
boolean validBet = false;
- int amount = 0;
+ int amount;
do {
System.out.print("WHAT IS YOUR BET ");
amount = kbScanner.nextInt();
if(amount == 0) {
System.out.println("CHICKEN!!");
validBet = true;
- } else if(amount > this.playerAmount) {
+ } else if(amount > playerAmount) {
System.out.println("SORRY, MY FRIEND, BUT YOU BET TOO MUCH.");
- System.out.println("YOU HAVE ONLY " + this.playerAmount + " DOLLARS TO BET.");
+ System.out.println("YOU HAVE ONLY " + playerAmount + " DOLLARS TO BET.");
} else {
validBet = true;
}
@@ -140,13 +133,13 @@ public class AceyDucey {
}
private void displayBalance() {
- System.out.println("YOU NOW HAVE " + this.playerAmount + " DOLLARS.");
+ System.out.println("YOU NOW HAVE " + playerAmount + " DOLLARS.");
}
private void displayCards() {
System.out.println("HERE ARE YOUR NEXT TWO CARDS: ");
- System.out.println(this.firstCard.getName());
- System.out.println(this.secondCard.getName());
+ System.out.println(firstCard.getName());
+ System.out.println(secondCard.getName());
}
// Draw two dealer cards, and save them for later use.
@@ -154,9 +147,9 @@ public class AceyDucey {
private void drawCards() {
do {
- this.firstCard = randomCard();
- this.secondCard = randomCard();
- } while(this.firstCard.getValue() >= this.secondCard.getValue());
+ firstCard = randomCard();
+ secondCard = randomCard();
+ } while(firstCard.getValue() >= secondCard.getValue());
}
// Creates a random card
diff --git a/01 Acey Ducey/java/src/aceyducey/Game.java b/01 Acey Ducey/java/src/AceyDuceyGame.java
similarity index 72%
rename from 01 Acey Ducey/java/src/aceyducey/Game.java
rename to 01 Acey Ducey/java/src/AceyDuceyGame.java
index 54582f5f..1ce08c28 100644
--- a/01 Acey Ducey/java/src/aceyducey/Game.java
+++ b/01 Acey Ducey/java/src/AceyDuceyGame.java
@@ -1,20 +1,16 @@
-package aceyducey;
-
/**
* This class is used to invoke the game.
*
*/
-public class Game {
-
- private static AceyDucey game;
+public class AceyDuceyGame {
public static void main(String[] args) {
- boolean keepPlaying = true;
+ boolean keepPlaying;
+ AceyDucey game = new AceyDucey();
// Keep playing game until infinity or the player loses
do {
- game = new AceyDucey();
game.play();
System.out.println();
System.out.println();
diff --git a/01 Acey Ducey/java/src/aceyducey/Card.java b/01 Acey Ducey/java/src/Card.java
similarity index 98%
rename from 01 Acey Ducey/java/src/aceyducey/Card.java
rename to 01 Acey Ducey/java/src/Card.java
index ad15cced..d36f7301 100644
--- a/01 Acey Ducey/java/src/aceyducey/Card.java
+++ b/01 Acey Ducey/java/src/Card.java
@@ -1,5 +1,3 @@
-package aceyducey;
-
/**
* A card from a deck - the value is between 2-14 to cover
* cards with a face value of 2-9 and then a Jack, Queen, King, and Ace
From 38a73b16d8d839c8226f7f1216443e21a29637d3 Mon Sep 17 00:00:00 2001
From: Tim <70119791+journich@users.noreply.github.com>
Date: Sun, 21 Feb 2021 12:19:23 +1030
Subject: [PATCH 02/15] Remove iml
---
01 Acey Ducey/java/.gitignore | 1 +
1 file changed, 1 insertion(+)
create mode 100644 01 Acey Ducey/java/.gitignore
diff --git a/01 Acey Ducey/java/.gitignore b/01 Acey Ducey/java/.gitignore
new file mode 100644
index 00000000..862582b3
--- /dev/null
+++ b/01 Acey Ducey/java/.gitignore
@@ -0,0 +1 @@
+AceyDucey.iml
From a62ef7f0111190d3b2352e6f16b5edd809c4dccf Mon Sep 17 00:00:00 2001
From: Tim <70119791+journich@users.noreply.github.com>
Date: Sun, 21 Feb 2021 17:21:08 +1030
Subject: [PATCH 03/15] Delete AceyDucey.iml
---
01 Acey Ducey/java/AceyDucey.iml | 11 -----------
1 file changed, 11 deletions(-)
delete mode 100644 01 Acey Ducey/java/AceyDucey.iml
diff --git a/01 Acey Ducey/java/AceyDucey.iml b/01 Acey Ducey/java/AceyDucey.iml
deleted file mode 100644
index c90834f2..00000000
--- a/01 Acey Ducey/java/AceyDucey.iml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
+ * Based on the Basic game of Bullseye here + * https://github.com/coding-horror/basic-computer-games/blob/main/18%20Bullseye/bullseye.bas + *
+ * Note: The idea was to create a version of 1970's Basic game in Java, without introducing
+ * new features - no additional text, error checking, etc has been added.
+ */
public class Bullseye {
+ // Used for formatting output
public static final int FIRST_IDENT = 10;
public static final int SECOND_IDENT = 30;
public static final int THIRD_INDENT = 30;
- public static final double[] SHOT_ONE = new double[] { .65, .55, .5, .5};
- public static final double[] SHOT_TWO = new double[] { .99, .77, .43,.01};
- public static final double[] SHOT_THREE = new double[] { .95, .75, .45, .05 };
+ // Used to decide throw result
+ public static final double[] SHOT_ONE = new double[]{.65, .55, .5, .5};
+ public static final double[] SHOT_TWO = new double[]{.99, .77, .43, .01};
+ public static final double[] SHOT_THREE = new double[]{.95, .75, .45, .05};
private enum GAME_STATE {
STARTING,
@@ -20,14 +31,12 @@ public class Bullseye {
private GAME_STATE gameState;
- private ArrayList
+ * Based on the Basic game of Hurkle here
+ * https://github.com/coding-horror/basic-computer-games/blob/main/51%20Hurkle/hurkle.bas
+ *
+ * Note: The idea was to create a version of 1970's Basic game in Java, without introducing
+ * new features - no additional text, error checking, etc has been added.
+ */
public class Hurkle {
public static final int GRID_SIZE = 10;
@@ -17,7 +25,7 @@ public class Hurkle {
private GAME_STATE gameState;
// Used for keyboard input
- private Scanner kbScanner;
+ private final Scanner kbScanner;
private int guesses;
@@ -73,7 +81,7 @@ public class Hurkle {
} else {
showDirectionOfHurkle();
this.guesses++;
- if(this.guesses > MAX_GUESSES) {
+ if (this.guesses > MAX_GUESSES) {
System.out.println("SORRY, THAT'S "
+ MAX_GUESSES + " GUESSES.");
System.out.println("THE HURKLE IS AT "
@@ -98,25 +106,24 @@ public class Hurkle {
private void showDirectionOfHurkle() {
System.out.print("GO ");
- if(this.playerGuessYPos == this.hurkleYPos) {
+ if (this.playerGuessYPos == this.hurkleYPos) {
// don't print North or South because the player has chosen the
// same y grid pos as the hurkle
} else if (this.playerGuessYPos < this.hurkleYPos) {
System.out.print("NORTH");
- } else if(this.playerGuessYPos > this.hurkleYPos) {
+ } else if (this.playerGuessYPos > this.hurkleYPos) {
System.out.print("SOUTH");
}
- if(this.playerGuessXPos == this.hurkleXPos) {
+ if (this.playerGuessXPos == this.hurkleXPos) {
// don't print East or West because the player has chosen the
// same x grid pos as the hurkle
- } else if(this.playerGuessXPos < this.hurkleXPos) {
+ } else if (this.playerGuessXPos < this.hurkleXPos) {
System.out.print("EAST");
- } else if(this.playerGuessXPos > this.hurkleXPos) {
+ } else if (this.playerGuessXPos > this.hurkleXPos) {
System.out.print("WEST");
}
System.out.println();
- return;
}
private boolean foundHurkle() {
diff --git a/51 Hurkle/java/src/HurkleGame.java b/51 Hurkle/java/src/HurkleGame.java
index c582885e..1b527398 100644
--- a/51 Hurkle/java/src/HurkleGame.java
+++ b/51 Hurkle/java/src/HurkleGame.java
@@ -1,7 +1,7 @@
public class HurkleGame {
public static void main(String[] args) {
- Hurkle hurkle = new Hurkle();
- hurkle.play();
+ Hurkle hurkle = new Hurkle();
+ hurkle.play();
}
}
From 2822405815a78ce0b5f65269a59d0916eac52531 Mon Sep 17 00:00:00 2001
From: Tim <70119791+journich@users.noreply.github.com>
Date: Mon, 22 Feb 2021 09:24:49 +1030
Subject: [PATCH 11/15] cleanup
---
25 Chief/java/Chief.iml | 11 ----------
25 Chief/java/src/Chief.java | 38 +++++++++++++++++++++-------------
51 Hurkle/java/src/Hurkle.java | 2 +-
3 files changed, 25 insertions(+), 26 deletions(-)
delete mode 100644 25 Chief/java/Chief.iml
diff --git a/25 Chief/java/Chief.iml b/25 Chief/java/Chief.iml
deleted file mode 100644
index c90834f2..00000000
--- a/25 Chief/java/Chief.iml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
+ * Based on the Basic game of Hurkle here
+ * https://github.com/coding-horror/basic-computer-games/blob/main/25%20Chief/chief.bas
+ *
+ * Note: The idea was to create a version of 1970's Basic game in Java, without introducing
+ * new features - no additional text, error checking, etc has been added.
+ */
public class Chief {
private enum GAME_STATE {
@@ -14,6 +23,7 @@ public class Chief {
private GAME_STATE gameState;
+ // The number the computer determines to be the players starting number
private double calculatedNumber;
// Used for keyboard input
@@ -43,7 +53,7 @@ public class Chief {
// show an message to start
case READY_TO_START:
- if(!yesEntered(displayTextAndGetInput("ARE YOU READY TO TAKE THE TEST YOU CALLED ME OUT FOR? "))) {
+ if (!yesEntered(displayTextAndGetInput("ARE YOU READY TO TAKE THE TEST YOU CALLED ME OUT FOR? "))) {
System.out.println("SHUT UP, PALE FACE WITH WISE TONGUE.");
}
@@ -57,16 +67,16 @@ public class Chief {
displayTextAndGetInput(" WHAT DO YOU HAVE? "));
// Exact same formula used in the original game to calculate the players original number
- this.calculatedNumber = (playerNumber +1-5)*5/8*5-3;
+ this.calculatedNumber = (playerNumber + 1 - 5) * 5 / 8 * 5 - 3;
this.gameState = GAME_STATE.CALCULATE_AND_SHOW;
break;
// Enter the number to be used to calculate
case CALCULATE_AND_SHOW:
- if(yesEntered(
+ if (yesEntered(
displayTextAndGetInput("I BET YOUR NUMBER WAS " + this.calculatedNumber
- + ". AM I RIGHT? "))) {
+ + ". AM I RIGHT? "))) {
this.gameState = GAME_STATE.END_GAME;
} else {
@@ -76,27 +86,27 @@ public class Chief {
double f = number + 3;
double g = f / 5;
double h = g * 8;
- double i = h/5 + 5;
- double j = i -1;
+ double i = h / 5 + 5;
+ double j = i - 1;
System.out.println("SO YOU THINK YOU'RE SO SMART, EH?");
System.out.println("NOW WATCH.");
- System.out.println(number +" PLUS 3 EQUALS " + f + ". THIS DIVIDED BY 5 EQUALS " + g);
+ System.out.println(number + " PLUS 3 EQUALS " + f + ". THIS DIVIDED BY 5 EQUALS " + g);
System.out.println("THIS TIMES 8 EQUALS " + h + ". IF WE DIVIDE BY 5 AND ADD 5,");
System.out.println("WE GET " + i + ", WHICH, MINUS 1, EQUALS " + j + ".");
- if(yesEntered(displayTextAndGetInput("NOW DO YOU BELIEVE ME? "))) {
+ if (yesEntered(displayTextAndGetInput("NOW DO YOU BELIEVE ME? "))) {
this.gameState = GAME_STATE.END_GAME;
} else {
// Time for a lightning bolt.
System.out.println("YOU HAVE MADE ME MAD!!!");
System.out.println("THERE MUST BE A GREAT LIGHTNING BOLT!");
System.out.println();
- for(int x=30; x>=22; x--) {
+ for (int x = 30; x >= 22; x--) {
System.out.println(tabbedSpaces(x) + "X X");
}
System.out.println(tabbedSpaces(21) + "X XXX");
System.out.println(tabbedSpaces(20) + "X X");
System.out.println(tabbedSpaces(19) + "XX X");
- for(int y=20; y>=13; y--) {
+ for (int y = 20; y >= 13; y--) {
System.out.println(tabbedSpaces(y) + "X X");
}
System.out.println(tabbedSpaces(12) + "XX");
@@ -134,6 +144,7 @@ public class Chief {
Arrays.fill(repeat, ' ');
return new String(repeat);
}
+
private void instructions() {
System.out.println(" TAKE A NUMBER AND ADD 3. DIVIDE THIS NUMBER BY 5 AND");
System.out.println("MULTIPLY BY 8. DIVIDE BY 5 AND ADD THE SAME. SUBTRACT 1.");
@@ -141,7 +152,6 @@ public class Chief {
/**
* Basic information about the game
- *
*/
private void intro() {
System.out.println("CHIEF");
@@ -165,15 +175,15 @@ public class Chief {
* Returns true if a given string contains at least one of the varargs (2nd parameter).
* Note: Case insensitive comparison.
*
- * @param text string to search
+ * @param text string to search
* @param values varargs of type string containing values to compare
* @return true if one of the varargs arguments was found in text
*/
private boolean stringIsAnyValue(String text, String... values) {
// Cycle through the variable number of values and test each
- for(String val:values) {
- if(text.equalsIgnoreCase(val)) {
+ for (String val : values) {
+ if (text.equalsIgnoreCase(val)) {
return true;
}
}
diff --git a/51 Hurkle/java/src/Hurkle.java b/51 Hurkle/java/src/Hurkle.java
index 5d3ebcbf..ad177ead 100644
--- a/51 Hurkle/java/src/Hurkle.java
+++ b/51 Hurkle/java/src/Hurkle.java
@@ -1,7 +1,7 @@
import java.util.Scanner;
/**
- * Game of Hiurkle
+ * Game of Hurkle
*
* Based on the Basic game of Hurkle here
* https://github.com/coding-horror/basic-computer-games/blob/main/51%20Hurkle/hurkle.bas
From aa0f3f4338a477cc6b22a9db4d6b6c02d4ac5079 Mon Sep 17 00:00:00 2001
From: Tim <70119791+journich@users.noreply.github.com>
Date: Mon, 22 Feb 2021 09:29:16 +1030
Subject: [PATCH 12/15] cleanup
---
69 Pizza/java/Pizza.iml | 11 ---------
69 Pizza/java/src/Pizza.java | 42 ++++++++++++++++++++------------
69 Pizza/java/src/PizzaGame.java | 4 +--
3 files changed, 28 insertions(+), 29 deletions(-)
delete mode 100644 69 Pizza/java/Pizza.iml
diff --git a/69 Pizza/java/Pizza.iml b/69 Pizza/java/Pizza.iml
deleted file mode 100644
index c90834f2..00000000
--- a/69 Pizza/java/Pizza.iml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
+ * Based on the Basic game of Hurkle here
+ * https://github.com/coding-horror/basic-computer-games/blob/main/69%20Pizza/pizza.bas
+ *
+ * Note: The idea was to create a version of 1970's Basic game in Java, without introducing
+ * new features - no additional text, error checking, etc has been added.
+ */
public class Pizza {
private final int MAX_DELIVERIES = 5;
@@ -17,11 +26,11 @@ public class Pizza {
}
// houses that can order pizza
- private final char[] houses = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
+ private final char[] houses = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P'};
// size of grid
- private final int[] gridPos = new int[] { 1, 2, 3, 4};
+ private final int[] gridPos = new int[]{1, 2, 3, 4};
private GAME_STATE gameState;
@@ -79,11 +88,11 @@ public class Pizza {
case MORE_DIRECTIONS:
extendedIntro();
String moreInfo = displayTextAndGetInput("DO YOU NEED MORE DIRECTIONS? ");
- if(!yesOrNoEntered(moreInfo)) {
+ if (!yesOrNoEntered(moreInfo)) {
System.out.println("'YES' OR 'NO' PLEASE, NOW THEN,");
} else {
// More instructions selected
- if(yesEntered(moreInfo)) {
+ if (yesEntered(moreInfo)) {
displayMoreDirections();
// Player understand now?
if (yesEntered(displayTextAndGetInput("UNDERSTAND? "))) {
@@ -102,7 +111,7 @@ public class Pizza {
}
}
- break;
+ break;
// Too difficult to understand, game over!
case TOO_DIFFICULT:
@@ -114,7 +123,7 @@ public class Pizza {
case START_DELIVER:
// select a random house and "order" a pizza for them.
this.currentHouseDelivery = (int) (Math.random()
- * (this.houses.length) + 1) -1; // Deduct 1 for 0-based array
+ * (this.houses.length) + 1) - 1; // Deduct 1 for 0-based array
System.out.println("HELLO " + this.playerName + "'S PIZZA. THIS IS "
+ this.houses[this.currentHouseDelivery] + ".");
@@ -132,17 +141,17 @@ public class Pizza {
// Convert x,y entered by player to grid position of a house
int x = getDelimitedValue(answer, 0);
int y = getDelimitedValue(answer, 1);
- int calculatedPos = (x + (y -1) * 4) -1;
+ int calculatedPos = (x + (y - 1) * 4) - 1;
// Did the player select the right house to deliver?
- if(calculatedPos == this.currentHouseDelivery) {
+ if (calculatedPos == this.currentHouseDelivery) {
System.out.println("HELLO " + this.playerName + ". THIS IS " + this.houses[this.currentHouseDelivery]
+ ", THANKS FOR THE PIZZA.");
this.pizzaDeliveryCount++;
// Delivered enough pizza?
- if(this.pizzaDeliveryCount > MAX_DELIVERIES) {
+ if (this.pizzaDeliveryCount > MAX_DELIVERIES) {
this.gameState = GAME_STATE.END_GAME;
} else {
this.gameState = GAME_STATE.START_DELIVER;
@@ -157,7 +166,7 @@ public class Pizza {
// Sign off message for cases where the Chief is not upset
case END_GAME:
- if(yesEntered(displayTextAndGetInput("DO YOU WANT TO DELIVER MORE PIZZAS? "))) {
+ if (yesEntered(displayTextAndGetInput("DO YOU WANT TO DELIVER MORE PIZZAS? "))) {
init();
this.gameState = GAME_STATE.START_DELIVER;
} else {
@@ -179,7 +188,7 @@ public class Pizza {
System.out.println();
System.out.println(" -----1-----2-----3-----4-----");
int k = 3;
- for(int i=1; i<5; i++) {
+ for (int i = 1; i < 5; i++) {
System.out.println("-");
System.out.println("-");
System.out.println("-");
@@ -199,10 +208,10 @@ public class Pizza {
System.out.println("-");
System.out.println("-");
System.out.println(" -----1-----2-----3-----4-----");
-}
+ }
+
/**
* Basic information about the game
- *
*/
private void intro() {
System.out.println("PIZZA");
@@ -273,19 +282,20 @@ public class Pizza {
private boolean yesOrNoEntered(String text) {
return stringIsAnyValue(text, "Y", "YES", "N", "NO");
}
+
/**
* Returns true if a given string contains at least one of the varargs (2nd parameter).
* Note: Case insensitive comparison.
*
- * @param text string to search
+ * @param text string to search
* @param values varargs of type string containing values to compare
* @return true if one of the varargs arguments was found in text
*/
private boolean stringIsAnyValue(String text, String... values) {
// Cycle through the variable number of values and test each
- for(String val:values) {
- if(text.equalsIgnoreCase(val)) {
+ for (String val : values) {
+ if (text.equalsIgnoreCase(val)) {
return true;
}
}
diff --git a/69 Pizza/java/src/PizzaGame.java b/69 Pizza/java/src/PizzaGame.java
index 2a94afc9..b7074fa4 100644
--- a/69 Pizza/java/src/PizzaGame.java
+++ b/69 Pizza/java/src/PizzaGame.java
@@ -2,7 +2,7 @@ public class PizzaGame {
public static void main(String[] args) {
- Pizza pizza = new Pizza();
- pizza.play();
+ Pizza pizza = new Pizza();
+ pizza.play();
}
}
From 143370069bb7cb2c8d019100bbaf561e67da1198 Mon Sep 17 00:00:00 2001
From: Tim <70119791+journich@users.noreply.github.com>
Date: Mon, 22 Feb 2021 09:37:34 +1030
Subject: [PATCH 13/15] cleanup
---
01 Acey Ducey/java/src/AceyDucey.java | 23 ++++----
01 Acey Ducey/java/src/Card.java | 2 +-
18 Bullseye/java/src/Player.java | 3 +-
18 Bullseye/java/src/Shot.java | 4 +-
25 Chief/java/src/Chief.java | 22 +++----
47 Hi-Lo/java/src/HiLo.java | 2 +-
51 Hurkle/java/src/Hurkle.java | 46 +++++++--------
69 Pizza/java/src/Pizza.java | 82 +++++++++++++--------------
78 Sine Wave/java/src/SineWave.java | 2 +-
82 Stars/java/Stars.iml | 11 ----
82 Stars/java/src/Stars.java | 34 +++++------
11 files changed, 109 insertions(+), 122 deletions(-)
delete mode 100644 82 Stars/java/Stars.iml
diff --git a/01 Acey Ducey/java/src/AceyDucey.java b/01 Acey Ducey/java/src/AceyDucey.java
index 5320c8e0..43fc9950 100644
--- a/01 Acey Ducey/java/src/AceyDucey.java
+++ b/01 Acey Ducey/java/src/AceyDucey.java
@@ -2,12 +2,11 @@ import java.util.Scanner;
/**
* Game of AceyDucey
- *
+ *
* Based on the Basic game of AceyDucey here
* https://github.com/coding-horror/basic-computer-games/blob/main/01%20Acey%20Ducey/aceyducey.bas
- * Note: The idea was to create a version of 1970's Basic game in Java, without introducing
- * new features - no additional text, error checking, etc has been added.
- *
+ * Note: The idea was to create a version of the 1970's Basic game in Java, without introducing
+ * new features - no additional text, error checking, etc has been added.
*/
public class AceyDucey {
@@ -33,7 +32,7 @@ public class AceyDucey {
private final Scanner kbScanner;
// Constant value for cards from a deck - 2 lowest, 14 (Ace) highest
- public static final int LOW_CARD_RANGE =2;
+ public static final int LOW_CARD_RANGE = 2;
public static final int HIGH_CARD_RANGE = 14;
public AceyDucey() {
@@ -56,7 +55,7 @@ public class AceyDucey {
String playAgain = kbScanner.next().toUpperCase();
System.out.println();
System.out.println();
- if(playAgain.equals("YES")) {
+ if (playAgain.equals("YES")) {
return true;
} else {
System.out.println("O.K., HOPE YOU HAD FUN!");
@@ -70,7 +69,7 @@ public class AceyDucey {
// Keep playing hands until player runs out of cash
do {
- if(firstTimePlaying) {
+ if (firstTimePlaying) {
intro();
firstTimePlaying = false;
}
@@ -80,14 +79,14 @@ public class AceyDucey {
int betAmount = getBet();
playersCard = randomCard();
displayPlayerCard();
- if(playerWon()) {
+ if (playerWon()) {
System.out.println("YOU WIN!!");
playerAmount += betAmount;
} else {
System.out.println("SORRY, YOU LOSE");
playerAmount -= betAmount;
// Player run out of money?
- if(playerAmount <=0) {
+ if (playerAmount <= 0) {
gameOver = true;
}
}
@@ -118,10 +117,10 @@ public class AceyDucey {
do {
System.out.print("WHAT IS YOUR BET ");
amount = kbScanner.nextInt();
- if(amount == 0) {
+ if (amount == 0) {
System.out.println("CHICKEN!!");
validBet = true;
- } else if(amount > playerAmount) {
+ } else if (amount > playerAmount) {
System.out.println("SORRY, MY FRIEND, BUT YOU BET TOO MUCH.");
System.out.println("YOU HAVE ONLY " + playerAmount + " DOLLARS TO BET.");
} else {
@@ -149,7 +148,7 @@ public class AceyDucey {
do {
firstCard = randomCard();
secondCard = randomCard();
- } while(firstCard.getValue() >= secondCard.getValue());
+ } while (firstCard.getValue() >= secondCard.getValue());
}
// Creates a random card
diff --git a/01 Acey Ducey/java/src/Card.java b/01 Acey Ducey/java/src/Card.java
index d36f7301..88211002 100644
--- a/01 Acey Ducey/java/src/Card.java
+++ b/01 Acey Ducey/java/src/Card.java
@@ -12,7 +12,7 @@ public class Card {
private void init(int value) {
this.value = value;
- if(value <11) {
+ if (value < 11) {
this.name = String.valueOf(value);
} else {
switch (value) {
diff --git a/18 Bullseye/java/src/Player.java b/18 Bullseye/java/src/Player.java
index b67b9309..1a30935a 100644
--- a/18 Bullseye/java/src/Player.java
+++ b/18 Bullseye/java/src/Player.java
@@ -4,7 +4,8 @@
*/
public class Player {
- private String name;
+ private final String name;
+
private int score;
Player(String name) {
diff --git a/18 Bullseye/java/src/Shot.java b/18 Bullseye/java/src/Shot.java
index 01d8b283..43fa84e4 100644
--- a/18 Bullseye/java/src/Shot.java
+++ b/18 Bullseye/java/src/Shot.java
@@ -10,9 +10,7 @@ public class Shot {
// Array of doubles are passed for a specific type of shot
Shot(double[] shots) {
chances = new double[shots.length];
- for(int i=0; i
- * Note: The idea was to create a version of 1970's Basic game in Java, without introducing
+ * Note: The idea was to create a version of the 1970's Basic game in Java, without introducing
* new features - no additional text, error checking, etc has been added.
*/
public class Hurkle {
@@ -62,32 +62,32 @@ public class Hurkle {
// Start the game, set the number of players, names and round
case START_GAME:
- this.hurkleXPos = randomNumber();
- this.hurkleYPos = randomNumber();
- System.out.println("HURKLE AT : " + this.hurkleXPos + "," + this.hurkleYPos);
+ hurkleXPos = randomNumber();
+ hurkleYPos = randomNumber();
+ System.out.println("HURKLE AT : " + hurkleXPos + "," + hurkleYPos);
- this.guesses = 1;
+ guesses = 1;
gameState = GAME_STATE.GUESSING;
break;
// Guess an x,y position of the hurkle
case GUESSING:
- String guess = displayTextAndGetInput("GUESS #" + this.guesses + "? ");
- this.playerGuessXPos = getDelimitedValue(guess, 0);
- this.playerGuessYPos = getDelimitedValue(guess, 1);
+ String guess = displayTextAndGetInput("GUESS #" + guesses + "? ");
+ playerGuessXPos = getDelimitedValue(guess, 0);
+ playerGuessYPos = getDelimitedValue(guess, 1);
if (foundHurkle()) {
- this.gameState = GAME_STATE.PLAY_AGAIN;
+ gameState = GAME_STATE.PLAY_AGAIN;
} else {
showDirectionOfHurkle();
- this.guesses++;
- if (this.guesses > MAX_GUESSES) {
+ guesses++;
+ if (guesses > MAX_GUESSES) {
System.out.println("SORRY, THAT'S "
+ MAX_GUESSES + " GUESSES.");
System.out.println("THE HURKLE IS AT "
- + this.hurkleXPos + "," + this.hurkleYPos);
+ + hurkleXPos + "," + hurkleYPos);
System.out.println();
- this.gameState = GAME_STATE.PLAY_AGAIN;
+ gameState = GAME_STATE.PLAY_AGAIN;
}
}
@@ -96,7 +96,7 @@ public class Hurkle {
case PLAY_AGAIN:
System.out.println("LET'S PLAY AGAIN, HURKLE IS HIDING.");
System.out.println();
- this.gameState = GAME_STATE.START_GAME;
+ gameState = GAME_STATE.START_GAME;
break;
}
// Effectively an endless loop because the game never quits as per
@@ -106,30 +106,30 @@ public class Hurkle {
private void showDirectionOfHurkle() {
System.out.print("GO ");
- if (this.playerGuessYPos == this.hurkleYPos) {
+ if (playerGuessYPos == hurkleYPos) {
// don't print North or South because the player has chosen the
// same y grid pos as the hurkle
- } else if (this.playerGuessYPos < this.hurkleYPos) {
+ } else if (playerGuessYPos < hurkleYPos) {
System.out.print("NORTH");
- } else if (this.playerGuessYPos > this.hurkleYPos) {
+ } else if (playerGuessYPos > hurkleYPos) {
System.out.print("SOUTH");
}
- if (this.playerGuessXPos == this.hurkleXPos) {
+ if (playerGuessXPos == hurkleXPos) {
// don't print East or West because the player has chosen the
// same x grid pos as the hurkle
- } else if (this.playerGuessXPos < this.hurkleXPos) {
+ } else if (playerGuessXPos < hurkleXPos) {
System.out.print("EAST");
- } else if (this.playerGuessXPos > this.hurkleXPos) {
+ } else if (playerGuessXPos > hurkleXPos) {
System.out.print("WEST");
}
System.out.println();
}
private boolean foundHurkle() {
- if ((this.playerGuessXPos - this.hurkleXPos)
- - (this.playerGuessYPos - this.hurkleYPos) == 0) {
- System.out.println("YOU FOUND HIM IN " + this.guesses + " GUESSES.");
+ if ((playerGuessXPos - hurkleXPos)
+ - (playerGuessYPos - hurkleYPos) == 0) {
+ System.out.println("YOU FOUND HIM IN " + guesses + " GUESSES.");
return true;
}
diff --git a/69 Pizza/java/src/Pizza.java b/69 Pizza/java/src/Pizza.java
index fadfccc6..55bf8ceb 100644
--- a/69 Pizza/java/src/Pizza.java
+++ b/69 Pizza/java/src/Pizza.java
@@ -6,7 +6,7 @@ import java.util.Scanner;
* Based on the Basic game of Hurkle here
* https://github.com/coding-horror/basic-computer-games/blob/main/69%20Pizza/pizza.bas
*
- * Note: The idea was to create a version of 1970's Basic game in Java, without introducing
+ * Note: The idea was to create a version of the 1970's Basic game in Java, without introducing
* new features - no additional text, error checking, etc has been added.
*/
public class Pizza {
@@ -47,7 +47,7 @@ public class Pizza {
public Pizza() {
- this.gameState = GAME_STATE.STARTING;
+ gameState = GAME_STATE.STARTING;
// Initialise kb scanner
kbScanner = new Scanner(System.in);
@@ -59,29 +59,29 @@ public class Pizza {
public void play() {
do {
- switch (this.gameState) {
+ switch (gameState) {
// Show an introduction the first time the game is played.
case STARTING:
init();
intro();
- this.gameState = GAME_STATE.ENTER_NAME;
+ gameState = GAME_STATE.ENTER_NAME;
break;
// Enter the players name
case ENTER_NAME:
- this.playerName = displayTextAndGetInput("WHAT IS YOUR FIRST NAME? ");
- System.out.println("HI " + this.playerName + ". IN THIS GAME YOU ARE TO TAKE ORDERS");
+ playerName = displayTextAndGetInput("WHAT IS YOUR FIRST NAME? ");
+ System.out.println("HI " + playerName + ". IN GAME YOU ARE TO TAKE ORDERS");
System.out.println("FOR PIZZAS. THEN YOU ARE TO TELL A DELIVERY BOY");
System.out.println("WHERE TO DELIVER THE ORDERED PIZZAS.");
System.out.println();
- this.gameState = GAME_STATE.DRAW_MAP;
+ gameState = GAME_STATE.DRAW_MAP;
break;
// Draw the map
case DRAW_MAP:
drawMap();
- this.gameState = GAME_STATE.MORE_DIRECTIONS;
+ gameState = GAME_STATE.MORE_DIRECTIONS;
break;
// need more directions (how to play) ?
@@ -100,14 +100,14 @@ public class Pizza {
System.out.println();
System.out.println("GOOD LUCK!!");
System.out.println();
- this.gameState = GAME_STATE.START_DELIVER;
+ gameState = GAME_STATE.START_DELIVER;
} else {
// Not understood, essentially game over
- this.gameState = GAME_STATE.TOO_DIFFICULT;
+ gameState = GAME_STATE.TOO_DIFFICULT;
}
} else {
// no more directions were needed, start delivering pizza
- this.gameState = GAME_STATE.START_DELIVER;
+ gameState = GAME_STATE.START_DELIVER;
}
}
@@ -115,27 +115,27 @@ public class Pizza {
// Too difficult to understand, game over!
case TOO_DIFFICULT:
- System.out.println("THIS JOB IS DEFINITELY TOO DIFFICULT FOR YOU. THANKS ANYWAY");
- this.gameState = GAME_STATE.GAME_OVER;
+ System.out.println("JOB IS DEFINITELY TOO DIFFICULT FOR YOU. THANKS ANYWAY");
+ gameState = GAME_STATE.GAME_OVER;
break;
// Delivering pizza
case START_DELIVER:
// select a random house and "order" a pizza for them.
- this.currentHouseDelivery = (int) (Math.random()
- * (this.houses.length) + 1) - 1; // Deduct 1 for 0-based array
+ currentHouseDelivery = (int) (Math.random()
+ * (houses.length) + 1) - 1; // Deduct 1 for 0-based array
- System.out.println("HELLO " + this.playerName + "'S PIZZA. THIS IS "
- + this.houses[this.currentHouseDelivery] + ".");
+ System.out.println("HELLO " + playerName + "'S PIZZA. IS "
+ + houses[currentHouseDelivery] + ".");
System.out.println(" PLEASE SEND A PIZZA.");
- this.gameState = GAME_STATE.DELIVER_PIZZA;
+ gameState = GAME_STATE.DELIVER_PIZZA;
break;
// Try and deliver the pizza
case DELIVER_PIZZA:
- String question = " DRIVER TO " + this.playerName + ": WHERE DOES "
- + this.houses[this.currentHouseDelivery] + " LIVE ? ";
+ String question = " DRIVER TO " + playerName + ": WHERE DOES "
+ + houses[currentHouseDelivery] + " LIVE ? ";
String answer = displayTextAndGetInput(question);
// Convert x,y entered by player to grid position of a house
@@ -144,22 +144,22 @@ public class Pizza {
int calculatedPos = (x + (y - 1) * 4) - 1;
// Did the player select the right house to deliver?
- if (calculatedPos == this.currentHouseDelivery) {
- System.out.println("HELLO " + this.playerName + ". THIS IS " + this.houses[this.currentHouseDelivery]
+ if (calculatedPos == currentHouseDelivery) {
+ System.out.println("HELLO " + playerName + ". IS " + houses[currentHouseDelivery]
+ ", THANKS FOR THE PIZZA.");
- this.pizzaDeliveryCount++;
+ pizzaDeliveryCount++;
// Delivered enough pizza?
- if (this.pizzaDeliveryCount > MAX_DELIVERIES) {
- this.gameState = GAME_STATE.END_GAME;
+ if (pizzaDeliveryCount > MAX_DELIVERIES) {
+ gameState = GAME_STATE.END_GAME;
} else {
- this.gameState = GAME_STATE.START_DELIVER;
+ gameState = GAME_STATE.START_DELIVER;
}
} else {
- System.out.println("THIS IS " + houses[calculatedPos] + ". I DID NOT ORDER A PIZZA.");
+ System.out.println("IS " + houses[calculatedPos] + ". I DID NOT ORDER A PIZZA.");
System.out.println("I LIVE AT " + x + "," + y);
- // Don't change gameState so this state is executed again
+ // Don't change gameState so state is executed again
}
break;
@@ -168,18 +168,18 @@ public class Pizza {
case END_GAME:
if (yesEntered(displayTextAndGetInput("DO YOU WANT TO DELIVER MORE PIZZAS? "))) {
init();
- this.gameState = GAME_STATE.START_DELIVER;
+ gameState = GAME_STATE.START_DELIVER;
} else {
System.out.println();
- System.out.println("O.K. " + this.playerName + ", SEE YOU LATER!");
+ System.out.println("O.K. " + playerName + ", SEE YOU LATER!");
System.out.println();
- this.gameState = GAME_STATE.GAME_OVER;
+ gameState = GAME_STATE.GAME_OVER;
}
break;
// GAME_OVER State does not specifically have a case
}
- } while (this.gameState != GAME_STATE.GAME_OVER);
+ } while (gameState != GAME_STATE.GAME_OVER);
}
private void drawMap() {
@@ -194,13 +194,13 @@ public class Pizza {
System.out.println("-");
System.out.println("-");
- System.out.print(this.gridPos[k]);
+ System.out.print(gridPos[k]);
int pos = 16 - 4 * i;
- System.out.print(" " + this.houses[pos]);
- System.out.print(" " + this.houses[pos + 1]);
- System.out.print(" " + this.houses[pos + 2]);
- System.out.print(" " + this.houses[pos + 3]);
- System.out.println(" " + this.gridPos[k]);
+ System.out.print(" " + houses[pos]);
+ System.out.print(" " + houses[pos + 1]);
+ System.out.print(" " + houses[pos + 2]);
+ System.out.print(" " + houses[pos + 3]);
+ System.out.println(" " + gridPos[k]);
k = k - 1;
}
System.out.println("-");
@@ -238,14 +238,14 @@ public class Pizza {
System.out.println("DELIVERED. THEN A DELIVERY BOY WILL");
System.out.println("ASK YOU FOR THE LOCATION.");
System.out.println(" EXAMPLE:");
- System.out.println("THIS IS J. PLEASE SEND A PIZZA.");
- System.out.println("DRIVER TO " + this.playerName + ". WHERE DOES J LIVE?");
+ System.out.println("IS J. PLEASE SEND A PIZZA.");
+ System.out.println("DRIVER TO " + playerName + ". WHERE DOES J LIVE?");
System.out.println("YOUR ANSWER WOULD BE 2,3");
System.out.println();
}
private void init() {
- this.pizzaDeliveryCount = 1;
+ pizzaDeliveryCount = 1;
}
/**
diff --git a/78 Sine Wave/java/src/SineWave.java b/78 Sine Wave/java/src/SineWave.java
index 7d917a75..f3b3c7eb 100644
--- a/78 Sine Wave/java/src/SineWave.java
+++ b/78 Sine Wave/java/src/SineWave.java
@@ -6,7 +6,7 @@ import java.util.Arrays;
* Based on the Sine Wave program here
* https://github.com/coding-horror/basic-computer-games/blob/main/78%20Sine%20Wave/sinewave.bas
*
- * Note: The idea was to create a version of this 1970's Basic program in Java, without introducing
+ * Note: The idea was to create a version of the 1970's Basic program in Java, without introducing
* new features - no additional text, error checking, etc has been added.
*/
public class SineWave {
diff --git a/82 Stars/java/Stars.iml b/82 Stars/java/Stars.iml
deleted file mode 100644
index c90834f2..00000000
--- a/82 Stars/java/Stars.iml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
* Based on the Basic game of Bombardment here
* https://github.com/coding-horror/basic-computer-games/blob/main/11%20Bombardment/bombardment.bas
- *
- * Note: The idea was to create a version of this 1970's Basic game in Java, without introducing
- * new features - no additional text, error checking, etc has been added.
+ *
+ * Note: The idea was to create a version of the 1970's Basic game in Java, without introducing
+ * new features - no additional text, error checking, etc has been added.
*/
public class Bombardment {
@@ -28,11 +28,11 @@ public class Bombardment {
private GAME_STATE gameState;
- public static final String[] PLAYER_HIT_MESSAGES = { "ONE DOWN, THREE TO GO.",
- "TWO DOWN, TWO TO GO.", "THREE DOWN, ONE TO GO." };
+ public static final String[] PLAYER_HIT_MESSAGES = {"ONE DOWN, THREE TO GO.",
+ "TWO DOWN, TWO TO GO.", "THREE DOWN, ONE TO GO."};
public static final String[] COMPUTER_HIT_MESSAGES = {"YOU HAVE ONLY THREE OUTPOSTS LEFT.",
- "YOU HAVE ONLY TWO OUTPOSTS LEFT.", "YOU HAVE ONLY ONE OUTPOST LEFT." };
+ "YOU HAVE ONLY TWO OUTPOSTS LEFT.", "YOU HAVE ONLY ONE OUTPOST LEFT."};
private HashSet
* Based on the Basic game of Trap here
* https://github.com/coding-horror/basic-computer-games/blob/main/92%20Trap/trap.bas
- *
- * Note: The idea was to create a version of 1970's Basic game in Java, without introducing
- * new features - no additional text, error checking, etc has been added.
+ *
+ * Note: The idea was to create a version of the 1970's Basic game in Java, without introducing
+ * new features - no additional text, error checking, etc has been added.
*/
public class Trap {
@@ -45,7 +45,6 @@ public class Trap {
/**
* Main game loop
- *
*/
public void play() {
@@ -55,7 +54,7 @@ public class Trap {
// Show an introduction and optional instructions the first time the game is played.
case STARTING:
intro();
- if(yesEntered(displayTextAndGetInput("INSTRUCTIONS? "))) {
+ if (yesEntered(displayTextAndGetInput("INSTRUCTIONS? "))) {
instructions();
}
gameState = GAME_STATE.START_GAME;
@@ -72,11 +71,11 @@ public class Trap {
case GUESSING:
System.out.println();
String playerRangeGuess = displayTextAndGetInput("GUESS # " + currentPlayersGuess + "? ");
- int startRange = getDelimitedValue(playerRangeGuess,0);
- int endRange = getDelimitedValue(playerRangeGuess,1);
+ int startRange = getDelimitedValue(playerRangeGuess, 0);
+ int endRange = getDelimitedValue(playerRangeGuess, 1);
// Has the player won?
- if(startRange == computersNumber && endRange == computersNumber) {
+ if (startRange == computersNumber && endRange == computersNumber) {
System.out.println("YOU GOT IT!!!");
System.out.println();
gameState = GAME_STATE.PLAY_AGAIN;
@@ -84,7 +83,7 @@ public class Trap {
// show where the guess is at
System.out.println(showGuessResult(startRange, endRange));
currentPlayersGuess++;
- if(currentPlayersGuess > MAX_GUESSES) {
+ if (currentPlayersGuess > MAX_GUESSES) {
System.out.println("SORRY, THAT'S " + MAX_GUESSES + " GUESSES. THE NUMBER WAS "
+ computersNumber);
gameState = GAME_STATE.PLAY_AGAIN;
@@ -104,15 +103,15 @@ public class Trap {
* Show the players guess result
*
* @param start start range entered by player
- * @param end end range
+ * @param end end range
* @return text to indicate their progress.
*/
private String showGuessResult(int start, int end) {
String status;
- if(start <= computersNumber && computersNumber <= end) {
+ if (start <= computersNumber && computersNumber <= end) {
status = "YOU HAVE TRAPPED MY NUMBER.";
- } else if(computersNumber < start) {
+ } else if (computersNumber < start) {
status = "MY NUMBER IS SMALLER THAN YOUR TRAP NUMBERS.";
} else {
status = "MY NUMBER IS LARGER THAN YOUR TRAP NUMBERS.";
@@ -157,7 +156,7 @@ public class Trap {
/**
* Checks whether player entered Y or YES to a question.
*
- * @param text player string from kb
+ * @param text player string from kb
* @return true of Y or YES was entered, otherwise false
*/
private boolean yesEntered(String text) {
@@ -169,7 +168,7 @@ public class Trap {
* Useful to check for Y or YES for example
* Comparison is case insensitive.
*
- * @param text source string
+ * @param text source string
* @param values a range of values to compare against the source string
* @return true if a comparison was found in one of the variable number of strings passed
*/
diff --git a/92 Trap/java/TrapGame.java b/92 Trap/java/src/TrapGame.java
similarity index 100%
rename from 92 Trap/java/TrapGame.java
rename to 92 Trap/java/src/TrapGame.java