();
+ arrayListOfUnderscores();
+ }
+ /**
+ * Call this method when the user supplies a char as a guess.
+ * This method will add that char to the list of guessed letters, and refigure the
+ * array of true/false.
+ *
+ * @param c
+ */
+ public void handleGuess(char c) {
+ lettersGuessed.setTrue(c);
+ for (int i = 0; i < goalWordArray.length; i++) {
+ if (goalWordArray[i] == c) {
+ hits[i] = true;
+ screenedWord.set(i, c);
+ }
+ }
+ }
+
+ /**
+ * takes the array of indexes and the arrayList of guesses, and the string that you are guessing and it adds the
+ * string to the arrayList of correctGuesses
+ *
+ * Example: addToArrayList([1,3,5], List{_ _ _ _ _ _}, "a") => "_ a _ a _ a"
+ */
+ public void arrayListOfUnderscores() {
+ for (int i = 0; i < goalWord.length(); i++) {
+ screenedWord.add('_');
+ }
+ }
+
+ //checks if the screenedWord is full of the letters and not blank at all
+ public boolean playerHasWon() {
+ for (int i = 0; i < hits.length; i++) {
+ if (hits[i] == false) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public boolean isInWord(char c) {
+ boolean result = false;
+
+ for (int i = 0; i < goalWordArray.length; i++) {
+ if (goalWordArray[i] == c) {
+ result = true;
+ }
+ }
+
+ return result;
+ }
+
+
+
+ public int getGuesses() {
+ return guesses;
+ }
+
+ public List getScreenedWord() {
+ return screenedWord;
+ }
+
+ public String getStatus() {
+ return "your status is " + screenedWord;
+ }
+ public String getGoalWord() {
+ return goalWord;
+ }
+}
\ No newline at end of file
diff --git a/src/org/vashonsd/Games/EO/EmmeGame.java b/src/main/java/org/vashonsd/Games/EO/EmmeGame.java
similarity index 100%
rename from src/org/vashonsd/Games/EO/EmmeGame.java
rename to src/main/java/org/vashonsd/Games/EO/EmmeGame.java
diff --git a/src/org/vashonsd/Games/HA/HuthaifaGame.java b/src/main/java/org/vashonsd/Games/HA/HuthaifaGame.java
similarity index 100%
rename from src/org/vashonsd/Games/HA/HuthaifaGame.java
rename to src/main/java/org/vashonsd/Games/HA/HuthaifaGame.java
diff --git a/src/main/java/org/vashonsd/Games/HA/RockPaperScissors.java b/src/main/java/org/vashonsd/Games/HA/RockPaperScissors.java
new file mode 100644
index 0000000..1989371
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/HA/RockPaperScissors.java
@@ -0,0 +1,87 @@
+package org.vashonsd.Games.HA;
+
+import org.vashonsd.Utils.Minigame;
+
+import java.util.Map;
+import java.util.Random;
+import java.util.Scanner;
+import java.util.HashMap;
+
+public class RockPaperScissors extends Minigame {
+ final String[] rps = new String[]{"Rock", "Paper", "Scissor"};
+ Random rand = new Random();
+ String computerChoice = rps[rand.nextInt(rps.length)];
+ HashMap rpslookup = new HashMap();
+ int[][] WinnerTable = new int[3][3];
+ int userScore ;
+ int computerScore;
+ int finalScore;
+
+
+
+ public RockPaperScissors() {
+ super("RPS", "A simple game of rock, paper, scissors", "quit");
+ // Rock = 0, Paper = 1, Scissors = 2
+ WinnerTable[0][0] = 0; // 0 == nobody wins
+ WinnerTable[0][1] = 2; // 2 == second player wins
+ WinnerTable[0][2] = 1;
+ WinnerTable[1][1] = 0;
+ WinnerTable[1][0] = 1; // 1 == first player wins
+ WinnerTable[1][2] = 2;
+ WinnerTable[2][0] = 1;
+ WinnerTable[2][1] = 2;
+ WinnerTable[2][2] = 0;
+
+
+
+ rpslookup.put("ROCK", 0);
+ rpslookup.put("PAPER", 1);
+ rpslookup.put("SCISSORS", 2);
+ }
+
+
+ @Override
+ public String start() {
+ return "The game just starte\n Chooes: Rock, paper, or scissor?";
+ }
+
+ @Override
+ public String handle(String userChoice) {
+ computerChoice = rps[rand.nextInt(rps.length - 1)];
+ int p1 = rpslookup.get(computerChoice.toUpperCase());
+ int p2;
+ if (rpslookup.containsKey(userChoice.toUpperCase())) {
+ p2 = rpslookup.get(userChoice.toUpperCase());
+ } else {
+ return "I don't understand " + userChoice + "; I need Rock, Paper or Scissors";
+ }
+
+ int whowins = WinnerTable[p1][p2];
+ while (finalScore < 5) {
+ if (whowins == 0) {
+
+ return "You chose " + userChoice.toUpperCase() + "," + " The computer chose " + computerChoice.toUpperCase() + ". It's a tie!. " +userScore+" - "+computerScore;
+
+ } else if (whowins == 1) {
+ computerScore++;
+ finalScore++;
+ return "You chose " + userChoice.toUpperCase() + "," + " The computer chose " + computerChoice.toUpperCase() + ". The computer win!. " +userScore+" - "+computerScore;
+ } else if (whowins == 2) {
+ userScore++;
+ finalScore++;
+ return "You chose " + userChoice.toUpperCase() + "," + " The computer chose " + computerChoice.toUpperCase() + ". You win!. " +userScore+" - "+computerScore;
+ }
+ return "Try again!";
+ }
+ if(userScore>computerScore){
+ return "You won the game! "+userScore+" - "+computerScore;
+ }
+ return "You lost!"+userScore+" - "+computerScore;
+ }
+
+
+ @Override
+ public String quit() {
+ return "Good Bye.";
+ }
+}
\ No newline at end of file
diff --git a/src/org/vashonsd/Games/MinigameFactory.java b/src/main/java/org/vashonsd/Games/MinigameFactory.java
similarity index 73%
rename from src/org/vashonsd/Games/MinigameFactory.java
rename to src/main/java/org/vashonsd/Games/MinigameFactory.java
index 03e547c..bd26be2 100644
--- a/src/org/vashonsd/Games/MinigameFactory.java
+++ b/src/main/java/org/vashonsd/Games/MinigameFactory.java
@@ -4,10 +4,12 @@
import org.vashonsd.Games.BR.BeckettGame;
import org.vashonsd.Games.EO.EmmeGame;
import org.vashonsd.Games.HA.HuthaifaGame;
+import org.vashonsd.Games.HA.RockPaperScissors;
import org.vashonsd.Games.NA.NabilGame;
-import org.vashonsd.Games.NE.NoahGame;
+//import org.vashonsd.Games.NE.NoahGame;
import org.vashonsd.Games.RI.RobertGame;
-import org.vashonsd.Games.SP.SamGame;
+import org.vashonsd.Games.RPS_games.RockPaperPlus;
+import org.vashonsd.Games.SP.NewSamGame;
import org.vashonsd.Games.SR.SeanGame;
import org.vashonsd.Utils.Minigame;
@@ -27,13 +29,14 @@ public class MinigameFactory {
addGame(new TwentyQuestions());
addGame(new AngelicaGame());
addGame(new BeckettGame());
- addGame(new EmmeGame());
- addGame(new HuthaifaGame());
- addGame(new NoahGame());
- addGame(new RobertGame());
- addGame(new SamGame());
+// addGame(new EmmeGame());
+ addGame(new RockPaperScissors());
+// addGame(new NoahGame());
+// addGame(new RobertGame());
+ addGame(new NewSamGame());
addGame(new SeanGame());
addGame(new NabilGame());
+ addGame(new RockPaperPlus());
}
public static void addGame(Minigame m) {
@@ -43,7 +46,7 @@ public static void addGame(Minigame m) {
public static String listGames() {
String result = "";
String spacer = "";
- for(Minigame m : games.values()) {
+ for (Minigame m : games.values()) {
result += spacer + m.getName() + " - " + m.getDescription();
spacer = "\n";
}
diff --git a/src/org/vashonsd/Games/NA/NabilGame.java b/src/main/java/org/vashonsd/Games/NA/NabilGame.java
similarity index 100%
rename from src/org/vashonsd/Games/NA/NabilGame.java
rename to src/main/java/org/vashonsd/Games/NA/NabilGame.java
diff --git a/src/main/java/org/vashonsd/Games/NE/Choice.java b/src/main/java/org/vashonsd/Games/NE/Choice.java
new file mode 100755
index 0000000..b20c1cd
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/NE/Choice.java
@@ -0,0 +1,66 @@
+package org.vashonsd.Games.NE;
+
+import java.util.Random;
+
+public class Choice {
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public ChoiceType getWinCase() {
+ return winCase;
+ }
+
+ public void setWinCase(ChoiceType winCase) {
+ this.winCase = winCase;
+ }
+
+ public ChoiceType getTieCase() {
+ return tieCase;
+ }
+
+ public void setTieCase(ChoiceType tieCase) {
+ this.tieCase = tieCase;
+ }
+
+ public ChoiceType getLoseCase() {
+ return loseCase;
+ }
+
+ public void setLoseCase(ChoiceType loseCase) {
+ this.loseCase = loseCase;
+ }
+
+ public ChoiceType getMyType() {
+ return myType;
+ }
+
+ public void setMyType(ChoiceType myType) {
+ this.myType = myType;
+ }
+
+ private String name;
+ private ChoiceType myType;
+ private ChoiceType winCase;
+ private ChoiceType tieCase;
+ private ChoiceType loseCase;
+
+ public Choice(String name) {
+ this.name = name;
+ }
+
+ public String determineWinner(Choice c) {
+ if(this.getWinCase() == c.getMyType()) {
+ return "You Win!";
+ } else if (this.getLoseCase() == c.getMyType()) {
+ return "You Lose!";
+ } else {
+ return "You Tied!";
+ }
+ }
+}
diff --git a/src/main/java/org/vashonsd/Games/NE/ChoiceType.java b/src/main/java/org/vashonsd/Games/NE/ChoiceType.java
new file mode 100755
index 0000000..c380582
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/NE/ChoiceType.java
@@ -0,0 +1,5 @@
+package org.vashonsd.Games.NE;
+
+public enum ChoiceType {
+ ROCK, PAPER, SCISSORS
+}
diff --git a/src/main/java/org/vashonsd/Games/NE/NoahGame.java b/src/main/java/org/vashonsd/Games/NE/NoahGame.java
new file mode 100755
index 0000000..8fa62cc
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/NE/NoahGame.java
@@ -0,0 +1,155 @@
+package org.vashonsd.Games.NE;
+import java.util.Random;
+import org.vashonsd.Utils.Minigame;
+
+/**
+ * Created by andy on 5/2/18.
+ */
+
+ public class NoahGame extends Minigame {
+ int win = 0;
+ int loss = 0;
+ int tie = 0;
+ int numRock = 0;
+ int numPaper = 0;
+ int numScissors = 0;
+ int numRounds = 0;
+ Choice userChoice;
+ Choice computerChoice;
+
+
+
+
+ public NoahGame() {
+ super("Noah", "It's Rock Paper Scissors...", "quit");
+ }
+
+ @Override
+ public String start() {
+ //setUp();
+ return ("Welcome to the game! It's Rock, Paper, Scissors\nIf you don't know how to play, type \"rules\" in the input field." +
+ "\nType Rock, Paper or Scissors to begin!");
+ }
+
+ /**
+ * Call this method to get the game into its initial state.
+ */
+
+ @Override
+ public String handle(String str) {
+ String score = "You have " + win + " wins \nYou have " + loss + " losses \nYou have " + tie + " ties";
+
+ if (str.equalsIgnoreCase("rules")) {
+ return "Paper covers Rock\nRock smashes Scissors\nAnd Scissors cuts Paper\nType 'score' to get the score of the game";
+ } else if (str.equalsIgnoreCase("score")) {
+ return score + "\n---------------\nType to play again:\n";
+ }
+ Random rand = new Random();
+ int pick = rand.nextInt(3);
+ if (pick == 0) {
+ computerChoice = new Rock();
+ } else if (pick == 1) {
+ computerChoice = new Paper();
+ } else if (pick ==2){
+ computerChoice = new Scissors();
+
+ }else if(numRounds>=5 && numRock/(numPaper+numScissors)>=.45){
+ if (Math.random() > 0.50) {
+ computerChoice = new Paper();
+ }
+ }
+ else if(numRounds>=5 && numPaper/(numRock+numScissors)>=.45){
+ if (Math.random() > 0.50) {
+ computerChoice = new Scissors();
+ }
+ }
+ else if(numRounds>=5 && numScissors/(numPaper+numRock)>=.45){
+ if (Math.random() > 0.50) {
+ computerChoice = new Rock();
+ }
+ }
+
+ //The game has just started, so we need to collect the user's choice.
+ if (str.equalsIgnoreCase("rock")) {
+ numRock++;
+ spin();
+ userChoice = new Rock();
+ } else if (str.equalsIgnoreCase("paper")) {
+ numPaper++;
+ spin();
+ userChoice = new Paper();
+ } else if (str.equalsIgnoreCase("scissors")) {
+ numScissors++;
+ spin();
+ userChoice = new Scissors();
+ } else {
+ return "I don't recognize "+ str +"\n---------------\nType to play again:\n";
+
+ }
+
+
+
+ //If the use types something illegal, reject it.
+
+ //Otherwise, set userChoice to the correct Choice.
+
+ //Then use a randomizer to set the computerChoice.
+
+
+ String winner = userChoice.determineWinner(computerChoice);
+ System.out.println("\nYou picked: " + userChoice.getName() + ", The computer picked: " + computerChoice.getName() +
+ "\n\n" + winner);
+ if (winner.contains("Win")) {
+ win++;
+ }
+ if (winner.contains("Lose")) {
+ loss++;
+ }
+ if (winner.contains("Tie")) {
+ tie++;
+ }
+ return "---------------\nType to play again:\n";
+
+
+ }
+
+
+
+ @Override
+ public String quit () {
+ return "You probably lost to the computer lol ";
+ }
+
+
+ private void spin() {
+ System.out.println("Rock...");
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ System.out.println("Paper...");
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ System.out.println("Scissors...");
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ System.out.println("Shoot!");
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+
+
+
+
diff --git a/src/main/java/org/vashonsd/Games/NE/Paper.java b/src/main/java/org/vashonsd/Games/NE/Paper.java
new file mode 100755
index 0000000..8bfc919
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/NE/Paper.java
@@ -0,0 +1,11 @@
+package org.vashonsd.Games.NE;
+
+public class Paper extends Choice {
+
+ public Paper() {
+ super("paper");
+ setMyType(ChoiceType.PAPER);
+ setLoseCase(ChoiceType.SCISSORS);
+ setWinCase(ChoiceType.ROCK);
+ }
+}
diff --git a/src/main/java/org/vashonsd/Games/NE/Rock.java b/src/main/java/org/vashonsd/Games/NE/Rock.java
new file mode 100755
index 0000000..9847159
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/NE/Rock.java
@@ -0,0 +1,11 @@
+package org.vashonsd.Games.NE;
+
+public class Rock extends Choice{
+
+ public Rock() {
+ super("rock");
+ setMyType(ChoiceType.ROCK);
+ setWinCase(ChoiceType.SCISSORS);
+ setLoseCase(ChoiceType.PAPER);
+ }
+}
diff --git a/src/main/java/org/vashonsd/Games/NE/Scissors.java b/src/main/java/org/vashonsd/Games/NE/Scissors.java
new file mode 100755
index 0000000..a24b50f
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/NE/Scissors.java
@@ -0,0 +1,11 @@
+package org.vashonsd.Games.NE;
+
+public class Scissors extends Choice{
+
+ public Scissors() {
+ super("scissors");
+ setMyType(ChoiceType.SCISSORS);
+ setWinCase(ChoiceType.PAPER);
+ setLoseCase(ChoiceType.ROCK);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/vashonsd/Games/RI/RobertGame.java b/src/main/java/org/vashonsd/Games/RI/RobertGame.java
new file mode 100644
index 0000000..15ee028
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/RI/RobertGame.java
@@ -0,0 +1,48 @@
+package org.vashonsd.Games.RI;
+
+import org.vashonsd.Utils.Minigame;
+
+import java.util.Random;
+
+public class RobertGame extends Minigame {
+ private int length = 6;
+ private int width = 5;
+ private String[][] grid = new String[length][width];
+ private String gridText;
+ public RobertGame(){super("Minesweeper", "A game where you have to avoid all of the mines", "quit"); }
+
+ public String start(){
+ for(int i = 0; i < length - 1; i++) {
+ for (int j = 0; j < width - 1; j++) {
+ Random random = new Random();
+ int num = random.nextInt(3) + 1;
+ if (num == 1) {
+ grid[j][i] = "1";
+ } else {
+ grid[j][i] = "2";
+ }
+ }
+ }
+ for(int x = 0; x < length - 1; x++) {
+ for(int y = 0; y < width; y++) {
+ gridText = gridText + grid[x][y] + " ";
+ }
+ gridText = gridText + "\n";
+ }
+ return gridText;
+ }
+
+ @Override
+ public String handle(String str) {
+
+ return str;
+ }
+
+ @Override
+ public String quit() {
+ return "Thanks for playing!";
+ }
+
+
+
+}
diff --git a/src/main/java/org/vashonsd/Games/RPS_games/Choice.java b/src/main/java/org/vashonsd/Games/RPS_games/Choice.java
new file mode 100644
index 0000000..50293eb
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/RPS_games/Choice.java
@@ -0,0 +1,47 @@
+package org.vashonsd.Games.RPS_games;
+
+/**
+ * Created by andy on 5/10/18.
+ */
+public class Choice {
+
+
+ private final int LOSE = -1;
+ private final int TIE = 0;
+ private final int WIN = 1;
+
+ private String name;
+ private ChoiceType type;
+
+ private ChoiceType winCase;
+ private ChoiceType loseCase;
+
+ public Choice(String name, ChoiceType type, ChoiceType winCase, ChoiceType loseCase) {
+ this.name = name;
+ this.type = type;
+ this.winCase = winCase;
+ this.loseCase = loseCase;
+ }
+
+ public ChoiceType getType() {
+ return type;
+ }
+
+ public void setType(ChoiceType type) {
+ this.type = type;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int evaluate(Choice c) {
+ if(c.getType() == winCase) {
+ return WIN;
+ } else if (c.getType() == loseCase) {
+ return LOSE;
+ } else {
+ return TIE;
+ }
+ }
+}
diff --git a/src/main/java/org/vashonsd/Games/RPS_games/ChoiceType.java b/src/main/java/org/vashonsd/Games/RPS_games/ChoiceType.java
new file mode 100644
index 0000000..67fd35d
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/RPS_games/ChoiceType.java
@@ -0,0 +1,8 @@
+package org.vashonsd.Games.RPS_games;
+
+/**
+ * Created by andy on 5/10/18.
+ */
+public enum ChoiceType {
+ ROCK, PAPER, SCISSORS
+}
diff --git a/src/main/java/org/vashonsd/Games/RPS_games/Paper.java b/src/main/java/org/vashonsd/Games/RPS_games/Paper.java
new file mode 100644
index 0000000..2e23762
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/RPS_games/Paper.java
@@ -0,0 +1,11 @@
+package org.vashonsd.Games.RPS_games;
+
+/**
+ * Created by andy on 5/10/18.
+ */
+public class Paper extends Choice {
+
+ public Paper() {
+ super("Paper", ChoiceType.PAPER, ChoiceType.ROCK, ChoiceType.SCISSORS);
+ }
+}
diff --git a/src/main/java/org/vashonsd/Games/RPS_games/Rock.java b/src/main/java/org/vashonsd/Games/RPS_games/Rock.java
new file mode 100644
index 0000000..65750e7
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/RPS_games/Rock.java
@@ -0,0 +1,11 @@
+package org.vashonsd.Games.RPS_games;
+
+/**
+ * Created by andy on 5/10/18.
+ */
+public class Rock extends Choice {
+
+ public Rock() {
+ super("Rock", ChoiceType.ROCK, ChoiceType.SCISSORS, ChoiceType.PAPER);
+ }
+}
diff --git a/src/main/java/org/vashonsd/Games/RPS_games/RockPaperPlus.java b/src/main/java/org/vashonsd/Games/RPS_games/RockPaperPlus.java
new file mode 100644
index 0000000..d924b69
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/RPS_games/RockPaperPlus.java
@@ -0,0 +1,63 @@
+package org.vashonsd.Games.RPS_games;
+
+import org.vashonsd.Utils.Minigame;
+
+import java.util.Random;
+
+/**
+ * Created by andy on 5/10/18.
+ */
+public class RockPaperPlus extends Minigame {
+ Choice userChoice;
+ Choice computerChoice;
+
+ public RockPaperPlus() {
+ super("Rock", "A basic rock, paper, scissors game.", "quit");
+ setComputerChoice();
+ }
+
+ @Override
+ public String start() {
+ return "Welcome to Rock, Paper, Scissors! Type your choice.";
+ }
+
+ @Override
+ public String handle(String str) {
+ if(str.equalsIgnoreCase("rock")) {
+ userChoice = new Rock();
+ } else if (str.equalsIgnoreCase("paper")) {
+ userChoice = new Paper();
+ } else if (str.equalsIgnoreCase("scissors")) {
+ userChoice = new Scissors();
+ } else {
+ return "You need to choose either rock, paper, or scissors.";
+ }
+ int result = userChoice.evaluate(computerChoice);
+ String rep = "The computer chose " + computerChoice.getName() + ". ";
+ switch (result) {
+ case -1: rep += "You lose!";
+ break;
+ case 1: rep += "You win!";
+ break;
+ default: rep += "Tie!";
+ }
+ return rep;
+ }
+
+ private void setComputerChoice() {
+ Random r = new Random();
+ int choice = r.nextInt(2);
+ switch (choice) {
+ case 0: computerChoice = new Rock();
+ break;
+ case 1: computerChoice = new Paper();
+ break;
+ default: computerChoice = new Scissors();
+ }
+ }
+
+ @Override
+ public String quit() {
+ return null;
+ }
+}
diff --git a/src/main/java/org/vashonsd/Games/RPS_games/Scissors.java b/src/main/java/org/vashonsd/Games/RPS_games/Scissors.java
new file mode 100644
index 0000000..d4de0f9
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/RPS_games/Scissors.java
@@ -0,0 +1,11 @@
+package org.vashonsd.Games.RPS_games;
+
+/**
+ * Created by andy on 5/10/18.
+ */
+public class Scissors extends Choice {
+
+ public Scissors() {
+ super("Scissors", ChoiceType.SCISSORS, ChoiceType.PAPER, ChoiceType.ROCK);
+ }
+}
diff --git a/src/main/java/org/vashonsd/Games/SP/NewSamGame.java b/src/main/java/org/vashonsd/Games/SP/NewSamGame.java
new file mode 100644
index 0000000..5b19dce
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/SP/NewSamGame.java
@@ -0,0 +1,113 @@
+package org.vashonsd.Games.SP;
+
+import org.vashonsd.Utils.Cards.Deck;
+import org.vashonsd.Utils.Cards.Hand;
+import org.vashonsd.Utils.Minigame;
+import org.vashonsd.Utils.Utils;
+
+import java.util.Scanner;
+
+/**
+ * Created by andy on 5/2/18.
+ */
+public class NewSamGame extends Minigame {
+
+ private Player human;
+ private Player computer;
+
+ private Deck deck;
+
+ private int currentBet;
+ private boolean betSet;
+
+ public NewSamGame() {
+ super("Blackjack", "A betting game, kind of, it sucks", "quit");
+ human = new Player();
+ computer = new Player();
+ deck = new Deck();
+ deck.shuffle();
+ for (int i = 0; i < human.getHandStartingSize(); i++) {
+ human.takeCard(deck.deal());
+ }
+ for (int i = 0; i < computer.getHandStartingSize(); i++) {
+ computer.takeCard(deck.deal());
+ }
+ Scanner sc = new Scanner(System.in);
+ }
+
+ @Override
+ public String start() {
+ betSet = false;
+ return " Welcome to the game. You have " + human.getCash() +"$" + "\n Your hand is: " + human.getHand() + " Your hand has a value of " + human.getHand().getHandValue() + "\n How much would you like to bet?";
+ }
+
+ @Override
+ public String quit() {
+ deck = new Deck();
+ deck.shuffle();
+ human.getHand().resetHand();
+ computer.getHand().resetHand();
+ for (int i = 0; i < human.getHandStartingSize(); i++) {
+ human.takeCard(deck.deal());
+ }
+ for (int i = 0; i < computer.getHandStartingSize(); i++) {
+ computer.takeCard(deck.deal());
+ }
+ return "See ya later";
+ }
+
+ @Override
+ public String handle(String str) {
+ if(!betSet) {
+ if(Utils.IsInteger(str)) {
+ currentBet = Integer.parseInt(str);
+ betSet = true;
+ Hand userHandStart = human.getHand();
+ return "You bet " + currentBet + "\nYour starting hand is " + human.getHand().toString() + " Your hand had a value of " + userHandStart.getHandValue();
+ } else {
+ return "your bet must be a number.";
+ }
+ } else {
+ if(str.equalsIgnoreCase("yes")) {
+ deck.shuffle();
+ } else if(str.equalsIgnoreCase("no")) {
+ return null;
+ }
+ if(str.equalsIgnoreCase("hit")) {
+ Hand userHand = human.getHand();
+ userHand.takeCard(deck.deal());
+ if(userHand.getHandValue() > 21) {
+ int i = currentBet;
+ int cash = human.getCash() - currentBet;
+ return "You busted my man and lost, you now have " + cash + "$";
+ }
+ return "Your hand is " + userHand.toString() + ", total of " + userHand.getHandValue();
+ } else if(str.equalsIgnoreCase("stand")){
+
+ if(human.getHand().getHandValue() > 21) {
+ int i = currentBet;
+ int cash = human.getCash() - currentBet;
+ return "You busted my man and lost, you now have " + cash + "$";
+ }
+ while(computer.getHand().getHandValue() <= 17) {
+ computer.getHand().takeCard(deck.deal());
+ }
+ if(computer.getHand().getHandValue() > 21) {
+ int cash = currentBet + human.getCash();
+ return "You win, the computer busted, you now have " + cash + "$";
+ }
+ if(human.getHand().getHandValue() > computer.getHand().getHandValue()) {
+ int cash = currentBet + human.getCash();
+ return "You win, your final hand was " + human.getHand() + "\nThe computer had " + computer.getHand() + "\nYour total hand value: " + human.getHand().getHandValue() + "\ncomputer total hand value: " + computer.getHand().getHandValue() + "\nYou now have " + cash + "$";
+ } else if(human.getHand().getHandValue() < computer.getHand().getHandValue()) {
+ int cash = human.getCash() - currentBet;
+ return "You lose, your final hand was " + human.getHand() + "\nThe computer had " + computer.getHand() + "\nYour total hand value: " + human.getHand().getHandValue() + "\ncomputer total hand value: " + computer.getHand().getHandValue() + "\nYou now have " + cash + "$";
+ } else {
+ return "PUSH";
+ }
+ } else {
+ return "Try typing hit or stand";
+ }
+ }
+ }
+}
diff --git a/src/main/java/org/vashonsd/Games/SP/Player.java b/src/main/java/org/vashonsd/Games/SP/Player.java
new file mode 100644
index 0000000..9cddeff
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/SP/Player.java
@@ -0,0 +1,57 @@
+package org.vashonsd.Games.SP;
+
+import org.vashonsd.Utils.Cards.Card;
+import org.vashonsd.Utils.Cards.Hand;
+import java.util.ArrayList;
+
+public class Player {
+
+ private Hand hand;
+ private int cash =100;
+
+ ArrayList hands;
+ private int handvalue = 0;
+ private Card[] aHand;
+
+ public int getCash() {
+ return cash;
+ }
+
+ public void resetCash() { cash = 100; }
+
+ public void setCash(int cash) {
+ this.cash = cash;
+ }
+
+ public Hand getHand() {
+ return hand;
+ }
+
+ public void setHand(Hand hand) {
+ this.hand = hand;
+ }
+
+ public Player() {
+ hand = new Hand(5, 2);
+ }
+
+ public int getHandCapacity() {
+ return this.hand.getCapacity();
+ }
+
+ public void takeCard(Card deal) {
+ hand.takeCard(deal);
+ }
+
+ public int getHandStartingSize() {
+ return hand.getStartingSize();
+ }
+
+ /* public static int calcHandValue(List hands) {
+ int handvalue = 0;
+ for (int i = 0; i < hands.size(); i++) {
+ handvalue += hands.get(i).getValue();
+ }
+ return handvalue;
+ }*/
+}
diff --git a/src/main/java/org/vashonsd/Games/SR/Board.java b/src/main/java/org/vashonsd/Games/SR/Board.java
new file mode 100644
index 0000000..d08abfa
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/SR/Board.java
@@ -0,0 +1,136 @@
+package org.vashonsd.Games.SR;
+
+public class Board {
+ public Space[][] board;
+ public Path[] paths;
+ int count;
+ //A board has 8 "paths" which are the combinations of square that represent a win.
+ //Other than that the board is a 2d array of space objects.
+ public Board() {
+ paths = new Path[8];
+ board=new Space[3][3];
+ count=0;
+ for(int i=0;i<3;i++){
+ for(int c=0;c<3;c++){
+ count++;
+ board[i][c]= new Space(State.EMPTY,count);
+ }
+ }
+ setGroupings();
+ }
+
+
+
+ public void setSpace(int x, int y, State state){
+ board[x][y].setValue(state);
+}
+ //This is part of a future hope for this code where I clean up user input from the x and y cordinates
+ public void setSpace(int num, State state){
+ for(int i=0;i<3;i++){
+ for(int c=0;c<3;c++){
+ if(board[i][c].getNumber()==num){
+ board[i][c].setValue(state);
+ }
+ }
+ }
+ }
+ public Space getSpace(int x, int y){
+ return board[x][y];
+ }
+
+ //checks to see if the user has won by looping through all possible combinations of win
+ public boolean xWins() {
+ setGroupings();
+ boolean isFalse=true;
+ for(int i=0;i<8;i++) {
+ if (paths[i].xWin()) {
+ isFalse=false;
+ }
+ }
+ if(isFalse){
+ return false;
+ }
+ else{
+ return true;
+ }
+ }
+ //checks to see if the user has tied the computer by returning true if neither player has won and the board is full
+ public boolean tie(){
+ setGroupings();
+ int y=0;
+ for(int i=0;i<3;i++){
+ for(int x=0;x<3;x++){
+ if(board[x][i].getValue().equals(State.EMPTY)){
+ y++;
+ }
+ }
+ }
+ if(y>0||yWins()||xWins()){
+ return false;
+ }
+ else{
+ return true;
+ }
+ }
+ //Checks to see if the computer has won by checking all possible combinations of win
+ public boolean yWins() {
+ setGroupings();
+ boolean isFalse=true;
+ for(int i=0;i<8;i++) {
+ if (paths[i].oWin()) {
+ isFalse=false;
+ }
+ }
+ if(isFalse){
+ return false;
+ }
+ else{
+ return true;
+ }
+ }
+
+ //turns one row from the board into a printable row
+ public String toeFormat(Space[] spc){
+ String a=spc[0].toString();
+ String b=spc[1].toString();
+ String c=spc[2].toString();
+ return a +"|"+b+"|"+c;
+ }
+
+ //uses the toeFormat method to print a graphic representation of the game board
+ public String toString(){
+ Space[] one= new Space[3];
+ Space[] two=new Space[3];
+ Space[] three=new Space[3];
+ for(int i=0;i<3;i++){
+ one[i]=board[0][i];
+ two[i]=board[1][i];
+ three[i]=board[2][i];
+ }
+
+ return String.format(toeFormat(one)+"%n"+toeFormat(two)+"%n"+toeFormat(three));
+ }
+
+ //sets all of the paths to their coresponding place on the board, used to refresh the paths once players make moves
+ public void setGroupings(){
+ Path hOne= new Path(board[0][0],board[0][1],board[0][2]);
+ paths[0]=hOne;
+ Path hTwo = new Path(board[1][0],board[1][1],board[1][2]);
+ paths[1]=hTwo;
+ Path hThree = new Path(board[2][0],board[2][1],board[2][2]);
+ paths[2]=hThree;
+ Path vOne=new Path(board[0][0],board[1][0],board[2][0]);
+ paths[3]=vOne;
+ Path vTwo= new Path(board[0][1],board[1][1],board[2][1]);
+ paths[4]=vTwo;
+ Path vThree = new Path(board[0][2],board[1][2],board[2][2]);
+ paths[5]=vThree;
+ Path dOne=new Path(board[0][0],board[1][1],board[2][2]);
+ paths[6]=dOne;
+ Path dTwo= new Path(board[2][0],board[1][1],board[0][2]);
+ paths[7] = dTwo;
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/vashonsd/Games/SR/Path.java b/src/main/java/org/vashonsd/Games/SR/Path.java
new file mode 100644
index 0000000..357b946
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/SR/Path.java
@@ -0,0 +1,71 @@
+package org.vashonsd.Games.SR;
+
+public class Path {
+ Space one;
+ Space two;
+ Space three;
+ Space[] row;
+ int numX;
+ int numY;
+ int[] spaceOne;
+ int[] spaceTwo;
+ int[] spaceThree;
+
+ //Every path contains three spaces that when identical represent a win these spaces are set into an array
+ //they also have a number of x and o contained inside for checking for wins
+ public Path(Space one, Space two, Space three) {
+ this.one=one;
+ this.two=two;
+ this.three=three;
+ row = new Space[3];
+ row[0]=one;
+ row[1]=two;
+ row[2]=three;
+ numX=0;
+ numY=0;
+ setNumXY();
+ }
+
+ public Space getSpaceAt(int x){
+ return row[x];
+ }
+
+ //checks to see if they player has won a row
+ public Boolean xWin(){
+ return (one.isX() && two.isX() && three.isX());
+ }
+
+ //Checks to see if the computer has won
+ public boolean oWin(){
+ return (one.isO() && two.isO() && three.isO());
+ }
+
+ public int getNumX(){
+ return numX;
+ }
+
+ public int getNumY(){
+ return numY;
+ }
+
+ //sets the number of xs and os in the path by looping through the path and adding one for each instance of x or o to their respective counters
+ public void setNumXY(){
+ for(int i=0;i<3;i++){
+ if(row[i].getValue()==State.X){
+ numX++;
+ }
+ else if(row[i].getValue()==State.O){
+ numY++;
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "Path{" +
+ "one=" + one +
+ ", two=" + two +
+ ", three=" + three +
+ '}';
+ }
+}
diff --git a/src/main/java/org/vashonsd/Games/SR/SeanGame.java b/src/main/java/org/vashonsd/Games/SR/SeanGame.java
new file mode 100644
index 0000000..6634807
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/SR/SeanGame.java
@@ -0,0 +1,170 @@
+package org.vashonsd.Games.SR;
+
+import org.vashonsd.Utils.Minigame;
+import org.vashonsd.Utils.Utils;
+
+
+/**
+ * Created by andy on 5/2/18.
+ */
+public class SeanGame extends Minigame {
+ Board toeBoard;
+
+ public SeanGame() {
+ super("Sean", "like tic tac toe but worse", "quit");
+ }
+
+ @Override
+ public String start() {
+ setUp();
+ return "each position on the tic tac board has an x and y coordinate from 0 to 2 where the upper left is 0; type them in the format x,y" +
+ "\n0|1|2" +
+ "\n1| | " +
+ "\n2| | ";
+ }
+
+ //Sets array used for storing player and computer game moves to inital values
+ public void setUp() {
+ toeBoard = new Board();
+ }
+
+
+ // //Handle method which interacts with the user in the game.
+ //handle parses the users string into into x and y cordinates and sets the space to them
+ @Override
+ public String handle(String str) {
+ int x;
+ int y;
+ //parse the input.
+ try {
+ if (str.length() == 3) {
+ String b = str.substring(0, 1);
+ String d = str.substring(2, 3);
+ y = Integer.parseInt(b);
+ x = Integer.parseInt(d);
+ if (x < 3 && y < 3 && toeBoard.getSpace(x, y).getValue() == State.EMPTY) {
+ toeBoard.setSpace(x, y, State.X);
+ } else {
+ return "you cannot play there";
+ }
+ } else {
+ return "you cant play there";
+ }
+ } catch (NumberFormatException nfe) {
+ return "your number is to formatted in x,y";
+ }
+ return detWinner();
+ }
+
+ //
+//
+// //method that decides where the computer plays, uses a random number unless the computer can block a move or play to win
+ public void compProcess() {
+ toeBoard.setGroupings();
+ int comp = Utils.newRand(2);
+ int comp2 = Utils.newRand(2);
+ if(!win()) {
+ if(!block()){
+ if(!makeTwo()) {
+ if (toeBoard.getSpace(comp, comp2).getValue() == State.EMPTY) {
+ toeBoard.setSpace(comp, comp2, State.O);
+ } else if (toeBoard.tie() || toeBoard.xWins() || toeBoard.yWins()) {
+ quit();
+ } else {
+ compProcess();
+ }
+ }
+ }
+ }
+
+ }
+ // determines if the computer can make a move to win by looping through paths and playing if the computer has 2 o's in one path
+ public boolean win(){
+ toeBoard.setGroupings();
+ for(int i=0;i<8;i++){
+ if(toeBoard.paths[i].getNumY()==2){
+ for(int x=0;x<3;x++){
+ if(toeBoard.paths[i].getSpaceAt(x).containsValue(State.EMPTY)){
+ int z= toeBoard.paths[i].getSpaceAt(x).getNumber();
+ toeBoard.setSpace(z,State.O);
+ return true;
+ }
+ }
+ }
+ if(i==8){
+ return false;
+ }
+ }
+ return false;
+ }
+
+ //Makes a row of two for the computer
+ public boolean makeTwo(){
+ toeBoard.setGroupings();
+ for(int i=0;i<8;i++){
+ if(toeBoard.paths[i].getNumY()==1){
+ for(int x=0;x<3;x++){
+ if(toeBoard.paths[i].getSpaceAt(x).containsValue(State.EMPTY)){
+ int z= toeBoard.paths[i].getSpaceAt(x).getNumber();
+ toeBoard.setSpace(z,State.O);
+ return true;
+ }
+ }
+ }
+ if(i==8){
+ return false;
+ }
+ }
+ return false;
+ }
+
+ //determines if the computer can block a play to win by the user, by looping through paths to see if the opponent has two in a path
+ public boolean block(){
+ toeBoard.setGroupings();
+ for(int i=0;i<8;i++){
+ if(toeBoard.paths[i].getNumX()==2){
+ for(int x=0;x<3;x++){
+ if(toeBoard.paths[i].getSpaceAt(x).containsValue(State.EMPTY)){
+ int z= toeBoard.paths[i].getSpaceAt(x).getNumber();
+ toeBoard.setSpace(z,State.O);
+ return true;
+ }
+ }
+ }
+ if(i==8){
+ return false;
+ }
+ }
+ return false;
+ }
+
+
+
+ //determines who has won by checking
+ //also runs the compProcess method if the game is still going and prints out the board.
+ public String detWinner() {
+ if(!toeBoard.tie()&&!toeBoard.xWins()&&!toeBoard.yWins()) {
+ compProcess();
+ }
+ if (toeBoard.xWins()) {
+ return "You win!";
+ } else if (toeBoard.yWins()) {
+ return "You lose";
+ }else if(toeBoard.tie()){
+ return "tie";
+ }
+ else {
+ return toeBoard.toString();
+ }
+ }
+
+ @Override
+ public String quit() {
+
+ return "adios";
+
+ }
+
+
+}
+
diff --git a/src/main/java/org/vashonsd/Games/SR/Space.java b/src/main/java/org/vashonsd/Games/SR/Space.java
new file mode 100644
index 0000000..eb8bc7b
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/SR/Space.java
@@ -0,0 +1,62 @@
+package org.vashonsd.Games.SR;
+import java.util.HashMap;
+public class Space {
+
+ private State value;
+ public int number;
+
+ public int getNumber() {
+ return number;
+ }
+
+ public boolean containsValue(State state){
+ if(value==state){
+ return true;
+ }
+ else{
+ return false;
+ }
+ }
+
+ public void setNumber(int number) {
+ this.number = number;
+ }
+
+ public Space(State value, int number){
+ this.value=value;
+ this.number=number;
+ }
+
+ public State getValue() {
+ return value;
+ }
+
+ public boolean isX() {
+ return this.value == State.X;
+ }
+
+ public boolean isO() {
+ return this.value == State.O;
+ }
+
+ //switch to check what the value of a space is and print it
+ public String toString(){
+ String str = "";
+ switch(value) {
+ case O:
+ str = "O";
+ break;
+ case X:
+ str = "X";
+ break;
+ case EMPTY:
+ str = " ";
+ break;
+ }
+ return str;
+ }
+
+ public void setValue(State input){
+ this.value=input;
+ }
+}
diff --git a/src/main/java/org/vashonsd/Games/SR/State.java b/src/main/java/org/vashonsd/Games/SR/State.java
new file mode 100644
index 0000000..c9b9635
--- /dev/null
+++ b/src/main/java/org/vashonsd/Games/SR/State.java
@@ -0,0 +1,5 @@
+package org.vashonsd.Games.SR;
+//Enum state used for the game board values
+public enum State {
+ EMPTY, X, O
+}
diff --git a/src/org/vashonsd/Games/TwentyQuestions.java b/src/main/java/org/vashonsd/Games/TwentyQuestions.java
similarity index 75%
rename from src/org/vashonsd/Games/TwentyQuestions.java
rename to src/main/java/org/vashonsd/Games/TwentyQuestions.java
index a291ba0..83cae7e 100644
--- a/src/org/vashonsd/Games/TwentyQuestions.java
+++ b/src/main/java/org/vashonsd/Games/TwentyQuestions.java
@@ -13,7 +13,7 @@ public class TwentyQuestions extends Minigame {
private int targetNumber;
public TwentyQuestions() {
- super("20Q", "Guess a number between 0 and 1,000", "quit");
+ super("20q", "Guess a number between 0 and 1,000", "quit");
}
@Override
@@ -29,16 +29,23 @@ private void setUp() {
@Override
public String handle(String str) {
+ int rQuestions=20;
if(!Utils.IsInteger(str)) {
return "You must guess a number.";
}
int guess = Integer.parseInt(str);
+ if(rQuestions==0){
+ return "You lose"+quit();
+
+ }
if(!(guess >= 1 && guess <=500)) {
return "Your guess must be between 1 and 500.";
} else if(guess < targetNumber) {
- return "too small";
+ rQuestions--;
+ return "too small: you have "+rQuestions+" guesses remaining.";
} else if(guess > targetNumber) {
- return "too big";
+ rQuestions--;
+ return "too big: you have "+rQuestions+" guesses remaining.";
} else {
setUp();
return "Congratulations! You guessed it!\nGuess another, or type " + quitWord + " to quit.";
diff --git a/src/org/vashonsd/Main.java b/src/main/java/org/vashonsd/Main.java
similarity index 89%
rename from src/org/vashonsd/Main.java
rename to src/main/java/org/vashonsd/Main.java
index 84453f0..73db668 100644
--- a/src/org/vashonsd/Main.java
+++ b/src/main/java/org/vashonsd/Main.java
@@ -3,19 +3,22 @@
import org.vashonsd.Utils.Minigame;
import org.vashonsd.Games.MinigameFactory;
+import java.lang.reflect.InvocationTargetException;
import java.util.Scanner;
public class Main {
+
private static final String quitWord = "quit";
private static Minigame currentGame;
- public static void main(String[] args) {
+ public static void main(String[] args) throws IllegalAccessException, InstantiationException {
Scanner in = new Scanner(System.in);
String userIn = "";
while(userIn != quitWord) {
if (currentGame == null) {
System.out.println(MinigameFactory.listGames());
+
System.out.println("Type the name of the game you would like to play: ");
userIn = in.nextLine();
if(userIn.equalsIgnoreCase(quitWord)) break;
diff --git a/src/main/java/org/vashonsd/Utils/API.java b/src/main/java/org/vashonsd/Utils/API.java
new file mode 100644
index 0000000..252193b
--- /dev/null
+++ b/src/main/java/org/vashonsd/Utils/API.java
@@ -0,0 +1,68 @@
+package org.vashonsd.Utils;
+
+import com.fasterxml.jackson.core.io.JsonStringEncoder;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.DeserializationConfig;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by andy on 5/20/18.
+ */
+public class API {
+
+ private static CloseableHttpClient httpclient;
+
+ private static ObjectMapper mapper;
+
+ /**
+ * This is a simple utility for taking a String in JSON format and returning it as a Map of String : Object.
+ *
+ * @param json The JSON object, represented as a url-escape String, to be parsed.
+ * @return a Map
+ */
+ public static Map parseJSONToMap(String json) throws IOException {
+ mapper = new ObjectMapper();
+ mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
+ mapper.enable(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT);
+ mapper.enable(DeserializationFeature.WRAP_EXCEPTIONS);
+ TypeReference> typeRef
+ = new TypeReference>() {};
+ return mapper.readValue(json, typeRef);
+ }
+
+ public static String callAPI(String uri) throws IOException {
+ httpclient = HttpClients.createDefault();
+ HttpGet httpGet = new HttpGet(uri);
+ CloseableHttpResponse response1 = httpclient.execute(httpGet);
+ HttpEntity entity1 = response1.getEntity();
+ String result;
+ if(!(response1.getStatusLine().getStatusCode() == 200)) {
+ throw new IOException(response1.getStatusLine().getReasonPhrase());
+ } else {
+ result = EntityUtils.toString(entity1);
+ }
+ return result;
+ }
+
+ public static Map mapFromAPICall(String uri) throws IOException {
+ String resp = callAPI(uri);
+ ObjectMapper mapper = new ObjectMapper();
+ StringWriter writer = new StringWriter();
+ mapper.writeValue(writer, resp);
+ String jsonified = writer.toString();
+ return parseJSONToMap(jsonified);
+ }
+}
diff --git a/src/main/java/org/vashonsd/Utils/Cards/Card.java b/src/main/java/org/vashonsd/Utils/Cards/Card.java
new file mode 100644
index 0000000..090f221
--- /dev/null
+++ b/src/main/java/org/vashonsd/Utils/Cards/Card.java
@@ -0,0 +1,166 @@
+package org.vashonsd.Utils.Cards;
+
+public class Card
+{
+ // These constants represent the possible suits and
+ // can be used to index into the suits array to get
+ // their string representation.
+ private static final int HEARTS = 0;
+ private static final int DIAMONDS = 1;
+ private static final int SPADES = 2;
+ private static final int CLUBS = 3;
+
+ // These constants represent the ranks of the non-number
+ // cards, or cards above 10. To maintain the ordering after
+ // 2-10, the integer values are 11, 12, 13, and 14 and
+ // also allow us to index into the ranks array to get their
+ // String representation.
+ private static final int JACK = 11;
+ private static final int QUEEN = 12;
+ private static final int KING = 13;
+ private static final int ACE = 14;
+
+ // Instance variables
+
+ // This represents the rank of the card, the value from 2 to Ace.
+ private int rank;
+
+ // This represents the suit of the card, one of hearts, diamonds, spades or clubs.
+ private int suit;
+
+ // This represents the value of the card, which is 10 for face cards or 11 for an ace.
+ private int value;
+
+ // This String array allows us to easily get the String value of a Card from its rank.
+ // There are two Xs in the front to provide padding so numbers have their String representation
+ // at the corresponding index. For example, the String for 2 is at index 2.
+ private String[] ranks = {"X", "X", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
+
+ // The String array allow us to easily get the String value of the Card for its suit. This
+ // is the same order as the suits above so we can index into this array.
+ private String[] suits = {"H", "D", "S", "C"};
+
+ /**
+ * This is the constructor to create a new Card. To create a new card
+ * we pass in its rank and its suit.
+ *
+ * @param r The rank of the card, as an int.
+ * @param s The suit of the card, as an int.
+ */
+ public Card(int r, int s)
+ {
+ rank = r;
+ suit = s;
+ }
+
+ // Getter Methods
+
+ /**
+ * This returns the rank of the card as an integer.
+ *
+ * @return rank of card as an int.
+ */
+ public int getRank()
+ {
+ return rank;
+ }
+
+ /**
+ * This returns the suit of the card as an integer.
+ *
+ * @return suit of card as an int.
+ */
+ public int getSuit()
+ {
+ return suit;
+ }
+
+ /**
+ * This returns the value of the card as an integer.
+ *
+ * For facecards the value is 10, which is different
+ * than their rank underlying value. For aces the default
+ * value is 11.
+ *
+ * @return The value of the card as an int.
+ */
+ public int getValue()
+ {
+ int value = rank;
+ if(rank > 10)
+ {
+ value = 10;
+ }
+
+ if(rank == ACE)
+ {
+ value = 11;
+ }
+
+ return value;
+ }
+
+ /**
+ * This utility method converts from a rank integer to a String.
+ *
+ * @param r The rank.
+ * @return String version of rank.
+ */
+ public String rankToString(int r)
+ {
+ return ranks[r];
+ }
+
+ /**
+ * This utility method converts from a suit integer to a String.
+ *
+ * @param s The suit.
+ * @return String version of suit.
+ */
+ public String suitToString(int s)
+ {
+ return suits[s];
+ }
+
+ /**
+ * Return the String version of the suit.
+ *
+ * @return String version of suit.
+ */
+ public String getSuitAsString()
+ {
+ return suitToString(suit);
+ }
+
+ /**
+ * Return the String version of the rank.
+ *
+ * @return String version of the rank.
+ */
+ public String getRankAsString()
+ {
+ return rankToString(rank);
+ }
+
+ /**
+ * This returns the String representation of a card which
+ * will be two characters. For example, the two of hearts would
+ * return 2H. Face cards have a short string so the ace of
+ * spades would return AS.
+ *
+ * @return String representation of Card.
+ */
+ public String toString()
+ {
+ // Get a string for rank
+ String rankString = ranks[rank];
+
+ // Get a string for the suit
+ String suitString = suits[suit];
+
+ // combine those
+ return rankString + suitString;
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/vashonsd/Utils/Cards/Deck.java b/src/main/java/org/vashonsd/Utils/Cards/Deck.java
new file mode 100644
index 0000000..7fd7cfe
--- /dev/null
+++ b/src/main/java/org/vashonsd/Utils/Cards/Deck.java
@@ -0,0 +1,90 @@
+package org.vashonsd.Utils.Cards;
+
+import java.util.*;
+
+public class Deck
+{
+ private static final int HEARTS = 0;
+ private static final int DIAMONDS = 1;
+ private static final int SPADES = 2;
+ private static final int CLUBS = 3;
+
+ private static final int JACK = 11;
+ private static final int QUEEN = 12;
+ private static final int KING = 13;
+ private static final int ACE = 14;
+
+ // Instance variables
+
+ // This stores the deck which is a list of the Card objects.
+ private ArrayList deck;
+
+ /**
+ * This creates a Deck. A Deck starts as a list of 52 cards.
+ * We loop through each suit and rank and construct a card
+ * and add it to the deck.
+ */
+ public Deck()
+ {
+ deck = new ArrayList();
+
+ for(int rank = 2; rank <= ACE; rank++)
+ {
+ for(int suit = HEARTS; suit <= CLUBS; suit++)
+ {
+ Card card = new Card(rank, suit);
+ deck.add(card);
+ }
+ }
+ }
+
+ // Getter method
+
+ /**
+ * This getter method returns the ArrayList of cards.
+ * @return ArrayList of the Cards.
+ */
+ public ArrayList getCards()
+ {
+ return deck;
+ }
+
+ /**
+ * This deals the first Card from the deck by removing it.
+ * @return The first Card in the deck.
+ */
+ public Card deal()
+ {
+ return deck.remove(0);
+ }
+
+ /**
+ * This prints out the current state of the deck.
+ */
+ public void print()
+ {
+ for(Card card: deck)
+ {
+ System.out.println(card);
+ }
+ }
+
+ /**
+ * This shuffles the deck by making 52 swaps of
+ * card positions.
+ */
+ public void shuffle()
+ {
+ for(int i = 0; i < deck.size(); i++)
+ {
+ Random rand = new Random();
+ int randomIndex = rand.nextInt(52);
+ Card x = deck.get(i);
+ Card y = deck.get(randomIndex);
+
+ deck.set(i, y);
+ deck.set(randomIndex, x);
+ }
+ }
+
+}
diff --git a/src/main/java/org/vashonsd/Utils/Cards/Hand.java b/src/main/java/org/vashonsd/Utils/Cards/Hand.java
new file mode 100644
index 0000000..234f659
--- /dev/null
+++ b/src/main/java/org/vashonsd/Utils/Cards/Hand.java
@@ -0,0 +1,56 @@
+package org.vashonsd.Utils.Cards;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Hand {
+
+ int capacity;
+ int startingSize;
+
+ List cards = new ArrayList();
+
+ public Hand(int capacity, int startingSize) {
+ this.capacity = capacity;
+ this.startingSize = startingSize;
+ }
+
+ @Override
+ public String toString() {
+ return "" + cards;
+ }
+
+ public void takeCard(Card c) {
+ cards.add(c);
+ }
+
+ public void resetHand() {
+ cards.removeAll(cards);
+ }
+
+ public int getCapacity() {
+ return capacity;
+ }
+
+ public void setCapacity(int capacity) {
+ this.capacity = capacity;
+ }
+
+ public int getStartingSize() {
+ return startingSize;
+ }
+
+ public int getHandValue() {
+
+ int total = 0;
+ for(Card card : cards) {
+ total += card.getValue();
+ }
+ return total;
+ }
+
+ public void setStartingSize(int startingSize) {
+ this.startingSize = startingSize;
+ }
+
+}
diff --git a/src/main/java/org/vashonsd/Utils/LetterStore.java b/src/main/java/org/vashonsd/Utils/LetterStore.java
new file mode 100644
index 0000000..8dd2cdb
--- /dev/null
+++ b/src/main/java/org/vashonsd/Utils/LetterStore.java
@@ -0,0 +1,56 @@
+package org.vashonsd.Utils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This class can be used to record what letters have been guessed, or eliminated, or anything else.
+ */
+public class LetterStore {
+
+ Map store;
+
+ public LetterStore() {
+ store = new HashMap();
+ for(int i = 97; i < 123; i++) {
+ store.put((char)i, false);
+ }
+ }
+
+ public void setTrue(char c) {
+ store.put(c, true);
+ }
+
+ public void setFalse(char c) {
+ store.put(c, false);
+ }
+
+ public boolean getStatus(char c) {
+ return store.get(c);
+ }
+ /**
+ * Returns a List of all the characters that are marked true.
+ * @return A List of Characters.
+ */
+ public List getTrueValues() {
+ List result = new ArrayList();
+ for(Map.Entry entry : store.entrySet()) {
+ if(entry.getValue()) {
+ result.add(entry.getKey());
+ }
+ }
+ return result;
+ }
+
+ public int getSize(){
+ return store.size();
+ }
+ @Override
+ public String toString() {
+ return "LetterStore{" +
+ "store=" + store +
+ '}';
+ }
+}
diff --git a/src/main/java/org/vashonsd/Utils/Minigame.java b/src/main/java/org/vashonsd/Utils/Minigame.java
new file mode 100644
index 0000000..7a34d6f
--- /dev/null
+++ b/src/main/java/org/vashonsd/Utils/Minigame.java
@@ -0,0 +1,65 @@
+package org.vashonsd.Utils;
+
+/**
+ * A Minigame can be run as a text-based game that interacts with the user.
+ *
+ * The mechanics of interacting with the user are left out of this code.
+ * It uses public methods to start, to finish, and, in between, respond
+ * to Strings with Strings.
+ */
+public abstract class Minigame {
+ protected String name;
+ protected String description;
+ protected String quitWord;
+
+ public Minigame(String name, String description, String quitWord) {
+ this.name = name;
+ this.description = description;
+ this.quitWord = quitWord;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public String getDescription() {
+ return this.description;
+ }
+
+ public String getQuitWord() {
+ return this.quitWord;
+ }
+
+ /**
+ * This method will be called when the game is started.
+ *
+ * This method can be used just to return a welcome message,
+ * or it could also be used to set up the starting state of a game.
+ * If the game will ever restarting, consider creating a setUp()
+ * method that can be reused.
+ *
+ * @return A String representing a greeting.
+ */
+ public abstract String start();
+
+ /**
+ * This method will be called while the game is in play.
+ *
+ * handle() is the sole public method that should be called during
+ * game interactions.
+ *
+ * @param str The String representing input from the user.
+ * @return The response to the user.
+ */
+ public abstract String handle(String str);
+
+ // //Handle method which interacts with the user in the game.
+
+
+ /**
+ * This method will be called with the user signals a quit.
+ *
+ * @return A String representing an exit message
+ */
+ public abstract String quit();
+}
diff --git a/src/org/vashonsd/Utils/Placeholder.java b/src/main/java/org/vashonsd/Utils/Placeholder.java
similarity index 93%
rename from src/org/vashonsd/Utils/Placeholder.java
rename to src/main/java/org/vashonsd/Utils/Placeholder.java
index e90c508..7a90293 100644
--- a/src/org/vashonsd/Utils/Placeholder.java
+++ b/src/main/java/org/vashonsd/Utils/Placeholder.java
@@ -3,7 +3,7 @@
/**
* Created by andy on 5/2/18.
*/
-public class Placeholder extends Minigame {
+public abstract class Placeholder extends Minigame {
public Placeholder(String name) {
diff --git a/src/main/java/org/vashonsd/Utils/Randomizer.java b/src/main/java/org/vashonsd/Utils/Randomizer.java
new file mode 100644
index 0000000..fa906d3
--- /dev/null
+++ b/src/main/java/org/vashonsd/Utils/Randomizer.java
@@ -0,0 +1,105 @@
+package org.vashonsd.Utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class Randomizer{
+
+ public static Random theInstance = null;
+ private static List words;
+
+ public Randomizer(){
+
+ }
+
+ public static Random getInstance(){
+ if(theInstance == null){
+ theInstance = new Random();
+ }
+ return theInstance;
+ }
+
+ /**
+ * Return a random boolean value.
+ * @return True or false value simulating a coin flip.
+ */
+ public static boolean nextBoolean(){
+ return Randomizer.getInstance().nextBoolean();
+ }
+
+ /**
+ * This method simulates a weighted coin flip which will return
+ * true with the probability passed as a parameter.
+ *
+ * @param probability The probability that the method returns true, a value between 0 to 1 inclusive.
+ * @return True or false value simulating a weighted coin flip.
+ */
+ public static boolean nextBoolean(double probability){
+ return Randomizer.nextDouble() < probability;
+ }
+
+ /**
+ * This method returns a random integer.
+ * @return A random integer.
+ */
+ public static int nextInt(){
+ return Randomizer.getInstance().nextInt();
+ }
+
+ /**
+ * This method returns a random integer between 0 and n, exclusive.
+ * @param n The maximum value for the range.
+ * @return A random integer between 0 and n, exclusive.
+ */
+ public static int nextInt(int n){
+ return Randomizer.getInstance().nextInt(n);
+ }
+
+ /**
+ * Return a number between min and max, inclusive.
+ * @param min The minimum integer value of the range, inclusive.
+ * @param max The maximum integer value in the range, inclusive.
+ * @return A random integer between min and max.
+ */
+ public static int nextInt(int min, int max){
+ return min + Randomizer.nextInt(max - min + 1);
+ }
+
+ /**
+ * Return a random double between 0 and 1.
+ * @return A random double between 0 and 1.
+ */
+ public static double nextDouble(){
+ return Randomizer.getInstance().nextDouble();
+ }
+
+ /**
+ * Return a random double between min and max.
+ * @param min The minimum double value in the range.
+ * @param max The maximum double value in the rang.
+ * @return A random double between min and max.
+ */
+ public static double nextDouble(double min, double max){
+ return min + (max - min) * Randomizer.nextDouble();
+ }
+
+ public static String randomWord() throws IOException {
+ words = Utils.readFromFile("google-10000-english-usa-no-swears-medium.txt");
+ return words.get(
+ getInstance().nextInt(words.size())
+ );
+ }
+
+ public static String randomWord(int n) throws IOException {
+ words = Utils.readFromFile("google-10000-english-usa-no-swears-medium.txt");
+ List wordList = words.stream()
+ .filter(x -> x.length() >= n)
+ .collect(Collectors.toList());
+ return wordList.get(getInstance().nextInt(wordList.size()));
+ }
+}
diff --git a/src/main/java/org/vashonsd/Utils/Utils.java b/src/main/java/org/vashonsd/Utils/Utils.java
new file mode 100644
index 0000000..777b3e5
--- /dev/null
+++ b/src/main/java/org/vashonsd/Utils/Utils.java
@@ -0,0 +1,144 @@
+package org.vashonsd.Utils;
+
+import org.apache.commons.io.IOUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Array;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.*;
+
+public class Utils {
+
+ static final String pathPrefix = "src/main/resources/";
+
+ /**
+ * Returns true if the given String is an integer, false otherwise.
+ *
+ * Note that this method still returns true if the String is negative or zero.
+ */
+ public static boolean IsInteger(String s) {
+ if(s.isEmpty()) return false;
+ for(int i = 0; i < s.length(); i++) {
+ if(i == 0 && s.charAt(i) == '-') {
+ if(s.length() == 1) return false;
+ else continue;
+ }
+ if( !Character.isDigit(s.charAt(i)) ) return false;
+ }
+ return true;
+ }
+
+ /**
+ * Returns a (pseudo)random die roll from 1 to the maximum number provided.
+ * @param max
+ * @return
+ */
+ public static int rollDie(int max) {
+ Random rand = new Random();
+ return rand.nextInt(max)+1;
+ }
+
+ /**
+ * Returns true if we can find the String sub inside the String str.
+ *
+ * Example: wordIsInside("ladder", "deal") -> true
+ * wordIsInside("hallway", "witch") -> false
+ */
+ public static boolean wordIsInside(String str, String sub) {
+
+ if (sub.length() > str.length() || sub.isEmpty()) {
+ return false;
+ }
+
+ else {
+
+ //Take all the characters in the "outer" word and put them in an ArrayList.
+ ArrayList outer = new ArrayList();
+ for(Character c: str.toCharArray()) {
+ outer.add(c);
+ }
+
+ //Do the same with the Characters in the inner word.
+ ArrayList inner = new ArrayList();
+ for(Character c: sub.toCharArray()) {
+ inner.add(c);
+ }
+
+
+ for (Character c : inner) {
+ if(!outer.remove(c)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * This method will return all the lines from the given file as an array of strings.
+ *
+ * It is up to the user what to do with that array.
+ *
+ * @param filename The name of the file. Please make it unique.
+ * @return All the lines of the file, in the form of an array of Strings.
+ */
+ public static List readFromFile(String filename) throws IOException {
+
+ InputStream is = Utils.class.getClassLoader().getResourceAsStream(filename);
+ return IOUtils.readLines(is);
+ }
+ //Just a little random number method I wrote to make a part of my code cleaner
+ public static int newRand(int bound) {
+ Random set = new Random();
+ int ret = set.nextInt(bound );
+ return ret;
+ }
+
+ public static void writeToFile(List strings, String filename) throws IOException {
+ Path path = Paths.get(pathPrefix + filename);
+ Files.write(path, strings, StandardCharsets.UTF_8);
+ }
+
+ public static void appendToFile(List strings, String filename) throws IOException {
+ Path path = Paths.get(pathPrefix + filename);
+ List previousLines = readFromFile(filename);
+ previousLines.addAll(strings);
+ writeToFile(previousLines, filename);
+ }
+
+//_______________________________________________________________________________________________________
+
+// Loops through the string and checks if the letter exists in the string
+ public static boolean letterIsInWord(String goalWord,
+ String guessedLetter) {
+ char c = guessedLetter.charAt(0);
+ for (int i = 0; i < goalWord.length(); i++) {
+ if(c == goalWord.charAt(i)) {
+ return true;
+ }
+ }
+ return false;
+ }
+//shows all the indexes of a word where a letter exists
+ public static int[] allIndexesOf(String word, char search){
+ ArrayList indexesOfString = new ArrayList();
+ for(int i = 0; i trues = letterStore.getTrueValues();
+ Assert.assertEquals(trues.size(), 2);
+ Set truesSet = new HashSet(trues);
+ Assert.assertTrue(truesSet.contains('n'));
+ Assert.assertTrue(truesSet.contains('a'));
+ System.out.println(trues);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/org/vashonsd/Utils/RandomizerTest.java b/src/test/java/org/vashonsd/Utils/RandomizerTest.java
new file mode 100644
index 0000000..15ec351
--- /dev/null
+++ b/src/test/java/org/vashonsd/Utils/RandomizerTest.java
@@ -0,0 +1,41 @@
+package org.vashonsd.Utils;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.*;
+
+public class RandomizerTest {
+
+ @Test
+ public void testRandomWord() {
+ try {
+ System.out.println(Randomizer.randomWord());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void randomWord() {
+ }
+
+ @Test
+ public void randomWord1() {
+ boolean sentinel = true;
+ for(int i = 0; i<100; i++) {
+ try {
+ String w = Randomizer.randomWord(5);
+ if(w.length() < 5 ) {
+ sentinel = false;
+ }
+ } catch (IOException e) {
+ sentinel = false;
+ e.printStackTrace();
+ }
+ }
+ Assert.assertTrue(sentinel);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/org/vashonsd/Utils/RoundTest.java b/src/test/java/org/vashonsd/Utils/RoundTest.java
new file mode 100644
index 0000000..c0eae82
--- /dev/null
+++ b/src/test/java/org/vashonsd/Utils/RoundTest.java
@@ -0,0 +1,21 @@
+package org.vashonsd.Utils;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.vashonsd.Games.BR.Round;
+
+public class RoundTest {
+
+ Round round;
+
+ @Before
+ public void setUp() {
+ round = new Round();
+ }
+
+ @Test
+ public void printScreenedWord() throws Exception {
+ System.out.println(round.getScreenedWord());
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/org/vashonsd/Utils/UtilsTest.java b/src/test/java/org/vashonsd/Utils/UtilsTest.java
new file mode 100644
index 0000000..6b42756
--- /dev/null
+++ b/src/test/java/org/vashonsd/Utils/UtilsTest.java
@@ -0,0 +1,122 @@
+package org.vashonsd.Utils;
+
+import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.*;
+
+/**
+ * Created by andy on 5/20/18.
+ */
+public class UtilsTest {
+// @Test
+// public void testLetterIsInWord() throws Exception {
+// Assert.assertTrue(Utils.letterIsInWord("eaten","e"));
+// Assert.assertFalse(Utils.letterIsInWord("eaten", "j"));
+// }
+
+// @Test
+// public void testAddToArrayList() {
+// ArrayList word = new ArrayList ();
+// Assert.assertArrayEquals("{0,4}" == Utils.addToArrayList(new int[] {0,4}, word, "h");
+//
+// }
+
+// @Before
+// public void setUp() throws Exception {
+// Map rollFrequencies = new HashMap();
+// int dieMax = 12;
+// for(int i=0; i<1000; i++) {
+// int roll = Utils.rollDie(dieMax);
+// int val = rollFrequencies.containsKey(roll) ? rollFrequencies.get(roll) : 0;
+// rollFrequencies.put(roll, val+1);
+// }
+// List testLines = new ArrayList();
+// testLines.addAll(Arrays.asList(new String[] {"one", "two", "three"}));
+// }
+//
+// @After
+// public void tearDown() throws Exception {
+//
+// }
+
+ @Test
+ public void testAppendToFile() throws Exception {
+
+ }
+
+ @Test
+ public void testIsInteger() throws Exception {
+ Assert.assertTrue(Utils.IsInteger("3"));
+ Assert.assertFalse(Utils.IsInteger("th4"));
+ }
+
+
+// @Test
+// public void testAllIndexesOfLetter() throws Exception {
+// String outer = "banana";
+// char inner = 'a';
+// Assert.assertArrayEquals(new int[]{1,3,5}, Utils.allIndexesOf("banana", 'a'));
+// }
+
+// @Test
+// public void testRollDie() throws Exception {
+// System.out.println(rollFrequencies);
+// }
+//
+// @Test
+// public void testRollDieProducesOnlyLegalNumbers() throws Exception {
+//
+// //First we will check if any values outside the Set were rolled
+// Set legalValues = new HashSet();
+// for(int i=1; i