Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
252 changes: 113 additions & 139 deletions .idea/workspace.xml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion CardGame UML.xml

This file was deleted.

Binary file removed CardGameUML.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions CardGameUML.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36" version="6.0.2.16" editor="www.draw.io" type="device"><diagram name="Page-1">7Vttc5s4EP41nkk/JIPAxvbH2Hnp3OSmmbpzd/2ogGx0Fcgj5Djur78VSGBArnGC07semWSCltXbPrurh8UeePP45V7gdfQ7DwkbuE74MvBuBq6LHM+Bf0qyyyW+qwUrQUOtVAoW9DsxPbV0Q0OSVhQl50zSdVUY8CQhgazIsBB8W1VbcladdY1XpCFYBJg1pX/SUEa5dDJySvlHQleRmRk5+s4TDr6tBN8ker6B6y2zn/x2jM1YWj+NcMi3eyLvduDNBecyv4pf5oQp2xqz5f3uDtwt1i1IItt0cPMOz5ht9NbnWIR6bXJn7JFuacxwAq1ZJGMGQgSXS57IhVZSbczoKoHrACYnAgTPREgKVr3WNyRfgzSIKAsf8I5v1BJTCSYzrVnEBf0Ow2IzB9wWUjuI61c0FqoniB2QCpKCzqPZNypEDziVWifgjOF1Sp+KBcdYrGgy41LyWCuZnd5RxuaccZEZwIDozbS9YGPk5aDNUYEkRAjhMZFiByqmgzvKu+jgQEM/b29LV3ONTrTnZqCpXVy796oYu4QYLjTKdsS9BuKX0BQ4AVNew9VCCpqsBq7PFB4hfYbLlbq8TDdU2nRgxj01S08jehJ1Sb1rze3AxrLqcqkU/BsxwCQ8c8nlHlZaZFyRka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1qLyTn4Ntv8NfTiXPTCX94nE4UzKHyWZEOWLrbl3Vf8VEfxw7oYTZhxa+LD7wdqusqMvElyg/bs3MIkoQwl8oUF0WpeF7Wjfvj+ycc30d81FIJsProqIsc06zWoga24EPX6rsP6jhfZxbcP7ET8zUL5JpDwGiHFMdcOSBNaucDGhqByt5mqKO84YivPOnjoaAR6MpBFSJx5UxM+5EICvZSp1+dYDjueJ9iXDpXaOoaSb1fG1LR5BT+qUcRLALS0rRyHA115a4169CjP/KM2Zuhp9VDbuzUHCvfiu5U+lZjnOKdwqGBcgM0BspeIO2p6Xg8uF7Pr86DRuMfruuIPlzkK7D3vvTcau/agyZfLlMiB/WgKxBsF4fNEvovEYdlTPmeW4spx/G7janpyTGFKsh6/8tocmvfGvL0PG3XdbK+ft9gjb7joQPN8ltsuXr5VUHv9h8=</diagram></mxfile>
Binary file added CardGameUMLpdf.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/java/reynoldstitko/gillian/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void main(String[] args) {
switch (chooseGame) {
case 1: {
theGame = new BlackJackGame(); //Using polymorphism
System.out.print("You chose to play no-bet BlackJack!\n");
System.out.print("You chose to play no-bet BlackJack (where Aces = 1)!\n");
break;
}

Expand Down
53 changes: 35 additions & 18 deletions src/main/java/reynoldstitko/gillian/BlackJackGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@
* Created by gillianreynolds-titko on 1/27/17.
*/
public class BlackJackGame extends Game {
public void start() {
Scanner scanner = new Scanner(System.in);
Hand playerOneHand = new Hand();
Hand playerTwoHand = new Hand();
int playerOneTotal = 0;
int playerTwoTotal = 0;

Scanner scanner = new Scanner(System.in);
Hand playerOneHand = new Hand();
Hand playerTwoHand = new Hand();
int playerOneTotal = 0;
int playerTwoTotal = 0;
Deck cardDeck = new Deck();

Deck cardDeck = new Deck();
public void start() {

//Shuffle the deck
cardDeck.shuffle();

//Deal 2 cards to each player, including the dealer
playerOneHand.addCardsToHand(cardDeck.deal(2));
playerTwoHand.addCardsToHand(cardDeck.deal(2));
dealTheCards();

//Show player1 their cards
System.out.println("Player 1, you have the following cards:");
Expand All @@ -35,7 +33,7 @@ public void start() {
boolean playerTwoPlaying = false;
String response = scanner.next();

while (response.equalsIgnoreCase("Hit") && playerOnePlaying == true) {
if (response.equalsIgnoreCase("Hit") && playerOnePlaying == true) {
playerOneHand.addCardsToHand(cardDeck.deal(1));
System.out.println("Player 1, you have the following cards:");
for (int i = 0; i < playerOneHand.getTheHand().size(); i++) {
Expand All @@ -48,8 +46,13 @@ public void start() {
playerOnePlaying = false;
playerTwoPlaying = true;
playerOneTotal = playerOneHand.sumRankValues(playerOneHand.getTheHand());
break;
//break;
}
//Account for player staying in the first move
} if(response.equalsIgnoreCase("Stay") && playerOnePlaying == true){
playerOnePlaying = false;
playerTwoPlaying = true;
playerOneTotal = playerOneHand.sumRankValues(playerOneHand.getTheHand());
}

System.out.println("Player 2, you have the following cards:");
Expand All @@ -60,7 +63,7 @@ public void start() {
System.out.println("Player 2, do you want to Hit or Stay?");
response = scanner.next();

while (response.equalsIgnoreCase("Hit") && playerTwoPlaying == true) {
if (response.equalsIgnoreCase("Hit") && playerTwoPlaying == true) {
//Show player2 their cards
playerTwoHand.addCardsToHand(cardDeck.deal(1));
System.out.println("Player 2, you have the following cards:");
Expand All @@ -72,20 +75,34 @@ public void start() {

if (response.equalsIgnoreCase("Stay")) {
playerTwoPlaying = false;
playerOnePlaying = false;
playerTwoTotal = playerTwoHand.sumRankValues(playerTwoHand.getTheHand());
break;
//break;
}
} if(response.equalsIgnoreCase("Stay") && playerTwoPlaying == true){
playerTwoPlaying = false;
playerOnePlaying = false;
playerTwoTotal = playerTwoHand.sumRankValues(playerTwoHand.getTheHand());
}

endTheGame(false, false);

}

//--Refactor and add a few helper methods
public void dealTheCards(){
//Deal 2 cards to each player, including the dealer
playerOneHand.addCardsToHand(cardDeck.deal(2));
playerTwoHand.addCardsToHand(cardDeck.deal(2));
}

public void endTheGame(boolean playerOnePlaying, boolean playerTwoPlaying){
if (playerOnePlaying == false && playerTwoPlaying == false) {
//Show game results here
System.out.print("Player 1 you got " + playerOneTotal + " points\n");
System.out.print("Player 2 you got " + playerTwoTotal + " points\n");
System.out.println("Game over!");
}

}

}


}
51 changes: 28 additions & 23 deletions src/main/java/reynoldstitko/gillian/GoFishGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
* Created by gillianreynolds-titko on 1/27/17.
*/
public class GoFishGame extends Game {
public void start(){

Scanner scanner = new Scanner(System.in);
Hand playerOneHand = new Hand();
Hand playerTwoHand = new Hand();
Scanner scanner = new Scanner(System.in);
Hand playerOneHand = new Hand();
Hand playerTwoHand = new Hand();
Deck cardDeck = new Deck();

Deck cardDeck = new Deck();
public void start(){

//Shuffle the deck
cardDeck.shuffle();

//Deal 5 cards to each player
playerOneHand.addCardsToHand(cardDeck.deal(5));
playerTwoHand.addCardsToHand(cardDeck.deal(5));
dealCardsToEachPlayer();

boolean isGameOver = false;

Expand Down Expand Up @@ -58,13 +57,7 @@ public void start(){

//Get the number of cards of the same rank and remove that number
int removedCards = playerTwoHand.countCardsInHandOfRank(playerTwoHand.getTheHand(), rank);
for(int i = 1; i <= removedCards; i++){
Card temp = playerTwoHand.removeCardFromHand(rank);
if(temp == null){

}else playerOneHand.addCardToHand(temp);
playerTwoHand.getTheHand().trimToSize();
}
removeCardsOfSameRank(removedCards, rank, playerTwoHand, playerOneHand);

} else {
//If no, then respond "Go fish" and deal one card to player from the deck
Expand Down Expand Up @@ -93,7 +86,6 @@ public void start(){
while (playerTwoStillPlaying && (playerTwoHand.getTheHand().size() !=0)){
System.out.println("Player 2, what rank card do you want to check for (Ace, Two, Three, etc to King)?");


//Get the player response for the rank
String rank = scanner.next();
//String suit = scanner.next();
Expand All @@ -103,16 +95,9 @@ public void start(){
//If yes, then move all the cards with that rank from player1 to player2,
// reducing player2's cards and increasing player 1's cards


//Get the number of cards of the same rank and remove that number
int removedCards = playerOneHand.countCardsInHandOfRank(playerOneHand.getTheHand(), rank);
for(int i = 1; i <= removedCards; i++){
Card temp = playerOneHand.removeCardFromHand(rank);
if (temp == null) {
} else playerTwoHand.addCardToHand(temp);
playerOneHand.getTheHand().trimToSize();

}
removeCardsOfSameRank(removedCards, rank, playerOneHand, playerTwoHand);

//Show the player1 list of cards
System.out.println("Player 1, you have the following cards:");
Expand All @@ -139,9 +124,29 @@ public void start(){
}

}
gameOver();
}

//---Refactor to create some helper methods
public void dealCardsToEachPlayer(){
//Deal 5 cards to each player
playerOneHand.addCardsToHand(cardDeck.deal(5));
playerTwoHand.addCardsToHand(cardDeck.deal(5));
}

public void gameOver(){
System.out.print("Player 1, you had "+ playerOneHand.getTheHand().size()+" cards left\n");
System.out.print("Player 2, you had "+ playerTwoHand.getTheHand().size()+" cards left\n");
System.out.print("Game over!");
scanner.close();
}

public void removeCardsOfSameRank(int removedCards, String rank, Hand firstPlayer, Hand otherPlayer){
for(int i = 1; i <= removedCards; i++){
Card temp = firstPlayer.removeCardFromHand(rank);
if (temp == null) {
} else otherPlayer.addCardToHand(temp);
firstPlayer.getTheHand().trimToSize();
}
}
}
9 changes: 0 additions & 9 deletions src/test/java/reynoldstitko/gillian/CardTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,4 @@ public void getRankValueTest(){
assertEquals("I expect to return a 4", expected, actual);
}

@Test
public void sumValuesTest(){
int expected = 3;
ArrayList<Card> cards = new ArrayList<>();
cards.add(new Card("Three", "Spades"));
cards.add(new Card("Three", "Hearts"));
//int actual = cards.sumRankValues();
//assertEquals("I expect a sum of 3", expected, actual);
}
}
Binary file modified target/classes/reynoldstitko/gillian/App.class
Binary file not shown.
Binary file modified target/classes/reynoldstitko/gillian/BlackJackGame.class
Binary file not shown.
Binary file modified target/classes/reynoldstitko/gillian/GoFishGame.class
Binary file not shown.
Binary file modified target/test-classes/reynoldstitko/gillian/CardTest.class
Binary file not shown.