From b7bd1c0756162fb20321a2ed120a58ee4df6981e Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 12 Jul 2021 21:47:00 -0400 Subject: [PATCH 001/104] Star squad --- .../zipcodewilmington/casino/models/Card.java | 54 +++++++++++++++++ .../github/zipcodewilmington/CardsTest.java | 59 +++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/models/Card.java create mode 100644 src/test/java/com/github/zipcodewilmington/CardsTest.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/models/Card.java b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java new file mode 100644 index 000000000..3464cec6f --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java @@ -0,0 +1,54 @@ +package com.github.zipcodewilmington.casino.models; + +import java.util.*; + +public class Card { + List cardPool; + Integer numberOfCards; // The deck will be made of + + public Card () { + this.numberOfCards = 52; + this.cardPool = new ArrayList<>(); + this.createDeck(numberOfCards); + } + + + public List createDeck (Integer numberOfCards) { + for (int i = 0; i <= 4; i++) { + for (int j = 2; j < (numberOfCards / 4); j++) { + this.cardPool.add(j); + } + } + return this.cardPool; + } + + public List polishDeck () { + for (int i = 0; i < this.cardPool.size(); i++) { + if (this.cardPool.get(i) > 11) { + this.cardPool.set(i, 10); + } + } + return this.cardPool; + } + + public List shuffleDeck () { + Collections.shuffle(this.cardPool); + return this.cardPool; + } + + public List getCardPool() { + return cardPool; + } + + public void setCardPool(List cardPool) { + this.cardPool = cardPool; + } + + public Integer getNumberOfCards() { + return numberOfCards; + } + + public void setNumberOfCards(Integer numberOfCards) { + this.numberOfCards = numberOfCards; + } +} diff --git a/src/test/java/com/github/zipcodewilmington/CardsTest.java b/src/test/java/com/github/zipcodewilmington/CardsTest.java new file mode 100644 index 000000000..269c3b91e --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/CardsTest.java @@ -0,0 +1,59 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.models.Card; +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; + +public class CardsTest { + @Test + public void constructorTest () { + Integer expected = 52; + + Card card = new Card(); + Integer actual = card.getNumberOfCards(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void createDeckTest () { + // Given + Card card = new Card(); + + Integer expected = 52; + Integer actual = card.getNumberOfCards(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void polishDeckTest () { + Card card = new Card(); + + card.createDeck(52); + List result = card.polishDeck(); + + System.out.println(result); + } + + @Test + public void shuffleDeckTest () { + Card card = new Card(); + + List result = card.shuffleDeck(); + + System.out.println(result); // Visual test + } + + @Test + public void setCardPoolTest () { + Card card = new Card(); + } + + @Test + public void setNumberOfCardsTest () { + + } +} From 05d5a74b79d4f5ff63b2fbf06adde18c4ed00301 Mon Sep 17 00:00:00 2001 From: Nathan Date: Mon, 12 Jul 2021 21:58:29 -0400 Subject: [PATCH 002/104] edited GameInterface --- .../casino/GameInterface.java | 19 ++++++++++++++++++- .../casino/games/slots/SlotsGame.java | 3 ++- .../casino/games/slots/SlotsPlayer.java | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java index 9873f1ed9..4f5e662c5 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java +++ b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java @@ -1,7 +1,8 @@ package com.github.zipcodewilmington.casino; /** - * Created by leon on 7/21/2020. + * Author: Nathan + * Date: 7/12/21 */ public interface GameInterface extends Runnable { /** @@ -20,4 +21,20 @@ public interface GameInterface extends Runnable { * specifies how the game will run */ void run(); + + /** + * Calculate player's winning payout amount of bet x multiplier + * @return (double) amount of money winnings + */ + Double calculateWinnings(Double betAmount); + + /** + * Subtract the bet amount from player's balance + */ + void subtractBetFromBalance(Double betAmount); + + /** + * Add winnings amount to player's balance + */ + void addMoneyToBalance(PlayerInterface Player, Double winnings); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index 8cb20c787..78d2fca4d 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -1,7 +1,8 @@ package com.github.zipcodewilmington.casino.games.slots; /** - * Created by leon on 7/21/2020. + * Created by Nathan on 7/12/21 */ public class SlotsGame { + } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java index f89ebd7f5..c5c6df9d3 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java @@ -4,4 +4,5 @@ * Created by leon on 7/21/2020. */ public class SlotsPlayer { + } \ No newline at end of file From 37cd7b09f7f3f4f89edf6197da0f4e306711d323 Mon Sep 17 00:00:00 2001 From: Zach Date: Mon, 12 Jul 2021 22:08:57 -0400 Subject: [PATCH 003/104] completed Dice class and tests --- .../zipcodewilmington/casino/models/Dice.java | 65 ++++++++++++++ .../github/zipcodewilmington/DiceTest.java | 88 +++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/models/Dice.java create mode 100644 src/test/java/com/github/zipcodewilmington/DiceTest.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/models/Dice.java b/src/main/java/com/github/zipcodewilmington/casino/models/Dice.java new file mode 100644 index 000000000..3df284267 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/models/Dice.java @@ -0,0 +1,65 @@ +package com.github.zipcodewilmington.casino.models; + +public class Dice { + private Integer numDice; + private Integer maxRoll; + private Integer maxBinIndex; + private Integer[] rollValues; + private Integer[] bins; + + public Dice(Integer numberOfDice){ + this.numDice = numberOfDice; + this.maxRoll = numberOfDice * 6; + this.maxBinIndex = numberOfDice * 6 - numberOfDice - 1; + this.rollValues = new Integer[this.numDice]; + this.bins = new Integer[numberOfDice * 6 - numberOfDice - 1]; + this.initializeDiceList(); + this.initializeBins(); + } + + public Integer getNumDice(){ + return this.numDice; + } + + public Integer[] getRollValues(){ + return this.rollValues; + } + + public Integer[] getBins(){ + return this.bins; + } + + public Integer getBin(Integer binNumber){ + return this.bins[binNumber - numDice]; + } + + public Integer getMaxBinIndex() { return this.maxBinIndex; } + + public Integer getMaxRoll(){ return this.maxRoll;} + + public void incrementBin(Integer binNumber){ + this.bins[binNumber - numDice]++; + } + + public void initializeDiceList(){ + for(int i = 0; i < numDice; i++){ + this.rollValues[i] = 0; + } + } + + public void initializeBins(){ + for(int i = 0; i < maxBinIndex; i++){ + this.bins[i] = 0; + } + } + + public Integer tossAndSum(){ + int sum = 0; + for(int i = 0; i < numDice; i++){ + sum += (Math.random() * 7) + 1; + } + this.incrementBin(sum); + return sum; + } + +} diff --git a/src/test/java/com/github/zipcodewilmington/DiceTest.java b/src/test/java/com/github/zipcodewilmington/DiceTest.java new file mode 100644 index 000000000..357497dd4 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/DiceTest.java @@ -0,0 +1,88 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.models.Dice; +import org.junit.Assert; +import org.junit.Test; + +public class DiceTest { + @Test + public void diceConstructorTest1() { + Dice dice = new Dice(2); + Integer actual = dice.getNumDice(); + Integer expected = 2; + + Assert.assertEquals(expected, actual); + } + + @Test + public void diceConstructorTest2() { + Dice dice = new Dice(3); + Integer expected = 18; + Integer actual = dice.getMaxRoll(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void diceConstructorTest3() { + Dice dice = new Dice(3); + Integer expected = 14; + Integer actual = dice.getMaxBinIndex(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void diceConstructorTest4() { + Dice dice = new Dice(3); + Integer expected = 3; + Integer actual = dice.getRollValues().length; + + Assert.assertEquals(expected, actual); + } + + @Test + public void diceConstructorTest5() { + Dice dice = new Dice(2); + Integer expected = 10; + Integer actual = dice.getBins().length; + + Assert.assertEquals(expected, actual); + } + + @Test + public void diceConstructorTest6() { + Dice dice = new Dice(2); + Integer[] expected = {0, 0}; + Integer[] actual = dice.getRollValues(); + + Assert.assertArrayEquals(expected, actual); + } + + @Test + public void diceConstructorTest7(){ + Dice dice = new Dice(2); + Integer[] expected = {0,0,0,0,0,0,0,0,0}; + Integer[] actual = dice.getBins(); + + Assert.assertArrayEquals(expected, actual); + } + + @Test + public void getBinQuantityTest(){ + Dice dice = new Dice(2); + dice.tossAndSum(); + Integer[] bins = dice.getBins(); + Integer actual = 0; + for(int i = 2; i < dice.getMaxBinIndex(); i++){ + if(dice.getBin(i) > 0){ + actual = dice.getBin(i); + break; + } + } + Integer expected = 1; + + Assert.assertEquals(expected, actual); + } + +} From b9631bd2a8f82b3e154c35f66f5176a995ba07f3 Mon Sep 17 00:00:00 2001 From: Nathan Date: Mon, 12 Jul 2021 22:18:34 -0400 Subject: [PATCH 004/104] started slots class --- .../com/github/zipcodewilmington/casino/games/slots/Slots.java | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java new file mode 100644 index 000000000..c7bfcae69 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java @@ -0,0 +1,2 @@ +package com.github.zipcodewilmington.casino.games.slots;public class Slots { +} From ef997057200376d8d7314e70be6640bec7744a10 Mon Sep 17 00:00:00 2001 From: Nathan Date: Mon, 12 Jul 2021 22:19:43 -0400 Subject: [PATCH 005/104] started slots class --- .../zipcodewilmington/casino/games/slots/Slots.java | 11 ++++++++++- .../casino/games/slots/SlotsGame.java | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java index c7bfcae69..4c0543226 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java @@ -1,2 +1,11 @@ -package com.github.zipcodewilmington.casino.games.slots;public class Slots { +package com.github.zipcodewilmington.casino.games.slots; + +import java.util.List; + +public class Slots { + private static String[] slotItems = {"Peach", "Cherry", "Diamond", "Plum", "Seven", "Nine"}; + String[][] slots = new String[3][3]; + public void spinSlots(){ + } + } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index 78d2fca4d..2f3740d50 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -5,4 +5,5 @@ */ public class SlotsGame { + } From d23c2a2b97cd4652d1ff98bba7bb0850bec1ce5d Mon Sep 17 00:00:00 2001 From: Nathan Date: Mon, 12 Jul 2021 21:58:29 -0400 Subject: [PATCH 006/104] edited GameInterface --- .../casino/GameInterface.java | 19 ++++++++++++++++++- .../casino/games/slots/SlotsGame.java | 3 ++- .../casino/games/slots/SlotsPlayer.java | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java index 9873f1ed9..4f5e662c5 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java +++ b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java @@ -1,7 +1,8 @@ package com.github.zipcodewilmington.casino; /** - * Created by leon on 7/21/2020. + * Author: Nathan + * Date: 7/12/21 */ public interface GameInterface extends Runnable { /** @@ -20,4 +21,20 @@ public interface GameInterface extends Runnable { * specifies how the game will run */ void run(); + + /** + * Calculate player's winning payout amount of bet x multiplier + * @return (double) amount of money winnings + */ + Double calculateWinnings(Double betAmount); + + /** + * Subtract the bet amount from player's balance + */ + void subtractBetFromBalance(Double betAmount); + + /** + * Add winnings amount to player's balance + */ + void addMoneyToBalance(PlayerInterface Player, Double winnings); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index 8cb20c787..78d2fca4d 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -1,7 +1,8 @@ package com.github.zipcodewilmington.casino.games.slots; /** - * Created by leon on 7/21/2020. + * Created by Nathan on 7/12/21 */ public class SlotsGame { + } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java index f89ebd7f5..c5c6df9d3 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java @@ -4,4 +4,5 @@ * Created by leon on 7/21/2020. */ public class SlotsPlayer { + } \ No newline at end of file From e14aeb859c09a310c3641bb0d2df61fd7d6e33ea Mon Sep 17 00:00:00 2001 From: Nathan Date: Mon, 12 Jul 2021 22:18:34 -0400 Subject: [PATCH 007/104] started slots class --- .../com/github/zipcodewilmington/casino/games/slots/Slots.java | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java new file mode 100644 index 000000000..c7bfcae69 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java @@ -0,0 +1,2 @@ +package com.github.zipcodewilmington.casino.games.slots;public class Slots { +} From d937b7e4a86df65dcd9a0a195994e5db2cdea251 Mon Sep 17 00:00:00 2001 From: Nathan Date: Mon, 12 Jul 2021 22:19:43 -0400 Subject: [PATCH 008/104] started slots class --- .../zipcodewilmington/casino/games/slots/Slots.java | 11 ++++++++++- .../casino/games/slots/SlotsGame.java | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java index c7bfcae69..4c0543226 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java @@ -1,2 +1,11 @@ -package com.github.zipcodewilmington.casino.games.slots;public class Slots { +package com.github.zipcodewilmington.casino.games.slots; + +import java.util.List; + +public class Slots { + private static String[] slotItems = {"Peach", "Cherry", "Diamond", "Plum", "Seven", "Nine"}; + String[][] slots = new String[3][3]; + public void spinSlots(){ + } + } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index 78d2fca4d..2f3740d50 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -5,4 +5,5 @@ */ public class SlotsGame { + } From 0e6255e67595fadbafac9fd03c3837b354cc09c6 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 12 Jul 2021 23:56:46 -0400 Subject: [PATCH 009/104] Started BlackJack, needs a lot of reform --- .../casino/games/blackjack/BlackJack.java | 97 +++++++++++++++++++ .../zipcodewilmington/BlackJackTest.java | 40 ++++++++ 2 files changed, 137 insertions(+) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java create mode 100644 src/test/java/com/github/zipcodewilmington/BlackJackTest.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java new file mode 100644 index 000000000..48beee802 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -0,0 +1,97 @@ +package com.github.zipcodewilmington.casino.games.blackjack; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.models.Card; + +import java.util.*; + +public class BlackJack implements GameInterface, PlayerInterface { + Card card = new Card(); + List playersHand; + List dealersHand; + Deque deckOfCards = new LinkedList<>(generateNewDeck(52)); + + public BlackJack () { + this.playersHand = new ArrayList<>(); + this.dealersHand = new ArrayList<>(); + } + + public List generateNewDeck (Integer numberOfCards) { + card.createDeck(numberOfCards); + card.polishDeck(); + card.shuffleDeck(); + return card.getCardPool(); + } + + public List givePlayerCard () { + Integer valueOfCard = deckOfCards.pop(); + this.playersHand.add(valueOfCard); + return this.playersHand; + } + + public Integer playersCurrentValue () { + Integer sum = 0; + for (int i = 0; i < this.playersHand.size(); i++) { + sum += this.playersHand.get(i); + } + return sum; + } + + public List getPlayersHand() { + return playersHand; + } + + public void setPlayersHand(List playersHand) { + this.playersHand = playersHand; + } + + public List getDealersHand() { + return dealersHand; + } + + public void setDealersHand(List dealersHand) { + this.dealersHand = dealersHand; + } + + @Override + public void add(PlayerInterface player) { + + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public void run() { + + } + + @Override + public Double calculateWinnings(Double betAmount) { + return null; + } + + @Override + public void subtractBetFromBalance(Double betAmount) { + + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Double winnings) { + + } + + @Override + public CasinoAccount getArcadeAccount() { + return null; + } + + @Override + public SomeReturnType play() { + return null; + } +} diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackTest.java new file mode 100644 index 000000000..b17361a7e --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BlackJackTest.java @@ -0,0 +1,40 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.games.blackjack.BlackJack; +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; + +public class BlackJackTest { + @Test + public void generateNewDeckTest() { + BlackJack bj = new BlackJack(); + Integer expected = 165; + + Integer actual1 = bj.generateNewDeck(52).size(); + List actual = bj.generateNewDeck(52); + System.out.println(actual); + + Assert.assertEquals(expected, actual1); + } + + @Test + public void givePlayerCardTest() { + BlackJack bj = new BlackJack(); + Integer expected = 2; + + bj.givePlayerCard(); + bj.givePlayerCard(); + Integer actual = bj.getPlayersHand().size(); + + System.out.println(bj.getPlayersHand()); + Assert.assertEquals(expected, actual); + } + + @Test + public void playersCurrentValueTest () { + BlackJack bj = new BlackJack(); + // Solid stopping point = need to populate array for test + } +} From b6997ba351b0bb37ae7f3f9408c2c65489e2b754 Mon Sep 17 00:00:00 2001 From: Zach Date: Tue, 13 Jul 2021 02:05:44 -0400 Subject: [PATCH 010/104] Completed Beetle.java and tests for Beetle.java --- .../casino/games/Beetle/Beetle.java | 92 ++++++++++ .../casino/games/Beetle/BeetleGame.java | 58 +++++++ .../casino/games/Beetle/BeetlePlayer.java | 4 + .../github/zipcodewilmington/BeetleTest.java | 162 ++++++++++++++++++ 4 files changed, 316 insertions(+) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java create mode 100644 src/test/java/com/github/zipcodewilmington/BeetleTest.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java new file mode 100644 index 000000000..56461ccc5 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java @@ -0,0 +1,92 @@ +package com.github.zipcodewilmington.casino.games.Beetle; + +import com.github.zipcodewilmington.casino.models.Dice; + +public class Beetle{ + private Dice dice = new Dice(1); + private Integer currentPlayer = 0; + private Integer[][] playerBeetles; + private Integer[] scoreboard; + private Integer numPlayers; + + public Beetle(Integer numPlayers){ + this.numPlayers = numPlayers; + this.playerBeetles = new Integer[numPlayers][6]; + this.scoreboard = new Integer[numPlayers]; + this.initializeBeetleCards(); + this.initializeScoreboards(); + } + + public void initializeBeetleCards(){ + for(int i = 0; i < numPlayers; i++){ + for(int j = 0; j < 6; j++){ + this.playerBeetles[i][j] = 0; + } + } + } + + public void initializeScoreboards(){ + for(int i = 0; i < numPlayers; i++){ + this.scoreboard[i] = 0; + } + } + + public Dice getDice() { + return dice; + } + + public Integer getCurrentPlayer() { + return currentPlayer; + } + + public Integer[][] getPlayerBeetles() { + return playerBeetles; + } + + public Integer getNumPlayers() { + return numPlayers; + } + + public Integer[] getPlayerCard(Integer playerNumber){ + return this.getPlayerBeetles()[playerNumber]; + } + + public void setCurrentPlayer(Integer currentPlayer) { + this.currentPlayer = currentPlayer; + } + + public void setPlayerBeetles(Integer player, Integer diceRoll) { + this.playerBeetles[player][diceRoll]++; + //return this.checkWinner(player); + } + + public void refreshBeetle(Integer player){ + this.playerBeetles[player] = new Integer[] {0, 0, 0, 0, 0, 0}; + } + + + public Boolean checkWinner(Integer player){ + if(this.beetleIsComplete(player)){ + this.scoreboard[player] += 6; + if(this.getScore(player) == 30){ + return true; + } else { + this.refreshBeetle(player); + } + } + return false; + } + + public Boolean beetleIsComplete(Integer player){ + Integer[] playerBeetle = getPlayerCard(player); + for(int i = 0; i < 6; i++){ + if(playerBeetle[i] == 0) + return false; + } + return true; + } + + public Integer getScore(Integer player){ + return this.scoreboard[player]; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java new file mode 100644 index 000000000..6a23520c3 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -0,0 +1,58 @@ +package com.github.zipcodewilmington.casino.games.Beetle; + +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; + +public class BeetleGame implements GameInterface { + private PlayerInterface[] players; + private Beetle game; + private Boolean isRunning = false; + public void add(PlayerInterface player){ + + } + + /** + * removes a player from the game + * @param player the player to be removed from the game + */ + public void remove(PlayerInterface player){ + + } + + /** + * specifies how the game will run + */ + public void run(){ + if(isRunning){ + + } + } + + /** + * Calculate player's winning payout amount of bet x multiplier + * @return (double) amount of money winnings + */ + public Double calculateWinnings(Double betAmount){ + return 0.00; + } + + /** + * Subtract the bet amount from player's balance + */ + public void subtractBetFromBalance(Double betAmount){} + + + /** + * Add winnings amount to player's balance + */ + public void addMoneyToBalance(PlayerInterface Player, Double winnings){ + + } + + public void initGame(){ + this.game = new Beetle(this.players.length); + } + + + +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java new file mode 100644 index 000000000..34b4ceb45 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java @@ -0,0 +1,4 @@ +package com.github.zipcodewilmington.casino.games.Beetle; + +public class BeetlePlayer { +} diff --git a/src/test/java/com/github/zipcodewilmington/BeetleTest.java b/src/test/java/com/github/zipcodewilmington/BeetleTest.java new file mode 100644 index 000000000..d1de50bd9 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BeetleTest.java @@ -0,0 +1,162 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.games.Beetle.Beetle; +import org.junit.Assert; +import org.junit.Test; + +public class BeetleTest { + @Test + public void constructorTest1(){ + Beetle beetle = new Beetle(3); + Integer expected = 3; + Integer actual = beetle.getPlayerBeetles().length; + + Assert.assertEquals(expected, actual); + } + + @Test + public void constructorTest2(){ + Beetle beetle = new Beetle(2); + Integer expected = 6; + Integer[][] playerCards = beetle.getPlayerBeetles(); + Integer actual = playerCards[0].length; + + Assert.assertEquals(expected, actual); + } + + @Test + public void constructorTest3(){ + Beetle beetle = new Beetle(4); + Integer expected = 0; + Integer[][] playerCards = beetle.getPlayerBeetles(); + Integer actual = playerCards[0][0]; + + Assert.assertEquals(expected, actual); + } + + @Test + public void constructorTest4(){ + Beetle beetle = new Beetle(2); + Integer expected = 0; + Integer actual = beetle.getScore(0); + + Assert.assertEquals(expected, actual); + } + + @Test + public void numPlayersTest(){ + Beetle beetle = new Beetle(2); + Integer expected = 2; + Integer actual = beetle.getNumPlayers(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void setPlayerTest(){ + Beetle beetle = new Beetle(2); + Integer expected = 1; + beetle.setCurrentPlayer(1); + Integer actual = beetle.getCurrentPlayer(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void setPlayerBeetleTest(){ + Beetle beetle = new Beetle(2); + Integer expected = 1; + beetle.setPlayerBeetles(0, beetle.getDice().tossAndSum()); + Integer actual = 0; + Integer[] playerCard = beetle.getPlayerCard(0); + for(int i = 0; i < 6; i++){ + if(playerCard[i] > 0){ + actual++; + } + } + Assert.assertEquals(expected, actual); + } + + @Test + public void beetleIsCompleteTest1(){ + Beetle beetle = new Beetle(2); + Boolean expected = true; + for(int i = 0; i < 6; i++) { + beetle.setPlayerBeetles(0, i); + } + Boolean actual = beetle.beetleIsComplete(0); + + Assert.assertEquals(expected, actual); + } + + @Test + public void beetleIsCompleteTest2(){ + Beetle beetle = new Beetle(2); + Boolean expected = false; + Boolean actual = beetle.beetleIsComplete(0); + + Assert.assertEquals(expected, actual); + } + + @Test + public void checkWinnerTest1(){ + Beetle beetle = new Beetle(2); + Boolean actual = false; + for(int i = 0; i < 5; i++){ + for(int j = 0; j < 6; j++){ + beetle.setPlayerBeetles(0, j); + } + actual = beetle.checkWinner(0); + } + Assert.assertTrue(actual); + } + + @Test + public void checkWinnerTest2(){ + Beetle beetle = new Beetle(2); + Boolean actual = false; + for(int i = 0; i < 4; i++){ + for(int j = 0; j < 6; j++){ + beetle.setPlayerBeetles(0, j); + } + actual = beetle.checkWinner(0); + } + Assert.assertFalse(actual); + } + + @Test + public void getScoreTest1(){ + Beetle beetle = new Beetle(2); + for(int j = 0; j < 6; j++){ + beetle.setPlayerBeetles(0, j); + } + beetle.checkWinner(0); + Integer expected = 6; + Integer actual = beetle.getScore(0); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getScoreTest2(){ + Beetle beetle = new Beetle(2); + + Integer expected = 0; + Integer actual = beetle.getScore(0); + + Assert.assertEquals(expected, actual); + } + + @Test + public void refreshBeetleTest(){ + Beetle beetle = new Beetle(2); + for(int j = 0; j < 6; j++){ + beetle.setPlayerBeetles(0, j); + } + beetle.refreshBeetle(0); + Integer[] actual = beetle.getPlayerCard(0); + Integer[] expected = new Integer[] {0, 0, 0, 0, 0, 0}; + + Assert.assertArrayEquals(actual, expected); + } +} From 6ddad3f1e2c5caffa7fa58bbbea2d41ed5ddba8f Mon Sep 17 00:00:00 2001 From: Dipinti Date: Tue, 13 Jul 2021 06:13:26 -0400 Subject: [PATCH 011/104] Player.java ready --- .../zipcodewilmington/casino/Player.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/Player.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/Player.java b/src/main/java/com/github/zipcodewilmington/casino/Player.java new file mode 100644 index 000000000..f81eef273 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/Player.java @@ -0,0 +1,42 @@ +package com.github.zipcodewilmington.casino; + +public class Player{ + + String name; + Double balance; + Double currentBet = 0.0; + + public Player(String name, Double initialDeposit) { + this.name = name; + this.balance = initialDeposit; + } + + + public String getName() { + return name; + } + + + public Double getBalance() { + return balance; + } + + private void setCurrentBet(Double currentBet) { + this.currentBet = currentBet; + } + + public void setBalance(Double deposit) { + this.balance = balance + deposit; + } + + + public Double makeBet(Double betAmount) { + currentBet = betAmount; + balance = balance - currentBet; + return currentBet; + } + + private Double getCurrentBet() { + return currentBet; + } +} From 76d125f90c59fd8f53047c7f4b2d723af6fbade9 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Jul 2021 10:40:02 -0400 Subject: [PATCH 012/104] Have to reform cards, updating BlackJack --- .../github/zipcodewilmington/casino/models/Card.java | 9 +++++---- .../java/com/github/zipcodewilmington/CardsTest.java | 11 ++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/models/Card.java b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java index 3464cec6f..091142af6 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/models/Card.java +++ b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java @@ -12,6 +12,9 @@ public Card () { this.createDeck(numberOfCards); } + // Alter the loop to provide the correct amount of 10's + // Jack/Queen/King + // Should have 16 - 10 values in a 52 deck public List createDeck (Integer numberOfCards) { for (int i = 0; i <= 4; i++) { @@ -22,18 +25,16 @@ public List createDeck (Integer numberOfCards) { return this.cardPool; } - public List polishDeck () { + public void polishDeck () { for (int i = 0; i < this.cardPool.size(); i++) { if (this.cardPool.get(i) > 11) { this.cardPool.set(i, 10); } } - return this.cardPool; } - public List shuffleDeck () { + public void shuffleDeck () { Collections.shuffle(this.cardPool); - return this.cardPool; } public List getCardPool() { diff --git a/src/test/java/com/github/zipcodewilmington/CardsTest.java b/src/test/java/com/github/zipcodewilmington/CardsTest.java index 269c3b91e..d5e0d1e93 100644 --- a/src/test/java/com/github/zipcodewilmington/CardsTest.java +++ b/src/test/java/com/github/zipcodewilmington/CardsTest.java @@ -33,18 +33,19 @@ public void polishDeckTest () { Card card = new Card(); card.createDeck(52); - List result = card.polishDeck(); - - System.out.println(result); + card.polishDeck(); + System.out.println(card.getCardPool().size()); + System.out.println(card.getCardPool()); +// System.out.println(result); } @Test public void shuffleDeckTest () { Card card = new Card(); - List result = card.shuffleDeck(); +// List result = card.shuffleDeck(); - System.out.println(result); // Visual test +// System.out.println(result); // Visual test } @Test From bd973acff53dab718c3a6a8fa530da1e39bc518a Mon Sep 17 00:00:00 2001 From: Zach Date: Tue, 13 Jul 2021 13:38:29 -0400 Subject: [PATCH 013/104] Ready 2 Merge --- .../casino/games/Beetle/BeetleGame.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index 6a23520c3..2f21ffe7d 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -3,12 +3,15 @@ import com.github.zipcodewilmington.casino.GameInterface; import com.github.zipcodewilmington.casino.PlayerInterface; +import java.util.ArrayList; + public class BeetleGame implements GameInterface { - private PlayerInterface[] players; + private ArrayList players = new ArrayList(); private Beetle game; private Boolean isRunning = false; + private PlayerInterface player; public void add(PlayerInterface player){ - + players.add(player); } /** @@ -16,7 +19,7 @@ public void add(PlayerInterface player){ * @param player the player to be removed from the game */ public void remove(PlayerInterface player){ - + players.remove(player); } /** @@ -39,7 +42,9 @@ public Double calculateWinnings(Double betAmount){ /** * Subtract the bet amount from player's balance */ - public void subtractBetFromBalance(Double betAmount){} + public void subtractBetFromBalance(Double betAmount){ + + } /** From 52b857aab0889efaded14679c06001af0b617db6 Mon Sep 17 00:00:00 2001 From: Nathan Date: Tue, 13 Jul 2021 13:38:41 -0400 Subject: [PATCH 014/104] Take this shit --- .../casino/GameInterface.java | 1 + .../casino/games/slots/Slots.java | 56 ++++++++++++++++++- .../casino/games/slots/SlotsGame.java | 37 +++++++++++- .../github/zipcodewilmington/SlotsTest.java | 35 ++++++++++++ 4 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/github/zipcodewilmington/SlotsTest.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java index 4f5e662c5..4f2fc095d 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java +++ b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java @@ -37,4 +37,5 @@ public interface GameInterface extends Runnable { * Add winnings amount to player's balance */ void addMoneyToBalance(PlayerInterface Player, Double winnings); + } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java index 4c0543226..5e0d02d54 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java @@ -3,9 +3,59 @@ import java.util.List; public class Slots { - private static String[] slotItems = {"Peach", "Cherry", "Diamond", "Plum", "Seven", "Nine"}; - String[][] slots = new String[3][3]; - public void spinSlots(){ + private static final String[] slotItems = {"Peach", "Cherry", "Diamond", "Plum", "Seven", "Nine"}; + private String[][] slots = new String[3][3]; + + public Slots(){ + this.slots = new String[][] { + {"Peach", "Cherry", "Diamond"}, + {"Diamond", "Plum", "Nine"}, + {"Seven", "Peach", "Diamond"}}; + } + + public String[][] getSlots() { + return slots; } + + +// public void spinSlots(){ +// for(String[] slot: slots){ +// slot[0] = randomSlotItem(); +// slot[1] = randomSlotItem(); +// slot[2] = ramdomSlotItem(); +// } +// } + + public static String ramdomSlotItem(){ + int input = (int) ((Math.random() * (7 - 1)) + 1); + String result; + switch(input){ + case 1: + result = slotItems[0]; + break; + case 2: + result = slotItems[1]; + break; + case 3: + result = slotItems[2]; + break; + case 4: + result = slotItems[3]; + break; + case 5: + result = slotItems[4]; + break; + case 6: + result = slotItems[5]; + break; + default: + throw new IllegalStateException("Unexpected value: " + input); + } + return result; + } + + + + } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index 2f3740d50..3a64e690b 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -1,9 +1,44 @@ package com.github.zipcodewilmington.casino.games.slots; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; + /** * Created by Nathan on 7/12/21 */ -public class SlotsGame { +public class SlotsGame implements GameInterface { + private static String[] slotItems = {"Peach", "Cherry", "Diamond", "Plum", "Seven", "Nine"}; + private String[][] slots = new String[3][3]; + + + + @Override + public void add(PlayerInterface player) { + + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public void run() { + + } + + @Override + public Double calculateWinnings(Double betAmount) { + return null; + } + + @Override + public void subtractBetFromBalance(Double betAmount) { + + } + @Override + public void addMoneyToBalance(PlayerInterface Player, Double winnings) { + } } diff --git a/src/test/java/com/github/zipcodewilmington/SlotsTest.java b/src/test/java/com/github/zipcodewilmington/SlotsTest.java new file mode 100644 index 000000000..0dc8cd614 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/SlotsTest.java @@ -0,0 +1,35 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.games.slots.Slots; +import org.junit.Assert; +import org.junit.Test; + +public class SlotsTest { + + @Test + public void slotConstructorTest(){ + //given + String[][] expected = { + {"Peach", "Cherry", "Diamond"}, + {"Diamond", "Plum", "Nine"}, + {"Seven", "Peach", "Diamond"}}; + //when + Slots slot = new Slots(); + String[][] retrieved = slot.getSlots(); + //then + Assert.assertEquals(expected, retrieved); + } + + @Test + public void randomItemTest(){ + //given + String[] given = {"Peach", "Cherry", "Diamond"}; + String[] retrieved = new String[3]; + //when + for(String element: retrieved){ + element = Slots.ramdomSlotItem(); //Not updating retrieved + } + //then + Assert.assertFalse(given.equals(retrieved)); + } +} From 151543fd6852530bcb8bec6e00a2aaaccb0da25d Mon Sep 17 00:00:00 2001 From: Nathan Date: Tue, 13 Jul 2021 15:10:45 -0400 Subject: [PATCH 015/104] SLOTS SLOTS SLOTS --- .../casino/GameInterface.java | 2 +- .../casino/games/Beetle/BeetleGame.java | 4 ++-- .../casino/games/blackjack/BlackJack.java | 2 +- .../casino/games/slots/Slots.java | 17 ++++++++++------- .../casino/games/slots/SlotsGame.java | 2 +- .../github/zipcodewilmington/SlotsTest.java | 18 +++++++++++++++--- 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java index 4f2fc095d..1e825b192 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java +++ b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java @@ -26,7 +26,7 @@ public interface GameInterface extends Runnable { * Calculate player's winning payout amount of bet x multiplier * @return (double) amount of money winnings */ - Double calculateWinnings(Double betAmount); + Double calculateWinnings(Double multiplier, Double betAmount); /** * Subtract the bet amount from player's balance diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index 2f21ffe7d..3a889e300 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -35,7 +35,7 @@ public void run(){ * Calculate player's winning payout amount of bet x multiplier * @return (double) amount of money winnings */ - public Double calculateWinnings(Double betAmount){ + public Double calculateWinnings(Double multiplier, Double betAmount){ return 0.00; } @@ -55,7 +55,7 @@ public void addMoneyToBalance(PlayerInterface Player, Double winnings){ } public void initGame(){ - this.game = new Beetle(this.players.length); + this.game = new Beetle(this.players.size()); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java index 48beee802..9b0abd156 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -71,7 +71,7 @@ public void run() { } @Override - public Double calculateWinnings(Double betAmount) { + public Double calculateWinnings(Double multiplier, Double betAmount) { return null; } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java index 5e0d02d54..b91b62784 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java @@ -1,10 +1,13 @@ package com.github.zipcodewilmington.casino.games.slots; + +import java.util.ArrayList; import java.util.List; public class Slots { private static final String[] slotItems = {"Peach", "Cherry", "Diamond", "Plum", "Seven", "Nine"}; private String[][] slots = new String[3][3]; + private List slotsList = new ArrayList<>(); public Slots(){ this.slots = new String[][] { @@ -18,14 +21,14 @@ public String[][] getSlots() { } + public void spinSlots(){ -// public void spinSlots(){ -// for(String[] slot: slots){ -// slot[0] = randomSlotItem(); -// slot[1] = randomSlotItem(); -// slot[2] = ramdomSlotItem(); -// } -// } + for (int a = 0; a < 3; a++) { + this.slots[a][0] = ramdomSlotItem(); + this.slots[a][1] = ramdomSlotItem(); + this.slots[a][2] = ramdomSlotItem(); + } + } public static String ramdomSlotItem(){ int input = (int) ((Math.random() * (7 - 1)) + 1); diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index 3a64e690b..81a36ff91 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -28,7 +28,7 @@ public void run() { } @Override - public Double calculateWinnings(Double betAmount) { + public Double calculateWinnings(Double multiplier, Double betAmount) { return null; } diff --git a/src/test/java/com/github/zipcodewilmington/SlotsTest.java b/src/test/java/com/github/zipcodewilmington/SlotsTest.java index 0dc8cd614..9dfd492f6 100644 --- a/src/test/java/com/github/zipcodewilmington/SlotsTest.java +++ b/src/test/java/com/github/zipcodewilmington/SlotsTest.java @@ -24,12 +24,24 @@ public void slotConstructorTest(){ public void randomItemTest(){ //given String[] given = {"Peach", "Cherry", "Diamond"}; - String[] retrieved = new String[3]; + String[] retrieved = {"Peach", "Cherry", "Diamond"}; //when - for(String element: retrieved){ - element = Slots.ramdomSlotItem(); //Not updating retrieved + for (int i = 0; i < retrieved.length; i++) { + retrieved[i] = Slots.ramdomSlotItem(); } //then Assert.assertFalse(given.equals(retrieved)); } + + @Test + public void spinSlotsTest(){ + //given + Slots slotMachine = new Slots(); + String[][] given = slotMachine.getSlots(); + //when + slotMachine.spinSlots(); + String[][] retrieved = slotMachine.getSlots(); + //then + Assert.assertFalse(given.equals(retrieved)); + } } From c920eee14a51bf4333bea092628bca61c0e4c5e4 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Jul 2021 15:11:34 -0400 Subject: [PATCH 016/104] 21 21 21 --- .../casino/GameInterface.java | 2 +- .../casino/games/Beetle/BeetleGame.java | 4 +- .../casino/games/blackjack/BlackJack.java | 33 +++++++++++---- .../casino/games/slots/SlotsGame.java | 2 +- .../zipcodewilmington/casino/models/Card.java | 27 ++++-------- .../zipcodewilmington/BlackJackTest.java | 42 +++++++++++++++++-- .../github/zipcodewilmington/CardsTest.java | 15 ++++--- 7 files changed, 85 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java index 4f2fc095d..1e825b192 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java +++ b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java @@ -26,7 +26,7 @@ public interface GameInterface extends Runnable { * Calculate player's winning payout amount of bet x multiplier * @return (double) amount of money winnings */ - Double calculateWinnings(Double betAmount); + Double calculateWinnings(Double multiplier, Double betAmount); /** * Subtract the bet amount from player's balance diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index 2f21ffe7d..3a889e300 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -35,7 +35,7 @@ public void run(){ * Calculate player's winning payout amount of bet x multiplier * @return (double) amount of money winnings */ - public Double calculateWinnings(Double betAmount){ + public Double calculateWinnings(Double multiplier, Double betAmount){ return 0.00; } @@ -55,7 +55,7 @@ public void addMoneyToBalance(PlayerInterface Player, Double winnings){ } public void initGame(){ - this.game = new Beetle(this.players.length); + this.game = new Beetle(this.players.size()); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java index 48beee802..7b7278932 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -8,20 +8,19 @@ import java.util.*; public class BlackJack implements GameInterface, PlayerInterface { - Card card = new Card(); List playersHand; List dealersHand; - Deque deckOfCards = new LinkedList<>(generateNewDeck(52)); + Deque deckOfCards; + Double betAmount; // Equal to user input public BlackJack () { this.playersHand = new ArrayList<>(); this.dealersHand = new ArrayList<>(); + this.deckOfCards = new ArrayDeque<>(generateNewDeck()); } - public List generateNewDeck (Integer numberOfCards) { - card.createDeck(numberOfCards); - card.polishDeck(); - card.shuffleDeck(); + public List generateNewDeck () { + Card card = new Card(); return card.getCardPool(); } @@ -31,7 +30,14 @@ public List givePlayerCard () { return this.playersHand; } + public List giveDealerCard () { + Integer valueOfCard = deckOfCards.pop(); + this.dealersHand.add(valueOfCard); + return this.dealersHand; + } + public Integer playersCurrentValue () { + givePlayerCard(); Integer sum = 0; for (int i = 0; i < this.playersHand.size(); i++) { sum += this.playersHand.get(i); @@ -39,6 +45,19 @@ public Integer playersCurrentValue () { return sum; } + public Integer dealersCurrentValue () { + giveDealerCard(); + Integer sum = 0; + for (int i = 0; i < this.dealersHand.size(); i++) { + sum += this.dealersHand.get(i); + } + return sum; + } + + public void playerBroke21 () { + + } + public List getPlayersHand() { return playersHand; } @@ -71,7 +90,7 @@ public void run() { } @Override - public Double calculateWinnings(Double betAmount) { + public Double calculateWinnings(Double multiplier, Double betAmount) { return null; } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index 3a64e690b..81a36ff91 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -28,7 +28,7 @@ public void run() { } @Override - public Double calculateWinnings(Double betAmount) { + public Double calculateWinnings(Double multiplier, Double betAmount) { return null; } diff --git a/src/main/java/com/github/zipcodewilmington/casino/models/Card.java b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java index 091142af6..2a4def12d 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/models/Card.java +++ b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java @@ -4,28 +4,27 @@ public class Card { List cardPool; - Integer numberOfCards; // The deck will be made of - public Card () { - this.numberOfCards = 52; + public Card() { this.cardPool = new ArrayList<>(); - this.createDeck(numberOfCards); + this.createDeck(); + this.polishDeck(); + this.shuffleDeck(); } // Alter the loop to provide the correct amount of 10's // Jack/Queen/King // Should have 16 - 10 values in a 52 deck - public List createDeck (Integer numberOfCards) { - for (int i = 0; i <= 4; i++) { - for (int j = 2; j < (numberOfCards / 4); j++) { + public void createDeck() { + for (int i = 0; i < 4; i++) { + for (int j = 2; j < 15; j++) { this.cardPool.add(j); } } - return this.cardPool; } - public void polishDeck () { + public void polishDeck() { for (int i = 0; i < this.cardPool.size(); i++) { if (this.cardPool.get(i) > 11) { this.cardPool.set(i, 10); @@ -33,7 +32,7 @@ public void polishDeck () { } } - public void shuffleDeck () { + public void shuffleDeck() { Collections.shuffle(this.cardPool); } @@ -44,12 +43,4 @@ public List getCardPool() { public void setCardPool(List cardPool) { this.cardPool = cardPool; } - - public Integer getNumberOfCards() { - return numberOfCards; - } - - public void setNumberOfCards(Integer numberOfCards) { - this.numberOfCards = numberOfCards; - } } diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackTest.java index b17361a7e..60ae907a9 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackTest.java @@ -12,8 +12,8 @@ public void generateNewDeckTest() { BlackJack bj = new BlackJack(); Integer expected = 165; - Integer actual1 = bj.generateNewDeck(52).size(); - List actual = bj.generateNewDeck(52); + Integer actual1 = bj.generateNewDeck().size(); + List actual = bj.generateNewDeck(); System.out.println(actual); Assert.assertEquals(expected, actual1); @@ -32,9 +32,45 @@ public void givePlayerCardTest() { Assert.assertEquals(expected, actual); } + @Test + public void giveDealerCardTest () { + BlackJack bj = new BlackJack(); + Integer expected = 2; + + bj.giveDealerCard(); + bj.giveDealerCard(); + Integer actual = bj.getDealersHand().size(); + + System.out.println(bj.getDealersHand()); + Assert.assertEquals(expected, actual); + } + @Test public void playersCurrentValueTest () { BlackJack bj = new BlackJack(); - // Solid stopping point = need to populate array for test + List expected = bj.getPlayersHand(); + + bj.playersCurrentValue(); + Integer actual = bj.playersCurrentValue(); + + System.out.println(expected); + System.out.println(actual); + } + + @Test + public void dealersCurrentValueTest () { + BlackJack bj = new BlackJack(); + List expected = bj.getDealersHand(); + + bj.dealersCurrentValue(); + Integer actual = bj.dealersCurrentValue(); + + System.out.println(expected); + System.out.println(actual); + } + + @Test + public void playerBroke21Test () { + } } diff --git a/src/test/java/com/github/zipcodewilmington/CardsTest.java b/src/test/java/com/github/zipcodewilmington/CardsTest.java index d5e0d1e93..490a5e821 100644 --- a/src/test/java/com/github/zipcodewilmington/CardsTest.java +++ b/src/test/java/com/github/zipcodewilmington/CardsTest.java @@ -12,7 +12,7 @@ public void constructorTest () { Integer expected = 52; Card card = new Card(); - Integer actual = card.getNumberOfCards(); + Integer actual = card.getCardPool().size(); Assert.assertEquals(expected, actual); } @@ -20,19 +20,19 @@ public void constructorTest () { @Test public void createDeckTest () { // Given - Card card = new Card(); - Integer expected = 52; - Integer actual = card.getNumberOfCards(); + + Card card = new Card(); + Integer actual = card.getCardPool().size(); Assert.assertEquals(expected, actual); + } @Test public void polishDeckTest () { Card card = new Card(); - card.createDeck(52); card.polishDeck(); System.out.println(card.getCardPool().size()); System.out.println(card.getCardPool()); @@ -43,9 +43,8 @@ public void polishDeckTest () { public void shuffleDeckTest () { Card card = new Card(); -// List result = card.shuffleDeck(); - -// System.out.println(result); // Visual test + System.out.println(card.getCardPool().size()); + System.out.println(card.getCardPool()); // Visual test } @Test From 38df35b23aa548e6e989c5f5330cbc9b86f79aeb Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Jul 2021 15:39:58 -0400 Subject: [PATCH 017/104] Setting up my branch --- .../casino/games/blackjack/BlackJack.java | 18 +++++++++++++++++- .../zipcodewilmington/BlackJackTest.java | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java index 7b7278932..4e08ad9dc 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -55,7 +55,23 @@ public Integer dealersCurrentValue () { } public void playerBroke21 () { - + if (playersCurrentValue() > 21) { + subtractBetFromBalance(betAmount); + } + } + + public void playerBlackJack () { + if (playersCurrentValue() == 21) { + calculateWinnings(3.0, betAmount); + } + } + + public void dealerConditions () { + if (dealersCurrentValue() > 21) { + calculateWinnings(2.0, betAmount); //Players winnings, not dealers (Player won) + } else if (dealersCurrentValue() <= 21 && dealersCurrentValue() > playersCurrentValue()) { + subtractBetFromBalance(betAmount); + } } public List getPlayersHand() { diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackTest.java index 60ae907a9..5c84f980e 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackTest.java @@ -70,7 +70,7 @@ public void dealersCurrentValueTest () { } @Test - public void playerBroke21Test () { + public void playerBroke21orBlackJackTest () { } } From 9c740362444bd7048540510c169f33c068d313af Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Jul 2021 16:06:17 -0400 Subject: [PATCH 018/104] what --- .../zipcodewilmington/casino/games/blackjack/BlackJack.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java index 9b0abd156..b22c4c04e 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -39,6 +39,8 @@ public Integer playersCurrentValue () { return sum; } + public void ahhWork () {} + public List getPlayersHand() { return playersHand; } From 079ecb13b6288d28cd0ed02e05001bd99d36c6b1 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Jul 2021 16:26:38 -0400 Subject: [PATCH 019/104] pushin for the cushion --- .../zipcodewilmington/casino/games/blackjack/BlackJack.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java index 48beee802..da3e91336 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -39,6 +39,10 @@ public Integer playersCurrentValue () { return sum; } + public void pleaseWork () { + + } + public List getPlayersHand() { return playersHand; } From 698fc050edba26fb1341c05a612dd16fc1b01793 Mon Sep 17 00:00:00 2001 From: Nathan Date: Tue, 13 Jul 2021 16:32:38 -0400 Subject: [PATCH 020/104] Solved some problems --- .../casino/games/slots/Slots.java | 42 +++++++------------ .../github/zipcodewilmington/SlotsTest.java | 29 +++++++++++++ 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java index b91b62784..dec1ba30d 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java @@ -2,6 +2,8 @@ import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; public class Slots { @@ -20,44 +22,32 @@ public String[][] getSlots() { return slots; } + public void setSlots(String[][] slots) { + this.slots = slots; + } public void spinSlots(){ - + String[][] newSlot = new String[3][3]; for (int a = 0; a < 3; a++) { - this.slots[a][0] = ramdomSlotItem(); - this.slots[a][1] = ramdomSlotItem(); - this.slots[a][2] = ramdomSlotItem(); + newSlot[a][0] = ramdomSlotItem(); + newSlot[a][1] = ramdomSlotItem(); + newSlot[a][2] = ramdomSlotItem(); } + setSlots(newSlot); } public static String ramdomSlotItem(){ int input = (int) ((Math.random() * (7 - 1)) + 1); String result; - switch(input){ - case 1: - result = slotItems[0]; - break; - case 2: - result = slotItems[1]; - break; - case 3: - result = slotItems[2]; - break; - case 4: - result = slotItems[3]; - break; - case 5: - result = slotItems[4]; - break; - case 6: - result = slotItems[5]; - break; - default: - throw new IllegalStateException("Unexpected value: " + input); - } + result = slotItems[input -1]; return result; } + public static void findWinnings(){ + //HashMap; + + } + diff --git a/src/test/java/com/github/zipcodewilmington/SlotsTest.java b/src/test/java/com/github/zipcodewilmington/SlotsTest.java index 9dfd492f6..97f2fa7c5 100644 --- a/src/test/java/com/github/zipcodewilmington/SlotsTest.java +++ b/src/test/java/com/github/zipcodewilmington/SlotsTest.java @@ -20,6 +20,35 @@ public void slotConstructorTest(){ Assert.assertEquals(expected, retrieved); } + @Test + public void setSlotTest(){ + //given + Slots slot = new Slots(); + String[][] given = { + {"Cherry", "Cherry", "Cherry"}, + {"Diamond", "Plum", "Nine"}, + {"Seven", "Peach", "Diamond"}}; + //when + slot.setSlots(given); + String[][] retrieved = slot.getSlots(); + //then + Assert.assertEquals(given,retrieved); + } + + @Test + public void getSlotTest(){ + //given + String[][] expected = { + {"Peach", "Cherry", "Diamond"}, + {"Diamond", "Plum", "Nine"}, + {"Seven", "Peach", "Diamond"}}; + //when + Slots slot = new Slots(); + String[][] retrieved = slot.getSlots(); + //then + Assert.assertEquals(expected, retrieved); + } + @Test public void randomItemTest(){ //given From 13561fdffd5a7624fc80edcf7943c6a78cb9e08f Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Jul 2021 16:37:02 -0400 Subject: [PATCH 021/104] uhh --- src/test/java/com/github/zipcodewilmington/BlackJackTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackTest.java index b17361a7e..a81fc753d 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackTest.java @@ -36,5 +36,8 @@ public void givePlayerCardTest() { public void playersCurrentValueTest () { BlackJack bj = new BlackJack(); // Solid stopping point = need to populate array for test + bj.givePlayerCard(); + bj.givePlayerCard(); + System.out.println(bj.playersCurrentValue()); } } From 96fa77edc8460ee7944262bd0dda2ed4373b8615 Mon Sep 17 00:00:00 2001 From: Zach Date: Tue, 13 Jul 2021 16:52:43 -0400 Subject: [PATCH 022/104] testing --- .../zipcodewilmington/casino/games/Beetle/BeetleGame.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index 3a889e300..ff6f24938 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -31,6 +31,9 @@ public void run(){ } } + public String test(){ + return ""; + } /** * Calculate player's winning payout amount of bet x multiplier * @return (double) amount of money winnings From c4d34c35bdfa815b819a756511e3bc21e1bcadd8 Mon Sep 17 00:00:00 2001 From: Nathan Date: Tue, 13 Jul 2021 16:53:45 -0400 Subject: [PATCH 023/104] Edited BeetleGame --- .../casino/games/Beetle/BeetleGame.java | 2 +- .../zipcodewilmington/casino/games/slots/Slots.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index ff6f24938..a00b9b9c1 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -32,7 +32,7 @@ public void run(){ } public String test(){ - return ""; + return "NATHAN WAS HERE"; } /** * Calculate player's winning payout amount of bet x multiplier diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java index dec1ba30d..970289ee9 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java @@ -44,7 +44,16 @@ public static String ramdomSlotItem(){ } public static void findWinnings(){ - //HashMap; + HashMap winningLines = new HashMap<>(); + winningLines.put(1,"Lose"); + winningLines.put(2,"Lose"); + winningLines.put(3,"Lose"); + winningLines.put(4,"Lose"); + winningLines.put(5,"Lose"); + winningLines.put(6,"Lose"); + winningLines.put(7,"Lose"); + + } From b7067a74c00ebe7f2eab99378fa02447fa4365c3 Mon Sep 17 00:00:00 2001 From: Jarryd Stamatelos Date: Tue, 13 Jul 2021 18:42:36 -0400 Subject: [PATCH 024/104] feat(black-jack): update readme for example --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index d2512752a..3305b41c6 100644 --- a/README.md +++ b/README.md @@ -73,3 +73,8 @@ * from the browser, navigate to the _forked_ project from **your** github account. * click the `Pull Requests` tab. * select `New Pull Request` + + + + +## Adding a line to the readMe for git hub example From c3a89cc7766bdcdfd7b327050883b3e09942e72e Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Tue, 13 Jul 2021 18:53:28 -0400 Subject: [PATCH 025/104] Dev (#16) * what * pushin for the cushion * feat(black-jack): update readme for example Co-authored-by: Nick Co-authored-by: NicholasWolak <85853075+NicholasWolak@users.noreply.github.com> Co-authored-by: Jarryd Stamatelos --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index d2512752a..3305b41c6 100644 --- a/README.md +++ b/README.md @@ -73,3 +73,8 @@ * from the browser, navigate to the _forked_ project from **your** github account. * click the `Pull Requests` tab. * select `New Pull Request` + + + + +## Adding a line to the readMe for git hub example From 56a1db9d36e941089afb4f50aaf82311f2c1b574 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Jul 2021 20:19:03 -0400 Subject: [PATCH 026/104] feat/black-jack update --- .../casino/games/blackjack/BlackJack.java | 71 +++---------- .../casino/games/blackjack/BlackJackGame.java | 100 ++++++++++++++++++ 2 files changed, 117 insertions(+), 54 deletions(-) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java index 4e08ad9dc..e09810a4c 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -7,14 +7,15 @@ import java.util.*; -public class BlackJack implements GameInterface, PlayerInterface { +public class BlackJack { List playersHand; + List playersHandOnSplit; List dealersHand; Deque deckOfCards; - Double betAmount; // Equal to user input public BlackJack () { this.playersHand = new ArrayList<>(); + this.playersHandOnSplit = new ArrayList<>(); this.dealersHand = new ArrayList<>(); this.deckOfCards = new ArrayDeque<>(generateNewDeck()); } @@ -30,6 +31,12 @@ public List givePlayerCard () { return this.playersHand; } + public List givePlayerCardOnSplit () { + Integer valueOfCard = deckOfCards.pop(); + this.playersHandOnSplit.add(valueOfCard); + return this.playersHandOnSplit; + } + public List giveDealerCard () { Integer valueOfCard = deckOfCards.pop(); this.dealersHand.add(valueOfCard); @@ -54,23 +61,19 @@ public Integer dealersCurrentValue () { return sum; } - public void playerBroke21 () { + public boolean playerBreaks21 () { if (playersCurrentValue() > 21) { - subtractBetFromBalance(betAmount); + return true; + } else { + return false; } } - public void playerBlackJack () { + public boolean playerHitsBlackJack () { if (playersCurrentValue() == 21) { - calculateWinnings(3.0, betAmount); - } - } - - public void dealerConditions () { - if (dealersCurrentValue() > 21) { - calculateWinnings(2.0, betAmount); //Players winnings, not dealers (Player won) - } else if (dealersCurrentValue() <= 21 && dealersCurrentValue() > playersCurrentValue()) { - subtractBetFromBalance(betAmount); + return true; + } else { + return false; } } @@ -89,44 +92,4 @@ public List getDealersHand() { public void setDealersHand(List dealersHand) { this.dealersHand = dealersHand; } - - @Override - public void add(PlayerInterface player) { - - } - - @Override - public void remove(PlayerInterface player) { - - } - - @Override - public void run() { - - } - - @Override - public Double calculateWinnings(Double multiplier, Double betAmount) { - return null; - } - - @Override - public void subtractBetFromBalance(Double betAmount) { - - } - - @Override - public void addMoneyToBalance(PlayerInterface Player, Double winnings) { - - } - - @Override - public CasinoAccount getArcadeAccount() { - return null; - } - - @Override - public SomeReturnType play() { - return null; - } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java new file mode 100644 index 000000000..d05746c24 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -0,0 +1,100 @@ +package com.github.zipcodewilmington.casino.games.blackjack; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.utils.IOConsole; + +import java.util.Scanner; + +public class BlackJackGame implements GameInterface, PlayerInterface { + private BlackJack game; + private Boolean isRunning = false; + private PlayerInterface player; + private Double userBet; + IOConsole input = new IOConsole(); + + @Override + public void add(PlayerInterface player) { + + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public void run() { + while(isRunning) { + // include betting range + + BlackJack bj = new BlackJack(); + Integer userInput = input.getIntegerInput("1. Start A Hand" + "\n" + "2. Quit" + "\n"); + + switch (userInput) { + case 1: // include betting forum in case 1 + startGame(); + break; + case 2: + isRunning = true; + } + } + } + + public void startGame () { + BlackJack bj = new BlackJack(); + bj.givePlayerCard(); + System.out.println("Your starting card : " + bj.playersCurrentValue()); + bj.givePlayerCard(); + System.out.println("Your second next card : " + bj.playersCurrentValue()); + boolean isWinner = false; + Integer userChoice = input.getIntegerInput("1. Hit" + "\n" + "2. Stay"); + while (isWinner) { + switch (userChoice) { + case 1: + bj.givePlayerCard(); + bj.playersCurrentValue(); + if(bj.playerBreaks21()) { + System.out.println("Sorry bud, you got " + bj.playersCurrentValue() + + "better luck next time"); + subtractBetFromBalance(userBet); + isWinner = true; + } else if (bj.playerHitsBlackJack()) { + System.out.println("BLACK JACK!!"); + calculateWinnings(3.0, userBet); + isWinner = true; + } + break; + case 2: + + } + } + } + + @Override + public Double calculateWinnings(Double multiplier, Double betAmount) { + return multiplier * betAmount; + } + + @Override + public void subtractBetFromBalance(Double betAmount) { + + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Double winnings) { + + } + + @Override + public CasinoAccount getArcadeAccount() { + return null; + } + + @Override + public SomeReturnType play() { + return null; + } +} From dbda6904574bc29af01a9b35978ef212a3acd518 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Jul 2021 20:43:25 -0400 Subject: [PATCH 027/104] pulling --- .../zipcodewilmington/casino/games/blackjack/BlackJackGame.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index d05746c24..27574d10a 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -68,7 +68,7 @@ public void startGame () { } break; case 2: - + } } } From 412c509f82d74b3b4e090a4e041cc3b888752b18 Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Tue, 13 Jul 2021 20:48:40 -0400 Subject: [PATCH 028/104] CasinoAccount and CasinoAccountManager.java (#19) Co-authored-by: Zach --- .../casino/CasinoAccount.java | 29 +++++++++++++++++++ .../casino/CasinoAccountManager.java | 23 ++++++++++----- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java index 654c749b4..4a4295907 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java @@ -1,9 +1,38 @@ package com.github.zipcodewilmington.casino; +import com.github.zipcodewilmington.Casino; + +import java.util.ArrayList; +import java.util.List; + /** * Created by leon on 7/21/2020. * `ArcadeAccount` is registered for each user of the `Arcade`. * The `ArcadeAccount` is used to log into the system to select a `Game` to play. */ public class CasinoAccount { + private String password; + private String accountName; + + + public CasinoAccount(String accountName, String accountPassword){ + this.accountName = accountName; + this.password = accountPassword; + } + + + + /* + public void setPassword(String password){ + if(this.validPass()){ + if(this.confirmPass()){ + this.password = password; + } else { + + } + } + } + + */ + } diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java index 2d09ec2a0..e1b55bd40 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java @@ -1,11 +1,15 @@ package com.github.zipcodewilmington.casino; +import java.util.ArrayList; +import java.util.List; + /** * Created by leon on 7/21/2020. * `ArcadeAccountManager` stores, manages, and retrieves `ArcadeAccount` objects * it is advised that every instruction in this class is logged */ public class CasinoAccountManager { + private List accountList = new ArrayList(); /** * @param accountName name of account to be returned * @param accountPassword password of account to be returned @@ -26,10 +30,12 @@ public CasinoAccount getAccount(String accountName, String accountPassword) { * @return new instance of `ArcadeAccount` with specified `accountName` and `accountPassword` */ public CasinoAccount createAccount(String accountName, String accountPassword) { - String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); - String currentClassName = getClass().getName(); - String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; - throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); + CasinoAccount myAccount = new CasinoAccount(accountName, accountPassword); + return myAccount; + //String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); + //String currentClassName = getClass().getName(); + //String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; + //throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); } /** @@ -38,9 +44,10 @@ public CasinoAccount createAccount(String accountName, String accountPassword) { * @param casinoAccount the arcadeAccount to be added to `this.getArcadeAccountList()` */ public void registerAccount(CasinoAccount casinoAccount) { - String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); - String currentClassName = getClass().getName(); - String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; - throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); + this.accountList.add(casinoAccount); + //String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); + //String currentClassName = getClass().getName(); + //String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; + //throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); } } From 36b2994354f8ad08142e2caad89d2cddcc047103 Mon Sep 17 00:00:00 2001 From: Dipinti Date: Tue, 13 Jul 2021 21:14:05 -0400 Subject: [PATCH 029/104] plinkogame and plinkotest done --- .../casino/games/plinko/PlinkoGame.java | 100 ++++++++++++++++++ .../github/zipcodewilmington/PlinkoTest.java | 44 ++++++++ 2 files changed, 144 insertions(+) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java create mode 100644 src/test/java/com/github/zipcodewilmington/PlinkoTest.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java new file mode 100644 index 000000000..c9fc6140a --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java @@ -0,0 +1,100 @@ +package com.github.zipcodewilmington.casino.games.plinko; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +public class PlinkoGame implements GameInterface,PlayerInterface { + private Map moneyGenerator=new HashMap(); + public int initialPosition; + private double betAmount; + public int randomNumber; + + public PlinkoGame(int initialPosition){ + this.initialPosition=initialPosition; + } + + public String playPlinko(int initialPosition){ + if(initialPosition<10 && initialPosition>0){ + int max=9; + int min=1; + Random rand = new Random(); + int randomNumber=rand.nextInt(max - min + 1) + min; + return String.valueOf(randomNumber); + } + else + return "Invalid Entry"; + } + + @Override + public void add(PlayerInterface player) { + + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public void run() { + if (initialPosition < 10 && initialPosition > 0) { + int max = 9; + int min = 1; + Random rand = new Random(); + randomNumber = rand.nextInt(max - min + 1) + min; + System.out.println("Now your position is: " + randomNumber); + } + else + { + System.out.println("Invalid Entry"); + } + } + + @Override + public Double calculateWinnings(Double multiplier, Double betAmount) { + moneyGenerator.put(1,200.00); + moneyGenerator.put(2,0.00); + moneyGenerator.put(3,3000.00); + moneyGenerator.put(4,30.50); + moneyGenerator.put(5,0.00); + moneyGenerator.put(6,0.00); + moneyGenerator.put(7,1.00); + moneyGenerator.put(8,750.50); + moneyGenerator.put(9,0.00); + Double moneyWon=0.0; + for (Integer pos:moneyGenerator.keySet()) + { + if(pos.equals(randomNumber)){ + moneyWon=moneyGenerator.get(pos); + } + } + return moneyWon; + } + + + @Override + public void subtractBetFromBalance(Double betAmount) { + + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Double winnings) { + + } + + @Override + public CasinoAccount getArcadeAccount() { + return null; + } + + @Override + public SomeReturnType play() { + return null; + } +} + diff --git a/src/test/java/com/github/zipcodewilmington/PlinkoTest.java b/src/test/java/com/github/zipcodewilmington/PlinkoTest.java new file mode 100644 index 000000000..8596899de --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/PlinkoTest.java @@ -0,0 +1,44 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.games.plinko.PlinkoGame; +import org.junit.Assert; +import org.junit.Test; + +public class PlinkoTest { + + @Test + public void testCalculateWinnings() { + //given + Double expectedValue=0.0; + PlinkoGame plinkoGame=new PlinkoGame(7); + plinkoGame.run(); + //when + Double actualValue=plinkoGame.calculateWinnings(2.00,200.00); + //then + System.out.println(actualValue); + Assert.assertEquals(expectedValue,actualValue); + } + + @Test + public void testConstructor(){ + //given + int expectedValue=8; + //when + PlinkoGame plinkoGame=new PlinkoGame(8); + int actualValue=plinkoGame.initialPosition; + //then + Assert.assertEquals(expectedValue,actualValue); + } + + @Test + public void testPlayPlinko(){ + //given + String expectedValue="Invalid Entry"; + //when + PlinkoGame plinkoGame=new PlinkoGame(10); + String actualValue=plinkoGame.playPlinko(10); + //then + Assert.assertFalse(expectedValue, Boolean.parseBoolean(actualValue)); + } +} + From 215c282dea0773bd7aa0b3a7ddaf24f06beed64c Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Tue, 13 Jul 2021 21:14:18 -0400 Subject: [PATCH 030/104] Feature/casino account (#20) * CasinoAccount and CasinoAccountManager.java * updated CasinoAccount, CasinoAccountManager and Casino java files Co-authored-by: Zach --- .../com/github/zipcodewilmington/Casino.java | 2 +- .../zipcodewilmington/casino/CasinoAccount.java | 17 ++++++----------- .../casino/CasinoAccountManager.java | 10 ++++++++++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index 5eae9ac0c..72e424327 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -42,7 +42,7 @@ public void run() { } else { // TODO - implement better exception handling String errorMessage = "No account found with name of [ %s ] and password of [ %s ]"; - throw new RuntimeException(String.format(errorMessage, accountPassword, accountName)); + //throw new RuntimeException(String.format(errorMessage, accountPassword, accountName)); } } else if ("create-account".equals(arcadeDashBoardInput)) { console.println("Welcome to the account-creation screen."); diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java index 4a4295907..580cf89b1 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java @@ -21,18 +21,13 @@ public CasinoAccount(String accountName, String accountPassword){ } - - /* - public void setPassword(String password){ - if(this.validPass()){ - if(this.confirmPass()){ - this.password = password; - } else { - - } - } +feature/CasinoAccount + public String getPassword() { + return password; } - */ + public String getAccountName() { + return accountName; + } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java index e1b55bd40..459c69af5 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java @@ -16,6 +16,16 @@ public class CasinoAccountManager { * @return `ArcadeAccount` with specified `accountName` and `accountPassword` */ public CasinoAccount getAccount(String accountName, String accountPassword) { + for(int i = 0; i < accountList.size(); i++){ + CasinoAccount currentAccount = accountList.get(i); + if(currentAccount.getAccountName() == accountName && + currentAccount.getPassword() == accountPassword){ + return currentAccount; + } else { + System.out.println("Account Name or Password does not match. Are you really you?"); + return null; + } + } String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); String currentClassName = getClass().getName(); String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; From a2018af0a715baab598acf924b96708a3ff302f5 Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Tue, 13 Jul 2021 21:24:07 -0400 Subject: [PATCH 031/104] Feature/casino account (#21) * CasinoAccount and CasinoAccountManager.java * updated CasinoAccount, CasinoAccountManager and Casino java files Co-authored-by: Zach From 71abb548dac44b6e74f87a8ec3c29ffba6aac537 Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Tue, 13 Jul 2021 21:27:02 -0400 Subject: [PATCH 032/104] pulling (#22) Co-authored-by: Nick --- .../zipcodewilmington/casino/games/blackjack/BlackJackGame.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index d05746c24..27574d10a 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -68,7 +68,7 @@ public void startGame () { } break; case 2: - + } } } From 5c5161361875087fd6dcae4cb98282d05955ff73 Mon Sep 17 00:00:00 2001 From: Dipinti Date: Tue, 13 Jul 2021 21:29:59 -0400 Subject: [PATCH 033/104] plinko.java is ready --- .../com/github/zipcodewilmington/Casino.java | 2 +- .../zipcodewilmington/casino/CasinoAccount.java | 17 ++++++----------- .../casino/CasinoAccountManager.java | 10 ++++++++++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index 5eae9ac0c..72e424327 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -42,7 +42,7 @@ public void run() { } else { // TODO - implement better exception handling String errorMessage = "No account found with name of [ %s ] and password of [ %s ]"; - throw new RuntimeException(String.format(errorMessage, accountPassword, accountName)); + //throw new RuntimeException(String.format(errorMessage, accountPassword, accountName)); } } else if ("create-account".equals(arcadeDashBoardInput)) { console.println("Welcome to the account-creation screen."); diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java index 4a4295907..580cf89b1 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java @@ -21,18 +21,13 @@ public CasinoAccount(String accountName, String accountPassword){ } - - /* - public void setPassword(String password){ - if(this.validPass()){ - if(this.confirmPass()){ - this.password = password; - } else { - - } - } +feature/CasinoAccount + public String getPassword() { + return password; } - */ + public String getAccountName() { + return accountName; + } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java index e1b55bd40..459c69af5 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java @@ -16,6 +16,16 @@ public class CasinoAccountManager { * @return `ArcadeAccount` with specified `accountName` and `accountPassword` */ public CasinoAccount getAccount(String accountName, String accountPassword) { + for(int i = 0; i < accountList.size(); i++){ + CasinoAccount currentAccount = accountList.get(i); + if(currentAccount.getAccountName() == accountName && + currentAccount.getPassword() == accountPassword){ + return currentAccount; + } else { + System.out.println("Account Name or Password does not match. Are you really you?"); + return null; + } + } String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); String currentClassName = getClass().getName(); String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; From 278a0ca87fa271bda212aa66449fd5fd62bf0f7b Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Tue, 13 Jul 2021 21:36:11 -0400 Subject: [PATCH 034/104] Feature/casino account (#23) * CasinoAccount and CasinoAccountManager.java * updated CasinoAccount, CasinoAccountManager and Casino java files Co-authored-by: Zach From 248f47f2b724f57c0db4a61ff1106907b11a1623 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Jul 2021 21:44:43 -0400 Subject: [PATCH 035/104] (feat:black-jack) game logic completed, need refinment and bet input --- .../casino/games/blackjack/BlackJack.java | 24 +++++++++++++++++++ .../casino/games/blackjack/BlackJackGame.java | 15 ++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java index e09810a4c..5f16b25b1 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -12,6 +12,8 @@ public class BlackJack { List playersHandOnSplit; List dealersHand; Deque deckOfCards; + BlackJackGame theGame = new BlackJackGame(); + boolean gameEnd = false; public BlackJack () { this.playersHand = new ArrayList<>(); @@ -61,6 +63,28 @@ public Integer dealersCurrentValue () { return sum; } + public void dealersGame () { + while(!gameEnd) { + System.out.println("The dealer has : " + dealersCurrentValue()); + if (dealersCurrentValue() > 21) { + System.out.println("You win!"); + theGame.calculateWinnings(2.0, theGame.userBet); + gameEnd = true; + } else if (dealersCurrentValue() == 21) { + System.out.println("The dealer has won!"); + theGame.subtractBetFromBalance(theGame.userBet); + gameEnd = true; + } else if (dealersCurrentValue() > playersCurrentValue()) { + System.out.println("The dealer has won!"); + theGame.subtractBetFromBalance(theGame.userBet); + gameEnd = true; + } else { + giveDealerCard(); + System.out.println("The dealer has : " + dealersCurrentValue()); + } + } + } + public boolean playerBreaks21 () { if (playersCurrentValue() > 21) { return true; diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index 27574d10a..66c53e156 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -12,8 +12,9 @@ public class BlackJackGame implements GameInterface, PlayerInterface { private BlackJack game; private Boolean isRunning = false; private PlayerInterface player; - private Double userBet; + Double userBet; IOConsole input = new IOConsole(); + boolean isWinner = false; @Override public void add(PlayerInterface player) { @@ -49,9 +50,8 @@ public void startGame () { System.out.println("Your starting card : " + bj.playersCurrentValue()); bj.givePlayerCard(); System.out.println("Your second next card : " + bj.playersCurrentValue()); - boolean isWinner = false; Integer userChoice = input.getIntegerInput("1. Hit" + "\n" + "2. Stay"); - while (isWinner) { + while (!isWinner) { switch (userChoice) { case 1: bj.givePlayerCard(); @@ -68,9 +68,14 @@ public void startGame () { } break; case 2: - - } + bj.giveDealerCard(); + System.out.println("The dealers first card : " + bj.dealersCurrentValue()); + bj.giveDealerCard(); + System.out.println("The dealer has : " + bj.dealersCurrentValue()); + bj.dealersGame(); + break; } + } } @Override From eb43adc5aea6f2808ae5192219035b42dfc3e7ff Mon Sep 17 00:00:00 2001 From: tnguyen1912 Date: Tue, 13 Jul 2021 22:17:36 -0400 Subject: [PATCH 036/104] Feature/slots (#24) * new feature incoming * 950 attempt Co-authored-by: Nathan Co-authored-by: ZachSinger <32113115+ZachSinger@users.noreply.github.com> --- .../casino/CasinoAccount.java | 1 + .../casino/GameInterface.java | 6 +- .../casino/games/Beetle/BeetleGame.java | 15 +++++ .../casino/games/blackjack/BlackJack.java | 52 +++++++++++++++ .../casino/games/slots/Slots.java | 64 ++++++++++++++----- .../casino/games/slots/SlotsGame.java | 14 ++-- .../github/zipcodewilmington/SlotsTest.java | 57 +++++++++++++++++ 7 files changed, 184 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java index 580cf89b1..cd2f4bb82 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java @@ -21,6 +21,7 @@ public CasinoAccount(String accountName, String accountPassword){ } + feature/CasinoAccount public String getPassword() { return password; diff --git a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java index 1e825b192..01ddd0568 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java +++ b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java @@ -26,16 +26,16 @@ public interface GameInterface extends Runnable { * Calculate player's winning payout amount of bet x multiplier * @return (double) amount of money winnings */ - Double calculateWinnings(Double multiplier, Double betAmount); + Integer calculateWinnings(Integer multiplier, Integer betAmount); /** * Subtract the bet amount from player's balance */ - void subtractBetFromBalance(Double betAmount); + void subtractBetFromBalance(Integer betAmount); /** * Add winnings amount to player's balance */ - void addMoneyToBalance(PlayerInterface Player, Double winnings); + void addMoneyToBalance(PlayerInterface Player, Integer winnings); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index a00b9b9c1..cbc91fb07 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -31,6 +31,21 @@ public void run(){ } } + @Override + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return null; + } + + @Override + public void subtractBetFromBalance(Integer betAmount) { + + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + + } + public String test(){ return "NATHAN WAS HERE"; } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java index e09810a4c..24374b05e 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -13,6 +13,8 @@ public class BlackJack { List dealersHand; Deque deckOfCards; + Integer betAmount; // Equal to user input + public BlackJack () { this.playersHand = new ArrayList<>(); this.playersHandOnSplit = new ArrayList<>(); @@ -71,6 +73,15 @@ public boolean playerBreaks21 () { public boolean playerHitsBlackJack () { if (playersCurrentValue() == 21) { + calculateWinnings(3, betAmount); + } + } + + public void dealerConditions () { + if (dealersCurrentValue() > 21) { + calculateWinnings(2, betAmount); //Players winnings, not dealers (Player won) + } else if (dealersCurrentValue() <= 21 && dealersCurrentValue() > playersCurrentValue()) { + subtractBetFromBalance(betAmount); return true; } else { return false; @@ -92,4 +103,45 @@ public List getDealersHand() { public void setDealersHand(List dealersHand) { this.dealersHand = dealersHand; } + + @Override + public void add(PlayerInterface player) { + + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public void run() { + + } + + @Override + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return null; + } + + @Override + public void subtractBetFromBalance(Integer betAmount) { + + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + + } + + @Override + public CasinoAccount getArcadeAccount() { + return null; + } + + @Override + public SomeReturnType play() { + return null; + } + } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java index 970289ee9..ebbfe37ad 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java @@ -1,21 +1,32 @@ package com.github.zipcodewilmington.casino.games.slots; - -import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; -import java.util.List; + public class Slots { private static final String[] slotItems = {"Peach", "Cherry", "Diamond", "Plum", "Seven", "Nine"}; private String[][] slots = new String[3][3]; - private List slotsList = new ArrayList<>(); + private HashMap winningLines = new HashMap<>(); + + public Slots(String[][] slots) { + //this.winningLines = new HashMap<>(); + this.slots = slots; + initializeWinningLines(); + } public Slots(){ + //this.winningLines = new HashMap<>(); this.slots = new String[][] { {"Peach", "Cherry", "Diamond"}, {"Diamond", "Plum", "Nine"}, {"Seven", "Peach", "Diamond"}}; + initializeWinningLines(); + } + + private void initializeWinningLines(){ + for (int i = 1; i < 9; i++) { + winningLines.put(i, "LOSE"); + } } public String[][] getSlots() { @@ -26,6 +37,10 @@ public void setSlots(String[][] slots) { this.slots = slots; } + public HashMap getWinningLines() { + return winningLines; + } + public void spinSlots(){ String[][] newSlot = new String[3][3]; for (int a = 0; a < 3; a++) { @@ -43,18 +58,35 @@ public static String ramdomSlotItem(){ return result; } - public static void findWinnings(){ - HashMap winningLines = new HashMap<>(); - winningLines.put(1,"Lose"); - winningLines.put(2,"Lose"); - winningLines.put(3,"Lose"); - winningLines.put(4,"Lose"); - winningLines.put(5,"Lose"); - winningLines.put(6,"Lose"); - winningLines.put(7,"Lose"); - - + public void setWinningLines(){ + String[][] currentSlots = this.getSlots(); + HashMap newWinningLines = new HashMap<>(); + for (int i = 0; i < 3; i++) { + //setting horizontally + if(currentSlots[i][0].equals(currentSlots[i][1]) && currentSlots[i][0].equals(currentSlots[i][2])){ + newWinningLines.put((i+1),"WIN"); + } + //setting vertically + if(currentSlots[0][i].equals(currentSlots[1][i]) && currentSlots[2][i].equals(currentSlots[i][2])){ + newWinningLines.put((i+4),"WIN"); + } + } + //setting diagonally + if(currentSlots[0][0].equals(currentSlots[1][1]) && currentSlots[0][0].equals(currentSlots[2][2])){ + newWinningLines.put(7,"WIN"); + } + if(currentSlots[2][2].equals(currentSlots[1][1]) && currentSlots[2][2].equals(currentSlots[0][0])){ + newWinningLines.put(8,"WIN"); + } + this.winningLines = newWinningLines; + } + public String[] compareBetVsWinningLines(Integer[] bets){ + String[] result = new String[bets.length]; + for (int i = 0; i < bets.length; i++) { + result[i] = winningLines.get(bets[i]); + } + return result; } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index 81a36ff91..102c0eb63 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -7,9 +7,6 @@ * Created by Nathan on 7/12/21 */ public class SlotsGame implements GameInterface { - private static String[] slotItems = {"Peach", "Cherry", "Diamond", "Plum", "Seven", "Nine"}; - private String[][] slots = new String[3][3]; - @Override @@ -24,21 +21,26 @@ public void remove(PlayerInterface player) { @Override public void run() { + Slots slotMachine = new Slots(); + //Integer[] bets = takeBet(); + slotMachine.spinSlots(); + //slotMachine.compareBetVsWinningLines(); + } @Override - public Double calculateWinnings(Double multiplier, Double betAmount) { + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { return null; } @Override - public void subtractBetFromBalance(Double betAmount) { + public void subtractBetFromBalance(Integer betAmount) { } @Override - public void addMoneyToBalance(PlayerInterface Player, Double winnings) { + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { } } diff --git a/src/test/java/com/github/zipcodewilmington/SlotsTest.java b/src/test/java/com/github/zipcodewilmington/SlotsTest.java index 97f2fa7c5..e21f3cf68 100644 --- a/src/test/java/com/github/zipcodewilmington/SlotsTest.java +++ b/src/test/java/com/github/zipcodewilmington/SlotsTest.java @@ -4,6 +4,8 @@ import org.junit.Assert; import org.junit.Test; +import java.util.HashMap; + public class SlotsTest { @Test @@ -73,4 +75,59 @@ public void spinSlotsTest(){ //then Assert.assertFalse(given.equals(retrieved)); } + + @Test + public void initializeWinningLinesTest(){ + //given + Slots slot = new Slots(); + String[] expected = {"LOSE","LOSE","LOSE","LOSE","LOSE","LOSE","LOSE","LOSE",}; + HashMap initialWinningLines = slot.getWinningLines(); + String[] returned = new String[8]; + for (int i = 0; i < initialWinningLines.size(); i++) { + returned[i] = (String) initialWinningLines.get(i + 1); + } + //then + Assert.assertEquals(expected, returned); + + } + + @Test + public void setWinningLinesTest(){ + //given + String[][] given = { + {"Peach", "Peach", "Peach"}, + {"Peach", "Peach", "Peach"}, + {"Peach", "Peach", "Peach"}}; + Slots slot = new Slots(given); + String[] expected = {"WIN","WIN","WIN","WIN","WIN","WIN","WIN","WIN"}; + //when + slot.setWinningLines(); + HashMap winningLines = slot.getWinningLines(); + String[] returned = new String[8]; + for (int i = 0; i < winningLines.size(); i++) { + returned[i] = (String) winningLines.get(i + 1); + } + //then + Assert.assertEquals(expected,returned); + + } + + @Test + public void compareBetVsWinningLinesTest(){ + //given + String[][] given = { + {"Peach", "Peach", "Peach"}, + {"Peach", "Peach", "Peach"}, + {"Peach", "Peach", "Peach"}}; + Slots slot = new Slots(given); + slot.setWinningLines(); + String[] expected = {"WIN","WIN","WIN","WIN","WIN","WIN","WIN","WIN"}; + Integer [] bets = {1,2,3,4,5,6,7,8}; + //when + String[] returned = slot.compareBetVsWinningLines(bets); + //then + Assert.assertEquals(expected, returned); + } + + } From ffc4938af97e56215bc5edf32caf203ef76db278 Mon Sep 17 00:00:00 2001 From: Zach Date: Tue, 13 Jul 2021 22:22:02 -0400 Subject: [PATCH 037/104] CasinoAccountManager and Casino thru to game selection. Account logins successful --- .../github/zipcodewilmington/casino/CasinoAccount.java | 2 +- .../zipcodewilmington/casino/CasinoAccountManager.java | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java index 580cf89b1..70b97fef0 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java @@ -21,7 +21,7 @@ public CasinoAccount(String accountName, String accountPassword){ } -feature/CasinoAccount + public String getPassword() { return password; } diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java index 459c69af5..0e8b08ef8 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java @@ -18,9 +18,11 @@ public class CasinoAccountManager { public CasinoAccount getAccount(String accountName, String accountPassword) { for(int i = 0; i < accountList.size(); i++){ CasinoAccount currentAccount = accountList.get(i); - if(currentAccount.getAccountName() == accountName && - currentAccount.getPassword() == accountPassword){ - return currentAccount; + String pass = currentAccount.getPassword(); + String name = currentAccount.getAccountName(); + if(name.equals(accountName)) + if(pass.equals(accountPassword)){ + return currentAccount; } else { System.out.println("Account Name or Password does not match. Are you really you?"); return null; From 9308a8f4300fa43281b1dcfd3eb7af5b62851b32 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Jul 2021 22:26:03 -0400 Subject: [PATCH 038/104] (feat:black-jack) game logic built, continuing on formatting --- .../casino/games/blackjack/BlackJackGame.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index 66c53e156..749124ea3 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -6,10 +6,8 @@ import com.github.zipcodewilmington.casino.PlayerInterface; import com.github.zipcodewilmington.utils.IOConsole; -import java.util.Scanner; public class BlackJackGame implements GameInterface, PlayerInterface { - private BlackJack game; private Boolean isRunning = false; private PlayerInterface player; Double userBet; @@ -30,12 +28,13 @@ public void remove(PlayerInterface player) { public void run() { while(isRunning) { // include betting range - BlackJack bj = new BlackJack(); Integer userInput = input.getIntegerInput("1. Start A Hand" + "\n" + "2. Quit" + "\n"); switch (userInput) { - case 1: // include betting forum in case 1 + case 1: + this.userBet = Double.valueOf(input.getIntegerInput("How much would you like to bet?")); + // include betting forum in case 1 startGame(); break; case 2: @@ -48,8 +47,8 @@ public void startGame () { BlackJack bj = new BlackJack(); bj.givePlayerCard(); System.out.println("Your starting card : " + bj.playersCurrentValue()); - bj.givePlayerCard(); - System.out.println("Your second next card : " + bj.playersCurrentValue()); + System.out.println("Your second next card : " + bj.givePlayerCard()); + System.out.println("Hand value : " + bj.playersCurrentValue()); Integer userChoice = input.getIntegerInput("1. Hit" + "\n" + "2. Stay"); while (!isWinner) { switch (userChoice) { From 321ff082353a34dec7b086c6944acf622f8bb099 Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Tue, 13 Jul 2021 22:28:29 -0400 Subject: [PATCH 039/104] Feature/casino account (#27) * CasinoAccount and CasinoAccountManager.java * updated CasinoAccount, CasinoAccountManager and Casino java files Co-authored-by: Zach --- .../com/github/zipcodewilmington/casino/CasinoAccount.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java index c5f41dcb6..cd5b53aef 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java @@ -21,11 +21,6 @@ public CasinoAccount(String accountName, String accountPassword){ } - -<<<<<<< HEAD -======= -feature/CasinoAccount ->>>>>>> eb43adc5aea6f2808ae5192219035b42dfc3e7ff public String getPassword() { return password; } From f60d2829ff17534e5bbb0c9c52f9c55e798bbe14 Mon Sep 17 00:00:00 2001 From: NicholasWolak <85853075+NicholasWolak@users.noreply.github.com> Date: Tue, 13 Jul 2021 22:31:08 -0400 Subject: [PATCH 040/104] Feat/black jack (#26) * pulling * (feat:black-jack) game logic completed, need refinment and bet input * (feat:black-jack) game logic built, continuing on formatting Co-authored-by: Nick --- .../casino/games/blackjack/BlackJack.java | 24 +++++++++++++++++ .../casino/games/blackjack/BlackJackGame.java | 27 ++++++++++++------- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java index 24374b05e..61bce33e2 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -12,6 +12,8 @@ public class BlackJack { List playersHandOnSplit; List dealersHand; Deque deckOfCards; + BlackJackGame theGame = new BlackJackGame(); + boolean gameEnd = false; Integer betAmount; // Equal to user input @@ -63,6 +65,28 @@ public Integer dealersCurrentValue () { return sum; } + public void dealersGame () { + while(!gameEnd) { + System.out.println("The dealer has : " + dealersCurrentValue()); + if (dealersCurrentValue() > 21) { + System.out.println("You win!"); + theGame.calculateWinnings(2.0, theGame.userBet); + gameEnd = true; + } else if (dealersCurrentValue() == 21) { + System.out.println("The dealer has won!"); + theGame.subtractBetFromBalance(theGame.userBet); + gameEnd = true; + } else if (dealersCurrentValue() > playersCurrentValue()) { + System.out.println("The dealer has won!"); + theGame.subtractBetFromBalance(theGame.userBet); + gameEnd = true; + } else { + giveDealerCard(); + System.out.println("The dealer has : " + dealersCurrentValue()); + } + } + } + public boolean playerBreaks21 () { if (playersCurrentValue() > 21) { return true; diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index 27574d10a..dde701b86 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -6,14 +6,13 @@ import com.github.zipcodewilmington.casino.PlayerInterface; import com.github.zipcodewilmington.utils.IOConsole; -import java.util.Scanner; public class BlackJackGame implements GameInterface, PlayerInterface { - private BlackJack game; private Boolean isRunning = false; private PlayerInterface player; - private Double userBet; + Double userBet; IOConsole input = new IOConsole(); + boolean isWinner = false; @Override public void add(PlayerInterface player) { @@ -29,12 +28,13 @@ public void remove(PlayerInterface player) { public void run() { while(isRunning) { // include betting range - BlackJack bj = new BlackJack(); Integer userInput = input.getIntegerInput("1. Start A Hand" + "\n" + "2. Quit" + "\n"); switch (userInput) { - case 1: // include betting forum in case 1 + case 1: + this.userBet = Double.valueOf(input.getIntegerInput("How much would you like to bet?")); + // include betting forum in case 1 startGame(); break; case 2: @@ -47,11 +47,10 @@ public void startGame () { BlackJack bj = new BlackJack(); bj.givePlayerCard(); System.out.println("Your starting card : " + bj.playersCurrentValue()); - bj.givePlayerCard(); - System.out.println("Your second next card : " + bj.playersCurrentValue()); - boolean isWinner = false; + System.out.println("Your second next card : " + bj.givePlayerCard()); + System.out.println("Hand value : " + bj.playersCurrentValue()); Integer userChoice = input.getIntegerInput("1. Hit" + "\n" + "2. Stay"); - while (isWinner) { + while (!isWinner) { switch (userChoice) { case 1: bj.givePlayerCard(); @@ -69,8 +68,18 @@ public void startGame () { break; case 2: + bj.giveDealerCard(); + System.out.println("The dealers first card : " + bj.dealersCurrentValue()); + bj.giveDealerCard(); + System.out.println("The dealer has : " + bj.dealersCurrentValue()); + bj.dealersGame(); + break; + + } + } + } } @Override From d7b6482c7912d86dd1dc9cf068cef51d41c89219 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Jul 2021 22:46:08 -0400 Subject: [PATCH 041/104] commiting for merge --- .../casino/games/blackjack/BlackJack.java | 83 ++++--------------- .../casino/games/blackjack/BlackJackGame.java | 30 +++---- .../casino/games/plinko/PlinkoGame.java | 28 +++---- .../github/zipcodewilmington/PlinkoTest.java | 4 +- 4 files changed, 46 insertions(+), 99 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java index 61bce33e2..d401cf26d 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -7,7 +7,7 @@ import java.util.*; -public class BlackJack { +public class BlackJack { List playersHand; List playersHandOnSplit; List dealersHand; @@ -17,46 +17,46 @@ public class BlackJack { Integer betAmount; // Equal to user input - public BlackJack () { + public BlackJack() { this.playersHand = new ArrayList<>(); this.playersHandOnSplit = new ArrayList<>(); this.dealersHand = new ArrayList<>(); this.deckOfCards = new ArrayDeque<>(generateNewDeck()); } - public List generateNewDeck () { + public List generateNewDeck() { Card card = new Card(); return card.getCardPool(); } - public List givePlayerCard () { + public List givePlayerCard() { Integer valueOfCard = deckOfCards.pop(); this.playersHand.add(valueOfCard); return this.playersHand; } - public List givePlayerCardOnSplit () { + public List givePlayerCardOnSplit() { Integer valueOfCard = deckOfCards.pop(); this.playersHandOnSplit.add(valueOfCard); return this.playersHandOnSplit; } - public List giveDealerCard () { + public List giveDealerCard() { Integer valueOfCard = deckOfCards.pop(); this.dealersHand.add(valueOfCard); return this.dealersHand; } - public Integer playersCurrentValue () { + public Integer playersCurrentValue() { givePlayerCard(); Integer sum = 0; for (int i = 0; i < this.playersHand.size(); i++) { - sum += this.playersHand.get(i); + sum += this.playersHand.get(i); } return sum; } - public Integer dealersCurrentValue () { + public Integer dealersCurrentValue() { giveDealerCard(); Integer sum = 0; for (int i = 0; i < this.dealersHand.size(); i++) { @@ -65,12 +65,12 @@ public Integer dealersCurrentValue () { return sum; } - public void dealersGame () { - while(!gameEnd) { - System.out.println("The dealer has : " + dealersCurrentValue()); + public void dealersGame() { + while (!gameEnd) { + System.out.println("The dealer has : " + dealersCurrentValue()); if (dealersCurrentValue() > 21) { System.out.println("You win!"); - theGame.calculateWinnings(2.0, theGame.userBet); + theGame.calculateWinnings(2, theGame.userBet); gameEnd = true; } else if (dealersCurrentValue() == 21) { System.out.println("The dealer has won!"); @@ -87,7 +87,7 @@ public void dealersGame () { } } - public boolean playerBreaks21 () { + public boolean playerBreaks21() { if (playersCurrentValue() > 21) { return true; } else { @@ -95,17 +95,9 @@ public boolean playerBreaks21 () { } } - public boolean playerHitsBlackJack () { + public boolean playerHitsBlackJack() { if (playersCurrentValue() == 21) { - calculateWinnings(3, betAmount); - } - } - - public void dealerConditions () { - if (dealersCurrentValue() > 21) { - calculateWinnings(2, betAmount); //Players winnings, not dealers (Player won) - } else if (dealersCurrentValue() <= 21 && dealersCurrentValue() > playersCurrentValue()) { - subtractBetFromBalance(betAmount); + theGame.calculateWinnings(3, betAmount); return true; } else { return false; @@ -127,45 +119,4 @@ public List getDealersHand() { public void setDealersHand(List dealersHand) { this.dealersHand = dealersHand; } - - @Override - public void add(PlayerInterface player) { - - } - - @Override - public void remove(PlayerInterface player) { - - } - - @Override - public void run() { - - } - - @Override - public Integer calculateWinnings(Integer multiplier, Integer betAmount) { - return null; - } - - @Override - public void subtractBetFromBalance(Integer betAmount) { - - } - - @Override - public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { - - } - - @Override - public CasinoAccount getArcadeAccount() { - return null; - } - - @Override - public SomeReturnType play() { - return null; - } - -} +} \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index dde701b86..7935ee07a 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -10,7 +10,7 @@ public class BlackJackGame implements GameInterface, PlayerInterface { private Boolean isRunning = false; private PlayerInterface player; - Double userBet; + Integer userBet; IOConsole input = new IOConsole(); boolean isWinner = false; @@ -33,7 +33,7 @@ public void run() { switch (userInput) { case 1: - this.userBet = Double.valueOf(input.getIntegerInput("How much would you like to bet?")); + this.userBet = (input.getIntegerInput("How much would you like to bet?")); // include betting forum in case 1 startGame(); break; @@ -62,7 +62,7 @@ public void startGame () { isWinner = true; } else if (bj.playerHitsBlackJack()) { System.out.println("BLACK JACK!!"); - calculateWinnings(3.0, userBet); + calculateWinnings(3, userBet); isWinner = true; } break; @@ -74,36 +74,32 @@ public void startGame () { System.out.println("The dealer has : " + bj.dealersCurrentValue()); bj.dealersGame(); break; - - } - } } - } @Override - public Double calculateWinnings(Double multiplier, Double betAmount) { - return multiplier * betAmount; + public CasinoAccount getArcadeAccount() { + return null; } @Override - public void subtractBetFromBalance(Double betAmount) { - + public SomeReturnType play() { + return null; } @Override - public void addMoneyToBalance(PlayerInterface Player, Double winnings) { - + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return null; } @Override - public CasinoAccount getArcadeAccount() { - return null; + public void subtractBetFromBalance(Integer betAmount) { + } @Override - public SomeReturnType play() { - return null; + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java index c9fc6140a..42cd5ae10 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java @@ -9,7 +9,7 @@ import java.util.Random; public class PlinkoGame implements GameInterface,PlayerInterface { - private Map moneyGenerator=new HashMap(); + private Map moneyGenerator=new HashMap(); public int initialPosition; private double betAmount; public int randomNumber; @@ -56,17 +56,17 @@ public void run() { } @Override - public Double calculateWinnings(Double multiplier, Double betAmount) { - moneyGenerator.put(1,200.00); - moneyGenerator.put(2,0.00); - moneyGenerator.put(3,3000.00); - moneyGenerator.put(4,30.50); - moneyGenerator.put(5,0.00); - moneyGenerator.put(6,0.00); - moneyGenerator.put(7,1.00); - moneyGenerator.put(8,750.50); - moneyGenerator.put(9,0.00); - Double moneyWon=0.0; + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + moneyGenerator.put(1,200); + moneyGenerator.put(2,0); + moneyGenerator.put(3,3000); + moneyGenerator.put(4,30); + moneyGenerator.put(5,0); + moneyGenerator.put(6,0); + moneyGenerator.put(7,1); + moneyGenerator.put(8,750); + moneyGenerator.put(9,0); + Integer moneyWon=0; for (Integer pos:moneyGenerator.keySet()) { if(pos.equals(randomNumber)){ @@ -78,12 +78,12 @@ public Double calculateWinnings(Double multiplier, Double betAmount) { @Override - public void subtractBetFromBalance(Double betAmount) { + public void subtractBetFromBalance(Integer betAmount) { } @Override - public void addMoneyToBalance(PlayerInterface Player, Double winnings) { + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { } diff --git a/src/test/java/com/github/zipcodewilmington/PlinkoTest.java b/src/test/java/com/github/zipcodewilmington/PlinkoTest.java index 8596899de..781c43d59 100644 --- a/src/test/java/com/github/zipcodewilmington/PlinkoTest.java +++ b/src/test/java/com/github/zipcodewilmington/PlinkoTest.java @@ -9,11 +9,11 @@ public class PlinkoTest { @Test public void testCalculateWinnings() { //given - Double expectedValue=0.0; + Integer expectedValue=0; PlinkoGame plinkoGame=new PlinkoGame(7); plinkoGame.run(); //when - Double actualValue=plinkoGame.calculateWinnings(2.00,200.00); + Integer actualValue=plinkoGame.calculateWinnings(2,200); //then System.out.println(actualValue); Assert.assertEquals(expectedValue,actualValue); From a867caf8dc027e133e4544516778f033ca394442 Mon Sep 17 00:00:00 2001 From: Nathan Date: Tue, 13 Jul 2021 23:29:10 -0400 Subject: [PATCH 042/104] added new comment in slots --- .../com/github/zipcodewilmington/casino/games/slots/Slots.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java index ebbfe37ad..ec0b36e6b 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java @@ -89,7 +89,7 @@ public String[] compareBetVsWinningLines(Integer[] bets){ return result; } - +//new comment } From f751781200732225c86f1b6ad53a6829624fbc86 Mon Sep 17 00:00:00 2001 From: Zach Date: Tue, 13 Jul 2021 23:35:34 -0400 Subject: [PATCH 043/104] Changed Double data type to Integer in Player class --- .../github/zipcodewilmington/casino/Player.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/Player.java b/src/main/java/com/github/zipcodewilmington/casino/Player.java index f81eef273..607512047 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/Player.java +++ b/src/main/java/com/github/zipcodewilmington/casino/Player.java @@ -3,10 +3,10 @@ public class Player{ String name; - Double balance; - Double currentBet = 0.0; + Integer balance; + Integer currentBet = 0; - public Player(String name, Double initialDeposit) { + public Player(String name, Integer initialDeposit) { this.name = name; this.balance = initialDeposit; } @@ -17,26 +17,26 @@ public String getName() { } - public Double getBalance() { + public Integer getBalance() { return balance; } - private void setCurrentBet(Double currentBet) { + private void setCurrentBet(Integer currentBet) { this.currentBet = currentBet; } - public void setBalance(Double deposit) { + public void setBalance(Integer deposit) { this.balance = balance + deposit; } - public Double makeBet(Double betAmount) { + public Integer makeBet(Integer betAmount) { currentBet = betAmount; balance = balance - currentBet; return currentBet; } - private Double getCurrentBet() { + private Integer getCurrentBet() { return currentBet; } } From e8242784916a95b39b6689bcc48c21c29fd5930c Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Jul 2021 23:41:21 -0400 Subject: [PATCH 044/104] (feat:black-jack) just to be safe --- .../casino/games/blackjack/BlackJackGame.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index 2ce25ac1d..79c6e2e54 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -71,26 +71,15 @@ public void startGame () { } break; case 2: - - - - bj.giveDealerCard(); System.out.println("The dealers first card : " + bj.dealersCurrentValue()); bj.giveDealerCard(); System.out.println("The dealer has : " + bj.dealersCurrentValue()); bj.dealersGame(); break; - - - - } - } } - - @Override From 4b6447fa6b8a008ae052d999c926162121a38547 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Jul 2021 23:48:24 -0400 Subject: [PATCH 045/104] Safety check --- .../java/com/github/zipcodewilmington/casino/models/Card.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/github/zipcodewilmington/casino/models/Card.java b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java index 2a4def12d..ad6c46b36 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/models/Card.java +++ b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java @@ -5,6 +5,9 @@ public class Card { List cardPool; + // Let's hope this works! If you can see this, that'd be cool + // Boilage + public Card() { this.cardPool = new ArrayList<>(); this.createDeck(); From 800164ec69f67257e31f63eff614c45b138718f1 Mon Sep 17 00:00:00 2001 From: Zach Date: Wed, 14 Jul 2021 00:19:42 -0400 Subject: [PATCH 046/104] Updated player interface by removing run method, changed Double Integer on Beetle Game and BeetlePlayer --- .../casino/PlayerInterface.java | 2 +- .../casino/games/Beetle/BeetleGame.java | 28 +++++-------------- .../casino/games/Beetle/BeetlePlayer.java | 5 ++++ .../zipcodewilmington/casino/models/Card.java | 2 +- 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java b/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java index c50b5113b..9d6800a71 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java +++ b/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java @@ -17,5 +17,5 @@ public interface PlayerInterface { * @param specify any return type you would like here * @return whatever return value you would like */ - SomeReturnType play(); + // SomeReturnType play(); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index cbc91fb07..bf2ba13e0 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -31,36 +31,20 @@ public void run(){ } } - @Override - public Integer calculateWinnings(Integer multiplier, Integer betAmount) { - return null; - } - - @Override - public void subtractBetFromBalance(Integer betAmount) { - - } - @Override - public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { - } - - public String test(){ - return "NATHAN WAS HERE"; - } /** * Calculate player's winning payout amount of bet x multiplier * @return (double) amount of money winnings */ - public Double calculateWinnings(Double multiplier, Double betAmount){ - return 0.00; + public Integer calculateWinnings(Integer multiplier, Integer betAmount){ + return 0; } /** * Subtract the bet amount from player's balance */ - public void subtractBetFromBalance(Double betAmount){ + public void subtractBetFromBalance(Integer betAmount){ } @@ -68,12 +52,14 @@ public void subtractBetFromBalance(Double betAmount){ /** * Add winnings amount to player's balance */ - public void addMoneyToBalance(PlayerInterface Player, Double winnings){ + public void addMoneyToBalance(PlayerInterface Player, Integer winnings){ } - public void initGame(){ + public void initGame(Integer players){ this.game = new Beetle(this.players.size()); + this.isRunning = true; + this.run(); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java index 34b4ceb45..b4c16f59e 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java @@ -1,4 +1,9 @@ package com.github.zipcodewilmington.casino.games.Beetle; public class BeetlePlayer { + private Integer bet; + + public BeetlePlayer(){ + + } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/models/Card.java b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java index ad6c46b36..296ce2f9a 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/models/Card.java +++ b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java @@ -6,7 +6,7 @@ public class Card { List cardPool; // Let's hope this works! If you can see this, that'd be cool - // Boilage + // Boilage <== hack public Card() { this.cardPool = new ArrayList<>(); From 895135d1ca183ca519361df234bde9a8c9ee8e07 Mon Sep 17 00:00:00 2001 From: Nathan Date: Wed, 14 Jul 2021 00:53:13 -0400 Subject: [PATCH 047/104] finished getBetSelections --- .../casino/games/slots/Slots.java | 2 +- .../casino/games/slots/SlotsGame.java | 51 +++++++++++++++++-- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java index ec0b36e6b..623f58539 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java @@ -89,7 +89,7 @@ public String[] compareBetVsWinningLines(Integer[] bets){ return result; } -//new comment + //new comment } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index 102c0eb63..1fd008980 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -3,11 +3,13 @@ import com.github.zipcodewilmington.casino.GameInterface; import com.github.zipcodewilmington.casino.PlayerInterface; +import java.util.Scanner; + /** * Created by Nathan on 7/12/21 */ public class SlotsGame implements GameInterface { - + private Integer playerBetAmount; @Override public void add(PlayerInterface player) { @@ -22,11 +24,54 @@ public void remove(PlayerInterface player) { @Override public void run() { Slots slotMachine = new Slots(); - //Integer[] bets = takeBet(); + getBetAmount(); + Integer[] selectedBets = getBetSelections(); slotMachine.spinSlots(); - //slotMachine.compareBetVsWinningLines(); + String[] betResults = slotMachine.compareBetVsWinningLines(selectedBets); + calculateMultiplier(betResults); + + } + + private void getBetAmount() { + Scanner scanner = new Scanner(System.in); + System.out.println("How much you do want to bet?"); + Integer input = scanner.nextInt(); + playerBetAmount = input; + } + + private Integer[] getBetSelections() { + Scanner scanner = new Scanner(System.in); + System.out.println("How many lines do you want to bet on?"); + Integer numberOfLines = scanner.nextInt(); + + System.out.println( + "************************************************************************\n" + + "** Select the lines you want to bet on! **\n" + + "** 1. Top Horizontal 2. Middle Horizontal 3. Bottom Horizontal **\n" + + "** 4. Left Vertical 5. Middle Vertical 6. Right Vertical **\n" + + "** 7. Down Diagonal 8. Up Diagonal **\n" + + "************************************************************************"); + Integer count = 0; + Integer[] selectedLines = new Integer[numberOfLines]; + while (count < numberOfLines){ + System.out.println("Select your line #" + (count + 1)); + selectedLines[count] = scanner.nextInt(); + count++; + } + return selectedLines; + } + + private void calculateMultiplier(String[] betResults) { + Integer count = 0; + for(String outcome: betResults){ + if(outcome.equals("Win")){ + count++; + } else { + count--; + } + } } @Override From 2f402395f8da7c73d7f02515e1f2298e77e07771 Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Wed, 14 Jul 2021 08:19:12 -0400 Subject: [PATCH 048/104] Feature/beetle game (#34) * began implementation of BeetleGame * Moved to testing for BeetleGame, finished BeetleGame class. Cannot proceed until unneccesary @Override statements removed from BlackJack and Plinko, remove unneccessary PlayerInterface implementations Co-authored-by: Zach --- .../casino/games/Beetle/Beetle.java | 4 ++++ .../casino/games/Beetle/BeetleGame.java | 21 ++++++++++++++++++- .../github/zipcodewilmington/BeetleGame.java | 11 ++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/github/zipcodewilmington/BeetleGame.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java index 56461ccc5..f205cc4d5 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java @@ -60,6 +60,10 @@ public void setPlayerBeetles(Integer player, Integer diceRoll) { //return this.checkWinner(player); } + public void nextPlayer(){ + this.currentPlayer = (this.currentPlayer + 1) % this.numPlayers; + } + public void refreshBeetle(Integer player){ this.playerBeetles[player] = new Integer[] {0, 0, 0, 0, 0, 0}; } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index bf2ba13e0..479423e7d 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -26,12 +26,31 @@ public void remove(PlayerInterface player){ * specifies how the game will run */ public void run(){ + Integer turnCount = 0; if(isRunning){ - + turnCount++; + this.nextPlayer(); + game.getDice().tossAndSum(); + executeTurn(); + isGameOver(game.checkWinner(game.getCurrentPlayer())); } + System.out.println("game over after " + turnCount); } + public void isGameOver(boolean playerWon){ + if(playerWon){ + isRunning = false; + } + } + public void nextPlayer(){ + game.setCurrentPlayer(-1); + game.nextPlayer(); + } + public void executeTurn(){ + Integer currentPlayer = game.getCurrentPlayer(); + game.setPlayerBeetles(currentPlayer, game.getDice().tossAndSum()); + } /** * Calculate player's winning payout amount of bet x multiplier diff --git a/src/test/java/com/github/zipcodewilmington/BeetleGame.java b/src/test/java/com/github/zipcodewilmington/BeetleGame.java new file mode 100644 index 000000000..4761cbdd3 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BeetleGame.java @@ -0,0 +1,11 @@ +package com.github.zipcodewilmington; + +import org.junit.Test; + +public class BeetleGame { + @Test + public void testGameOver(){ + BeetleGame game = new BeetleGame(); + + } +} From 796b2c9bbbd5fff310ef6706dd5da85dd0dfa143 Mon Sep 17 00:00:00 2001 From: Dipinti Date: Wed, 14 Jul 2021 08:29:38 -0400 Subject: [PATCH 049/104] updated plinko.java without override methods --- .../casino/games/plinko/PlinkoGame.java | 47 ++++--------------- 1 file changed, 8 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java index c9fc6140a..e66e6d37e 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java @@ -8,11 +8,11 @@ import java.util.Map; import java.util.Random; -public class PlinkoGame implements GameInterface,PlayerInterface { +public class PlinkoGame { private Map moneyGenerator=new HashMap(); public int initialPosition; private double betAmount; - public int randomNumber; + public int multiplier; public PlinkoGame(int initialPosition){ this.initialPosition=initialPosition; @@ -30,24 +30,13 @@ public String playPlinko(int initialPosition){ return "Invalid Entry"; } - @Override - public void add(PlayerInterface player) { - - } - - @Override - public void remove(PlayerInterface player) { - - } - - @Override - public void run() { + public void run2() { if (initialPosition < 10 && initialPosition > 0) { int max = 9; int min = 1; Random rand = new Random(); - randomNumber = rand.nextInt(max - min + 1) + min; - System.out.println("Now your position is: " + randomNumber); + multiplier = rand.nextInt(max - min + 1) + min; + System.out.println("Now your position is: " + multiplier); } else { @@ -55,8 +44,8 @@ public void run() { } } - @Override - public Double calculateWinnings(Double multiplier, Double betAmount) { + + public Double calculateWinnings2(Integer multiplier, Double betAmount) { moneyGenerator.put(1,200.00); moneyGenerator.put(2,0.00); moneyGenerator.put(3,3000.00); @@ -69,32 +58,12 @@ public Double calculateWinnings(Double multiplier, Double betAmount) { Double moneyWon=0.0; for (Integer pos:moneyGenerator.keySet()) { - if(pos.equals(randomNumber)){ + if(pos.equals(multiplier)){ moneyWon=moneyGenerator.get(pos); } } return moneyWon; } - - @Override - public void subtractBetFromBalance(Double betAmount) { - - } - - @Override - public void addMoneyToBalance(PlayerInterface Player, Double winnings) { - - } - - @Override - public CasinoAccount getArcadeAccount() { - return null; - } - - @Override - public SomeReturnType play() { - return null; - } } From f79717ed14912033c5a1ee274164bf61602d7ccc Mon Sep 17 00:00:00 2001 From: Dipinti Date: Wed, 14 Jul 2021 08:32:10 -0400 Subject: [PATCH 050/104] also updated the plinkotest without overrides --- .../java/com/github/zipcodewilmington/PlinkoTest.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/github/zipcodewilmington/PlinkoTest.java b/src/test/java/com/github/zipcodewilmington/PlinkoTest.java index 8596899de..45381a94b 100644 --- a/src/test/java/com/github/zipcodewilmington/PlinkoTest.java +++ b/src/test/java/com/github/zipcodewilmington/PlinkoTest.java @@ -9,13 +9,12 @@ public class PlinkoTest { @Test public void testCalculateWinnings() { //given - Double expectedValue=0.0; - PlinkoGame plinkoGame=new PlinkoGame(7); - plinkoGame.run(); + Double expectedValue=750.50; + PlinkoGame plinkoGame=new PlinkoGame(8); + plinkoGame.run2(); //when - Double actualValue=plinkoGame.calculateWinnings(2.00,200.00); + Double actualValue=plinkoGame.calculateWinnings2(8,200.00); //then - System.out.println(actualValue); Assert.assertEquals(expectedValue,actualValue); } From e6c5995976d8c84ee448b37368e83aa0d33466cd Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 14 Jul 2021 09:19:09 -0400 Subject: [PATCH 051/104] pre-pull --- .../casino/games/blackjack/BlackJackGame.java | 8 ++++---- .../zipcodewilmington/casino/models/Card.java | 3 --- .../zipcodewilmington/BlackJackGameTest.java | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index 79c6e2e54..d2cce5d69 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -13,6 +13,7 @@ public class BlackJackGame implements GameInterface, PlayerInterface { Integer userBet; IOConsole input = new IOConsole(); boolean isWinner = false; + Integer totalWinnings = 0; @Override public void add(PlayerInterface player) { @@ -35,13 +36,11 @@ public void run() { case 1: this.userBet = (input.getIntegerInput("How much would you like to bet?")); - - this.userBet = (input.getIntegerInput("How much would you like to bet?")); - // include betting forum in case 1 startGame(); break; case 2: + // include the subtractWinnings when players leave table isRunning = true; } } @@ -94,7 +93,8 @@ public SomeReturnType play() { @Override public Integer calculateWinnings(Integer multiplier, Integer betAmount) { - return null; + totalWinnings = multiplier * betAmount; + return totalWinnings; } @Override diff --git a/src/main/java/com/github/zipcodewilmington/casino/models/Card.java b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java index ad6c46b36..2a4def12d 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/models/Card.java +++ b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java @@ -5,9 +5,6 @@ public class Card { List cardPool; - // Let's hope this works! If you can see this, that'd be cool - // Boilage - public Card() { this.cardPool = new ArrayList<>(); this.createDeck(); diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java new file mode 100644 index 000000000..125cf1a5b --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java @@ -0,0 +1,15 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.games.blackjack.BlackJackGame; +import org.junit.Test; + +public class BlackJackGameTest { + + @Test + public void runTest () { + BlackJackGame bj = new BlackJackGame(); + + Integer userInput = 1; + bj.run(); + } +} From 4ea382c9c9f73143c82b26c0191d5dbe33ec2b7b Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 14 Jul 2021 09:26:20 -0400 Subject: [PATCH 052/104] solid working branch for the the 14th --- .../casino/games/plinko/PlinkoGame.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java index fd882a351..99eb91253 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java @@ -45,6 +45,21 @@ public void run2() { } } + @Override + public void add(PlayerInterface player) { + + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public void run() { + + } + @Override public Integer calculateWinnings(Integer multiplier, Integer betAmount) { moneyGenerator.put(1,200); @@ -84,10 +99,5 @@ public CasinoAccount getArcadeAccount() { return null; } - @Override - public SomeReturnType play() { - return null; - } - } From c35138823ec5457d16214285f67349d6ad4f32aa Mon Sep 17 00:00:00 2001 From: Zach Date: Wed, 14 Jul 2021 09:33:21 -0400 Subject: [PATCH 053/104] resolved conflicts with previous merge to Dev branch --- .../zipcodewilmington/casino/games/Beetle/BeetleGame.java | 4 +++- .../{BeetleGame.java => BeetleGameTest.java} | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) rename src/test/java/com/github/zipcodewilmington/{BeetleGame.java => BeetleGameTest.java} (51%) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index 479423e7d..a8f7e73b3 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -81,6 +81,8 @@ public void initGame(Integer players){ this.run(); } - + public Boolean getIsRunning(){ + return this.isRunning; + } } diff --git a/src/test/java/com/github/zipcodewilmington/BeetleGame.java b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java similarity index 51% rename from src/test/java/com/github/zipcodewilmington/BeetleGame.java rename to src/test/java/com/github/zipcodewilmington/BeetleGameTest.java index 4761cbdd3..a125e9afd 100644 --- a/src/test/java/com/github/zipcodewilmington/BeetleGame.java +++ b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java @@ -1,11 +1,12 @@ package com.github.zipcodewilmington; +import com.github.zipcodewilmington.casino.games.Beetle.BeetleGame; import org.junit.Test; -public class BeetleGame { +public class BeetleGameTest { @Test public void testGameOver(){ BeetleGame game = new BeetleGame(); - + Boolean isGameOver = game.getIsRunning(); } } From a98113fdd99cc9792d1efce33c58ea5d32a1fbd1 Mon Sep 17 00:00:00 2001 From: Nathan Date: Wed, 14 Jul 2021 12:02:02 -0400 Subject: [PATCH 054/104] made more edits to slots game --- .../casino/GameInterface.java | 2 + .../zipcodewilmington/casino/Player.java | 4 -- .../casino/games/slots/Slots.java | 2 + .../casino/games/slots/SlotsGame.java | 55 ++++++++++++++----- 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java index 01ddd0568..1b29cf63c 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java +++ b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java @@ -38,4 +38,6 @@ public interface GameInterface extends Runnable { */ void addMoneyToBalance(PlayerInterface Player, Integer winnings); + + } diff --git a/src/main/java/com/github/zipcodewilmington/casino/Player.java b/src/main/java/com/github/zipcodewilmington/casino/Player.java index f81eef273..252cb3470 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/Player.java +++ b/src/main/java/com/github/zipcodewilmington/casino/Player.java @@ -1,7 +1,6 @@ package com.github.zipcodewilmington.casino; public class Player{ - String name; Double balance; Double currentBet = 0.0; @@ -11,12 +10,10 @@ public Player(String name, Double initialDeposit) { this.balance = initialDeposit; } - public String getName() { return name; } - public Double getBalance() { return balance; } @@ -29,7 +26,6 @@ public void setBalance(Double deposit) { this.balance = balance + deposit; } - public Double makeBet(Double betAmount) { currentBet = betAmount; balance = balance - currentBet; diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java index 623f58539..d40ff0e6f 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java @@ -81,11 +81,13 @@ public void setWinningLines(){ this.winningLines = newWinningLines; } + //Take an int[] of numbered lines to be on. public String[] compareBetVsWinningLines(Integer[] bets){ String[] result = new String[bets.length]; for (int i = 0; i < bets.length; i++) { result[i] = winningLines.get(bets[i]); } + //return a string[] of "WIN" or "LOSE" return result; } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index 1fd008980..a7430f0b4 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -1,18 +1,25 @@ package com.github.zipcodewilmington.casino.games.slots; import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.Player; import com.github.zipcodewilmington.casino.PlayerInterface; +import java.net.Inet4Address; import java.util.Scanner; /** * Created by Nathan on 7/12/21 */ -public class SlotsGame implements GameInterface { +public class SlotsGame implements GameInterface{ private Integer playerBetAmount; + private Integer betTotal; + private Integer loseMultiplier; + private Integer winMultiplier; + private PlayerInterface player; @Override public void add(PlayerInterface player) { + this.player = player; } @@ -23,17 +30,24 @@ public void remove(PlayerInterface player) { @Override public void run() { - Slots slotMachine = new Slots(); - getBetAmount(); - Integer[] selectedBets = getBetSelections(); - slotMachine.spinSlots(); - String[] betResults = slotMachine.compareBetVsWinningLines(selectedBets); - calculateMultiplier(betResults); - + Boolean quitGame = false; + while(quitGame = false) { + Slots slotMachine = new Slots(); + getBetAmount(); + Integer[] selectedBets = getBetSelections(); + //takeBetTotalFromPlayerBalance(); + slotMachine.spinSlots(); + String[] betResults = slotMachine.compareBetVsWinningLines(selectedBets); + calculateMultiplier(betResults); + Integer winnings = calculateWinnings(this.winMultiplier, playerBetAmount); + Integer losings = calculateWinnings(this.loseMultiplier, playerBetAmount); + Integer returnTotal = calculateReturnTotal(winnings, losings); + //addMoneyToBalance(, returnTotal); + + } } - private void getBetAmount() { Scanner scanner = new Scanner(System.in); System.out.println("How much you do want to bet?"); @@ -45,6 +59,8 @@ private Integer[] getBetSelections() { Scanner scanner = new Scanner(System.in); System.out.println("How many lines do you want to bet on?"); Integer numberOfLines = scanner.nextInt(); + Integer totalCost = playerBetAmount * numberOfLines; + System.out.println("The total cost to play is " + totalCost); System.out.println( "************************************************************************\n" + @@ -64,28 +80,37 @@ private Integer[] getBetSelections() { } private void calculateMultiplier(String[] betResults) { - Integer count = 0; + Integer countWin = 0; + Integer countLose = 0; + //Integer[] winVsLose = new Integer[2]; for(String outcome: betResults){ if(outcome.equals("Win")){ - count++; + countWin++; } else { - count--; + countLose--; } } + this.winMultiplier = countWin; + this.loseMultiplier = countLose; + } + + public Integer calculateReturnTotal(Integer winnings, Integer losings){ + Integer returnTotal = this.betTotal + winnings - losings; + return returnTotal; } @Override public Integer calculateWinnings(Integer multiplier, Integer betAmount) { - return null; + return multiplier * betAmount; } @Override - public void subtractBetFromBalance(Integer betAmount) { - + public void subtractBetFromBalance(Integer losings) { } @Override public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { } + } From e67c9dd62c9ea1189e702ed6770336952d48adea Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 14 Jul 2021 13:18:56 -0400 Subject: [PATCH 055/104] Pushing for pull --- .../casino/games/blackjack/BlackJack.java | 5 ++++- .../casino/games/blackjack/BlackJackGame.java | 17 +++++++---------- .../zipcodewilmington/BlackJackGameTest.java | 3 +++ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java index 7138b34a3..74fc65827 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -90,8 +90,11 @@ public void dealersGame() { } } + public void playerSplit () { + if (playersHand.get(0) == playersHand.get(1)) { - + } + } public boolean playerBreaks21() { diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index c07b84265..56637b376 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -15,17 +15,16 @@ public class BlackJackGame implements GameInterface, PlayerInterface { boolean isWinner = false; Integer totalWinnings = 0; - @Override - public void add(PlayerInterface player) { + public void add(PlayerInterface player) { + this.player = player; } - @Override + public void remove(PlayerInterface player) { } - @Override public void run() { while(isRunning) { // include betting range @@ -52,8 +51,8 @@ public void startGame () { System.out.println("Your starting card : " + bj.playersCurrentValue()); System.out.println("Your second next card : " + bj.givePlayerCard()); System.out.println("Hand value : " + bj.playersCurrentValue()); - Integer userChoice = input.getIntegerInput("1. Hit" + "\n" + "2. Stay"); while (!isWinner) { + Integer userChoice = input.getIntegerInput("1. Hit" + "\n" + "2. Stay"); switch (userChoice) { case 1: bj.givePlayerCard(); @@ -81,25 +80,23 @@ public void startGame () { } - @Override public CasinoAccount getArcadeAccount() { return null; } - @Override public Integer calculateWinnings(Integer multiplier, Integer betAmount) { totalWinnings = multiplier * betAmount; return totalWinnings; } - @Override + public void subtractBetFromBalance(Integer betAmount) { } - @Override - public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + } } diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java index 125cf1a5b..ba6d92df6 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java @@ -1,5 +1,7 @@ package com.github.zipcodewilmington; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; import com.github.zipcodewilmington.casino.games.blackjack.BlackJackGame; import org.junit.Test; @@ -7,6 +9,7 @@ public class BlackJackGameTest { @Test public void runTest () { + Player player = new Player("Roger", 5000); BlackJackGame bj = new BlackJackGame(); Integer userInput = 1; From 4b68a1aed88c7c5872225e8946c45f8f8b709b1f Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Wed, 14 Jul 2021 13:22:16 -0400 Subject: [PATCH 056/104] Feature/beetle game test (#40) * fixed Player class to implement PlayerInterface, to allow for games with multiple players * Edited BeetlePlayer.java, working proto of BeetleGame, single test on BeetleGameTest, fixed error in Dice class logic that caused rolls/bin references to go out of range Co-authored-by: Zach --- .../github/zipcodewilmington/casino/Player.java | 13 +++++++++++-- .../casino/games/Beetle/Beetle.java | 2 +- .../casino/games/Beetle/BeetleGame.java | 17 +++++++++++++---- .../casino/games/Beetle/BeetlePlayer.java | 8 +++++--- .../zipcodewilmington/casino/models/Dice.java | 8 ++++---- .../zipcodewilmington/BeetleGameTest.java | 10 +++++++++- 6 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/Player.java b/src/main/java/com/github/zipcodewilmington/casino/Player.java index ababeb5cb..b1098791f 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/Player.java +++ b/src/main/java/com/github/zipcodewilmington/casino/Player.java @@ -1,9 +1,13 @@ package com.github.zipcodewilmington.casino; + +public class Player implements PlayerInterface{ + public class Player{ String name; Integer balance; Integer currentBet = 0; + CasinoAccount arcadeAccount; public Player(String name, Integer initialDeposit) { this.name = name; @@ -19,7 +23,7 @@ public Integer getBalance() { return balance; } - private void setCurrentBet(Integer currentBet) { + public void setCurrentBet(Integer currentBet) { this.currentBet = currentBet; } @@ -34,7 +38,12 @@ public Integer makeBet(Integer betAmount) { return currentBet; } - private Integer getCurrentBet() { + public Integer getCurrentBet() { return currentBet; } + + public CasinoAccount getArcadeAccount(){ + return this.arcadeAccount; + } + } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java index f205cc4d5..6a621ee77 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java @@ -56,7 +56,7 @@ public void setCurrentPlayer(Integer currentPlayer) { } public void setPlayerBeetles(Integer player, Integer diceRoll) { - this.playerBeetles[player][diceRoll]++; + this.playerBeetles[player][diceRoll - dice.getNumDice()]++; //return this.checkWinner(player); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index a8f7e73b3..23cd306c4 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -10,6 +10,14 @@ public class BeetleGame implements GameInterface { private Beetle game; private Boolean isRunning = false; private PlayerInterface player; + + public BeetleGame(PlayerInterface... players){ + this.game = new Beetle(players.length); + for(int i = 0; i < players.length; i++){ + this.add(players[i]); + } + } + public void add(PlayerInterface player){ players.add(player); } @@ -27,14 +35,16 @@ public void remove(PlayerInterface player){ */ public void run(){ Integer turnCount = 0; - if(isRunning){ + game.setCurrentPlayer(-1); + this.isRunning = true; + while(isRunning){ turnCount++; this.nextPlayer(); - game.getDice().tossAndSum(); + //game.getDice().tossAndSum(); executeTurn(); isGameOver(game.checkWinner(game.getCurrentPlayer())); } - System.out.println("game over after " + turnCount); + System.out.println("game over after, player " + game.getCurrentPlayer() + " wins"); } public void isGameOver(boolean playerWon){ @@ -43,7 +53,6 @@ public void isGameOver(boolean playerWon){ } } public void nextPlayer(){ - game.setCurrentPlayer(-1); game.nextPlayer(); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java index b4c16f59e..a6a298507 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java @@ -1,9 +1,11 @@ package com.github.zipcodewilmington.casino.games.Beetle; -public class BeetlePlayer { - private Integer bet; +import com.github.zipcodewilmington.casino.Player; - public BeetlePlayer(){ +public class BeetlePlayer extends Player { + private Integer bet; + public BeetlePlayer(String name, Integer initialDeposit){ + super(name, initialDeposit); } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/models/Dice.java b/src/main/java/com/github/zipcodewilmington/casino/models/Dice.java index 3df284267..d4e7e6d2d 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/models/Dice.java +++ b/src/main/java/com/github/zipcodewilmington/casino/models/Dice.java @@ -10,9 +10,9 @@ public class Dice { public Dice(Integer numberOfDice){ this.numDice = numberOfDice; this.maxRoll = numberOfDice * 6; - this.maxBinIndex = numberOfDice * 6 - numberOfDice - 1; + this.maxBinIndex = numberOfDice * 6 - numberOfDice; this.rollValues = new Integer[this.numDice]; - this.bins = new Integer[numberOfDice * 6 - numberOfDice - 1]; + this.bins = new Integer[numberOfDice * 6 - (numberOfDice - 1)] ; this.initializeDiceList(); this.initializeBins(); } @@ -48,7 +48,7 @@ public void initializeDiceList(){ } public void initializeBins(){ - for(int i = 0; i < maxBinIndex; i++){ + for(int i = 0; i <= maxBinIndex; i++){ this.bins[i] = 0; } } @@ -56,7 +56,7 @@ public void initializeBins(){ public Integer tossAndSum(){ int sum = 0; for(int i = 0; i < numDice; i++){ - sum += (Math.random() * 7) + 1; + sum += (Math.random() * 6) + 1; } this.incrementBin(sum); return sum; diff --git a/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java index a125e9afd..e72044a6a 100644 --- a/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java @@ -1,12 +1,20 @@ package com.github.zipcodewilmington; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; import com.github.zipcodewilmington.casino.games.Beetle.BeetleGame; +import com.github.zipcodewilmington.casino.games.Beetle.BeetlePlayer; import org.junit.Test; public class BeetleGameTest { @Test public void testGameOver(){ - BeetleGame game = new BeetleGame(); + BeetlePlayer player1 = new BeetlePlayer("Jeff", 10); + BeetlePlayer player2 = new BeetlePlayer("Aria", 10); + BeetleGame game = new BeetleGame(player1, player2); + game.add(player1); + game.add(player2); + game.run(); Boolean isGameOver = game.getIsRunning(); } } From f93574ce8709d0804f85d7c62adb66a201e63aa9 Mon Sep 17 00:00:00 2001 From: Zach Date: Wed, 14 Jul 2021 14:05:07 -0400 Subject: [PATCH 057/104] fixed unresolved/undetected merge issue in Player Class --- src/main/java/com/github/zipcodewilmington/casino/Player.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/Player.java b/src/main/java/com/github/zipcodewilmington/casino/Player.java index b1098791f..ecb9b799e 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/Player.java +++ b/src/main/java/com/github/zipcodewilmington/casino/Player.java @@ -3,7 +3,6 @@ public class Player implements PlayerInterface{ -public class Player{ String name; Integer balance; Integer currentBet = 0; From 67a1a6028a57788245dc351eb00e347bed759208 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 14 Jul 2021 14:37:02 -0400 Subject: [PATCH 058/104] (feat:black-jack) implementing 2 unique game conditions --- .../github/zipcodewilmington/casino/Player.java | 1 - .../casino/games/blackjack/BlackJack.java | 6 ++---- .../casino/games/blackjack/BlackJackGame.java | 15 ++++++++------- .../github/zipcodewilmington/utils/DemoMain.java | 9 +++++++++ .../zipcodewilmington/BlackJackGameTest.java | 1 + 5 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/github/zipcodewilmington/utils/DemoMain.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/Player.java b/src/main/java/com/github/zipcodewilmington/casino/Player.java index b1098791f..ecb9b799e 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/Player.java +++ b/src/main/java/com/github/zipcodewilmington/casino/Player.java @@ -3,7 +3,6 @@ public class Player implements PlayerInterface{ -public class Player{ String name; Integer balance; Integer currentBet = 0; diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java index 74fc65827..0cbede2a4 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -26,6 +26,8 @@ public BlackJack() { public List generateNewDeck() { Card card = new Card(); + card.polishDeck(); + card.shuffleDeck(); return card.getCardPool(); } @@ -48,7 +50,6 @@ public List giveDealerCard() { } public Integer playersCurrentValue() { - givePlayerCard(); Integer sum = 0; for (int i = 0; i < this.playersHand.size(); i++) { sum += this.playersHand.get(i); @@ -57,7 +58,6 @@ public Integer playersCurrentValue() { } public Integer dealersCurrentValue() { - giveDealerCard(); Integer sum = 0; for (int i = 0; i < this.dealersHand.size(); i++) { sum += this.dealersHand.get(i); @@ -85,7 +85,6 @@ public void dealersGame() { gameEnd = true; } else { giveDealerCard(); - System.out.println("The dealer has : " + dealersCurrentValue()); } } } @@ -97,7 +96,6 @@ public void playerSplit () { } public boolean playerBreaks21() { - if (playersCurrentValue() > 21) { return true; } else { diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index 56637b376..98bdb6c44 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -12,7 +12,6 @@ public class BlackJackGame implements GameInterface, PlayerInterface { private PlayerInterface player; Integer userBet; IOConsole input = new IOConsole(); - boolean isWinner = false; Integer totalWinnings = 0; @@ -26,7 +25,7 @@ public void remove(PlayerInterface player) { } public void run() { - while(isRunning) { + while(!isRunning) { // include betting range BlackJack bj = new BlackJack(); Integer userInput = input.getIntegerInput("1. Start A Hand" + "\n" + "2. Quit" + "\n"); @@ -46,20 +45,22 @@ public void run() { } public void startGame () { + boolean isWinner = false; BlackJack bj = new BlackJack(); bj.givePlayerCard(); System.out.println("Your starting card : " + bj.playersCurrentValue()); System.out.println("Your second next card : " + bj.givePlayerCard()); System.out.println("Hand value : " + bj.playersCurrentValue()); + while (!isWinner) { Integer userChoice = input.getIntegerInput("1. Hit" + "\n" + "2. Stay"); switch (userChoice) { case 1: bj.givePlayerCard(); - bj.playersCurrentValue(); - if(bj.playerBreaks21()) { + System.out.println(bj.playersCurrentValue()); + if(bj.playersCurrentValue() > 21) { System.out.println("Sorry bud, you got " + bj.playersCurrentValue() + - "better luck next time"); + ", better luck next time"); subtractBetFromBalance(userBet); isWinner = true; } else if (bj.playerHitsBlackJack()) { @@ -72,8 +73,8 @@ public void startGame () { bj.giveDealerCard(); System.out.println("The dealers first card : " + bj.dealersCurrentValue()); bj.giveDealerCard(); - System.out.println("The dealer has : " + bj.dealersCurrentValue()); bj.dealersGame(); + isWinner = true; break; } } @@ -97,6 +98,6 @@ public void subtractBetFromBalance(Integer betAmount) { public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { - + } } diff --git a/src/main/java/com/github/zipcodewilmington/utils/DemoMain.java b/src/main/java/com/github/zipcodewilmington/utils/DemoMain.java new file mode 100644 index 000000000..a0cf0bda8 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/utils/DemoMain.java @@ -0,0 +1,9 @@ +package com.github.zipcodewilmington.utils; + +import com.github.zipcodewilmington.casino.games.blackjack.BlackJackGame; + +public class DemoMain { + public static void main(String[] args) { + new BlackJackGame().run(); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java index ba6d92df6..0696a2399 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java @@ -14,5 +14,6 @@ public void runTest () { Integer userInput = 1; bj.run(); + } } From 287d5c718cff88debcb427ef48503f0c7fbfda0b Mon Sep 17 00:00:00 2001 From: Dipinti Date: Wed, 14 Jul 2021 15:55:06 -0400 Subject: [PATCH 059/104] keno game is ready --- .../casino/games/keno/Keno.java | 226 ++++++++++++++++++ .../github/zipcodewilmington/KenoTest.java | 18 ++ 2 files changed, 244 insertions(+) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/keno/Keno.java create mode 100644 src/test/java/com/github/zipcodewilmington/KenoTest.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/Keno.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/Keno.java new file mode 100644 index 000000000..493fed820 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/Keno.java @@ -0,0 +1,226 @@ +package com.github.zipcodewilmington.casino.games.keno; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; + +import java.util.Random; +import java.util.Scanner; + +public class Keno implements GameInterface, PlayerInterface { + int playerNumbers[] = new int[15]; + int computerGeneratedNumbers[] = new int[20]; + int kenoSpot, kenoCatch; + boolean continueGame = true; + Integer bet; + Player player; + Integer multiplier; + + public Integer getMultiplier() { + return multiplier; + } + + public void setMultiplier(Integer multiplier) { + this.multiplier = multiplier; + } + + + + public void setPlayerNumbers(int[] playerNumbers) { + this.playerNumbers = playerNumbers; + } + + @Override + public void add(PlayerInterface player) { + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public void run() { + //playerNums = getUserInput(); + //bet = getBet(player.getBalance()); + //player.makeBet(bet); + computerGeneratedNumbers = getComputerGeneratedNames(); + kenoSpot = getSpot(playerNumbers); + kenoCatch = getCatch(playerNumbers, computerGeneratedNumbers); + System.out.println("Catch: " + (kenoCatch + 1)); + Integer winningsAmount = 0; + + Integer winnings[][] = + { + {7, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, + {3, 9, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0}, + {4, 2, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 1, 10, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 1, 3, 15, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {1, 1, 2, 3, 30, 88, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {6, 0, 1, 6, 12, 64, 100, 0, 0, 0, 0, 0, 0, 0, 0}, + {3, 0, 1, 3, 6, 30, 90, 120, 0, 0, 0, 0, 0, 0, 0}, + {2, 0, 1, 2, 4, 8, 20, 80, 1200, 0, 0, 0, 0, 0, 0}, + {1, 0, 1, 2, 3, 5, 10, 30, 600, 1800, 0, 0, 0, 0, 0}, + {0, 1, 1, 1, 2, 6, 15, 25, 180, 1000, 3000, 0, 0, 0, 0}, + {0, 0, 5, 1, 2, 4, 24, 72, 250, 500, 2000, 4000, 0, 0, 0}, + {0, 0, 4, 0, 3, 4, 5, 20, 80, 240, 500, 3000, 6000, 0, 0}, + {0, 0, 0, 0, 2, 3, 5, 12, 50, 150, 500, 1000, 2000, 7500, 0}, + {0, 0, 0, 0, 1, 2, 5, 15, 50, 150, 300, 600, 1200, 2500, 10000} + }; + if(kenoCatch < 0) + { + multiplier = 0; + } + else + multiplier=winnings[kenoSpot][kenoCatch]; + + } + + + public static int getCatch(int[] playerArray, int[] computerArray) + { + int playerIndex; + int computerIndex; + int kenoCatch = 0; + for (playerIndex = 0; playerIndex < playerArray.length; playerIndex++) + { + for(computerIndex = 0; computerIndex < computerArray.length; computerIndex++) + { + if(playerArray[playerIndex] == computerArray[computerIndex]) + { + kenoCatch++; + } + } + } + kenoCatch-=1; + return kenoCatch; + } + + public static int getSpot(int[] playerArray) + { + int index; + int spot = 0; + for (index = 0; index < playerArray.length; index++) + { + if(playerArray[index] != 0) + { + spot++; + } + + } + spot -= 1; //Subtract one so it works properly in array + return spot; + } + + public static int[] getComputerGeneratedNames() + { + int[] computerNums = new int[20]; + Random rand = new Random(); + int index; + int randomNumber = 0; + + for (index = 0; index < computerNums.length; index++) + { + randomNumber = rand.nextInt(80) + 1; + if(isUnique(randomNumber, computerNums)) + { + computerNums[index] = randomNumber; + } + else + { + index--; + } + + } + return computerNums; + } + + public static int[] getUserInput() + { + Scanner input = new Scanner(System.in); // for input + boolean invalidInput = true; + boolean continuePlayer = true; + int playerNums[] = new int[15]; + int index; + int numberEntered; + String enterString; + System.out.println("You may enter up to 15 numbers"); + for (index = 0; index < playerNums.length; index++ ) + { + playerNums[index] = 0; + } + index = 0; + while(continuePlayer && index < 15) + { + do + { + do + { + System.out.println("Enter number " + (index+1)); + numberEntered = input.nextInt(); + if ((numberEntered > 0) && (numberEntered < 81)) + { + if(isUnique(numberEntered, playerNums)) + { + invalidInput = false; + playerNums[index] = numberEntered; + } + else + { + System.out.println("Sorry, you already entered that number before!"); + System.out.println("Try again! "); + invalidInput = true; + } + } + else + { + invalidInput = true; + System.out.println("Sorry, the number you entered is either less than 0 or greater than 80"); + System.out.println("Try again"); + System.out.println(""); + } + } while(invalidInput); + + }while(invalidInput); + + index++; + } + return playerNums; + } + + public static boolean isUnique(int number, int[] array) + { + int index; + for (index = 0; index < array.length; index++) + { + if(number == array[index]) + { + return false; + } + } + return true; + } + + + @Override + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return this.multiplier*betAmount; + } + + @Override + public void subtractBetFromBalance(Integer betAmount) { + player.setBalance(player.getBalance()-betAmount); + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + + } + + @Override + public CasinoAccount getArcadeAccount() { + return null; + } +} diff --git a/src/test/java/com/github/zipcodewilmington/KenoTest.java b/src/test/java/com/github/zipcodewilmington/KenoTest.java new file mode 100644 index 000000000..9563460c7 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/KenoTest.java @@ -0,0 +1,18 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.games.keno.Keno; +import org.junit.Test; + +public class KenoTest { + @Test + public void testRun(){ + Player player=new Player("Dipinti",3000); + Keno keno=new Keno(); + int[] playerNums={80,23,31,14,54,36,72,18,91,1,11,12,13,14,44}; + keno.setPlayerNumbers(playerNums); + keno.run(); + Integer winnings=keno.calculateWinnings(keno.getMultiplier(),3000); + System.out.println(winnings); + } +} From 0d6499a42abbcf4411f27d4d79c0da218648b6fd Mon Sep 17 00:00:00 2001 From: Nathan Date: Wed, 14 Jul 2021 17:56:02 -0400 Subject: [PATCH 060/104] Everything works except player --- .../zipcodewilmington/MainApplication.java | 7 +- .../zipcodewilmington/casino/Player.java | 1 - .../casino/games/slots/Slots.java | 13 ++- .../casino/games/slots/SlotsGame.java | 104 ++++++++++++++---- .../casino/games/slots/SlotsPlayer.java | 33 +++++- .../zipcodewilmington/SlotsGameTest.java | 57 ++++++++++ .../github/zipcodewilmington/SlotsTest.java | 8 ++ 7 files changed, 197 insertions(+), 26 deletions(-) create mode 100644 src/test/java/com/github/zipcodewilmington/SlotsGameTest.java diff --git a/src/main/java/com/github/zipcodewilmington/MainApplication.java b/src/main/java/com/github/zipcodewilmington/MainApplication.java index 508787a85..00cacf64c 100644 --- a/src/main/java/com/github/zipcodewilmington/MainApplication.java +++ b/src/main/java/com/github/zipcodewilmington/MainApplication.java @@ -1,7 +1,12 @@ package com.github.zipcodewilmington; +import com.github.zipcodewilmington.casino.games.slots.SlotsGame; + public class MainApplication { public static void main(String[] args) { - new Casino().run(); + //new Casino().run(); + + SlotsGame slotGame = new SlotsGame(); + slotGame.run(); } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/Player.java b/src/main/java/com/github/zipcodewilmington/casino/Player.java index b1098791f..ecb9b799e 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/Player.java +++ b/src/main/java/com/github/zipcodewilmington/casino/Player.java @@ -3,7 +3,6 @@ public class Player implements PlayerInterface{ -public class Player{ String name; Integer balance; Integer currentBet = 0; diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java index d40ff0e6f..58f7bc549 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java @@ -4,7 +4,7 @@ public class Slots { - private static final String[] slotItems = {"Peach", "Cherry", "Diamond", "Plum", "Seven", "Nine"}; + private static final String[] slotItems = {" Peach ", " Cherry", "Diamond", " Plum ", " Seven ", " Nine "}; private String[][] slots = new String[3][3]; private HashMap winningLines = new HashMap<>(); @@ -91,7 +91,16 @@ public String[] compareBetVsWinningLines(Integer[] bets){ return result; } - //new comment + public void displaySlots(){ + System.out.println( + "\u001B[34m -------------------------------\n" + + " "+ slots[0][0] +" | "+slots[0][1] + " | " +slots[0][2]+" \n" + + " -------------------------------\n" + + " "+ slots[1][0] +" | "+slots[1][1] + " | " +slots[1][2]+ " \n"+ + " -------------------------------\n" + + " "+ slots[2][0] +" | "+slots[2][1] + " | " +slots[2][2]+" \n" + + " -------------------------------\n"); + } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index a7430f0b4..008b6f3f5 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -1,10 +1,8 @@ package com.github.zipcodewilmington.casino.games.slots; import com.github.zipcodewilmington.casino.GameInterface; -import com.github.zipcodewilmington.casino.Player; import com.github.zipcodewilmington.casino.PlayerInterface; -import java.net.Inet4Address; import java.util.Scanner; /** @@ -15,12 +13,16 @@ public class SlotsGame implements GameInterface{ private Integer betTotal; private Integer loseMultiplier; private Integer winMultiplier; - private PlayerInterface player; + private PlayerInterface currentPlayer; + private Slots slotMachine; + + public SlotsGame(){ + + } @Override public void add(PlayerInterface player) { - this.player = player; - + this.currentPlayer = player; } @Override @@ -28,42 +30,79 @@ public void remove(PlayerInterface player) { } + public Integer getLoseMultiplier() { + return loseMultiplier; + } + + public Integer getWinMultiplier() { + return winMultiplier; + } + @Override public void run() { + printWelcome(); + Slots newSlotMachine = new Slots(); + slotMachine = newSlotMachine; + slotMachine.displaySlots(); + //addPlayer + + Scanner scanner = new Scanner(System.in); Boolean quitGame = false; - while(quitGame = false) { - Slots slotMachine = new Slots(); + while(!quitGame) { getBetAmount(); Integer[] selectedBets = getBetSelections(); - //takeBetTotalFromPlayerBalance(); + //take money from player object + + slotMachine.spinSlots(); + slotMachine.displaySlots(); + slotMachine.setWinningLines(); String[] betResults = slotMachine.compareBetVsWinningLines(selectedBets); - calculateMultiplier(betResults); + this.calculateMultiplier(betResults); Integer winnings = calculateWinnings(this.winMultiplier, playerBetAmount); Integer losings = calculateWinnings(this.loseMultiplier, playerBetAmount); Integer returnTotal = calculateReturnTotal(winnings, losings); - //addMoneyToBalance(, returnTotal); - + System.out.println("\u001B[31mYou won: " + winnings + " dollars!\n"); + //add winning to player object + + System.out.println("\u001B[36mWould you like to play again?\n" + + "1. Yes 2. No"); + Integer input = scanner.nextInt(); + if(input == 2){ + quitGame = true; + } + } } + private void printWelcome() { + System.out.println( + "\u001B[33m***********************************\n" + + "*** ***\n" + + "****** WELCOME TO SLOTS ******\n" + + "*** ***\n" + + "***********************************"); + } private void getBetAmount() { Scanner scanner = new Scanner(System.in); - System.out.println("How much you do want to bet?"); + System.out.println("\u001B[34mHow much you do want to bet?"); Integer input = scanner.nextInt(); playerBetAmount = input; } - private Integer[] getBetSelections() { + public Integer[] getBetSelections() { Scanner scanner = new Scanner(System.in); - System.out.println("How many lines do you want to bet on?"); + System.out.println("\u001B[35mHow many lines do you want to bet on?"); Integer numberOfLines = scanner.nextInt(); Integer totalCost = playerBetAmount * numberOfLines; - System.out.println("The total cost to play is " + totalCost); + System.out.println("\u001B[31mTotal cost to play: " + totalCost); + //function to subtract this total from player's wallet + + setBetTotal(totalCost); System.out.println( - "************************************************************************\n" + + "\u001B[36m************************************************************************\n" + "** Select the lines you want to bet on! **\n" + "** 1. Top Horizontal 2. Middle Horizontal 3. Bottom Horizontal **\n" + "** 4. Left Vertical 5. Middle Vertical 6. Right Vertical **\n" + @@ -72,22 +111,22 @@ private Integer[] getBetSelections() { Integer count = 0; Integer[] selectedLines = new Integer[numberOfLines]; while (count < numberOfLines){ - System.out.println("Select your line #" + (count + 1)); + System.out.println("\u001B[32mSelect your line #" + (count + 1)); selectedLines[count] = scanner.nextInt(); count++; } return selectedLines; } - private void calculateMultiplier(String[] betResults) { + public void calculateMultiplier(String[] betResults) { Integer countWin = 0; Integer countLose = 0; - //Integer[] winVsLose = new Integer[2]; + Integer[] winVsLose = new Integer[2]; for(String outcome: betResults){ - if(outcome.equals("Win")){ + if(outcome == "WIN"){ countWin++; } else { - countLose--; + countLose++; } } this.winMultiplier = countWin; @@ -110,7 +149,30 @@ public void subtractBetFromBalance(Integer losings) { @Override public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + } + + public Integer getPlayerBetAmount() { + return playerBetAmount; + } + + public void setPlayerBetAmount(Integer playerBetAmount) { + this.playerBetAmount = playerBetAmount; + } + + public Integer getBetTotal() { + return betTotal; + } + public void setBetTotal(Integer betTotal) { + this.betTotal = betTotal; } + + public PlayerInterface getCurrentPlayer() { + return currentPlayer; + } + + public void setCurrentPlayer(PlayerInterface currentPlayer) { + this.currentPlayer = currentPlayer; + } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java index c5c6df9d3..09d9b5290 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java @@ -1,8 +1,39 @@ package com.github.zipcodewilmington.casino.games.slots; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; + /** * Created by leon on 7/21/2020. */ -public class SlotsPlayer { +public class SlotsPlayer implements PlayerInterface { + private Integer accountTotal; + + public SlotsPlayer(){ + } + + @Override + public CasinoAccount getArcadeAccount() { + return null; + } + + public void subtractFromTotal(Integer value){ + Integer newTotal = accountTotal - value; + accountTotal = newTotal; + } + + public void addToTotal(Integer value){ + Integer newTotal = accountTotal + value; + accountTotal = newTotal; + } + + public Integer getAccountTotal() { + return accountTotal; + } + + public void setAccountTotal(Integer accountTotal) { + this.accountTotal = accountTotal; + } } \ No newline at end of file diff --git a/src/test/java/com/github/zipcodewilmington/SlotsGameTest.java b/src/test/java/com/github/zipcodewilmington/SlotsGameTest.java new file mode 100644 index 000000000..a2e55e43b --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/SlotsGameTest.java @@ -0,0 +1,57 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.games.slots.SlotsGame; +import org.junit.Assert; +import org.junit.Test; + +public class SlotsGameTest { + @Test + public void calculateMultiplierTest(){ + //given + SlotsGame newSlotsGame = new SlotsGame(); + String[] betResults = {"WIN", "WIN", "LOSE", "LOSE"}; + Integer expectedWin = 2; + Integer expectedLose = 2; + //when + newSlotsGame.calculateMultiplier(betResults); + Integer retrievedWin = newSlotsGame.getWinMultiplier(); + Integer retrievedLose = newSlotsGame.getLoseMultiplier(); + //then + Assert.assertEquals(expectedWin, retrievedWin); + Assert.assertEquals(expectedLose, retrievedLose); + + + } + + @Test + public void calculateWinningsTest(){ + //given + SlotsGame newGame = new SlotsGame(); + Integer expected = 10; + //when + Integer actual = newGame.calculateWinnings(2, 5); + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void calculateReturnTotal(){ + //given + SlotsGame newGame = new SlotsGame(); + newGame.setBetTotal(80); + Integer expected = 100; + //when + Integer actual = newGame.calculateReturnTotal(50, 30); + //then + Assert.assertEquals(expected, actual); + + } + + @Test + public void getBetSelectionTest(){ + //given + SlotsGame newGame = new SlotsGame(); + newGame.getBetSelections(); + + } +} diff --git a/src/test/java/com/github/zipcodewilmington/SlotsTest.java b/src/test/java/com/github/zipcodewilmington/SlotsTest.java index e21f3cf68..005b7e429 100644 --- a/src/test/java/com/github/zipcodewilmington/SlotsTest.java +++ b/src/test/java/com/github/zipcodewilmington/SlotsTest.java @@ -129,5 +129,13 @@ public void compareBetVsWinningLinesTest(){ Assert.assertEquals(expected, returned); } + @Test + public void displaySlotsTest(){ + //given + Slots slot = new Slots(); + //when + slot.displaySlots(); + //then - check output + } } From d4f21a98585d03a527d97da5b7d854705fabb482 Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Wed, 14 Jul 2021 18:15:05 -0400 Subject: [PATCH 061/104] NumberGuessGame.java and NumberGuessGameTests.java submitted (#43) Co-authored-by: Zach --- .../games/numberguess/NumberGuessGame.java | 24 +++++++++ .../NumberGuessGameTests.java | 51 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java index 795709488..f4b502240 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java @@ -1,7 +1,31 @@ package com.github.zipcodewilmington.casino.games.numberguess; +import java.util.ArrayList; +import java.util.List; + /** * Created by leon on 7/21/2020. */ public class NumberGuessGame { + private Integer maxNumber; + + public NumberGuessGame(){ + this.maxNumber = 20; + } + + public void setMaxNumber(Integer number){ + this.maxNumber = number; + } + + public Integer getGuessRange(Integer guessedNumber, Integer actualNumber){ + return Math.abs(guessedNumber - actualNumber); + } + + public Double guessRangePercentage(Integer range){ + return range.doubleValue() / this.maxNumber; + } + + public Integer getMaxNumber() { + return maxNumber; + } } \ No newline at end of file diff --git a/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java b/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java new file mode 100644 index 000000000..8f1955c6e --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java @@ -0,0 +1,51 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessGame; +import org.junit.Assert; +import org.junit.Test; + +public class NumberGuessGameTests { + + @Test + public void constructorTest1(){ + NumberGuessGame game = new NumberGuessGame(); + Integer actual = game.getMaxNumber(); + Integer expected = 20; + + Assert.assertEquals(actual, expected); + } + + @Test + public void setMaxNumberTest(){ + NumberGuessGame game = new NumberGuessGame(); + game.setMaxNumber(50); + Integer actual = game.getMaxNumber(); + Integer expected = 50; + + Assert.assertEquals(actual, expected); + } + + @Test + public void getGuessRange(){ + NumberGuessGame game = new NumberGuessGame(); + Integer guessedNumber = 10; + Integer actualNumber = 5; + Integer actual = game.getGuessRange(guessedNumber, actualNumber); + Integer expected = 5; + + Assert.assertEquals(actual, expected); + } + + @Test + public void getGuessPercentage(){ + NumberGuessGame game = new NumberGuessGame(); + Integer guessedNumber = 10; + Integer max = game.getMaxNumber(); + Integer actualNumber = 5; + Integer range = Math.abs(guessedNumber - actualNumber); + Double actual = game.guessRangePercentage(range); + Double expected = 0.25; + + Assert.assertEquals(actual, expected); + } +} From 4bd45137c1f6427f17fa0ffaf125aaa3dfb4c73d Mon Sep 17 00:00:00 2001 From: Nathan Date: Wed, 14 Jul 2021 18:20:12 -0400 Subject: [PATCH 062/104] commit 620 --- .../com/github/zipcodewilmington/casino/games/slots/Slots.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java index 58f7bc549..a4f03f2e9 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java @@ -102,5 +102,5 @@ public void displaySlots(){ " -------------------------------\n"); } - +// } From 22c31a7559e7f8f50d73b13a109a32e5900a91cd Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 14 Jul 2021 19:05:24 -0400 Subject: [PATCH 063/104] (feat:black-jack) cleaned the code --- .../casino/games/blackjack/BlackJack.java | 26 ++- .../casino/games/blackjack/BlackJackGame.java | 158 ++++++++++++++---- .../zipcodewilmington/BlackJackGameTest.java | 19 +++ 3 files changed, 157 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java index 0cbede2a4..098d34ef1 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -49,6 +49,14 @@ public List giveDealerCard() { return this.dealersHand; } + public Integer splitPlayersCurrentValue () { + Integer sum = 0; + for (int i = 0; i < this.playersHandOnSplit.size(); i++) { + sum += this.playersHandOnSplit.get(i); + } + return sum; + } + public Integer playersCurrentValue() { Integer sum = 0; for (int i = 0; i < this.playersHand.size(); i++) { @@ -65,15 +73,12 @@ public Integer dealersCurrentValue() { return sum; } - - - public void dealersGame() { while (!gameEnd) { System.out.println("The dealer has : " + dealersCurrentValue()); if (dealersCurrentValue() > 21) { System.out.println("You win!"); - theGame.calculateWinnings(2, theGame.userBet); + theGame.addMoneyToBalance(theGame.player, theGame.calculateWinnings(2, theGame.userBet)); gameEnd = true; } else if (dealersCurrentValue() == 21) { System.out.println("The dealer has won!"); @@ -89,14 +94,17 @@ public void dealersGame() { } } - public void playerSplit () { - if (playersHand.get(0) == playersHand.get(1)) { - + public boolean playerBreaks21() { + if (playersCurrentValue() > 21) { + return true; + } else { + return false; } } - public boolean playerBreaks21() { - if (playersCurrentValue() > 21) { + public boolean splitPlayerHitsBlackJack () { + if (splitPlayersCurrentValue() == 21) { + theGame.calculateWinnings(3, betAmount); return true; } else { return false; diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index 98bdb6c44..bc1db3f5a 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -9,36 +9,51 @@ public class BlackJackGame implements GameInterface, PlayerInterface { private Boolean isRunning = false; - private PlayerInterface player; + private PlayerInterface playerInt; Integer userBet; IOConsole input = new IOConsole(); - Integer totalWinnings = 0; + Integer winnings = 0; + BlackJack bj; + Player player = new Player("Allen", 5000); + public BlackJackGame () { + + } + public void add(PlayerInterface player) { - this.player = player; + this.playerInt = player; } public void remove(PlayerInterface player) { - + player = null; } + public void run() { + System.out.println("\u001B[36m============================================================"); + System.out.println("\u001B[36m===== ====="); + System.out.println("\u001B[36m===== WELCOME ====="); + System.out.println("\u001B[36m===== TO ====="); + System.out.println("\u001B[36m===== B L A C K ====="); + System.out.println("\u001B[36m===== J A C K ====="); + System.out.println("\u001B[36m===== ====="); + System.out.println("\u001B[36m============================================================"); while(!isRunning) { // include betting range - BlackJack bj = new BlackJack(); - Integer userInput = input.getIntegerInput("1. Start A Hand" + "\n" + "2. Quit" + "\n"); + Integer userInput = input.getIntegerInput("\u001B[32m1. Start A Hand" + "\n" + "\u001B[31m2. Quit" + "\n"); switch (userInput) { case 1: - - this.userBet = (input.getIntegerInput("How much would you like to bet?")); - // include betting forum in case 1 + BlackJack freshHand = new BlackJack(); + bj = freshHand; + this.userBet = (input.getIntegerInput("\u001B[32mHow much would you like to bet?")); + // subtractBetFromBalance(userBet); + // System.out.println("You bet " + player.getBalance()); startGame(); break; case 2: - // include the subtractWinnings when players leave table isRunning = true; } } @@ -46,58 +61,127 @@ public void run() { public void startGame () { boolean isWinner = false; - BlackJack bj = new BlackJack(); + bj.givePlayerCard(); System.out.println("Your starting card : " + bj.playersCurrentValue()); System.out.println("Your second next card : " + bj.givePlayerCard()); System.out.println("Hand value : " + bj.playersCurrentValue()); + if (bj.playersHand.get(0).equals(bj.playersHand.get(1))) { // include conditional on starting blackjack! + splitPlayer(); + } else { + standardGame(); // Apparently the dealer can win with 12 without conditional above + } + } + public void standardGame () { + boolean isWinner = false; while (!isWinner) { + System.out.println("Your hand value " + bj.playersCurrentValue()); Integer userChoice = input.getIntegerInput("1. Hit" + "\n" + "2. Stay"); - switch (userChoice) { - case 1: - bj.givePlayerCard(); - System.out.println(bj.playersCurrentValue()); - if(bj.playersCurrentValue() > 21) { - System.out.println("Sorry bud, you got " + bj.playersCurrentValue() + - ", better luck next time"); - subtractBetFromBalance(userBet); - isWinner = true; - } else if (bj.playerHitsBlackJack()) { - System.out.println("BLACK JACK!!"); - calculateWinnings(3, userBet); - isWinner = true; - } - break; - case 2: - bj.giveDealerCard(); - System.out.println("The dealers first card : " + bj.dealersCurrentValue()); - bj.giveDealerCard(); - bj.dealersGame(); - isWinner = true; - break; - } + switch (userChoice) { + case 1: + isWinner = checkStandardWinner(isWinner); + break; + case 2: + bj.giveDealerCard(); + System.out.println("The dealers first card : " + bj.dealersCurrentValue()); + bj.giveDealerCard(); + bj.dealersGame(); + isWinner = true; + break; } } + } + + public void splitPlayer () { + Integer choice = input.getIntegerInput("1. Split" + "\n" + "2. No, I'll play this hand"); + if (choice.equals(2)) { + standardGame(); + } else { // include another betting portion for this hand + splitHandRound(); + } + } + private void splitPlayerHitsBlackJack(Integer splitBet) { + System.out.println("BLACK JACK!!"); + calculateWinnings(3, splitBet); + addMoneyToBalance(this.player, calculateWinnings(3, splitBet)); + standardGame(); + } + + private void splitPlayerBust(Integer splitBet) { + System.out.println("Sorry bud, you got " + bj.splitPlayersCurrentValue() + + ", you still have one more hand!"); + subtractBetFromBalance(splitBet); + standardGame(); + } + + private Integer secondHandBet() { + Integer splitValue = bj.playersHand.get(1); + bj.playersHandOnSplit.add(splitValue); + bj.playersHand.set(1, 0); + Integer splitBet = input.getIntegerInput("Please place your bet for the second hand"); + System.out.println("Your hand has been split! Current value " + bj.splitPlayersCurrentValue() + "\n" + "\n"); + return splitBet; + } + public CasinoAccount getArcadeAccount() { return null; } public Integer calculateWinnings(Integer multiplier, Integer betAmount) { - totalWinnings = multiplier * betAmount; - return totalWinnings; + winnings = multiplier * 4; + return winnings; } public void subtractBetFromBalance(Integer betAmount) { - + this.player.setBalance(player.getBalance() - betAmount); } public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + this.player.setBalance(player.getBalance() + winnings); + } + + private boolean checkStandardWinner(boolean isWinner) { + bj.givePlayerCard(); + System.out.println("Current hand value " + bj.playersCurrentValue()); + if(bj.playersCurrentValue() > 21) { + System.out.println("Sorry bud, you got " + bj.playersCurrentValue() + + ", better luck next time"); + subtractBetFromBalance(userBet); + isWinner = true; + } else if (bj.playerHitsBlackJack()) { + System.out.println("BLACK JACK!!"); + addMoneyToBalance(this.player, calculateWinnings(3, userBet)); + isWinner = true; + } + return isWinner; + } + private void splitHandRound() { + boolean isWinnerSecondHand = false; + Integer splitBet = secondHandBet(); + while (!isWinnerSecondHand) { + Integer userInput = input.getIntegerInput("1. Hit" + "\n" + "2. Stay"); + switch (userInput) { + case 1: + bj.givePlayerCardOnSplit(); + System.out.println("Current hand value " + bj.splitPlayersCurrentValue()); + if (bj.splitPlayersCurrentValue() > 21) { + splitPlayerBust(splitBet); + isWinnerSecondHand = true; + } else if (bj.splitPlayerHitsBlackJack()) { + splitPlayerHitsBlackJack(splitBet); + isWinnerSecondHand = true; + } + break; + case 2: + standardGame(); + } + } } } diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java index 0696a2399..1ca463c19 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java @@ -2,9 +2,13 @@ import com.github.zipcodewilmington.casino.Player; import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.blackjack.BlackJack; import com.github.zipcodewilmington.casino.games.blackjack.BlackJackGame; import org.junit.Test; +import java.util.Arrays; +import java.util.List; + public class BlackJackGameTest { @Test @@ -16,4 +20,19 @@ public void runTest () { bj.run(); } + + @Test + public void splitPlayer () { + BlackJackGame bjg = new BlackJackGame(); + BlackJack bj = new BlackJack(); + + List input = Arrays.asList(10, 10); + bj.setPlayersHand(input); + System.out.println(bj.getPlayersHand()); + System.out.println(bj.playersCurrentValue()); + + + bjg.splitPlayer(); + + } } From e84f1099e207e7cfdf8971454d08074c150b3bed Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Wed, 14 Jul 2021 19:12:51 -0400 Subject: [PATCH 064/104] Feature/number guessing (#45) * NumberGuessGame.java and NumberGuessGameTests.java submitted * Edited Player and PlayerInterface, Casino class Co-authored-by: Zach --- .../com/github/zipcodewilmington/Casino.java | 30 +++++++++++++++---- .../zipcodewilmington/casino/Player.java | 3 ++ .../casino/PlayerInterface.java | 4 ++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index 72e424327..b3f2a6ff4 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -1,9 +1,7 @@ package com.github.zipcodewilmington; -import com.github.zipcodewilmington.casino.CasinoAccount; -import com.github.zipcodewilmington.casino.CasinoAccountManager; -import com.github.zipcodewilmington.casino.GameInterface; -import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.*; +import com.github.zipcodewilmington.casino.games.Beetle.BeetleGame; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessGame; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessPlayer; import com.github.zipcodewilmington.casino.games.slots.SlotsGame; @@ -11,12 +9,15 @@ import com.github.zipcodewilmington.utils.AnsiColor; import com.github.zipcodewilmington.utils.IOConsole; +import java.util.Locale; + /** * Created by leon on 7/21/2020. */ public class Casino implements Runnable { private final IOConsole console = new IOConsole(AnsiColor.BLUE); - + private CasinoAccount casinoAccount; + private PlayerInterface player; @Override public void run() { String arcadeDashBoardInput; @@ -29,6 +30,9 @@ public void run() { CasinoAccount casinoAccount = casinoAccountManager.getAccount(accountName, accountPassword); boolean isValidLogin = casinoAccount != null; if (isValidLogin) { + this.casinoAccount = casinoAccount; + this.player = new Player(accountName, 500); + this.player.setArcadeAccount(casinoAccount); String gameSelectionInput = getGameSelectionInput().toUpperCase(); if (gameSelectionInput.equals("SLOTS")) { play(new SlotsGame(), new SlotsPlayer()); @@ -66,10 +70,24 @@ private String getGameSelectionInput() { return console.getStringInput(new StringBuilder() .append("Welcome to the Game Selection Dashboard!") .append("\nFrom here, you can select any of the following options:") - .append("\n\t[ SLOTS ], [ NUMBERGUESS ]") + .append("\n\t[ SLOTS ], [ NUMBERGUESS ], [ PLINKO ], [ BEETLE ], [ BLACKJACK ]" + + "[ KENO ]") .toString()); } + private void processGameSelection(String input){ + input = input.toLowerCase(Locale.ROOT); + GameInterface gameObject; + switch(input){ + case "beetle": + gameObject = new BeetleGame(); + default: + gameObject = new BeetleGame(); + } + + play(gameObject, player); + } + private void play(Object gameObject, Object playerObject) { GameInterface game = (GameInterface)gameObject; PlayerInterface player = (PlayerInterface)playerObject; diff --git a/src/main/java/com/github/zipcodewilmington/casino/Player.java b/src/main/java/com/github/zipcodewilmington/casino/Player.java index ecb9b799e..af9cafa23 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/Player.java +++ b/src/main/java/com/github/zipcodewilmington/casino/Player.java @@ -45,4 +45,7 @@ public CasinoAccount getArcadeAccount(){ return this.arcadeAccount; } + public void setArcadeAccount(CasinoAccount arcadeAccount) { + this.arcadeAccount = arcadeAccount; + } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java b/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java index 9d6800a71..7fd3978b8 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java +++ b/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java @@ -11,11 +11,13 @@ public interface PlayerInterface { * @return the `ArcadeAccount` used to log into the `Arcade` system to play this game */ CasinoAccount getArcadeAccount(); - + void setArcadeAccount(CasinoAccount casinoAccount); /** * Defines how a specific implementation of `PlayerInterface` plays their respective game. * @param specify any return type you would like here * @return whatever return value you would like */ + + // SomeReturnType play(); } From cf46939bc47ef9c5021551a0c5844d1f8d604c68 Mon Sep 17 00:00:00 2001 From: Nathan Date: Wed, 14 Jul 2021 19:14:14 -0400 Subject: [PATCH 065/104] new changes to slotsplayerclass --- .../com/github/zipcodewilmington/Casino.java | 2 ++ .../zipcodewilmington/MainApplication.java | 2 +- .../casino/games/slots/SlotsGame.java | 18 ++++++++++-------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index 72e424327..9fac3f691 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -32,6 +32,8 @@ public void run() { String gameSelectionInput = getGameSelectionInput().toUpperCase(); if (gameSelectionInput.equals("SLOTS")) { play(new SlotsGame(), new SlotsPlayer()); + + } else if (gameSelectionInput.equals("NUMBERGUESS")) { play(new NumberGuessGame(), new NumberGuessPlayer()); } else { diff --git a/src/main/java/com/github/zipcodewilmington/MainApplication.java b/src/main/java/com/github/zipcodewilmington/MainApplication.java index 00cacf64c..e7c76a02f 100644 --- a/src/main/java/com/github/zipcodewilmington/MainApplication.java +++ b/src/main/java/com/github/zipcodewilmington/MainApplication.java @@ -4,7 +4,7 @@ public class MainApplication { public static void main(String[] args) { - //new Casino().run(); +// new Casino().run(); SlotsGame slotGame = new SlotsGame(); slotGame.run(); diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index 008b6f3f5..4ddf472c9 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -13,7 +13,7 @@ public class SlotsGame implements GameInterface{ private Integer betTotal; private Integer loseMultiplier; private Integer winMultiplier; - private PlayerInterface currentPlayer; + private SlotsPlayer currentPlayer; private Slots slotMachine; public SlotsGame(){ @@ -22,7 +22,7 @@ public SlotsGame(){ @Override public void add(PlayerInterface player) { - this.currentPlayer = player; + this.currentPlayer = (SlotsPlayer) player; } @Override @@ -40,19 +40,23 @@ public Integer getWinMultiplier() { @Override public void run() { + Scanner scanner = new Scanner(System.in); printWelcome(); Slots newSlotMachine = new Slots(); slotMachine = newSlotMachine; + System.out.println("Make a deposit to your account!"); + Integer deposit = scanner.nextInt(); + //add deposit to currentPlayer account + currentPlayer.setAccountTotal(deposit); slotMachine.displaySlots(); - //addPlayer - Scanner scanner = new Scanner(System.in); Boolean quitGame = false; while(!quitGame) { getBetAmount(); Integer[] selectedBets = getBetSelections(); - //take money from player object + //take money from player object + currentPlayer.subtractFromTotal(betTotal); slotMachine.spinSlots(); slotMachine.displaySlots(); @@ -64,7 +68,7 @@ public void run() { Integer returnTotal = calculateReturnTotal(winnings, losings); System.out.println("\u001B[31mYou won: " + winnings + " dollars!\n"); //add winning to player object - + currentPlayer.addToTotal(winnings); System.out.println("\u001B[36mWould you like to play again?\n" + "1. Yes 2. No"); Integer input = scanner.nextInt(); @@ -97,8 +101,6 @@ public Integer[] getBetSelections() { Integer numberOfLines = scanner.nextInt(); Integer totalCost = playerBetAmount * numberOfLines; System.out.println("\u001B[31mTotal cost to play: " + totalCost); - //function to subtract this total from player's wallet - setBetTotal(totalCost); System.out.println( From a2684bc10ab6c3d49cd02cfc79e022bc34c1ede8 Mon Sep 17 00:00:00 2001 From: Nathan Date: Wed, 14 Jul 2021 19:16:36 -0400 Subject: [PATCH 066/104] changes made to slotsGame line 178 --- .../github/zipcodewilmington/casino/games/slots/SlotsGame.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index 4ddf472c9..508798261 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -175,6 +175,6 @@ public PlayerInterface getCurrentPlayer() { } public void setCurrentPlayer(PlayerInterface currentPlayer) { - this.currentPlayer = currentPlayer; + this.currentPlayer = (SlotsPlayer) currentPlayer; } } From b8a628a4dff4780ffd0710fff283925db9050752 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 14 Jul 2021 20:17:19 -0400 Subject: [PATCH 067/104] (feat:black-jack) Logic: completed / Test:To be done --- .../casino/games/blackjack/BlackJackGame.java | 54 +++++++++---------- .../zipcodewilmington/BlackJackGameTest.java | 48 ++++++++++++----- 2 files changed, 61 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index bc1db3f5a..6c400894a 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -14,7 +14,7 @@ public class BlackJackGame implements GameInterface, PlayerInterface { IOConsole input = new IOConsole(); Integer winnings = 0; BlackJack bj; - Player player = new Player("Allen", 5000); + Player player; public BlackJackGame () { @@ -60,8 +60,6 @@ public void run() { } public void startGame () { - boolean isWinner = false; - bj.givePlayerCard(); System.out.println("Your starting card : " + bj.playersCurrentValue()); System.out.println("Your second next card : " + bj.givePlayerCard()); @@ -69,7 +67,7 @@ public void startGame () { if (bj.playersHand.get(0).equals(bj.playersHand.get(1))) { // include conditional on starting blackjack! splitPlayer(); } else { - standardGame(); // Apparently the dealer can win with 12 without conditional above + standardGame(); } } @@ -103,29 +101,6 @@ public void splitPlayer () { } - private void splitPlayerHitsBlackJack(Integer splitBet) { - System.out.println("BLACK JACK!!"); - calculateWinnings(3, splitBet); - addMoneyToBalance(this.player, calculateWinnings(3, splitBet)); - standardGame(); - } - - private void splitPlayerBust(Integer splitBet) { - System.out.println("Sorry bud, you got " + bj.splitPlayersCurrentValue() + - ", you still have one more hand!"); - subtractBetFromBalance(splitBet); - standardGame(); - } - - private Integer secondHandBet() { - Integer splitValue = bj.playersHand.get(1); - bj.playersHandOnSplit.add(splitValue); - bj.playersHand.set(1, 0); - Integer splitBet = input.getIntegerInput("Please place your bet for the second hand"); - System.out.println("Your hand has been split! Current value " + bj.splitPlayersCurrentValue() + "\n" + "\n"); - return splitBet; - } - public CasinoAccount getArcadeAccount() { return null; } @@ -138,7 +113,7 @@ public Integer calculateWinnings(Integer multiplier, Integer betAmount) { public void subtractBetFromBalance(Integer betAmount) { - this.player.setBalance(player.getBalance() - betAmount); + this.player.makeBet(betAmount); } @@ -146,6 +121,20 @@ public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { this.player.setBalance(player.getBalance() + winnings); } + private void splitPlayerHitsBlackJack(Integer splitBet) { + System.out.println("BLACK JACK!!"); + calculateWinnings(3, splitBet); + addMoneyToBalance(this.player, calculateWinnings(3, splitBet)); + standardGame(); + } + + private void splitPlayerBust(Integer splitBet) { + System.out.println("Sorry bud, you got " + bj.splitPlayersCurrentValue() + + ", you still have one more hand!"); + subtractBetFromBalance(splitBet); + standardGame(); + } + private boolean checkStandardWinner(boolean isWinner) { bj.givePlayerCard(); System.out.println("Current hand value " + bj.playersCurrentValue()); @@ -162,6 +151,15 @@ private boolean checkStandardWinner(boolean isWinner) { return isWinner; } + private Integer secondHandBet() { + Integer splitValue = bj.playersHand.get(1); + bj.playersHandOnSplit.add(splitValue); + bj.playersHand.set(1, 0); + Integer splitBet = input.getIntegerInput("Please place your bet for the second hand"); + System.out.println("Your hand has been split! Current value " + bj.splitPlayersCurrentValue() + "\n" + "\n"); + return splitBet; + } + private void splitHandRound() { boolean isWinnerSecondHand = false; Integer splitBet = secondHandBet(); diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java index 1ca463c19..0f32d452a 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java @@ -4,6 +4,7 @@ import com.github.zipcodewilmington.casino.PlayerInterface; import com.github.zipcodewilmington.casino.games.blackjack.BlackJack; import com.github.zipcodewilmington.casino.games.blackjack.BlackJackGame; +import org.junit.Assert; import org.junit.Test; import java.util.Arrays; @@ -12,27 +13,48 @@ public class BlackJackGameTest { @Test - public void runTest () { - Player player = new Player("Roger", 5000); - BlackJackGame bj = new BlackJackGame(); + public void startGameTest () { + BlackJack bj = new BlackJack(); + BlackJackGame blackJackGame = new BlackJackGame(); - Integer userInput = 1; - bj.run(); + Integer choice = 2; } @Test - public void splitPlayer () { - BlackJackGame bjg = new BlackJackGame(); - BlackJack bj = new BlackJack(); + public void calculateWinningsTest () { + BlackJackGame blackJack = new BlackJackGame(); + Integer expected = 12; + + Integer multiplier = 3; + Integer betAmount = 4; + Integer actual = blackJack.calculateWinnings(multiplier, betAmount); - List input = Arrays.asList(10, 10); - bj.setPlayersHand(input); - System.out.println(bj.getPlayersHand()); - System.out.println(bj.playersCurrentValue()); + Assert.assertEquals(expected,actual); + } + + @Test + public void subtractFromBalance () { + BlackJackGame blackJack = new BlackJackGame(); + Player player = new Player("Steve", 100); + Integer expected = 60; + Integer bet = 40; + blackJack.subtractBetFromBalance(bet); + Integer actual = player.getBalance(); - bjg.splitPlayer(); + Assert.assertEquals(expected, actual); + } + @Test + public void addMoneyToBalanceTest () { + BlackJackGame bj = new BlackJackGame(); + + } + + @Test + public void splitPlayerHitsBlackJack () { + BlackJackGame bj = new BlackJackGame(); + } } From e036e3bba7595a1d69bc1929e0599bf5a4ab53e6 Mon Sep 17 00:00:00 2001 From: Nathan Date: Wed, 14 Jul 2021 20:28:11 -0400 Subject: [PATCH 068/104] Changed player class, slots fully functional --- .../com/github/zipcodewilmington/Casino.java | 5 ++- .../casino/CasinoAccount.java | 10 ++++- .../zipcodewilmington/casino/Player.java | 4 +- .../casino/games/Beetle/BeetlePlayer.java | 20 +++++++-- .../casino/games/slots/SlotsGame.java | 20 +++++---- .../casino/games/slots/SlotsPlayer.java | 41 ++++++++++--------- .../zipcodewilmington/BeetleGameTest.java | 14 +++---- .../zipcodewilmington/BlackJackGameTest.java | 2 +- .../github/zipcodewilmington/KenoTest.java | 2 +- 9 files changed, 72 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index b515c2119..b992d8eb8 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -31,11 +31,12 @@ public void run() { boolean isValidLogin = casinoAccount != null; if (isValidLogin) { this.casinoAccount = casinoAccount; - this.player = new Player(accountName, 500); + casinoAccount.alterAccountBalance(500); + this.player = new Player(accountName, casinoAccount); this.player.setArcadeAccount(casinoAccount); String gameSelectionInput = getGameSelectionInput().toUpperCase(); if (gameSelectionInput.equals("SLOTS")) { - play(new SlotsGame(), new SlotsPlayer()); + play(new SlotsGame(), new SlotsPlayer(this.player)); } else if (gameSelectionInput.equals("NUMBERGUESS")) { diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java index cd5b53aef..7883d56f3 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java @@ -13,14 +13,13 @@ public class CasinoAccount { private String password; private String accountName; - + private Integer accountBalance = 0; public CasinoAccount(String accountName, String accountPassword){ this.accountName = accountName; this.password = accountPassword; } - public String getPassword() { return password; } @@ -29,4 +28,11 @@ public String getAccountName() { return accountName; } + public Integer getAccountBalance() { + return accountBalance; + } + + public void alterAccountBalance(Integer value) { + this.accountBalance += value; + } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/Player.java b/src/main/java/com/github/zipcodewilmington/casino/Player.java index af9cafa23..0f5578c68 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/Player.java +++ b/src/main/java/com/github/zipcodewilmington/casino/Player.java @@ -8,9 +8,9 @@ public class Player implements PlayerInterface{ Integer currentBet = 0; CasinoAccount arcadeAccount; - public Player(String name, Integer initialDeposit) { + public Player(String name, CasinoAccount account) { this.name = name; - this.balance = initialDeposit; + this.arcadeAccount = account; } public String getName() { diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java index a6a298507..09b4f79cc 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java @@ -1,11 +1,23 @@ package com.github.zipcodewilmington.casino.games.Beetle; +import com.github.zipcodewilmington.casino.CasinoAccount; import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; -public class BeetlePlayer extends Player { - private Integer bet; +public class BeetlePlayer implements PlayerInterface { + private PlayerInterface player; + + public BeetlePlayer(PlayerInterface player){ + this.player = player; + } + + @Override + public CasinoAccount getArcadeAccount() { + return null; + } + + @Override + public void setArcadeAccount(CasinoAccount casinoAccount) { - public BeetlePlayer(String name, Integer initialDeposit){ - super(name, initialDeposit); } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index 508798261..938aeb73e 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -13,7 +13,7 @@ public class SlotsGame implements GameInterface{ private Integer betTotal; private Integer loseMultiplier; private Integer winMultiplier; - private SlotsPlayer currentPlayer; + private PlayerInterface currentPlayer; private Slots slotMachine; public SlotsGame(){ @@ -22,7 +22,7 @@ public SlotsGame(){ @Override public void add(PlayerInterface player) { - this.currentPlayer = (SlotsPlayer) player; + this.currentPlayer = player; } @Override @@ -44,19 +44,25 @@ public void run() { printWelcome(); Slots newSlotMachine = new Slots(); slotMachine = newSlotMachine; - System.out.println("Make a deposit to your account!"); - Integer deposit = scanner.nextInt(); +// System.out.println("Make a deposit to your account!"); +// Integer deposit = scanner.nextInt(); //add deposit to currentPlayer account - currentPlayer.setAccountTotal(deposit); +// currentPlayer.getArcadeAccount().alterAccountBalance(deposit); + slotMachine.spinSlots(); + //Display first slots slotMachine.displaySlots(); Boolean quitGame = false; while(!quitGame) { + + //print initial account balance + System.out.println("\u001B[35mCurrent account balance: " + currentPlayer.getArcadeAccount().getAccountBalance() + "\n"); + getBetAmount(); Integer[] selectedBets = getBetSelections(); //take money from player object - currentPlayer.subtractFromTotal(betTotal); + currentPlayer.getArcadeAccount().alterAccountBalance(betTotal * (-1)); slotMachine.spinSlots(); slotMachine.displaySlots(); @@ -68,7 +74,7 @@ public void run() { Integer returnTotal = calculateReturnTotal(winnings, losings); System.out.println("\u001B[31mYou won: " + winnings + " dollars!\n"); //add winning to player object - currentPlayer.addToTotal(winnings); + currentPlayer.getArcadeAccount().alterAccountBalance(winnings); System.out.println("\u001B[36mWould you like to play again?\n" + "1. Yes 2. No"); Integer input = scanner.nextInt(); diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java index bd9c2ed7f..543254a55 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java @@ -8,14 +8,15 @@ * Created by leon on 7/21/2020. */ public class SlotsPlayer implements PlayerInterface { - private Integer accountTotal; + private PlayerInterface player; - public SlotsPlayer(){ + public SlotsPlayer(PlayerInterface player){ + this.player = player; } @Override public CasinoAccount getArcadeAccount() { - return null; + return player.getArcadeAccount(); } @Override @@ -23,22 +24,22 @@ public void setArcadeAccount(CasinoAccount casinoAccount) { } - public void subtractFromTotal(Integer value){ - Integer newTotal = accountTotal - value; - accountTotal = newTotal; - } - - public void addToTotal(Integer value){ - Integer newTotal = accountTotal + value; - accountTotal = newTotal; - } - - public Integer getAccountTotal() { - return accountTotal; - } - - public void setAccountTotal(Integer accountTotal) { - this.accountTotal = accountTotal; - } +// public void subtractFromTotal(Integer value){ +// Integer newTotal = accountTotal - value; +// accountTotal = newTotal; +// } +// +// public void addToTotal(Integer value){ +// Integer newTotal = accountTotal + value; +// accountTotal = newTotal; +// } +// +// public Integer getAccountTotal() { +// return accountTotal; +// } +// +// public void setAccountTotal(Integer accountTotal) { +// this.accountTotal = accountTotal; +// } } \ No newline at end of file diff --git a/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java index e72044a6a..350af9fa4 100644 --- a/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java @@ -9,12 +9,12 @@ public class BeetleGameTest { @Test public void testGameOver(){ - BeetlePlayer player1 = new BeetlePlayer("Jeff", 10); - BeetlePlayer player2 = new BeetlePlayer("Aria", 10); - BeetleGame game = new BeetleGame(player1, player2); - game.add(player1); - game.add(player2); - game.run(); - Boolean isGameOver = game.getIsRunning(); +//// BeetlePlayer player1 = new BeetlePlayer("Jeff", 10); +//// BeetlePlayer player2 = new BeetlePlayer("Aria", 10); +// BeetleGame game = new BeetleGame(player1, player2); +// game.add(player1); +// game.add(player2); +// game.run(); +// Boolean isGameOver = game.getIsRunning(); } } diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java index 0696a2399..5f16e9705 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java @@ -9,7 +9,7 @@ public class BlackJackGameTest { @Test public void runTest () { - Player player = new Player("Roger", 5000); + //Player player = new Player("Roger", 5000); BlackJackGame bj = new BlackJackGame(); Integer userInput = 1; diff --git a/src/test/java/com/github/zipcodewilmington/KenoTest.java b/src/test/java/com/github/zipcodewilmington/KenoTest.java index 9563460c7..ea129ed35 100644 --- a/src/test/java/com/github/zipcodewilmington/KenoTest.java +++ b/src/test/java/com/github/zipcodewilmington/KenoTest.java @@ -7,7 +7,7 @@ public class KenoTest { @Test public void testRun(){ - Player player=new Player("Dipinti",3000); + //Player player=new Player("Dipinti",3000); Keno keno=new Keno(); int[] playerNums={80,23,31,14,54,36,72,18,91,1,11,12,13,14,44}; keno.setPlayerNumbers(playerNums); From 12143a666065d12b85bb6096ed4204a50d122b64 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 14 Jul 2021 20:32:04 -0400 Subject: [PATCH 069/104] prepull --- .../java/com/github/zipcodewilmington/BlackJackGameTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java index 0f32d452a..56efd009f 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java @@ -55,6 +55,6 @@ public void addMoneyToBalanceTest () { @Test public void splitPlayerHitsBlackJack () { BlackJackGame bj = new BlackJackGame(); - + } } From d397cec4fb48625ee740af3c8a08fb54610da95b Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 14 Jul 2021 21:15:07 -0400 Subject: [PATCH 070/104] (feat:black-jack) implemented betting --- .../casino/games/blackjack/BlackJack.java | 10 ++++---- .../casino/games/blackjack/BlackJackGame.java | 22 ++++++++-------- .../games/blackjack/BlackJackPlayer.java | 23 +++++++++++++++++ .../zipcodewilmington/BlackJackGameTest.java | 25 +++++++++---------- 4 files changed, 51 insertions(+), 29 deletions(-) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackPlayer.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java index 098d34ef1..e4933a871 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -78,15 +78,15 @@ public void dealersGame() { System.out.println("The dealer has : " + dealersCurrentValue()); if (dealersCurrentValue() > 21) { System.out.println("You win!"); - theGame.addMoneyToBalance(theGame.player, theGame.calculateWinnings(2, theGame.userBet)); + theGame.calculateWinnings(2, theGame.userBet); gameEnd = true; } else if (dealersCurrentValue() == 21) { System.out.println("The dealer has won!"); - theGame.subtractBetFromBalance(theGame.userBet); + theGame.calculateWinnings(0, theGame.userBet); gameEnd = true; } else if (dealersCurrentValue() > playersCurrentValue()) { System.out.println("The dealer has won!"); - theGame.subtractBetFromBalance(theGame.userBet); + theGame.calculateWinnings(0, theGame.userBet); gameEnd = true; } else { giveDealerCard(); @@ -104,7 +104,7 @@ public boolean playerBreaks21() { public boolean splitPlayerHitsBlackJack () { if (splitPlayersCurrentValue() == 21) { - theGame.calculateWinnings(3, betAmount); + theGame.calculateWinnings(3, theGame.userBet); return true; } else { return false; @@ -113,7 +113,7 @@ public boolean splitPlayerHitsBlackJack () { public boolean playerHitsBlackJack() { if (playersCurrentValue() == 21) { - theGame.calculateWinnings(3, betAmount); + theGame.calculateWinnings(3, theGame.userBet); return true; } else { return false; diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index 257f9e0c8..9e4c994c6 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -17,6 +17,7 @@ public class BlackJackGame implements GameInterface { //, PlayerInterface { Player player; + public BlackJackGame () { } @@ -27,7 +28,7 @@ public void add(PlayerInterface player) { public void remove(PlayerInterface player) { - player = null; + } @@ -42,15 +43,15 @@ public void run() { System.out.println("\u001B[36m============================================================"); while(!isRunning) { // include betting range - + playerInt.getArcadeAccount().alterAccountBalance(winnings); + System.out.println("Your current balance is... " + playerInt.getArcadeAccount().getAccountBalance()); Integer userInput = input.getIntegerInput("\u001B[32m1. Start A Hand" + "\n" + "\u001B[31m2. Quit" + "\n"); switch (userInput) { case 1: BlackJack freshHand = new BlackJack(); bj = freshHand; - this.userBet = (input.getIntegerInput("\u001B[32mHow much would you like to bet?")); - // subtractBetFromBalance(userBet); - // System.out.println("You bet " + player.getBalance()); + userBet = (input.getIntegerInput("\u001B[32mHow much would you like to bet?")); + playerInt.getArcadeAccount().alterAccountBalance(userBet * (-1)); startGame(); break; case 2: @@ -107,7 +108,7 @@ public CasinoAccount getArcadeAccount() { public Integer calculateWinnings(Integer multiplier, Integer betAmount) { - winnings = multiplier * 4; + winnings = multiplier * betAmount; return winnings; } @@ -118,20 +119,19 @@ public void subtractBetFromBalance(Integer betAmount) { public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { - this.player.setBalance(player.getBalance() + winnings); + } private void splitPlayerHitsBlackJack(Integer splitBet) { System.out.println("BLACK JACK!!"); calculateWinnings(3, splitBet); - addMoneyToBalance(this.player, calculateWinnings(3, splitBet)); standardGame(); } private void splitPlayerBust(Integer splitBet) { System.out.println("Sorry bud, you got " + bj.splitPlayersCurrentValue() + ", you still have one more hand!"); - subtractBetFromBalance(splitBet); + calculateWinnings(0, splitBet); standardGame(); } @@ -141,11 +141,11 @@ private boolean checkStandardWinner(boolean isWinner) { if(bj.playersCurrentValue() > 21) { System.out.println("Sorry bud, you got " + bj.playersCurrentValue() + ", better luck next time"); - subtractBetFromBalance(userBet); + calculateWinnings(0, userBet); isWinner = true; } else if (bj.playerHitsBlackJack()) { System.out.println("BLACK JACK!!"); - addMoneyToBalance(this.player, calculateWinnings(3, userBet)); + calculateWinnings(3, userBet); isWinner = true; } return isWinner; diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackPlayer.java new file mode 100644 index 000000000..7aa90e57a --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackPlayer.java @@ -0,0 +1,23 @@ +package com.github.zipcodewilmington.casino.games.blackjack; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; + +public class BlackJackPlayer implements PlayerInterface { + private PlayerInterface player; + + public BlackJackPlayer(PlayerInterface player) { + this.player = player; + } + + @Override + public CasinoAccount getArcadeAccount() { + return player.getArcadeAccount(); + } + + @Override + public void setArcadeAccount(CasinoAccount casinoAccount) { + + } +} diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java index 2d01267d4..8900a84dd 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java @@ -13,7 +13,6 @@ public class BlackJackGameTest { @Test - public void runTest () { //Player player = new Player("Roger", 5000); } @@ -37,18 +36,18 @@ public void calculateWinningsTest () { Assert.assertEquals(expected,actual); } - @Test - public void subtractFromBalance () { - BlackJackGame blackJack = new BlackJackGame(); - Player player = new Player("Steve", 100); - Integer expected = 60; - - Integer bet = 40; - blackJack.subtractBetFromBalance(bet); - Integer actual = player.getBalance(); - - Assert.assertEquals(expected, actual); - } +// @Test +// public void subtractFromBalance () { +// BlackJackGame blackJack = new BlackJackGame(); +// Player player = new Player("Steve", 100); +// Integer expected = 60; +// +// Integer bet = 40; +// blackJack.subtractBetFromBalance(bet); +// Integer actual = player.getBalance(); +// +// Assert.assertEquals(expected, actual); +// } @Test public void addMoneyToBalanceTest () { From 4a87167c27841d85ce7f4ea72c1a7ea193c55372 Mon Sep 17 00:00:00 2001 From: Zach Date: Wed, 14 Jul 2021 21:16:11 -0400 Subject: [PATCH 071/104] Linked BlackJack and Beetle instantiation --- .../com/github/zipcodewilmington/Casino.java | 20 +++++++--------- .../casino/games/Beetle/BeetleGame.java | 13 +++++++++- .../zipcodewilmington/BlackJackGameTest.java | 24 +++++++++---------- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index b992d8eb8..54ef0d7ee 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -2,6 +2,7 @@ import com.github.zipcodewilmington.casino.*; import com.github.zipcodewilmington.casino.games.Beetle.BeetleGame; +import com.github.zipcodewilmington.casino.games.blackjack.BlackJackGame; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessGame; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessPlayer; import com.github.zipcodewilmington.casino.games.slots.SlotsGame; @@ -35,17 +36,7 @@ public void run() { this.player = new Player(accountName, casinoAccount); this.player.setArcadeAccount(casinoAccount); String gameSelectionInput = getGameSelectionInput().toUpperCase(); - if (gameSelectionInput.equals("SLOTS")) { - play(new SlotsGame(), new SlotsPlayer(this.player)); - - - } else if (gameSelectionInput.equals("NUMBERGUESS")) { - play(new NumberGuessGame(), new NumberGuessPlayer()); - } else { - // TODO - implement better exception handling - String errorMessage = "[ %s ] is an invalid game selection"; - throw new RuntimeException(String.format(errorMessage, gameSelectionInput)); - } + processGameSelection(gameSelectionInput); } else { // TODO - implement better exception handling String errorMessage = "No account found with name of [ %s ] and password of [ %s ]"; @@ -84,6 +75,13 @@ private void processGameSelection(String input){ switch(input){ case "beetle": gameObject = new BeetleGame(); + break; + case "slots": + gameObject = new SlotsGame(); + break; + case "blackjack": + gameObject = new BlackJackGame(); + break; default: gameObject = new BeetleGame(); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index 23cd306c4..232ef98f5 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -2,6 +2,8 @@ import com.github.zipcodewilmington.casino.GameInterface; import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.utils.AnsiColor; +import com.github.zipcodewilmington.utils.IOConsole; import java.util.ArrayList; @@ -10,6 +12,7 @@ public class BeetleGame implements GameInterface { private Beetle game; private Boolean isRunning = false; private PlayerInterface player; + private IOConsole console = new IOConsole(); public BeetleGame(PlayerInterface... players){ this.game = new Beetle(players.length); @@ -17,7 +20,14 @@ public BeetleGame(PlayerInterface... players){ this.add(players[i]); } } - + private void printWelcome() { + System.out.println( + AnsiColor.YELLOW + "***********************************\n" + + "*** ***\n" + + "****** WELCOME TO BEETLE ******\n" + + "*** ***\n" + + "***********************************"); + } public void add(PlayerInterface player){ players.add(player); } @@ -34,6 +44,7 @@ public void remove(PlayerInterface player){ * specifies how the game will run */ public void run(){ + printWelcome(); Integer turnCount = 0; game.setCurrentPlayer(-1); this.isRunning = true; diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java index 0572292c9..c44bb0786 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java @@ -37,18 +37,18 @@ public void calculateWinningsTest () { Assert.assertEquals(expected,actual); } - @Test - public void subtractFromBalance () { - BlackJackGame blackJack = new BlackJackGame(); - Player player = new Player("Steve", 100); - Integer expected = 60; - - Integer bet = 40; - blackJack.subtractBetFromBalance(bet); - Integer actual = player.getBalance(); - - Assert.assertEquals(expected, actual); - } +// @Test +// public void subtractFromBalance () { +// BlackJackGame blackJack = new BlackJackGame(); +// Player player = new Player("Steve", 100); +// Integer expected = 60; +// +// Integer bet = 40; +// blackJack.subtractBetFromBalance(bet); +// Integer actual = player.getBalance(); +// +// Assert.assertEquals(expected, actual); +// } @Test public void addMoneyToBalanceTest () { From 13f6048efc575c59564c54a3476c0e9edaf446ce Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Wed, 14 Jul 2021 22:18:15 -0400 Subject: [PATCH 072/104] Working on IO for BeetleGame.java and routed Beetle through Casino so user can access game (#50) Co-authored-by: Zach --- .../casino/games/Beetle/BeetleGame.java | 44 +++++++++++++------ .../zipcodewilmington/utils/IOConsole.java | 8 +++- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index 232ef98f5..de8d79da0 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -13,21 +13,12 @@ public class BeetleGame implements GameInterface { private Boolean isRunning = false; private PlayerInterface player; private IOConsole console = new IOConsole(); + private Integer betAmt; - public BeetleGame(PlayerInterface... players){ - this.game = new Beetle(players.length); - for(int i = 0; i < players.length; i++){ - this.add(players[i]); - } - } - private void printWelcome() { - System.out.println( - AnsiColor.YELLOW + "***********************************\n" + - "*** ***\n" + - "****** WELCOME TO BEETLE ******\n" + - "*** ***\n" + - "***********************************"); + public BeetleGame(){ + this.game = new Beetle(2); } + public void add(PlayerInterface player){ players.add(player); } @@ -45,6 +36,8 @@ public void remove(PlayerInterface player){ */ public void run(){ printWelcome(); + console.newLine(); + this.setBetAmt(console.getIntegerInput("Place your bet")); Integer turnCount = 0; game.setCurrentPlayer(-1); this.isRunning = true; @@ -105,4 +98,29 @@ public Boolean getIsRunning(){ return this.isRunning; } + public Integer getBetAmt() { + return betAmt; + } + + public void setBetAmt(Integer betAmt) { + this.betAmt = betAmt; + } + + public void printWelcome() { + console.print( + "\u001B[33m***********************************\n" + + "*** ***\n" + + "****** WELCOME TO BEETLE ******\n" + + "*** ***\n" + + "***********************************"); + } + + + public void printBalanceAndBetText(){ + console.newLine(); + console.println("\u001B[35m Current account balance: " + this.player.getArcadeAccount().getAccountBalance()); + console.newLine(); + + } + } diff --git a/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java b/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java index c7afc01da..d4a4fe2b2 100644 --- a/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java +++ b/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java @@ -66,6 +66,12 @@ public Long getLongInput(String prompt, Object... args) { } public Integer getIntegerInput(String prompt, Object... args) { - return getLongInput(prompt, args).intValue(); + Integer input = getLongInput(prompt, args).intValue(); + //this.newLine(); + return input; + } + + public void newLine(){ + this.output.println(); } } \ No newline at end of file From 2a9c2e961a80d346abebbd68b001b7a7dde260ce Mon Sep 17 00:00:00 2001 From: Nathan Date: Wed, 14 Jul 2021 22:18:54 -0400 Subject: [PATCH 073/104] edited numberguessgame --- .../com/github/zipcodewilmington/Casino.java | 5 +- .../casino/games/blackjack/BlackJackGame.java | 2 +- .../casino/games/keno/Keno.java | 2 +- .../games/numberguess/NumberGuessGame.java | 47 ++++++++++++++++--- .../games/numberguess/NumberGuessPlayer.java | 20 +++++++- .../casino/games/plinko/PlinkoGame.java | 2 +- .../casino/games/slots/SlotsGame.java | 21 ++++----- .../casino/games/slots/SlotsPlayer.java | 19 -------- .../NumberGuessGameTests.java | 3 +- 9 files changed, 75 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index b992d8eb8..ae98158cd 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -34,13 +34,14 @@ public void run() { casinoAccount.alterAccountBalance(500); this.player = new Player(accountName, casinoAccount); this.player.setArcadeAccount(casinoAccount); + String gameSelectionInput = getGameSelectionInput().toUpperCase(); if (gameSelectionInput.equals("SLOTS")) { play(new SlotsGame(), new SlotsPlayer(this.player)); - } else if (gameSelectionInput.equals("NUMBERGUESS")) { - play(new NumberGuessGame(), new NumberGuessPlayer()); + play(new NumberGuessGame(), new NumberGuessPlayer(this.player)); + } else { // TODO - implement better exception handling String errorMessage = "[ %s ] is an invalid game selection"; diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index 40ae1ad3e..9c9e0065c 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -7,7 +7,7 @@ import com.github.zipcodewilmington.utils.IOConsole; -public class BlackJackGame implements GameInterface { //, PlayerInterface { +public class BlackJackGame implements GameInterface { private Boolean isRunning = false; private PlayerInterface player; Integer userBet; diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/Keno.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/Keno.java index 1a2a42c9f..5fe5f93a5 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/keno/Keno.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/Keno.java @@ -8,7 +8,7 @@ import java.util.Random; import java.util.Scanner; -public class Keno implements GameInterface{ //, PlayerInterface { +public class Keno implements GameInterface{ int playerNumbers[] = new int[15]; int computerGeneratedNumbers[] = new int[20]; int kenoSpot, kenoCatch; diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java index f4b502240..2c3a98340 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java @@ -1,24 +1,32 @@ package com.github.zipcodewilmington.casino.games.numberguess; -import java.util.ArrayList; -import java.util.List; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; + /** - * Created by leon on 7/21/2020. + * Authors: Zack, Nathan */ -public class NumberGuessGame { + +public class NumberGuessGame implements GameInterface { private Integer maxNumber; + private PlayerInterface currentPlayer; public NumberGuessGame(){ this.maxNumber = 20; } + @Override + public void run() { + + } + public void setMaxNumber(Integer number){ this.maxNumber = number; } - public Integer getGuessRange(Integer guessedNumber, Integer actualNumber){ - return Math.abs(guessedNumber - actualNumber); + public Double getGuessRange(Integer guessedNumber, Integer actualNumber){ + return guessRangePercentage(Math.abs(guessedNumber - actualNumber)); } public Double guessRangePercentage(Integer range){ @@ -28,4 +36,31 @@ public Double guessRangePercentage(Integer range){ public Integer getMaxNumber() { return maxNumber; } + + @Override + public void add(PlayerInterface player) { + this.currentPlayer = player; + } + + @Override + public void remove(PlayerInterface player) { + + } + + + + @Override + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return null; + } + + @Override + public void subtractBetFromBalance(Integer betAmount) { + + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + + } } \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessPlayer.java index aa5cce2e7..6abeb9922 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessPlayer.java @@ -1,7 +1,25 @@ package com.github.zipcodewilmington.casino.games.numberguess; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; + /** * Created by leon on 7/21/2020. */ -public class NumberGuessPlayer { +public class NumberGuessPlayer implements PlayerInterface { + private PlayerInterface player; + + public NumberGuessPlayer(PlayerInterface player){ + this.player = player; + } + + @Override + public CasinoAccount getArcadeAccount() { + return null; + } + + @Override + public void setArcadeAccount(CasinoAccount casinoAccount) { + + } } \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java index 0182c99c1..44baf0d45 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java @@ -8,7 +8,7 @@ import java.util.Map; import java.util.Random; -public class PlinkoGame implements GameInterface{ //,PlayerInterface { +public class PlinkoGame implements GameInterface{ private Map moneyGenerator=new HashMap(); public int initialPosition; diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index 938aeb73e..04fed4b26 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -2,6 +2,7 @@ import com.github.zipcodewilmington.casino.GameInterface; import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.utils.AnsiColor; import java.util.Scanner; @@ -17,7 +18,6 @@ public class SlotsGame implements GameInterface{ private Slots slotMachine; public SlotsGame(){ - } @Override @@ -44,10 +44,6 @@ public void run() { printWelcome(); Slots newSlotMachine = new Slots(); slotMachine = newSlotMachine; -// System.out.println("Make a deposit to your account!"); -// Integer deposit = scanner.nextInt(); - //add deposit to currentPlayer account -// currentPlayer.getArcadeAccount().alterAccountBalance(deposit); slotMachine.spinSlots(); //Display first slots slotMachine.displaySlots(); @@ -56,12 +52,12 @@ public void run() { while(!quitGame) { //print initial account balance - System.out.println("\u001B[35mCurrent account balance: " + currentPlayer.getArcadeAccount().getAccountBalance() + "\n"); + System.out.println("\u001B[35mCurrent account balance: " + currentPlayer.getArcadeAccount().getAccountBalance() + "\n"); getBetAmount(); Integer[] selectedBets = getBetSelections(); - //take money from player object + //take money from player account currentPlayer.getArcadeAccount().alterAccountBalance(betTotal * (-1)); slotMachine.spinSlots(); @@ -70,11 +66,10 @@ public void run() { String[] betResults = slotMachine.compareBetVsWinningLines(selectedBets); this.calculateMultiplier(betResults); Integer winnings = calculateWinnings(this.winMultiplier, playerBetAmount); - Integer losings = calculateWinnings(this.loseMultiplier, playerBetAmount); - Integer returnTotal = calculateReturnTotal(winnings, losings); System.out.println("\u001B[31mYou won: " + winnings + " dollars!\n"); - //add winning to player object + //add winnings to player object currentPlayer.getArcadeAccount().alterAccountBalance(winnings); + //Continue game? System.out.println("\u001B[36mWould you like to play again?\n" + "1. Yes 2. No"); Integer input = scanner.nextInt(); @@ -86,8 +81,8 @@ public void run() { } private void printWelcome() { - System.out.println( - "\u001B[33m***********************************\n" + + System.out.println("\u001B[33m"+ + "***********************************\n" + "*** ***\n" + "****** WELCOME TO SLOTS ******\n" + "*** ***\n" + @@ -96,7 +91,7 @@ private void printWelcome() { private void getBetAmount() { Scanner scanner = new Scanner(System.in); - System.out.println("\u001B[34mHow much you do want to bet?"); + System.out.println("\u001B[34m"+"How much you do want to bet?"); Integer input = scanner.nextInt(); playerBetAmount = input; } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java index 543254a55..2e76cef60 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java @@ -23,23 +23,4 @@ public CasinoAccount getArcadeAccount() { public void setArcadeAccount(CasinoAccount casinoAccount) { } - -// public void subtractFromTotal(Integer value){ -// Integer newTotal = accountTotal - value; -// accountTotal = newTotal; -// } -// -// public void addToTotal(Integer value){ -// Integer newTotal = accountTotal + value; -// accountTotal = newTotal; -// } -// -// public Integer getAccountTotal() { -// return accountTotal; -// } -// -// public void setAccountTotal(Integer accountTotal) { -// this.accountTotal = accountTotal; -// } - } \ No newline at end of file diff --git a/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java b/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java index 8f1955c6e..0af5f24ae 100644 --- a/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java +++ b/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java @@ -11,7 +11,6 @@ public void constructorTest1(){ NumberGuessGame game = new NumberGuessGame(); Integer actual = game.getMaxNumber(); Integer expected = 20; - Assert.assertEquals(actual, expected); } @@ -30,7 +29,7 @@ public void getGuessRange(){ NumberGuessGame game = new NumberGuessGame(); Integer guessedNumber = 10; Integer actualNumber = 5; - Integer actual = game.getGuessRange(guessedNumber, actualNumber); + Double actual = game.getGuessRange(guessedNumber, actualNumber); Integer expected = 5; Assert.assertEquals(actual, expected); From a587568682d097c614ff7673d9ab59c24584dac2 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 14 Jul 2021 22:37:43 -0400 Subject: [PATCH 074/104] (feat:black-jack) slight loop issue, see comments --- .../casino/games/blackjack/BlackJack.java | 40 +------ .../casino/games/blackjack/BlackJackGame.java | 103 ++++++++++++++---- 2 files changed, 83 insertions(+), 60 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java index e4933a871..bcbccd6dc 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -12,9 +12,6 @@ public class BlackJack { List playersHandOnSplit; List dealersHand; Deque deckOfCards; - BlackJackGame theGame = new BlackJackGame(); - boolean gameEnd = false; - Integer betAmount; // Equal to user input public BlackJack() { @@ -73,26 +70,7 @@ public Integer dealersCurrentValue() { return sum; } - public void dealersGame() { - while (!gameEnd) { - System.out.println("The dealer has : " + dealersCurrentValue()); - if (dealersCurrentValue() > 21) { - System.out.println("You win!"); - theGame.calculateWinnings(2, theGame.userBet); - gameEnd = true; - } else if (dealersCurrentValue() == 21) { - System.out.println("The dealer has won!"); - theGame.calculateWinnings(0, theGame.userBet); - gameEnd = true; - } else if (dealersCurrentValue() > playersCurrentValue()) { - System.out.println("The dealer has won!"); - theGame.calculateWinnings(0, theGame.userBet); - gameEnd = true; - } else { - giveDealerCard(); - } - } - } + public boolean playerBreaks21() { if (playersCurrentValue() > 21) { @@ -102,23 +80,7 @@ public boolean playerBreaks21() { } } - public boolean splitPlayerHitsBlackJack () { - if (splitPlayersCurrentValue() == 21) { - theGame.calculateWinnings(3, theGame.userBet); - return true; - } else { - return false; - } - } - public boolean playerHitsBlackJack() { - if (playersCurrentValue() == 21) { - theGame.calculateWinnings(3, theGame.userBet); - return true; - } else { - return false; - } - } public List getPlayersHand() { return playersHand; diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index 9e4c994c6..5aa1020d0 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -2,21 +2,26 @@ import com.github.zipcodewilmington.casino.CasinoAccount; import com.github.zipcodewilmington.casino.GameInterface; -import com.github.zipcodewilmington.casino.Player; import com.github.zipcodewilmington.casino.PlayerInterface; import com.github.zipcodewilmington.utils.IOConsole; -public class BlackJackGame implements GameInterface { //, PlayerInterface { +public class BlackJackGame implements GameInterface { private Boolean isRunning = false; private PlayerInterface playerInt; Integer userBet; + Integer splitBet; IOConsole input = new IOConsole(); Integer winnings = 0; BlackJack bj; - Player player; + /* Stuck in loop from split back to main hand against dealer + * need formatting on splitHand + * need refinement on formatting the beginning + * make it flashy + * betting restraints if the user falls below zero + */ public BlackJackGame () { @@ -44,13 +49,13 @@ public void run() { while(!isRunning) { // include betting range playerInt.getArcadeAccount().alterAccountBalance(winnings); - System.out.println("Your current balance is... " + playerInt.getArcadeAccount().getAccountBalance()); + System.out.println("Your current balance is... " + playerInt.getArcadeAccount().getAccountBalance() + "\n"); Integer userInput = input.getIntegerInput("\u001B[32m1. Start A Hand" + "\n" + "\u001B[31m2. Quit" + "\n"); switch (userInput) { case 1: BlackJack freshHand = new BlackJack(); bj = freshHand; - userBet = (input.getIntegerInput("\u001B[32mHow much would you like to bet?")); + userBet = (input.getIntegerInput("\u001B[32mHow much would you like to bet?" + "\n")); playerInt.getArcadeAccount().alterAccountBalance(userBet * (-1)); startGame(); break; @@ -61,15 +66,28 @@ public void run() { } public void startGame () { - bj.givePlayerCard(); - System.out.println("Your starting card : " + bj.playersCurrentValue()); - System.out.println("Your second next card : " + bj.givePlayerCard()); - System.out.println("Hand value : " + bj.playersCurrentValue()); - if (bj.playersHand.get(0).equals(bj.playersHand.get(1))) { // include conditional on starting blackjack! - splitPlayer(); - } else { - standardGame(); + boolean blackJack = false; + while (!blackJack) { + bj.givePlayerCard(); + System.out.println("Your starting card : " + bj.playersCurrentValue()); + System.out.println("Your second next card : " + bj.givePlayerCard()); + System.out.println("Hand value : " + bj.playersCurrentValue()); + if (twoCardBlackJack()) { + blackJack = true; + } else if (bj.playersHand.get(0).equals(bj.playersHand.get(1))) { // include conditional on starting blackjack! + splitPlayer(); + } else { + standardGame(); + } + } + } + + public boolean twoCardBlackJack () { + if ((bj.playersHand.get(0) + bj.playersHand.get(1)) == 21) { + calculateWinnings(3, userBet); + return true; } + return false; } public void standardGame () { @@ -79,13 +97,14 @@ public void standardGame () { Integer userChoice = input.getIntegerInput("1. Hit" + "\n" + "2. Stay"); switch (userChoice) { case 1: - isWinner = checkStandardWinner(isWinner); + checkStandardWinner(isWinner); + isWinner = true; break; case 2: bj.giveDealerCard(); System.out.println("The dealers first card : " + bj.dealersCurrentValue()); bj.giveDealerCard(); - bj.dealersGame(); + dealersGame(); isWinner = true; break; } @@ -107,14 +126,18 @@ public CasinoAccount getArcadeAccount() { } - public Integer calculateWinnings(Integer multiplier, Integer betAmount) { - winnings = multiplier * betAmount; - return winnings; + public Integer calculateWinnings(Integer multiplier, Integer userBet) { + if (multiplier == 0) { + return 0; + } else { + winnings = multiplier * userBet; + return winnings; + } } public void subtractBetFromBalance(Integer betAmount) { - this.player.makeBet(betAmount); + } @@ -143,7 +166,7 @@ private boolean checkStandardWinner(boolean isWinner) { ", better luck next time"); calculateWinnings(0, userBet); isWinner = true; - } else if (bj.playerHitsBlackJack()) { + } else if (playerHitsBlackJack()) { System.out.println("BLACK JACK!!"); calculateWinnings(3, userBet); isWinner = true; @@ -172,7 +195,7 @@ private void splitHandRound() { if (bj.splitPlayersCurrentValue() > 21) { splitPlayerBust(splitBet); isWinnerSecondHand = true; - } else if (bj.splitPlayerHitsBlackJack()) { + } else if (splitPlayerHitsBlackJack()) { splitPlayerHitsBlackJack(splitBet); isWinnerSecondHand = true; } @@ -182,4 +205,42 @@ private void splitHandRound() { } } } + public void dealersGame() { + boolean gameEnd = false; + while (!gameEnd) { + System.out.println("The dealer has : " + bj.dealersCurrentValue()); + if (bj.dealersCurrentValue() > 21) { + System.out.println("You win!"); + calculateWinnings(2, userBet); + gameEnd = true; + } else if (bj.dealersCurrentValue() == 21) { + System.out.println("The dealer has won!"); + calculateWinnings(0, userBet); + gameEnd = true; + } else if (bj.dealersCurrentValue() > bj.playersCurrentValue()) { + System.out.println("The dealer has won!"); + calculateWinnings(0, userBet); + gameEnd = true; + } else { + bj.giveDealerCard(); + } + } + } + public boolean splitPlayerHitsBlackJack () { + if (bj.splitPlayersCurrentValue() == 21) { + calculateWinnings(3, splitBet); + return true; + } else { + return false; + } + } + + public boolean playerHitsBlackJack() { + if (bj.playersCurrentValue() == 21) { + calculateWinnings(3, userBet); + return true; + } else { + return false; + } + } } From 16545d8ce8a327a985217e9281e358fb628ba482 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 14 Jul 2021 23:05:31 -0400 Subject: [PATCH 075/104] (feat:black-jack) added comments to polish --- .../casino/games/blackjack/BlackJackGame.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index 5aa1020d0..9ec32227f 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -17,10 +17,31 @@ public class BlackJackGame implements GameInterface { /* Stuck in loop from split back to main hand against dealer + + run() -> hand -> standard game -> hit/stay -> dealersGame() ---- loop starts, dealers final value gets + returned as the "starting value" for the "next hand" - run through main to blackjack to see + + somewhere in there the program isn't terminating to the originally starting point -- walk the program down + + reorder the 'helper' methods for more clarity + + * refine the format for the splitHandBet (potentially add it to the 'userBet') + * only condition - if one hand wins and the other loses + * maybe an if statement at the 'playerInt.getAccountBalance().alterAccountBalance()' to execute for splitBet as well + * betting restraints if the user falls below zero + * If time available, include the conditional on aces being 11 or 1 depending on the currentPlayerValue() + * if (currentPlayerValue() > 21) { + for (int i = 0; i < playersHand.size(); i++) { + if (playersHand.get(i).equalsTo(11)) { + playersHand.set(i, 1); + } + } + return playersCurrentValue;---(playersCurrentValue should be under 21 if there was an 11 in there. however, + that changes all values that were 11 to 1; would need to change just one value + } * need formatting on splitHand * need refinement on formatting the beginning * make it flashy - * betting restraints if the user falls below zero */ public BlackJackGame () { From 19ac0398a2efda0cc31f758298388a0240b99ac8 Mon Sep 17 00:00:00 2001 From: Zach Date: Wed, 14 Jul 2021 23:59:24 -0400 Subject: [PATCH 076/104] Added IO for Beetle.java, added input controls and betting. Next update to include winnings calculations --- .../casino/games/Beetle/Beetle.java | 30 +++++++++--- .../casino/games/Beetle/BeetleGame.java | 47 ++++++++++++++----- .../zipcodewilmington/utils/IOConsole.java | 4 ++ 3 files changed, 63 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java index 6a621ee77..122e7a535 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java @@ -68,15 +68,33 @@ public void refreshBeetle(Integer player){ this.playerBeetles[player] = new Integer[] {0, 0, 0, 0, 0, 0}; } + public String printBeetle(Integer player){ + Integer[] currentBeetle = this.getPlayerBeetles()[player]; + String output = "Body:"; + output += (currentBeetle[0].equals(0)) ? "0 " : "X "; + output += "Head:"; + output += (currentBeetle[1].equals(0)) ? "0 " : "X "; + output += "Legs:"; + output += (currentBeetle[2].equals(0)) ? "0 " : "X "; + output += "Eyes:"; + output += (currentBeetle[3].equals(0)) ? "0 " : "X "; + output += "Antenna:"; + output += (currentBeetle[4].equals(0)) ? "0 " : "X "; + output += "Tail:"; + output += (currentBeetle[5].equals(0)) ? "0 " : "X "; + + return output; + } public Boolean checkWinner(Integer player){ if(this.beetleIsComplete(player)){ - this.scoreboard[player] += 6; - if(this.getScore(player) == 30){ - return true; - } else { - this.refreshBeetle(player); - } + return true; + //this.scoreboard[player] += 6; + //if(this.getScore(player) == 30){ + //return true; + //} else { + //this.refreshBeetle(player); + //} } return false; } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index de8d79da0..a7395975e 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -20,7 +20,7 @@ public BeetleGame(){ } public void add(PlayerInterface player){ - players.add(player); + this.player = player; } /** @@ -35,20 +35,30 @@ public void remove(PlayerInterface player){ * specifies how the game will run */ public void run(){ + this.initGame(); + while(this.isRunning){ + this.nextPlayer(); + this.executeTurn(); + this.isGameOver(this.game.checkWinner(this.game.getCurrentPlayer())); + } + this.printBeetleCards(); + this.printWinnerMessage(); + } + + public void initGame(){ printWelcome(); console.newLine(); - this.setBetAmt(console.getIntegerInput("Place your bet")); + this.setBetAmt(printBalanceAndBetText()); Integer turnCount = 0; game.setCurrentPlayer(-1); this.isRunning = true; - while(isRunning){ - turnCount++; - this.nextPlayer(); - //game.getDice().tossAndSum(); - executeTurn(); - isGameOver(game.checkWinner(game.getCurrentPlayer())); - } - System.out.println("game over after, player " + game.getCurrentPlayer() + " wins"); + } + + public void printBeetleCards(){ + console.print("\u001B[32m Your Beetle: "); + console.println(game.printBeetle(0)); + console.print("\u001B[32m Dealer's Beetle: "); + console.println(game.printBeetle(1)); } public void isGameOver(boolean playerWon){ @@ -62,6 +72,11 @@ public void nextPlayer(){ public void executeTurn(){ Integer currentPlayer = game.getCurrentPlayer(); + if(game.getCurrentPlayer() == 0){ + this.printBeetleCards(); + console.println("Press enter to roll next dice"); + console.pressEnterToProceed(); + } game.setPlayerBeetles(currentPlayer, game.getDice().tossAndSum()); } @@ -116,11 +131,19 @@ public void printWelcome() { } - public void printBalanceAndBetText(){ + public Integer printBalanceAndBetText(){ console.newLine(); console.println("\u001B[35m Current account balance: " + this.player.getArcadeAccount().getAccountBalance()); console.newLine(); - + return console.getIntegerInput("\u001B[34m How much do you want to bet?"); + } + + public void printWinnerMessage(){ + if(this.game.getCurrentPlayer() == 0){ + console.println("You win!"); + } else { + console.println("Dealer wins..."); + } } } diff --git a/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java b/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java index d4a4fe2b2..b855d24db 100644 --- a/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java +++ b/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java @@ -74,4 +74,8 @@ public Integer getIntegerInput(String prompt, Object... args) { public void newLine(){ this.output.println(); } + + public void pressEnterToProceed(){ + this.input.nextLine(); + } } \ No newline at end of file From c5ddee5b29335c53574f62009e3468d59949cfd5 Mon Sep 17 00:00:00 2001 From: Nathan Date: Thu, 15 Jul 2021 00:58:28 -0400 Subject: [PATCH 077/104] many new codes in numberGuessGame --- .../games/numberguess/NumberGuessGame.java | 75 +++++++++++++++++-- .../NumberGuessGameTests.java | 8 +- 2 files changed, 74 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java index 2c3a98340..ef25bb083 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java @@ -3,6 +3,8 @@ import com.github.zipcodewilmington.casino.GameInterface; import com.github.zipcodewilmington.casino.PlayerInterface; +import java.util.Scanner; + /** * Authors: Zack, Nathan @@ -11,6 +13,11 @@ public class NumberGuessGame implements GameInterface { private Integer maxNumber; private PlayerInterface currentPlayer; + private Integer betAmount; + private Integer multiplier; + private Integer guessNumber; + private int randomNumber; + private Scanner scanner = new Scanner(System.in); public NumberGuessGame(){ this.maxNumber = 20; @@ -18,24 +25,82 @@ public NumberGuessGame(){ @Override public void run() { + Scanner scanner = new Scanner(System.in); + //print welcome + printWelcome(); + //print instruction for game + System.out.println("Guess the right number between 0 and 20 to double your bets!\nFeeling lucky??\n\n Increase the difficulty and increase your earnings!"); + //print difficulty levels and ask user to choose + setDifficultyLevel(); + //print player's current account balance + System.out.println("Your current account balance is: " + this.currentPlayer.getArcadeAccount().getAccountBalance()); + //ask for a bet amount + takeBet(); + //subtract bet amount from player's account + this.currentPlayer.getArcadeAccount().alterAccountBalance(betAmount); + //ask player to chose number from 0 to difficulty lvl + takeGuess(); + //generate actual number + pickRandomNumber(); + //compare difference + + //compute winnings + + //print winnings + + //add winnings to player's account + + } + + private void pickRandomNumber() { + this.randomNumber = (int) ((Math.random() * (maxNumber - 0)) + 0); + } + + private void takeGuess() { + System.out.println("Pick a number between 0 and " + maxNumber); + this.guessNumber = scanner.nextInt(); + + } + + private void takeBet() { + System.out.println("How much do you want to bet?"); + this.betAmount = scanner.nextInt(); + } + private void printWelcome() { + //TODO } - public void setMaxNumber(Integer number){ - this.maxNumber = number; + private void setDifficultyLevel() { + System.out.println("1. Start max at 20 and go for double.\n" + + "2. Change max to 30 and Triple your bets!\n" + + "3.Change max to 40 and QUADRUPLE your bets! OH MY!\n" + + "4.Change max to 50! SEND IT! TO THE MOON!"); + setMaxNumber(scanner.nextInt()); } - public Double getGuessRange(Integer guessedNumber, Integer actualNumber){ + + public Integer getGuessRange(Integer guessedNumber, Integer actualNumber){ return guessRangePercentage(Math.abs(guessedNumber - actualNumber)); } - public Double guessRangePercentage(Integer range){ - return range.doubleValue() / this.maxNumber; + + //Player can set difficulty level to get high yield + //Take this return - reward if guess is within 10% + //The closer to 0%, the higher reward + //10% = money back, 8% = 1.1 + + public Integer guessRangePercentage(Integer range){ + Double percent = ((range.doubleValue() / this.maxNumber) * 100); + return percent.intValue(); } public Integer getMaxNumber() { return maxNumber; } + public void setMaxNumber(Integer max){ + this.maxNumber = max; + } @Override public void add(PlayerInterface player) { diff --git a/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java b/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java index 0af5f24ae..493a6914b 100644 --- a/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java +++ b/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java @@ -29,8 +29,8 @@ public void getGuessRange(){ NumberGuessGame game = new NumberGuessGame(); Integer guessedNumber = 10; Integer actualNumber = 5; - Double actual = game.getGuessRange(guessedNumber, actualNumber); - Integer expected = 5; + Integer actual = game.getGuessRange(guessedNumber, actualNumber); + Integer expected = 25; Assert.assertEquals(actual, expected); } @@ -42,8 +42,8 @@ public void getGuessPercentage(){ Integer max = game.getMaxNumber(); Integer actualNumber = 5; Integer range = Math.abs(guessedNumber - actualNumber); - Double actual = game.guessRangePercentage(range); - Double expected = 0.25; + Integer actual = game.guessRangePercentage(range); + Integer expected = 25; Assert.assertEquals(actual, expected); } From 58542c355a8efc3618416bb0792bf6b5d4e14d9b Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Thu, 15 Jul 2021 01:25:16 -0400 Subject: [PATCH 078/104] pre finish changes (#53) Co-authored-by: Zach --- .../casino/games/Beetle/BeetleGame.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index a7395975e..31d3d1b3c 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -43,6 +43,7 @@ public void run(){ } this.printBeetleCards(); this.printWinnerMessage(); + console.println("Your payout is: " + this.determinePayout().toString()); } public void initGame(){ @@ -80,19 +81,27 @@ public void executeTurn(){ game.setPlayerBeetles(currentPlayer, game.getDice().tossAndSum()); } + public Integer determinePayout(){ + Integer payout = (int)(this.betAmt * 1.1); + if(this.game.getCurrentPlayer() == 0){ + this.player.getArcadeAccount().alterAccountBalance(payout); + return payout; + } + return 0; + } /** * Calculate player's winning payout amount of bet x multiplier * @return (double) amount of money winnings */ public Integer calculateWinnings(Integer multiplier, Integer betAmount){ - return 0; + return multiplier * betAmount; } /** * Subtract the bet amount from player's balance */ public void subtractBetFromBalance(Integer betAmount){ - + player.getArcadeAccount().alterAccountBalance(betAmount * -1); } From 579f0222a5bfc3304f818f06964db9d762fa2443 Mon Sep 17 00:00:00 2001 From: Dipinti Date: Thu, 15 Jul 2021 01:57:57 -0400 Subject: [PATCH 079/104] new plinko game is ready --- .../casino/games/keno/Keno.java | 226 ------------------ .../casino/games/plinko/PlinkoGame.java | 155 +++++++++--- .../casino/games/plinko/PlinkoPlayer.java | 17 ++ .../github/zipcodewilmington/KenoTest.java | 18 -- .../github/zipcodewilmington/PlinkoTest.java | 45 ---- 5 files changed, 140 insertions(+), 321 deletions(-) delete mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/keno/Keno.java create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java delete mode 100644 src/test/java/com/github/zipcodewilmington/KenoTest.java delete mode 100644 src/test/java/com/github/zipcodewilmington/PlinkoTest.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/Keno.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/Keno.java deleted file mode 100644 index 1a2a42c9f..000000000 --- a/src/main/java/com/github/zipcodewilmington/casino/games/keno/Keno.java +++ /dev/null @@ -1,226 +0,0 @@ -package com.github.zipcodewilmington.casino.games.keno; - -import com.github.zipcodewilmington.casino.CasinoAccount; -import com.github.zipcodewilmington.casino.GameInterface; -import com.github.zipcodewilmington.casino.Player; -import com.github.zipcodewilmington.casino.PlayerInterface; - -import java.util.Random; -import java.util.Scanner; - -public class Keno implements GameInterface{ //, PlayerInterface { - int playerNumbers[] = new int[15]; - int computerGeneratedNumbers[] = new int[20]; - int kenoSpot, kenoCatch; - boolean continueGame = true; - Integer bet; - Player player; - Integer multiplier; - - public Integer getMultiplier() { - return multiplier; - } - - public void setMultiplier(Integer multiplier) { - this.multiplier = multiplier; - } - - - - public void setPlayerNumbers(int[] playerNumbers) { - this.playerNumbers = playerNumbers; - } - - @Override - public void add(PlayerInterface player) { - } - - @Override - public void remove(PlayerInterface player) { - - } - - @Override - public void run() { - //playerNums = getUserInput(); - //bet = getBet(player.getBalance()); - //player.makeBet(bet); - computerGeneratedNumbers = getComputerGeneratedNames(); - kenoSpot = getSpot(playerNumbers); - kenoCatch = getCatch(playerNumbers, computerGeneratedNumbers); - System.out.println("Catch: " + (kenoCatch + 1)); - Integer winningsAmount = 0; - - Integer winnings[][] = - { - {7, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, - {3, 9, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0}, - {4, 2, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 1, 10, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 1, 3, 15, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 1, 2, 3, 30, 88, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {6, 0, 1, 6, 12, 64, 100, 0, 0, 0, 0, 0, 0, 0, 0}, - {3, 0, 1, 3, 6, 30, 90, 120, 0, 0, 0, 0, 0, 0, 0}, - {2, 0, 1, 2, 4, 8, 20, 80, 1200, 0, 0, 0, 0, 0, 0}, - {1, 0, 1, 2, 3, 5, 10, 30, 600, 1800, 0, 0, 0, 0, 0}, - {0, 1, 1, 1, 2, 6, 15, 25, 180, 1000, 3000, 0, 0, 0, 0}, - {0, 0, 5, 1, 2, 4, 24, 72, 250, 500, 2000, 4000, 0, 0, 0}, - {0, 0, 4, 0, 3, 4, 5, 20, 80, 240, 500, 3000, 6000, 0, 0}, - {0, 0, 0, 0, 2, 3, 5, 12, 50, 150, 500, 1000, 2000, 7500, 0}, - {0, 0, 0, 0, 1, 2, 5, 15, 50, 150, 300, 600, 1200, 2500, 10000} - }; - if(kenoCatch < 0) - { - multiplier = 0; - } - else - multiplier=winnings[kenoSpot][kenoCatch]; - - } - - - public static int getCatch(int[] playerArray, int[] computerArray) - { - int playerIndex; - int computerIndex; - int kenoCatch = 0; - for (playerIndex = 0; playerIndex < playerArray.length; playerIndex++) - { - for(computerIndex = 0; computerIndex < computerArray.length; computerIndex++) - { - if(playerArray[playerIndex] == computerArray[computerIndex]) - { - kenoCatch++; - } - } - } - kenoCatch-=1; - return kenoCatch; - } - - public static int getSpot(int[] playerArray) - { - int index; - int spot = 0; - for (index = 0; index < playerArray.length; index++) - { - if(playerArray[index] != 0) - { - spot++; - } - - } - spot -= 1; //Subtract one so it works properly in array - return spot; - } - - public static int[] getComputerGeneratedNames() - { - int[] computerNums = new int[20]; - Random rand = new Random(); - int index; - int randomNumber = 0; - - for (index = 0; index < computerNums.length; index++) - { - randomNumber = rand.nextInt(80) + 1; - if(isUnique(randomNumber, computerNums)) - { - computerNums[index] = randomNumber; - } - else - { - index--; - } - - } - return computerNums; - } - - public static int[] getUserInput() - { - Scanner input = new Scanner(System.in); // for input - boolean invalidInput = true; - boolean continuePlayer = true; - int playerNums[] = new int[15]; - int index; - int numberEntered; - String enterString; - System.out.println("You may enter up to 15 numbers"); - for (index = 0; index < playerNums.length; index++ ) - { - playerNums[index] = 0; - } - index = 0; - while(continuePlayer && index < 15) - { - do - { - do - { - System.out.println("Enter number " + (index+1)); - numberEntered = input.nextInt(); - if ((numberEntered > 0) && (numberEntered < 81)) - { - if(isUnique(numberEntered, playerNums)) - { - invalidInput = false; - playerNums[index] = numberEntered; - } - else - { - System.out.println("Sorry, you already entered that number before!"); - System.out.println("Try again! "); - invalidInput = true; - } - } - else - { - invalidInput = true; - System.out.println("Sorry, the number you entered is either less than 0 or greater than 80"); - System.out.println("Try again"); - System.out.println(""); - } - } while(invalidInput); - - }while(invalidInput); - - index++; - } - return playerNums; - } - - public static boolean isUnique(int number, int[] array) - { - int index; - for (index = 0; index < array.length; index++) - { - if(number == array[index]) - { - return false; - } - } - return true; - } - - - @Override - public Integer calculateWinnings(Integer multiplier, Integer betAmount) { - return this.multiplier*betAmount; - } - - @Override - public void subtractBetFromBalance(Integer betAmount) { - player.setBalance(player.getBalance()-betAmount); - } - - @Override - public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { - - } - -// @Override -// public CasinoAccount getArcadeAccount() { -// return null; -// } -} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java index 0182c99c1..1b72dddd3 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java @@ -7,43 +7,16 @@ import java.util.HashMap; import java.util.Map; import java.util.Random; +import java.util.Scanner; public class PlinkoGame implements GameInterface{ //,PlayerInterface { private Map moneyGenerator=new HashMap(); public int initialPosition; - private double betAmount; + private int bet; public int multiplier; + private int balance; - public PlinkoGame(int initialPosition){ - this.initialPosition=initialPosition; - } - - public String playPlinko(int initialPosition){ - if(initialPosition<10 && initialPosition>0){ - int max=9; - int min=1; - Random rand = new Random(); - int randomNumber=rand.nextInt(max - min + 1) + min; - return String.valueOf(randomNumber); - } - else - return "Invalid Entry"; - } - - public void run2() { - if (initialPosition < 10 && initialPosition > 0) { - int max = 9; - int min = 1; - Random rand = new Random(); - multiplier = rand.nextInt(max - min + 1) + min; - System.out.println("Now your position is: " + multiplier); - } - else - { - System.out.println("Invalid Entry"); - } - } @Override public void add(PlayerInterface player) { @@ -57,11 +30,65 @@ public void remove(PlayerInterface player) { @Override public void run() { + Scanner input = new Scanner(System.in); + printWelcome(); + balance = 100; //Start the player off with some money + boolean continueGame=true; + Integer playerNumber; + String userInput; + + System.out.println("\u001B[32mHello, and welcome to the game Plinko!"); + while(continueGame){ + System.out.println("\u001B[32mYou currently have: $" + balance); + System.out.println("\u001B[32mPlease enter a number position of your choice: "); + playerNumber = getUserInput(); + bet = (int) getBet(balance); + int plinkSpot=getPlinkoSpot(); + this.multiplier=plinkSpot; + System.out.println("\u001B[32mAfter playing, now your position is: "+plinkSpot); + balance += payout(plinkSpot); + subtractBetFromBalance(bet); + System.out.println("\u001B[32mYou now have: $" + balance); + if (balance <= 0) + { + continueGame = false; + System.out.println("\u001B[32mSorry, you ran out of money!"); + System.out.println("\u001B[32mBetter luck next time! :)"); + } + else + { + System.out.println("\u001B[32mWould you like to continue(y/n)?"); + userInput = input.nextLine(); + + if ((userInput.equals("y"))) + { + continueGame = true; + } + else + { + continueGame = false; + } + } + } + System.out.println("\u001B[32mThanks for playing!"); + System.out.println("\u001B[32mOverall, you now have: $" + balance); + } + private void printWelcome() { + System.out.println( + "\u001B[33m***********************************\n" + + "*** ***\n" + + "****** WELCOME TO PLINKO ******\n" + + "*** ***\n" + + "***********************************"); } @Override public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return this.multiplier*betAmount; + } + + private int payout(int plinkoSpot) { moneyGenerator.put(1,200); moneyGenerator.put(2,0); moneyGenerator.put(3,3000); @@ -75,7 +102,7 @@ public Integer calculateWinnings(Integer multiplier, Integer betAmount) { for (Integer pos:moneyGenerator.keySet()) { - if(pos.equals(multiplier)){ + if(pos.equals(plinkoSpot)){ moneyWon=moneyGenerator.get(pos); } } @@ -83,10 +110,74 @@ public Integer calculateWinnings(Integer multiplier, Integer betAmount) { } + private int getPlinkoSpot() { + int max = 9; + int min = 1; + Random rand = new Random(); + return rand.nextInt(max - min + 1) + min; + } + + public static double getBet(double playerMoney) + { + Scanner input = new Scanner(System.in); + double bet = 0; + boolean invalidInput = true; + while(invalidInput) + { + System.out.print("Enter the bet amount in whole dollars: $"); + bet = input.nextInt(); + if(bet < 0) + { + System.out.println("Bet amount can't be less than 0!"); + invalidInput = true; + } + else if(bet > playerMoney) + { + System.out.println("You don't have enough money to bet that!"); + invalidInput = true; + } + else + { + invalidInput = false; + } + } + return bet; + } + + private Integer getUserInput() { + Scanner input = new Scanner(System.in); // for input + boolean invalidInput = true; + boolean continuePlayer = true; + int numberEntered; + int playerNums=0; + String enterString; + + + while(invalidInput) + { + System.out.println("Enter number :"); + numberEntered = input.nextInt(); + + if ((numberEntered > 0) && (numberEntered < 10)){ + invalidInput = false; + playerNums = numberEntered; + break; + } + else{ + invalidInput = true; + System.out.println("Sorry, the number you entered is either less than 0 or greater than 9"); + System.out.println("Try again"); + System.out.println(""); + } + } + return playerNums; + } + + @Override public void subtractBetFromBalance(Integer betAmount) { - + balance-=bet; } @Override diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java new file mode 100644 index 000000000..d4bd43fa3 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java @@ -0,0 +1,17 @@ +package com.github.zipcodewilmington.casino.games.plinko; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; + +public class PlinkoPlayer implements PlayerInterface { + private PlayerInterface player; + @Override + public CasinoAccount getArcadeAccount() { + return player.getArcadeAccount(); + } + + @Override + public void setArcadeAccount(CasinoAccount casinoAccount) { + + } +} diff --git a/src/test/java/com/github/zipcodewilmington/KenoTest.java b/src/test/java/com/github/zipcodewilmington/KenoTest.java deleted file mode 100644 index ea129ed35..000000000 --- a/src/test/java/com/github/zipcodewilmington/KenoTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.zipcodewilmington; - -import com.github.zipcodewilmington.casino.Player; -import com.github.zipcodewilmington.casino.games.keno.Keno; -import org.junit.Test; - -public class KenoTest { - @Test - public void testRun(){ - //Player player=new Player("Dipinti",3000); - Keno keno=new Keno(); - int[] playerNums={80,23,31,14,54,36,72,18,91,1,11,12,13,14,44}; - keno.setPlayerNumbers(playerNums); - keno.run(); - Integer winnings=keno.calculateWinnings(keno.getMultiplier(),3000); - System.out.println(winnings); - } -} diff --git a/src/test/java/com/github/zipcodewilmington/PlinkoTest.java b/src/test/java/com/github/zipcodewilmington/PlinkoTest.java deleted file mode 100644 index bdf4e8ba5..000000000 --- a/src/test/java/com/github/zipcodewilmington/PlinkoTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.zipcodewilmington; - -import com.github.zipcodewilmington.casino.games.plinko.PlinkoGame; -import org.junit.Assert; -import org.junit.Test; - -public class PlinkoTest { - - @Test - public void testCalculateWinnings() { - //given - - Integer expectedValue=0; - PlinkoGame plinkoGame=new PlinkoGame(7); - plinkoGame.run(); - //when - Integer actualValue=plinkoGame.calculateWinnings(2,200); - - //then - Assert.assertEquals(expectedValue,actualValue); - } - - @Test - public void testConstructor(){ - //given - int expectedValue=8; - //when - PlinkoGame plinkoGame=new PlinkoGame(8); - int actualValue=plinkoGame.initialPosition; - //then - Assert.assertEquals(expectedValue,actualValue); - } - - @Test - public void testPlayPlinko(){ - //given - String expectedValue="Invalid Entry"; - //when - PlinkoGame plinkoGame=new PlinkoGame(10); - String actualValue=plinkoGame.playPlinko(10); - //then - Assert.assertFalse(expectedValue, Boolean.parseBoolean(actualValue)); - } -} - From 902b0785694f841d8da10d0a4294ee296fd55d71 Mon Sep 17 00:00:00 2001 From: Dipinti Date: Thu, 15 Jul 2021 02:00:14 -0400 Subject: [PATCH 080/104] new keno game is ready --- .../casino/games/keno/KenoGame.java | 309 ++++++++++++++++++ .../casino/games/keno/KenoPlayer.java | 19 ++ 2 files changed, 328 insertions(+) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java new file mode 100644 index 000000000..2a3d8720a --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java @@ -0,0 +1,309 @@ +package com.github.zipcodewilmington.casino.games.keno; + +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; + +import java.util.Random; +import java.util.Scanner; + +public class KenoGame implements GameInterface { + Integer multiplier; + KenoPlayer kenoPlayer; + KenoGame kenoGame; + Integer bet; + int balance; + @Override + public void add(PlayerInterface player) { + + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public void run() { + Scanner input = new Scanner(System.in); + printWelcome(); + balance = 100; //Start the player off with some money + int playerNums[] = new int[15]; + int computerNums[] = new int[20]; + int kenoSpot, kenoCatch; + boolean continueGame = true; + String userInput; + + + System.out.println("\u001B[32mHello, and welcome to the game Keno!"); + System.out.println("\u001B[32mThis is a high stakes game. You can win and lose money quickly!"); + while(continueGame) + { + System.out.println(); + System.out.println("\u001B[32mYou currently have: $" + balance); + System.out.println("\u001B[32mLet's get some numbers to begin."); + System.out.println("\u001B[32mYou may enter up to 15 numbers"); + playerNums = getUserInput(); + bet = (int) getBet(balance); + computerNums = getComputerNums(); + kenoSpot = getSpot(playerNums); + kenoCatch = getCatch(playerNums, computerNums); + System.out.println("\u001B[32mCatch: " + (kenoCatch + 1)); + balance += payout(kenoSpot, kenoCatch, bet); + subtractBetFromBalance(bet); + System.out.println("\u001B[32mYou now have: $" + balance); + if (balance <= 0) + { + continueGame = false; + System.out.println("\u001B[32mSorry, you ran out of money!"); + System.out.println("\u001B[32mBetter luck next time! :)"); + } + else + { + System.out.println("\u001B[32mWould you like to continue(y/n)?"); + userInput = input.nextLine(); + + if ((userInput.equals("y"))) + { + continueGame = true; + } + else + { + continueGame = false; + } + } + } + System.out.println("\u001B[32mThanks for playing!"); + System.out.println("\u001B[32mOverall, you now have: $" + balance); + + } + + private void printWelcome() { + System.out.println( + "\u001B[33m***********************************\n" + + "*** ***\n" + + "****** WELCOME TO KENO ******\n" + + "*** ***\n" + + "***********************************"); + } + + public static int[] getUserInput() + { + Scanner input = new Scanner(System.in); // for input + boolean invalidInput = true; + boolean continuePlayer = true; + int playerNums[] = new int[15]; + int index; + int numberEntered; + String enterString; + for (index = 0; index < playerNums.length; index++ ) + { + playerNums[index] = 0; + } + index = 0; + while(continuePlayer && index < 15) + { + do + { + do + { + System.out.println("\u001B[32mEnter number " + (index+1)); + numberEntered = input.nextInt(); + if ((numberEntered > 0) && (numberEntered < 81)) + { + if(isUnique(numberEntered, playerNums)) + { + invalidInput = false; + playerNums[index] = numberEntered; + } + else + { + System.out.println("\u001B[32mSorry, you already entered that number before!"); + System.out.println("\u001B[32mTry again! "); + invalidInput = true; + } + } + else + { + invalidInput = true; + System.out.println("\u001B[32mSorry, the number you entered is either less than 0 or greater than 79"); + System.out.println("\u001B[32mTry again"); + System.out.println(""); + } + } while(invalidInput); + + if(index < 14) //makes sure program doesn't ask to continue when on the last number + { + System.out.println("\u001B[32mDo you wish to continue? (y/n)"); + input.nextLine(); + enterString = input.nextLine(); + if ((enterString.equals("n")) || (enterString.equals("no"))) + { + invalidInput = false; + continuePlayer = false; + } + else if ((enterString.equals("y")) || (enterString.equals("yes"))) + { + invalidInput = false; + continuePlayer = true; + } + else + { + System.out.println("\u001B[32mSorry, I didn't understand that."); + System.out.println(""); + invalidInput = true; + } + + } + }while(invalidInput); + + index++; + } + return playerNums; + } + + public static boolean isUnique(int number, int[] array) + { + int index; + for (index = 0; index < array.length; index++) + { + if(number == array[index]) + { + return false; + } + } + return true; + } + + public static int[] getComputerNums() + { + int[] computerNums = new int[20]; + Random rand = new Random(); + int index; + int randomNumber = 0; + + for (index = 0; index < computerNums.length; index++) + { + randomNumber = rand.nextInt(80) + 1; + if(isUnique(randomNumber, computerNums)) + { + computerNums[index] = randomNumber; + } + else + { + index--; + } + + } + return computerNums; + } + + public static int getSpot(int[] playerArray) + { + int index; + int spot = 0; + for (index = 0; index < playerArray.length; index++) + { + if(playerArray[index] != 0) + { + spot++; + } + + } + spot -= 1; //Subtract one so it works properly in array + return spot; + } + + public static double getBet(double playerMoney) + { + Scanner input = new Scanner(System.in); + double bet = 0; + boolean invalidInput = true; + while(invalidInput) + { + System.out.print("\u001B[32mEnter the bet amount in whole dollars: $"); + bet = input.nextInt(); + if(bet < 0) + { + System.out.println("\u001B[32mBet amount can't be less than 0!"); + invalidInput = true; + } + else if(bet > playerMoney) + { + System.out.println("\u001B[32mYou don't have enough money to bet that!"); + invalidInput = true; + } + else + { + invalidInput = false; + } + } + return bet; + } + + public static int getCatch(int[] playerArray, int[] computerArray) + { + int playerIndex; + int computerIndex; + int kenoCatch = 0; + for (playerIndex = 0; playerIndex < playerArray.length; playerIndex++) + { + for(computerIndex = 0; computerIndex < computerArray.length; computerIndex++) + { + if(playerArray[playerIndex] == computerArray[computerIndex]) + { + kenoCatch++; + } + } + } + kenoCatch -= 1;//subtact one so it works in array + return kenoCatch; + } + + public double payout(int kenoSpot, int kenoCatch, int betAmount) + { + Integer payoutAmount = 0; + Integer payout[][] = + { + {3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //1 + {1, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //2 + {1, 2, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //3 + {0, 2, 6, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //4 + {0, 1, 3, 15, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//5 + {1, 1, 2, 3, 30, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0},//6 + {2, 0, 1, 6, 12, 36, 100, 0, 0, 0, 0, 0, 0, 0, 0},//7 + {0, 1, 1, 3, 6, 19, 90, 720, 0, 0, 0, 0, 0, 0, 0},//8 + {0, 1, 1, 2, 4, 8, 20, 80, 1200, 0, 0, 0, 0, 0, 0},//9 + {0, 1, 1, 2, 3, 5, 10, 30, 600, 1800, 0, 0, 0, 0, 0},//10 + {0, 0, 1, 1, 2, 6, 15, 25, 180, 1000, 3000, 0, 0, 0, 0},//11 + {0, 0, 0, 1, 2, 4, 24, 72, 250, 500, 2000, 4000, 0, 0, 0},//12 + {0, 0, 0, 1, 3, 4, 5, 20, 80, 240, 500, 3000, 6000, 0, 0},//13 + {0, 0, 0, 0, 2, 3, 5, 12, 50, 150, 500, 1000, 2000, 7500, 0},//14 + {0, 0, 0, 0, 1, 2, 5, 15, 50, 150, 300, 600, 1200, 2500, 10000}//15 + }; + if(kenoCatch < 0) + { + this.multiplier = 0; + } + else + { + multiplier = payout[kenoSpot][kenoCatch]; + payoutAmount = multiplier * betAmount; + } + return payoutAmount; + } + + @Override + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return this.multiplier*betAmount; + } + + @Override + public void subtractBetFromBalance(Integer betAmount) { + balance-=bet; + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + balance+=calculateWinnings(multiplier,bet); + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java new file mode 100644 index 000000000..75494d797 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java @@ -0,0 +1,19 @@ +package com.github.zipcodewilmington.casino.games.keno; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; + +public class KenoPlayer implements PlayerInterface { + private PlayerInterface player; + + public KenoPlayer(PlayerInterface player){this.player=player;} + @Override + public CasinoAccount getArcadeAccount() { + return player.getArcadeAccount(); + } + + @Override + public void setArcadeAccount(CasinoAccount casinoAccount) { + + } +} From 430bd89d2dc9c321f615b5ad5f949a8bad2fe575 Mon Sep 17 00:00:00 2001 From: Zach Date: Thu, 15 Jul 2021 08:53:39 -0400 Subject: [PATCH 081/104] Final payout information and new line formatting/spacing implemented for BeetleGame --- .../zipcodewilmington/casino/games/Beetle/Beetle.java | 8 +++++++- .../casino/games/Beetle/BeetleGame.java | 11 +++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java index 122e7a535..9c7f5f4a9 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java @@ -8,6 +8,8 @@ public class Beetle{ private Integer[][] playerBeetles; private Integer[] scoreboard; private Integer numPlayers; + private Integer lastDiceRolls[] = new Integer[2]; + public Beetle(Integer numPlayers){ this.numPlayers = numPlayers; @@ -57,7 +59,7 @@ public void setCurrentPlayer(Integer currentPlayer) { public void setPlayerBeetles(Integer player, Integer diceRoll) { this.playerBeetles[player][diceRoll - dice.getNumDice()]++; - //return this.checkWinner(player); + this.lastDiceRolls[player] = diceRoll; } public void nextPlayer(){ @@ -108,6 +110,10 @@ public Boolean beetleIsComplete(Integer player){ return true; } + public Integer getLastDiceRoll(Integer index){ + return this.lastDiceRolls[index]; + } + public Integer getScore(Integer player){ return this.scoreboard[player]; } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index 31d3d1b3c..53ee790f3 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -41,9 +41,13 @@ public void run(){ this.executeTurn(); this.isGameOver(this.game.checkWinner(this.game.getCurrentPlayer())); } + console.newLine(); + console.println("Final Beetle results: "); this.printBeetleCards(); + console.newLine(); this.printWinnerMessage(); console.println("Your payout is: " + this.determinePayout().toString()); + console.pressEnterToProceed(); } public void initGame(){ @@ -56,9 +60,11 @@ public void initGame(){ } public void printBeetleCards(){ - console.print("\u001B[32m Your Beetle: "); + console.print("\u001B[32m Your last dice roll: " + game.getLastDiceRoll(0)); + console.print( " Your Beetle: "); console.println(game.printBeetle(0)); - console.print("\u001B[32m Dealer's Beetle: "); + console.print("\u001B[32m Dealer's last dice roll: " + game.getLastDiceRoll(1)); + console.print(" Dealer's Beetle: "); console.println(game.printBeetle(1)); } @@ -153,6 +159,7 @@ public void printWinnerMessage(){ } else { console.println("Dealer wins..."); } + console.newLine(); } } From f8f11f3069e204419be61c024e6a043c88c15bde Mon Sep 17 00:00:00 2001 From: Dipinti Date: Thu, 15 Jul 2021 09:00:51 -0400 Subject: [PATCH 082/104] trying to merge plinko and keno games --- .../casino/games/keno/Keno.java | 226 ------------- .../casino/games/keno/KenoGame.java | 309 ++++++++++++++++++ .../casino/games/keno/KenoPlayer.java | 19 ++ .../casino/games/plinko/PlinkoGame.java | 158 +++++++-- .../casino/games/plinko/PlinkoPlayer.java | 17 + 5 files changed, 470 insertions(+), 259 deletions(-) delete mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/keno/Keno.java create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/Keno.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/Keno.java deleted file mode 100644 index 1a2a42c9f..000000000 --- a/src/main/java/com/github/zipcodewilmington/casino/games/keno/Keno.java +++ /dev/null @@ -1,226 +0,0 @@ -package com.github.zipcodewilmington.casino.games.keno; - -import com.github.zipcodewilmington.casino.CasinoAccount; -import com.github.zipcodewilmington.casino.GameInterface; -import com.github.zipcodewilmington.casino.Player; -import com.github.zipcodewilmington.casino.PlayerInterface; - -import java.util.Random; -import java.util.Scanner; - -public class Keno implements GameInterface{ //, PlayerInterface { - int playerNumbers[] = new int[15]; - int computerGeneratedNumbers[] = new int[20]; - int kenoSpot, kenoCatch; - boolean continueGame = true; - Integer bet; - Player player; - Integer multiplier; - - public Integer getMultiplier() { - return multiplier; - } - - public void setMultiplier(Integer multiplier) { - this.multiplier = multiplier; - } - - - - public void setPlayerNumbers(int[] playerNumbers) { - this.playerNumbers = playerNumbers; - } - - @Override - public void add(PlayerInterface player) { - } - - @Override - public void remove(PlayerInterface player) { - - } - - @Override - public void run() { - //playerNums = getUserInput(); - //bet = getBet(player.getBalance()); - //player.makeBet(bet); - computerGeneratedNumbers = getComputerGeneratedNames(); - kenoSpot = getSpot(playerNumbers); - kenoCatch = getCatch(playerNumbers, computerGeneratedNumbers); - System.out.println("Catch: " + (kenoCatch + 1)); - Integer winningsAmount = 0; - - Integer winnings[][] = - { - {7, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, - {3, 9, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0}, - {4, 2, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 1, 10, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 1, 3, 15, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 1, 2, 3, 30, 88, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {6, 0, 1, 6, 12, 64, 100, 0, 0, 0, 0, 0, 0, 0, 0}, - {3, 0, 1, 3, 6, 30, 90, 120, 0, 0, 0, 0, 0, 0, 0}, - {2, 0, 1, 2, 4, 8, 20, 80, 1200, 0, 0, 0, 0, 0, 0}, - {1, 0, 1, 2, 3, 5, 10, 30, 600, 1800, 0, 0, 0, 0, 0}, - {0, 1, 1, 1, 2, 6, 15, 25, 180, 1000, 3000, 0, 0, 0, 0}, - {0, 0, 5, 1, 2, 4, 24, 72, 250, 500, 2000, 4000, 0, 0, 0}, - {0, 0, 4, 0, 3, 4, 5, 20, 80, 240, 500, 3000, 6000, 0, 0}, - {0, 0, 0, 0, 2, 3, 5, 12, 50, 150, 500, 1000, 2000, 7500, 0}, - {0, 0, 0, 0, 1, 2, 5, 15, 50, 150, 300, 600, 1200, 2500, 10000} - }; - if(kenoCatch < 0) - { - multiplier = 0; - } - else - multiplier=winnings[kenoSpot][kenoCatch]; - - } - - - public static int getCatch(int[] playerArray, int[] computerArray) - { - int playerIndex; - int computerIndex; - int kenoCatch = 0; - for (playerIndex = 0; playerIndex < playerArray.length; playerIndex++) - { - for(computerIndex = 0; computerIndex < computerArray.length; computerIndex++) - { - if(playerArray[playerIndex] == computerArray[computerIndex]) - { - kenoCatch++; - } - } - } - kenoCatch-=1; - return kenoCatch; - } - - public static int getSpot(int[] playerArray) - { - int index; - int spot = 0; - for (index = 0; index < playerArray.length; index++) - { - if(playerArray[index] != 0) - { - spot++; - } - - } - spot -= 1; //Subtract one so it works properly in array - return spot; - } - - public static int[] getComputerGeneratedNames() - { - int[] computerNums = new int[20]; - Random rand = new Random(); - int index; - int randomNumber = 0; - - for (index = 0; index < computerNums.length; index++) - { - randomNumber = rand.nextInt(80) + 1; - if(isUnique(randomNumber, computerNums)) - { - computerNums[index] = randomNumber; - } - else - { - index--; - } - - } - return computerNums; - } - - public static int[] getUserInput() - { - Scanner input = new Scanner(System.in); // for input - boolean invalidInput = true; - boolean continuePlayer = true; - int playerNums[] = new int[15]; - int index; - int numberEntered; - String enterString; - System.out.println("You may enter up to 15 numbers"); - for (index = 0; index < playerNums.length; index++ ) - { - playerNums[index] = 0; - } - index = 0; - while(continuePlayer && index < 15) - { - do - { - do - { - System.out.println("Enter number " + (index+1)); - numberEntered = input.nextInt(); - if ((numberEntered > 0) && (numberEntered < 81)) - { - if(isUnique(numberEntered, playerNums)) - { - invalidInput = false; - playerNums[index] = numberEntered; - } - else - { - System.out.println("Sorry, you already entered that number before!"); - System.out.println("Try again! "); - invalidInput = true; - } - } - else - { - invalidInput = true; - System.out.println("Sorry, the number you entered is either less than 0 or greater than 80"); - System.out.println("Try again"); - System.out.println(""); - } - } while(invalidInput); - - }while(invalidInput); - - index++; - } - return playerNums; - } - - public static boolean isUnique(int number, int[] array) - { - int index; - for (index = 0; index < array.length; index++) - { - if(number == array[index]) - { - return false; - } - } - return true; - } - - - @Override - public Integer calculateWinnings(Integer multiplier, Integer betAmount) { - return this.multiplier*betAmount; - } - - @Override - public void subtractBetFromBalance(Integer betAmount) { - player.setBalance(player.getBalance()-betAmount); - } - - @Override - public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { - - } - -// @Override -// public CasinoAccount getArcadeAccount() { -// return null; -// } -} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java new file mode 100644 index 000000000..c0ecf7cb8 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java @@ -0,0 +1,309 @@ +package com.github.zipcodewilmington.casino.games.keno; + +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; + +import java.util.Random; +import java.util.Scanner; + +public class KenoGame implements GameInterface { + Integer multiplier; + KenoPlayer kenoPlayer; + KenoGame kenoGame; + Integer bet; + int balance; + @Override + public void add(PlayerInterface player) { + + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public void run() { + Scanner input = new Scanner(System.in); + printWelcome(); + balance = 100; //Start the player off with some money + int playerNums[] = new int[15]; + int computerNums[] = new int[20]; + int kenoSpot, kenoCatch; + boolean continueGame = true; + String userInput; + + + System.out.println("\u001B[32mHello, and welcome to the game Keno!"); + System.out.println("\u001B[32mThis is a high stakes game. You can win and lose money quickly!"); + while(continueGame) + { + System.out.println(); + System.out.println("\u001B[32mYou currently have: $" + balance); + System.out.println("\u001B[32mLet's get some numbers to begin."); + System.out.println("\u001B[32mYou may enter up to 15 numbers"); + playerNums = getUserInput(); + bet = (int) getBet(balance); + computerNums = getComputerNums(); + kenoSpot = getSpot(playerNums); + kenoCatch = getCatch(playerNums, computerNums); + System.out.println("\u001B[32mCatch: " + (kenoCatch + 1)); + balance += payout(kenoSpot, kenoCatch, bet); + subtractBetFromBalance(bet); + System.out.println("\u001B[32mYou now have: $" + balance); + if (balance <= 0) + { + continueGame = false; + System.out.println("\u001B[32mSorry, you ran out of money!"); + System.out.println("\u001B[32mBetter luck next time! :)"); + } + else + { + System.out.println("\u001B[32mWould you like to continue(y/n)?"); + userInput = input.nextLine(); + + if ((userInput.equals("y"))) + { + continueGame = true; + } + else + { + continueGame = false; + } + } + } + System.out.println("\u001B[32mThanks for playing!"); + System.out.println("\u001B[32mOverall, you now have: $" + balance); + + } + + private void printWelcome() { + System.out.println( + "\u001B[33m***********************************\n" + + "*** ***\n" + + "****** WELCOME TO KENO ******\n" + + "*** ***\n" + + "***********************************"); + } + + public static int[] getUserInput() + { + Scanner input = new Scanner(System.in); // for input + boolean invalidInput = true; + boolean continuePlayer = true; + int playerNums[] = new int[15]; + int index; + int numberEntered; + String enterString; + for (index = 0; index < playerNums.length; index++ ) + { + playerNums[index] = 0; + } + index = 0; + while(continuePlayer && index < 15) + { + do + { + do + { + System.out.println("\u001B[32mEnter number " + (index+1)); + numberEntered = input.nextInt(); + if ((numberEntered > 0) && (numberEntered < 81)) + { + if(isUnique(numberEntered, playerNums)) + { + invalidInput = false; + playerNums[index] = numberEntered; + } + else + { + System.out.println("\u001B[32mSorry, you already entered that number before!"); + System.out.println("\u001B[32mTry again! "); + invalidInput = true; + } + } + else + { + invalidInput = true; + System.out.println("\u001B[32mSorry, the number you entered is either less than 0 or greater than 79"); + System.out.println("\u001B[32mTry again"); + System.out.println(""); + } + } while(invalidInput); + + if(index < 14) //makes sure program doesn't ask to continue when on the last number + { + System.out.println("\u001B[32mDo you wish to continue? (y/n)"); + input.nextLine(); + enterString = input.nextLine(); + if ((enterString.equals("n")) || (enterString.equals("no"))) + { + invalidInput = false; + continuePlayer = false; + } + else if ((enterString.equals("y")) || (enterString.equals("yes"))) + { + invalidInput = false; + continuePlayer = true; + } + else + { + System.out.println("\u001B[32mSorry, I didn't understand that."); + System.out.println(""); + invalidInput = true; + } + + } + }while(invalidInput); + + index++; + } + return playerNums; + } + + public static boolean isUnique(int number, int[] array) + { + int index; + for (index = 0; index < array.length; index++) + { + if(number == array[index]) + { + return false; + } + } + return true; + } + + public static int[] getComputerNums() + { + int[] computerNums = new int[20]; + Random rand = new Random(); + int index; + int randomNumber = 0; + + for (index = 0; index < computerNums.length; index++) + { + randomNumber = rand.nextInt(80) + 1; + if(isUnique(randomNumber, computerNums)) + { + computerNums[index] = randomNumber; + } + else + { + index--; + } + + } + return computerNums; + } + + public static int getSpot(int[] playerArray) + { + int index; + int spot = 0; + for (index = 0; index < playerArray.length; index++) + { + if(playerArray[index] != 0) + { + spot++; + } + + } + spot -= 1; //Subtract one so it works properly in array + return spot; + } + + public static double getBet(double playerMoney) + { + Scanner input = new Scanner(System.in); + double bet = 0; + boolean invalidInput = true; + while(invalidInput) + { + System.out.print("\u001B[32mEnter the bet amount in whole dollars: $"); + bet = input.nextInt(); + if(bet < 0) + { + System.out.println("\u001B[32mBet amount can't be less than 0!"); + invalidInput = true; + } + else if(bet > playerMoney) + { + System.out.println("\u001B[32mYou don't have enough money to bet that!"); + invalidInput = true; + } + else + { + invalidInput = false; + } + } + return bet; + } + + public static int getCatch(int[] playerArray, int[] computerArray) + { + int playerIndex; + int computerIndex; + int kenoCatch = 0; + for (playerIndex = 0; playerIndex < playerArray.length; playerIndex++) + { + for(computerIndex = 0; computerIndex < computerArray.length; computerIndex++) + { + if(playerArray[playerIndex] == computerArray[computerIndex]) + { + kenoCatch++; + } + } + } + kenoCatch -= 1;//subtact one so it works in array + return kenoCatch; + } + + public double payout(int kenoSpot, int kenoCatch, int betAmount) + { + Integer payoutAmount = 0; + Integer payout[][] = + { + {3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //1 + {1, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //2 + {1, 2, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //3 + {0, 2, 6, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //4 + {0, 1, 3, 15, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//5 + {1, 1, 2, 3, 30, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0},//6 + {2, 0, 1, 6, 12, 36, 100, 0, 0, 0, 0, 0, 0, 0, 0},//7 + {0, 1, 1, 3, 6, 19, 90, 720, 0, 0, 0, 0, 0, 0, 0},//8 + {0, 1, 1, 2, 4, 8, 20, 80, 1200, 0, 0, 0, 0, 0, 0},//9 + {0, 1, 1, 2, 3, 5, 10, 30, 600, 1800, 0, 0, 0, 0, 0},//10 + {0, 0, 1, 1, 2, 6, 15, 25, 180, 1000, 3000, 0, 0, 0, 0},//11 + {0, 0, 0, 1, 2, 4, 24, 72, 250, 500, 2000, 4000, 0, 0, 0},//12 + {0, 0, 0, 1, 3, 4, 5, 20, 80, 240, 500, 3000, 6000, 0, 0},//13 + {0, 0, 0, 0, 2, 3, 5, 12, 50, 150, 500, 1000, 2000, 7500, 0},//14 + {0, 0, 0, 0, 1, 2, 5, 15, 50, 150, 300, 600, 1200, 2500, 10000}//15 + }; + if(kenoCatch < 0) + { + this.multiplier = 0; + } + else + { + multiplier = payout[kenoSpot][kenoCatch]; + payoutAmount = multiplier * betAmount; + } + return payoutAmount; + } + + @Override + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return this.multiplier*betAmount; + } + + @Override + public void subtractBetFromBalance(Integer betAmount) { + this.balance-=bet; + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + this.balance+=calculateWinnings(multiplier,bet); + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java new file mode 100644 index 000000000..4e8539548 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java @@ -0,0 +1,19 @@ +package com.github.zipcodewilmington.casino.games.keno; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; + +public class KenoPlayer implements PlayerInterface { + private PlayerInterface player; + + public KenoPlayer(PlayerInterface player){this.player=player;} + @Override + public CasinoAccount getArcadeAccount() { + return player.getArcadeAccount(); + } + + @Override + public void setArcadeAccount(CasinoAccount casinoAccount) { + + } +} \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java index 0182c99c1..26d907ca5 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java @@ -7,43 +7,16 @@ import java.util.HashMap; import java.util.Map; import java.util.Random; +import java.util.Scanner; -public class PlinkoGame implements GameInterface{ //,PlayerInterface { +public class PlinkoGame implements GameInterface{ private Map moneyGenerator=new HashMap(); public int initialPosition; - private double betAmount; + private int bet; public int multiplier; + private int balance; - public PlinkoGame(int initialPosition){ - this.initialPosition=initialPosition; - } - - public String playPlinko(int initialPosition){ - if(initialPosition<10 && initialPosition>0){ - int max=9; - int min=1; - Random rand = new Random(); - int randomNumber=rand.nextInt(max - min + 1) + min; - return String.valueOf(randomNumber); - } - else - return "Invalid Entry"; - } - - public void run2() { - if (initialPosition < 10 && initialPosition > 0) { - int max = 9; - int min = 1; - Random rand = new Random(); - multiplier = rand.nextInt(max - min + 1) + min; - System.out.println("Now your position is: " + multiplier); - } - else - { - System.out.println("Invalid Entry"); - } - } @Override public void add(PlayerInterface player) { @@ -57,11 +30,65 @@ public void remove(PlayerInterface player) { @Override public void run() { + Scanner input = new Scanner(System.in); + printWelcome(); + balance = 100; //Start the player off with some money + boolean continueGame=true; + Integer playerNumber; + String userInput; + + System.out.println("\u001B[32mHello, and welcome to the game Plinko!"); + while(continueGame){ + System.out.println("\u001B[32mYou currently have: $" + balance); + System.out.println("\u001B[32mPlease enter a number position of your choice: "); + playerNumber = getUserInput(); + bet = (int) getBet(balance); + int plinkSpot=getPlinkoSpot(); + this.multiplier=plinkSpot; + System.out.println("\u001B[32mAfter playing, now your position is: "+plinkSpot); + balance += payout(plinkSpot); + subtractBetFromBalance(bet); + System.out.println("\u001B[32mYou now have: $" + balance); + if (balance <= 0) + { + continueGame = false; + System.out.println("\u001B[32mSorry, you ran out of money!"); + System.out.println("\u001B[32mBetter luck next time! :)"); + } + else + { + System.out.println("\u001B[32mWould you like to continue(y/n)?"); + userInput = input.nextLine(); + + if ((userInput.equals("y"))) + { + continueGame = true; + } + else + { + continueGame = false; + } + } + } + System.out.println("\u001B[32mThanks for playing!"); + System.out.println("\u001B[32mOverall, you now have: $" + balance); + } + private void printWelcome() { + System.out.println( + "\u001B[33m***********************************\n" + + "*** ***\n" + + "****** WELCOME TO PLINKO ******\n" + + "*** ***\n" + + "***********************************"); } @Override public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return this.multiplier*betAmount; + } + + private int payout(int plinkoSpot) { moneyGenerator.put(1,200); moneyGenerator.put(2,0); moneyGenerator.put(3,3000); @@ -75,7 +102,7 @@ public Integer calculateWinnings(Integer multiplier, Integer betAmount) { for (Integer pos:moneyGenerator.keySet()) { - if(pos.equals(multiplier)){ + if(pos.equals(plinkoSpot)){ moneyWon=moneyGenerator.get(pos); } } @@ -83,10 +110,74 @@ public Integer calculateWinnings(Integer multiplier, Integer betAmount) { } + private int getPlinkoSpot() { + int max = 9; + int min = 1; + Random rand = new Random(); + return rand.nextInt(max - min + 1) + min; + } + + public static double getBet(double playerMoney) + { + Scanner input = new Scanner(System.in); + double bet = 0; + boolean invalidInput = true; + while(invalidInput) + { + System.out.print("Enter the bet amount in whole dollars: $"); + bet = input.nextInt(); + if(bet < 0) + { + System.out.println("Bet amount can't be less than 0!"); + invalidInput = true; + } + else if(bet > playerMoney) + { + System.out.println("You don't have enough money to bet that!"); + invalidInput = true; + } + else + { + invalidInput = false; + } + } + return bet; + } + + private Integer getUserInput() { + Scanner input = new Scanner(System.in); // for input + boolean invalidInput = true; + boolean continuePlayer = true; + int numberEntered; + int playerNums=0; + String enterString; + + + while(invalidInput) + { + System.out.println("Enter number :"); + numberEntered = input.nextInt(); + + if ((numberEntered > 0) && (numberEntered < 10)){ + invalidInput = false; + playerNums = numberEntered; + break; + } + else{ + invalidInput = true; + System.out.println("Sorry, the number you entered is either less than 0 or greater than 9"); + System.out.println("Try again"); + System.out.println(""); + } + } + return playerNums; + } + + @Override public void subtractBetFromBalance(Integer betAmount) { - + balance-=bet; } @Override @@ -101,3 +192,4 @@ public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { } + diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java new file mode 100644 index 000000000..d4bd43fa3 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java @@ -0,0 +1,17 @@ +package com.github.zipcodewilmington.casino.games.plinko; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; + +public class PlinkoPlayer implements PlayerInterface { + private PlayerInterface player; + @Override + public CasinoAccount getArcadeAccount() { + return player.getArcadeAccount(); + } + + @Override + public void setArcadeAccount(CasinoAccount casinoAccount) { + + } +} From 00ad0fa4e11dc8b70eb088ddb500f19496141b92 Mon Sep 17 00:00:00 2001 From: Zach Date: Thu, 15 Jul 2021 09:04:11 -0400 Subject: [PATCH 083/104] newLine error fixed in Beetle --- src/main/java/com/github/zipcodewilmington/Casino.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index f911a736f..3bb27fa89 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -5,6 +5,7 @@ import com.github.zipcodewilmington.casino.games.blackjack.BlackJackGame; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessGame; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessPlayer; +import com.github.zipcodewilmington.casino.games.plinko.PlinkoGame; import com.github.zipcodewilmington.casino.games.slots.SlotsGame; import com.github.zipcodewilmington.casino.games.slots.SlotsPlayer; import com.github.zipcodewilmington.utils.AnsiColor; @@ -83,6 +84,9 @@ private void processGameSelection(String input){ case "blackjack": gameObject = new BlackJackGame(); break; + case "numberguess": + gameObject = new NumberGuessGame(); + break; default: gameObject = new BeetleGame(); } From 00224c4086119543012e8cada2fcea2b83c88ee8 Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Thu, 15 Jul 2021 09:43:03 -0400 Subject: [PATCH 084/104] Added CSVUtils class, next feature will be implementation so user can access through console instead of creating new account (#56) Co-authored-by: Zach --- .../zipcodewilmington/utils/CSVUtils.java | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/main/java/com/github/zipcodewilmington/utils/CSVUtils.java diff --git a/src/main/java/com/github/zipcodewilmington/utils/CSVUtils.java b/src/main/java/com/github/zipcodewilmington/utils/CSVUtils.java new file mode 100644 index 000000000..8e08d131a --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/utils/CSVUtils.java @@ -0,0 +1,81 @@ +package com.github.zipcodewilmington.utils; + +import com.github.zipcodewilmington.Casino; +import com.github.zipcodewilmington.casino.CasinoAccount; + +import java.io.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class CSVUtils { + private static final char DEFAULT_SEPARATOR = ','; // (1) + + // (2) + public static void writeLine(Writer w, List values) throws IOException { + boolean first = true; + + StringBuilder sb = new StringBuilder(); + + // (3) + for (String value : values) { + if (!first) { + sb.append(DEFAULT_SEPARATOR); + } + sb.append(value); + first = false; + } + sb.append("\n"); + + w.append(sb.toString()); // (4) + } + + public static void csvFileSaver(CasinoAccount account) throws IOException { + String csvFile = "/accounts.csv"; + FileWriter writer = new FileWriter(csvFile); + Integer nextId = 1; + CSVUtils.writeLine(writer, new ArrayList(Arrays.asList(String.valueOf(nextId)))); + + List list = new ArrayList<>(); + list.add(account.getAccountName()); + list.add(account.getPassword()); + list.add(String.valueOf(account.getAccountBalance())); + + CSVUtils.writeLine(writer, list); + + + writer.flush(); + writer.close(); + } + + public static CasinoAccount loadData(){ + // (1) + String csvFile = "accounts.csv"; + String line = ""; + String csvSplitBy = ","; + Integer nextId = 1; + // (2) + try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) { + nextId = Integer.parseInt(br.readLine()); // (3) + + while ((line = br.readLine()) != null) { + // split line with comma + String[] account = line.split(csvSplitBy); + + String accountName = account[0]; + String password = account[1]; + String accountBalance = account[2]; + + + // (5) + //inventory.add(new Sneaker(id, name, brand, sport, size, qty, price)); + CasinoAccount loadedAccount = new CasinoAccount(accountName, password); + loadedAccount.alterAccountBalance(Integer.parseInt(accountBalance)); + return loadedAccount; + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } +} From 76927300ea31b16b61a2fb0830fb0ee3839152e2 Mon Sep 17 00:00:00 2001 From: Zach Date: Thu, 15 Jul 2021 11:50:02 -0400 Subject: [PATCH 085/104] switching to new branch after adding options for saving/loading --- src/main/java/com/github/zipcodewilmington/Casino.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index 3bb27fa89..4ade6c4c0 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -50,7 +50,7 @@ public void run() { String accountPassword = console.getStringInput("Enter your account password:"); CasinoAccount newAccount = casinoAccountManager.createAccount(accountName, accountPassword); casinoAccountManager.registerAccount(newAccount); - } + } } while (!"logout".equals(arcadeDashBoardInput)); } @@ -58,7 +58,7 @@ private String getArcadeDashboardInput() { return console.getStringInput(new StringBuilder() .append("Welcome to the Arcade Dashboard!") .append("\nFrom here, you can select any of the following options:") - .append("\n\t[ create-account ], [ select-game ]") + .append("\n\t[ create-account ], [ select-game ], [ load-saved-account ], [ save-account ]") .toString()); } From f65c2c78eacf2d78032bf6d2cab7316d6ebca2d1 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 15 Jul 2021 12:16:25 -0400 Subject: [PATCH 086/104] (feat:black-jack) fixed the death loop --- .../casino/games/blackjack/BlackJackGame.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index 9ec32227f..125060b53 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -87,19 +87,16 @@ public void run() { } public void startGame () { - boolean blackJack = false; - while (!blackJack) { bj.givePlayerCard(); System.out.println("Your starting card : " + bj.playersCurrentValue()); System.out.println("Your second next card : " + bj.givePlayerCard()); System.out.println("Hand value : " + bj.playersCurrentValue()); if (twoCardBlackJack()) { - blackJack = true; + calculateWinnings(3, userBet); } else if (bj.playersHand.get(0).equals(bj.playersHand.get(1))) { // include conditional on starting blackjack! splitPlayer(); } else { standardGame(); - } } } @@ -118,8 +115,10 @@ public void standardGame () { Integer userChoice = input.getIntegerInput("1. Hit" + "\n" + "2. Stay"); switch (userChoice) { case 1: - checkStandardWinner(isWinner); - isWinner = true; + bj.givePlayerCard(); + if (checkStandardWinner()) { + isWinner = true; + } break; case 2: bj.giveDealerCard(); @@ -179,20 +178,22 @@ private void splitPlayerBust(Integer splitBet) { standardGame(); } - private boolean checkStandardWinner(boolean isWinner) { - bj.givePlayerCard(); + private boolean checkStandardWinner() { + boolean playerWon; System.out.println("Current hand value " + bj.playersCurrentValue()); if(bj.playersCurrentValue() > 21) { System.out.println("Sorry bud, you got " + bj.playersCurrentValue() + ", better luck next time"); calculateWinnings(0, userBet); - isWinner = true; + playerWon = true; } else if (playerHitsBlackJack()) { System.out.println("BLACK JACK!!"); calculateWinnings(3, userBet); - isWinner = true; + playerWon = true; + } else { + playerWon = false; } - return isWinner; + return playerWon; } private Integer secondHandBet() { From cd5f41b36af57af72e7438cef0a8cc56f13d8d7b Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Thu, 15 Jul 2021 12:22:54 -0400 Subject: [PATCH 087/104] CSV loader and saver workinggit add -u (#57) Co-authored-by: Zach --- .../com/github/zipcodewilmington/Casino.java | 24 +++++++++++++++---- .../zipcodewilmington/utils/CSVUtils.java | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index 4ade6c4c0..ba93e5c4d 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -9,8 +9,10 @@ import com.github.zipcodewilmington.casino.games.slots.SlotsGame; import com.github.zipcodewilmington.casino.games.slots.SlotsPlayer; import com.github.zipcodewilmington.utils.AnsiColor; +import com.github.zipcodewilmington.utils.CSVUtils; import com.github.zipcodewilmington.utils.IOConsole; +import java.io.IOException; import java.util.Locale; /** @@ -32,10 +34,7 @@ public void run() { CasinoAccount casinoAccount = casinoAccountManager.getAccount(accountName, accountPassword); boolean isValidLogin = casinoAccount != null; if (isValidLogin) { - this.casinoAccount = casinoAccount; - casinoAccount.alterAccountBalance(500); - this.player = new Player(accountName, casinoAccount); - this.player.setArcadeAccount(casinoAccount); + String gameSelectionInput = getGameSelectionInput().toUpperCase(); processGameSelection(gameSelectionInput); @@ -50,7 +49,22 @@ public void run() { String accountPassword = console.getStringInput("Enter your account password:"); CasinoAccount newAccount = casinoAccountManager.createAccount(accountName, accountPassword); casinoAccountManager.registerAccount(newAccount); - } + this.casinoAccount = newAccount; + casinoAccount.alterAccountBalance(500); + this.player = new Player(accountName, casinoAccount); + this.player.setArcadeAccount(casinoAccount); + } else if("save-account".equals(arcadeDashBoardInput)){ + try { + CSVUtils.csvFileSaver(this.player.getArcadeAccount()); + } catch (IOException e) { + e.printStackTrace(); + console.println("Save unsuccessful, refer to error message above for more information"); + } + } else if("load-saved-account".equals(arcadeDashBoardInput)){ + this.casinoAccount = CSVUtils.loadData(); + this.player = new Player(this.casinoAccount.getAccountName(), this.casinoAccount); + casinoAccountManager.registerAccount(this.casinoAccount); + } } while (!"logout".equals(arcadeDashBoardInput)); } diff --git a/src/main/java/com/github/zipcodewilmington/utils/CSVUtils.java b/src/main/java/com/github/zipcodewilmington/utils/CSVUtils.java index 8e08d131a..f941b0009 100644 --- a/src/main/java/com/github/zipcodewilmington/utils/CSVUtils.java +++ b/src/main/java/com/github/zipcodewilmington/utils/CSVUtils.java @@ -31,7 +31,7 @@ public static void writeLine(Writer w, List values) throws IOException { } public static void csvFileSaver(CasinoAccount account) throws IOException { - String csvFile = "/accounts.csv"; + String csvFile = "accounts.csv"; FileWriter writer = new FileWriter(csvFile); Integer nextId = 1; CSVUtils.writeLine(writer, new ArrayList(Arrays.asList(String.valueOf(nextId)))); From 1b703cab26709865d1db7cc5ec3b3cb988d4516f Mon Sep 17 00:00:00 2001 From: Nathan Date: Thu, 15 Jul 2021 12:54:00 -0400 Subject: [PATCH 088/104] NumberGuessGame fleshed out --- .../zipcodewilmington/MainApplication.java | 6 +- .../games/numberguess/NumberGuessGame.java | 115 +++++++++++++----- .../NumberGuessGameTests.java | 1 + 3 files changed, 88 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/MainApplication.java b/src/main/java/com/github/zipcodewilmington/MainApplication.java index d6fd77829..e2169b7f8 100644 --- a/src/main/java/com/github/zipcodewilmington/MainApplication.java +++ b/src/main/java/com/github/zipcodewilmington/MainApplication.java @@ -1,12 +1,14 @@ package com.github.zipcodewilmington; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessGame; +import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessPlayer; import com.github.zipcodewilmington.casino.games.slots.SlotsGame; public class MainApplication { public static void main(String[] args) { new Casino().run(); -// SlotsGame slotGame = new SlotsGame(); -// slotGame.run(); } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java index ef25bb083..f83adf236 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java @@ -28,32 +28,76 @@ public void run() { Scanner scanner = new Scanner(System.in); //print welcome printWelcome(); - //print instruction for game - System.out.println("Guess the right number between 0 and 20 to double your bets!\nFeeling lucky??\n\n Increase the difficulty and increase your earnings!"); - //print difficulty levels and ask user to choose - setDifficultyLevel(); - //print player's current account balance - System.out.println("Your current account balance is: " + this.currentPlayer.getArcadeAccount().getAccountBalance()); - //ask for a bet amount - takeBet(); - //subtract bet amount from player's account - this.currentPlayer.getArcadeAccount().alterAccountBalance(betAmount); - //ask player to chose number from 0 to difficulty lvl - takeGuess(); - //generate actual number - pickRandomNumber(); - //compare difference - //compute winnings - - //print winnings - - //add winnings to player's account + Boolean quitGame = false; + while(!quitGame) { + + //print instruction for game + printInstructions(); + System.out.println("Guess the right number between 0 and 20 to double your bets!\n\n But WAIT! Feeling lucky??\n\nIncrease the difficulty and increase your earnings!"); + + //print difficulty levels and ask user to choose + setDifficultyLevel(); + //set multiplier + setMultiplier(maxNumber); + //print player's current account balance + System.out.println("Your current account balance is: $" + this.currentPlayer.getArcadeAccount().getAccountBalance()); + //ask for a bet amount + takeBet(); + //subtract bet amount from player's account + subtractBetFromBalance(betAmount); + //ask player to chose number from 0 to difficulty lvl + takeGuess(); + //generate actual number + pickRandomNumber(); + //compare difference + Integer guessRange = getGuessRange(guessNumber, randomNumber); + //calculate amount player won + Integer payout = calculatePayout(multiplier, guessRange, betAmount); + //print winnings + System.out.println("You won: $"+payout); + //add winnings to player's account + addMoneyToBalance(currentPlayer,payout); + //ask if player wants to play again + System.out.println("\u001B[36mWould you like to play again?\n" + + "1. Yes 2. No"); + Integer input = scanner.nextInt(); + if(input == 2){ + quitGame = true; + } + } + } + + private void printInstructions() { + } + + private Integer calculatePayout(Integer multiplier, Integer guessRange,Integer betAmount) { + Integer payout; + Double percent = 0.0; + Double multiplierAsDouble = multiplier.doubleValue(); + if (guessRange.equals(0)){ + percent = multiplierAsDouble * 1; + } else if(guessRange <= 10){ + percent = multiplierAsDouble * 0.8; + } else if(guessRange <= 25){ + percent = multiplierAsDouble * 0.6; + } else if(guessRange <= 35){ + percent = multiplierAsDouble * 0.4; + } else if(guessRange >= 36){ + percent = multiplierAsDouble * 0.0; + } + + Double payoutAsDouble = percent * betAmount; + payout = payoutAsDouble.intValue(); + + return payout; } private void pickRandomNumber() { - this.randomNumber = (int) ((Math.random() * (maxNumber - 0)) + 0); + Integer random = (int) ((Math.random() * (maxNumber - 0)) + 0); + this.randomNumber = random; + } private void takeGuess() { @@ -69,13 +113,14 @@ private void takeBet() { private void printWelcome() { //TODO + System.out.println("WELCOME WELCOME WELCOME!!!!!"); } private void setDifficultyLevel() { System.out.println("1. Start max at 20 and go for double.\n" + "2. Change max to 30 and Triple your bets!\n" + - "3.Change max to 40 and QUADRUPLE your bets! OH MY!\n" + - "4.Change max to 50! SEND IT! TO THE MOON!"); + "3. Change max to 40 and QUADRUPLE your bets! OH MY!\n" + + "4. Change max to 50! SEND IT! TO THE MOON!"); setMaxNumber(scanner.nextInt()); } @@ -84,12 +129,6 @@ public Integer getGuessRange(Integer guessedNumber, Integer actualNumber){ return guessRangePercentage(Math.abs(guessedNumber - actualNumber)); } - - //Player can set difficulty level to get high yield - //Take this return - reward if guess is within 10% - //The closer to 0%, the higher reward - //10% = money back, 8% = 1.1 - public Integer guessRangePercentage(Integer range){ Double percent = ((range.doubleValue() / this.maxNumber) * 100); return percent.intValue(); @@ -102,6 +141,19 @@ public void setMaxNumber(Integer max){ this.maxNumber = max; } + public void setMultiplier(Integer difficultyLvl) { + switch(difficultyLvl){ + case 20: + this.multiplier = 2; + case 30: + this.multiplier = 3; + case 40: + this.multiplier = 4; + case 50: + this.multiplier = 5; + } + } + @Override public void add(PlayerInterface player) { this.currentPlayer = player; @@ -113,7 +165,6 @@ public void remove(PlayerInterface player) { } - @Override public Integer calculateWinnings(Integer multiplier, Integer betAmount) { return null; @@ -121,11 +172,11 @@ public Integer calculateWinnings(Integer multiplier, Integer betAmount) { @Override public void subtractBetFromBalance(Integer betAmount) { - + this.currentPlayer.getArcadeAccount().alterAccountBalance((betAmount * -1)); } @Override public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { - + Player.getArcadeAccount().alterAccountBalance(winnings); } } \ No newline at end of file diff --git a/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java b/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java index 493a6914b..c6dfcc0c9 100644 --- a/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java +++ b/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java @@ -47,4 +47,5 @@ public void getGuessPercentage(){ Assert.assertEquals(actual, expected); } + } From cc93126c9e29cde8834448eefd1fe4938c1e8a04 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 15 Jul 2021 13:10:32 -0400 Subject: [PATCH 089/104] (feat:black-jack) functionality complete, polishing formatting --- .../casino/games/blackjack/BlackJackGame.java | 144 +++++++++++------- 1 file changed, 89 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index 125060b53..7677aa3d5 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -16,29 +16,8 @@ public class BlackJackGame implements GameInterface { BlackJack bj; - /* Stuck in loop from split back to main hand against dealer - - run() -> hand -> standard game -> hit/stay -> dealersGame() ---- loop starts, dealers final value gets - returned as the "starting value" for the "next hand" - run through main to blackjack to see - - somewhere in there the program isn't terminating to the originally starting point -- walk the program down - + /* reorder the 'helper' methods for more clarity - - * refine the format for the splitHandBet (potentially add it to the 'userBet') - * only condition - if one hand wins and the other loses - * maybe an if statement at the 'playerInt.getAccountBalance().alterAccountBalance()' to execute for splitBet as well - * betting restraints if the user falls below zero - * If time available, include the conditional on aces being 11 or 1 depending on the currentPlayerValue() - * if (currentPlayerValue() > 21) { - for (int i = 0; i < playersHand.size(); i++) { - if (playersHand.get(i).equalsTo(11)) { - playersHand.set(i, 1); - } - } - return playersCurrentValue;---(playersCurrentValue should be under 21 if there was an 11 in there. however, - that changes all values that were 11 to 1; would need to change just one value - } * need formatting on splitHand * need refinement on formatting the beginning * make it flashy @@ -48,16 +27,6 @@ public BlackJackGame () { } - public void add(PlayerInterface player) { - this.playerInt = player; - } - - - public void remove(PlayerInterface player) { - - } - - public void run() { System.out.println("\u001B[36m============================================================"); System.out.println("\u001B[36m===== ====="); @@ -77,6 +46,7 @@ public void run() { BlackJack freshHand = new BlackJack(); bj = freshHand; userBet = (input.getIntegerInput("\u001B[32mHow much would you like to bet?" + "\n")); + userBetCondition(); playerInt.getArcadeAccount().alterAccountBalance(userBet * (-1)); startGame(); break; @@ -111,7 +81,7 @@ public boolean twoCardBlackJack () { public void standardGame () { boolean isWinner = false; while (!isWinner) { - System.out.println("Your hand value " + bj.playersCurrentValue()); + System.out.println("With the value of " + bj.playersCurrentValue() + "\n"); Integer userChoice = input.getIntegerInput("1. Hit" + "\n" + "2. Stay"); switch (userChoice) { case 1: @@ -147,24 +117,11 @@ public CasinoAccount getArcadeAccount() { public Integer calculateWinnings(Integer multiplier, Integer userBet) { - if (multiplier == 0) { - return 0; - } else { winnings = multiplier * userBet; return winnings; - } } - public void subtractBetFromBalance(Integer betAmount) { - - } - - - public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { - - } - private void splitPlayerHitsBlackJack(Integer splitBet) { System.out.println("BLACK JACK!!"); calculateWinnings(3, splitBet); @@ -180,14 +137,19 @@ private void splitPlayerBust(Integer splitBet) { private boolean checkStandardWinner() { boolean playerWon; - System.out.println("Current hand value " + bj.playersCurrentValue()); + System.out.println("Current hand value " + bj.playersCurrentValue() + "\n"); if(bj.playersCurrentValue() > 21) { - System.out.println("Sorry bud, you got " + bj.playersCurrentValue() + - ", better luck next time"); - calculateWinnings(0, userBet); - playerWon = true; + playerBustButHasAces(); + if (bj.playersCurrentValue() > 21) { + System.out.println("Sorry bud, you got " + bj.playersCurrentValue() + + ", better luck next time" + "\n"); + calculateWinnings(0, userBet); + playerWon = true; + } else { + playerWon = false; + } } else if (playerHitsBlackJack()) { - System.out.println("BLACK JACK!!"); + System.out.println("BLACK JACK!!" + "\n"); calculateWinnings(3, userBet); playerWon = true; } else { @@ -196,11 +158,14 @@ private boolean checkStandardWinner() { return playerWon; } + private Integer secondHandBet() { Integer splitValue = bj.playersHand.get(1); bj.playersHandOnSplit.add(splitValue); bj.playersHand.set(1, 0); - Integer splitBet = input.getIntegerInput("Please place your bet for the second hand"); + Integer splitBet = input.getIntegerInput("Please place your bet for the second hand" + "\n"); + splitHandBetConditions(); + playerInt.getArcadeAccount().alterAccountBalance(splitBet * (-1)); System.out.println("Your hand has been split! Current value " + bj.splitPlayersCurrentValue() + "\n" + "\n"); return splitBet; } @@ -215,8 +180,13 @@ private void splitHandRound() { bj.givePlayerCardOnSplit(); System.out.println("Current hand value " + bj.splitPlayersCurrentValue()); if (bj.splitPlayersCurrentValue() > 21) { - splitPlayerBust(splitBet); - isWinnerSecondHand = true; + splitHandBustHasAces(); + if (bj.splitPlayersCurrentValue() > 21) { + splitPlayerBust(splitBet); + isWinnerSecondHand = true; + } else { + isWinnerSecondHand = false; + } } else if (splitPlayerHitsBlackJack()) { splitPlayerHitsBlackJack(splitBet); isWinnerSecondHand = true; @@ -248,6 +218,36 @@ public void dealersGame() { } } } + + public void playerBustButHasAces () { + for (int i = 0; i < bj.playersHand.size(); i++) { + if (bj.playersHand.get(i).equals(11)) { + bj.playersHand.set(i, 1); + System.out.println("You had an Ace - we reduced that 11 to a 1! Keep going!" + "\n" ); + break; + } + } + } + + public void dealerBustButHasAces () { + for (int i = 0; i < bj.dealersHand.size(); i++) { + if (bj.dealersHand.get(i).equals(11)) { + bj.dealersHand.set(i, 1); + break; + } + } + } + + public void splitHandBustHasAces () { + for (int i = 0; i < bj.playersHandOnSplit.size(); i++) { + if (bj.playersHandOnSplit.get(i).equals(11)) { + bj.playersHandOnSplit.set(i, 1); + System.out.println("You had an Ace - we reduced that 11 to a 1! Keep going!" + "\n" ); + break; + } + } + } + public boolean splitPlayerHitsBlackJack () { if (bj.splitPlayersCurrentValue() == 21) { calculateWinnings(3, splitBet); @@ -265,4 +265,38 @@ public boolean playerHitsBlackJack() { return false; } } + + public void userBetCondition () { + while (userBet > playerInt.getArcadeAccount().getAccountBalance()) { + System.out.println("Oh no! You're trying to place a bet with more money than you have..."); + userBet = (input.getIntegerInput("\u001B[32mHow much would you like to bet?" + "\n")); + } + } + + public void splitHandBetConditions () { + while (secondHandBet() > playerInt.getArcadeAccount().getAccountBalance()) { + System.out.println("You don't have enough money for that, Silly!"); + secondHandBet(); + } + } + + public void subtractBetFromBalance(Integer betAmount) { + + } + + + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + + } + + public void add(PlayerInterface player) { + this.playerInt = player; + } + + + public void remove(PlayerInterface player) { + + } + + } From 088d9cd192bd4b42d948671001f7a1c8c25a840c Mon Sep 17 00:00:00 2001 From: Dipinti Date: Thu, 15 Jul 2021 13:22:20 -0400 Subject: [PATCH 090/104] added test files --- .../casino/games/keno/KenoGame.java | 2 + .../casino/games/plinko/PlinkoGame.java | 5 +- .../zipcodewilmington/KenoGameTest.java | 47 +++++++++++++++++++ .../github/zipcodewilmington/KenoTest.java | 18 ------- .../zipcodewilmington/PlinkoGameTest.java | 35 ++++++++++++++ .../github/zipcodewilmington/PlinkoTest.java | 45 ------------------ 6 files changed, 87 insertions(+), 65 deletions(-) create mode 100644 src/test/java/com/github/zipcodewilmington/KenoGameTest.java delete mode 100644 src/test/java/com/github/zipcodewilmington/KenoTest.java create mode 100644 src/test/java/com/github/zipcodewilmington/PlinkoGameTest.java delete mode 100644 src/test/java/com/github/zipcodewilmington/PlinkoTest.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java index c0ecf7cb8..8bb46657d 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java @@ -48,6 +48,7 @@ public void run() { kenoSpot = getSpot(playerNums); kenoCatch = getCatch(playerNums, computerNums); System.out.println("\u001B[32mCatch: " + (kenoCatch + 1)); + System.out.println("\u001B[32mYou have won: $"+payout(kenoSpot,kenoCatch,bet)); balance += payout(kenoSpot, kenoCatch, bet); subtractBetFromBalance(bet); System.out.println("\u001B[32mYou now have: $" + balance); @@ -294,6 +295,7 @@ public double payout(int kenoSpot, int kenoCatch, int betAmount) @Override public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return this.multiplier*betAmount; } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java index 26d907ca5..7c9878420 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java @@ -15,7 +15,7 @@ public class PlinkoGame implements GameInterface{ public int initialPosition; private int bet; public int multiplier; - private int balance; + public int balance; @Override @@ -85,6 +85,7 @@ private void printWelcome() { @Override public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return this.multiplier*betAmount; } @@ -110,7 +111,7 @@ private int payout(int plinkoSpot) { } - private int getPlinkoSpot() { + public int getPlinkoSpot() { int max = 9; int min = 1; Random rand = new Random(); diff --git a/src/test/java/com/github/zipcodewilmington/KenoGameTest.java b/src/test/java/com/github/zipcodewilmington/KenoGameTest.java new file mode 100644 index 000000000..b7a628fb2 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/KenoGameTest.java @@ -0,0 +1,47 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.games.keno.KenoGame; +import org.junit.Assert; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class KenoGameTest { + + + @Test + void testForIsUnique() { + //given + KenoGame kenoGame=new KenoGame(); + //when + Boolean boolVal=kenoGame.isUnique(7, new int[]{7, 7}); + //then + Assert.assertFalse(String.valueOf(boolVal),false); + } + + @Test + void testisUnique() { + //given + KenoGame kenoGame=new KenoGame(); + //when + Boolean boolVal=kenoGame.isUnique(7, new int[]{1, 7}); + //then + Assert.assertTrue(String.valueOf(boolVal),true); + } + + + @Test + + void testPayOut(){ + //given + int kenoSpot=11; + int kenoCatch=9; + KenoGame kenoGame=new KenoGame(); + //when + Double expectedValue=kenoGame.payout(11,9,200); + //then + Assert.assertTrue(String.valueOf(expectedValue),true); + } + + +} \ No newline at end of file diff --git a/src/test/java/com/github/zipcodewilmington/KenoTest.java b/src/test/java/com/github/zipcodewilmington/KenoTest.java deleted file mode 100644 index ea129ed35..000000000 --- a/src/test/java/com/github/zipcodewilmington/KenoTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.zipcodewilmington; - -import com.github.zipcodewilmington.casino.Player; -import com.github.zipcodewilmington.casino.games.keno.Keno; -import org.junit.Test; - -public class KenoTest { - @Test - public void testRun(){ - //Player player=new Player("Dipinti",3000); - Keno keno=new Keno(); - int[] playerNums={80,23,31,14,54,36,72,18,91,1,11,12,13,14,44}; - keno.setPlayerNumbers(playerNums); - keno.run(); - Integer winnings=keno.calculateWinnings(keno.getMultiplier(),3000); - System.out.println(winnings); - } -} diff --git a/src/test/java/com/github/zipcodewilmington/PlinkoGameTest.java b/src/test/java/com/github/zipcodewilmington/PlinkoGameTest.java new file mode 100644 index 000000000..dc5a777f6 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/PlinkoGameTest.java @@ -0,0 +1,35 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.games.keno.KenoGame; +import com.github.zipcodewilmington.casino.games.plinko.PlinkoGame; +import org.junit.Assert; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class PlinkoGameTest { + + + + @Test + void getPlinkoSpotTest() { + //given + PlinkoGame plinkoGame=new PlinkoGame(); + //when + Integer expectedValue=plinkoGame.getPlinkoSpot(); + //then + Assert.assertFalse(String.valueOf(expectedValue),false); + } + + @Test + public void calculateWinningsTest() { + //given + PlinkoGame plinkoGame=new PlinkoGame(); + Integer expectedValue=plinkoGame.calculateWinnings(2,200); + //when + Integer actualValue=plinkoGame.calculateWinnings(2,200); + //then + Assert.assertEquals(expectedValue,actualValue); + } + +} \ No newline at end of file diff --git a/src/test/java/com/github/zipcodewilmington/PlinkoTest.java b/src/test/java/com/github/zipcodewilmington/PlinkoTest.java deleted file mode 100644 index bdf4e8ba5..000000000 --- a/src/test/java/com/github/zipcodewilmington/PlinkoTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.zipcodewilmington; - -import com.github.zipcodewilmington.casino.games.plinko.PlinkoGame; -import org.junit.Assert; -import org.junit.Test; - -public class PlinkoTest { - - @Test - public void testCalculateWinnings() { - //given - - Integer expectedValue=0; - PlinkoGame plinkoGame=new PlinkoGame(7); - plinkoGame.run(); - //when - Integer actualValue=plinkoGame.calculateWinnings(2,200); - - //then - Assert.assertEquals(expectedValue,actualValue); - } - - @Test - public void testConstructor(){ - //given - int expectedValue=8; - //when - PlinkoGame plinkoGame=new PlinkoGame(8); - int actualValue=plinkoGame.initialPosition; - //then - Assert.assertEquals(expectedValue,actualValue); - } - - @Test - public void testPlayPlinko(){ - //given - String expectedValue="Invalid Entry"; - //when - PlinkoGame plinkoGame=new PlinkoGame(10); - String actualValue=plinkoGame.playPlinko(10); - //then - Assert.assertFalse(expectedValue, Boolean.parseBoolean(actualValue)); - } -} - From 82905469fcfc69b12c56b9e4764e42bb539d2122 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 15 Jul 2021 13:33:51 -0400 Subject: [PATCH 091/104] fixed single error --- .../github/zipcodewilmington/casino/games/plinko/PlinkoGame.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java index 0c85ebc31..0f5e1b565 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java @@ -73,7 +73,6 @@ public void run() { } System.out.println("\u001B[32mThanks for playing!"); System.out.println("\u001B[32mOverall, you now have: $" + balance); - feature/DipintiTestFiles } From 10cf650caed1c0c8b73042f532b12fd58be06157 Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Thu, 15 Jul 2021 13:47:16 -0400 Subject: [PATCH 092/104] Feature/csv implement (#61) * CSV loader and saver workinggit add -u * csv changed, committing to clean branch Co-authored-by: Zach --- accounts.csv | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 accounts.csv diff --git a/accounts.csv b/accounts.csv new file mode 100644 index 000000000..4d64feb4e --- /dev/null +++ b/accounts.csv @@ -0,0 +1,2 @@ +1 +zz,ss,500 From 5c11cead1e84f34f40885346a61dfe865c9ef53a Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Thu, 15 Jul 2021 13:47:54 -0400 Subject: [PATCH 093/104] Full testing coverage for Beetle.java, 100% methods, 100% lines (#62) Co-authored-by: Zach --- .../casino/games/Beetle/Beetle.java | 12 +---- .../casino/games/Beetle/BeetlePlayer.java | 3 +- .../github/zipcodewilmington/BeetleTest.java | 52 +++++++++---------- 3 files changed, 27 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java index 9c7f5f4a9..85f4155cb 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java @@ -8,7 +8,7 @@ public class Beetle{ private Integer[][] playerBeetles; private Integer[] scoreboard; private Integer numPlayers; - private Integer lastDiceRolls[] = new Integer[2]; + private Integer lastDiceRolls[] = {0, 0}; public Beetle(Integer numPlayers){ @@ -66,10 +66,6 @@ public void nextPlayer(){ this.currentPlayer = (this.currentPlayer + 1) % this.numPlayers; } - public void refreshBeetle(Integer player){ - this.playerBeetles[player] = new Integer[] {0, 0, 0, 0, 0, 0}; - } - public String printBeetle(Integer player){ Integer[] currentBeetle = this.getPlayerBeetles()[player]; String output = "Body:"; @@ -91,12 +87,6 @@ public String printBeetle(Integer player){ public Boolean checkWinner(Integer player){ if(this.beetleIsComplete(player)){ return true; - //this.scoreboard[player] += 6; - //if(this.getScore(player) == 30){ - //return true; - //} else { - //this.refreshBeetle(player); - //} } return false; } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java index 09b4f79cc..3d801553c 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java @@ -11,12 +11,11 @@ public BeetlePlayer(PlayerInterface player){ this.player = player; } - @Override + public CasinoAccount getArcadeAccount() { return null; } - @Override public void setArcadeAccount(CasinoAccount casinoAccount) { } diff --git a/src/test/java/com/github/zipcodewilmington/BeetleTest.java b/src/test/java/com/github/zipcodewilmington/BeetleTest.java index d1de50bd9..e841f6104 100644 --- a/src/test/java/com/github/zipcodewilmington/BeetleTest.java +++ b/src/test/java/com/github/zipcodewilmington/BeetleTest.java @@ -1,5 +1,6 @@ package com.github.zipcodewilmington; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.github.zipcodewilmington.casino.games.Beetle.Beetle; import org.junit.Assert; import org.junit.Test; @@ -81,7 +82,7 @@ public void setPlayerBeetleTest(){ public void beetleIsCompleteTest1(){ Beetle beetle = new Beetle(2); Boolean expected = true; - for(int i = 0; i < 6; i++) { + for(int i = 1; i <= 6; i++) { beetle.setPlayerBeetles(0, i); } Boolean actual = beetle.beetleIsComplete(0); @@ -102,12 +103,10 @@ public void beetleIsCompleteTest2(){ public void checkWinnerTest1(){ Beetle beetle = new Beetle(2); Boolean actual = false; - for(int i = 0; i < 5; i++){ - for(int j = 0; j < 6; j++){ + for(int j = 1; j <= 6; j++){ beetle.setPlayerBeetles(0, j); } actual = beetle.checkWinner(0); - } Assert.assertTrue(actual); } @@ -115,48 +114,47 @@ public void checkWinnerTest1(){ public void checkWinnerTest2(){ Beetle beetle = new Beetle(2); Boolean actual = false; - for(int i = 0; i < 4; i++){ - for(int j = 0; j < 6; j++){ + for(int j = 1; j <= 5; j++){ beetle.setPlayerBeetles(0, j); } actual = beetle.checkWinner(0); - } Assert.assertFalse(actual); } @Test - public void getScoreTest1(){ + public void nextPlayerTest1(){ Beetle beetle = new Beetle(2); - for(int j = 0; j < 6; j++){ - beetle.setPlayerBeetles(0, j); - } - beetle.checkWinner(0); - Integer expected = 6; - Integer actual = beetle.getScore(0); - - Assert.assertEquals(expected, actual); + beetle.nextPlayer(); + Integer actual = beetle.getCurrentPlayer(); + Integer expected = 1; + Assert.assertEquals(actual, expected); } @Test - public void getScoreTest2(){ + public void nextPlayerTest2(){ Beetle beetle = new Beetle(2); - + beetle.nextPlayer(); + beetle.nextPlayer(); + Integer actual = beetle.getCurrentPlayer(); Integer expected = 0; - Integer actual = beetle.getScore(0); + Assert.assertEquals(actual, expected); + } + + @Test + public void printBeetleTest1(){ + Beetle beetle = new Beetle(2); + String expected = "Body:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 "; + String actual = beetle.printBeetle(0); Assert.assertEquals(expected, actual); } @Test - public void refreshBeetleTest(){ + public void getLastDiceRollTest(){ Beetle beetle = new Beetle(2); - for(int j = 0; j < 6; j++){ - beetle.setPlayerBeetles(0, j); - } - beetle.refreshBeetle(0); - Integer[] actual = beetle.getPlayerCard(0); - Integer[] expected = new Integer[] {0, 0, 0, 0, 0, 0}; + Integer actual = beetle.getLastDiceRoll(0); + Integer expected = 0; - Assert.assertArrayEquals(actual, expected); + Assert.assertEquals(expected, actual); } } From 60badcb8a87c2ed677f7aae7e123fbcf5b54b2ef Mon Sep 17 00:00:00 2001 From: Zach Date: Thu, 15 Jul 2021 13:51:59 -0400 Subject: [PATCH 094/104] Added Plinko and Keno to main menu switch case, games can now be selected --- src/main/java/com/github/zipcodewilmington/Casino.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index ba93e5c4d..d107df229 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -3,6 +3,7 @@ import com.github.zipcodewilmington.casino.*; import com.github.zipcodewilmington.casino.games.Beetle.BeetleGame; import com.github.zipcodewilmington.casino.games.blackjack.BlackJackGame; +import com.github.zipcodewilmington.casino.games.keno.KenoGame; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessGame; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessPlayer; import com.github.zipcodewilmington.casino.games.plinko.PlinkoGame; @@ -101,6 +102,12 @@ private void processGameSelection(String input){ case "numberguess": gameObject = new NumberGuessGame(); break; + case "plinko": + gameObject = new PlinkoGame(); + break; + case "keno": + gameObject = new KenoGame(); + break; default: gameObject = new BeetleGame(); } From 411e7ecac0f8f6105db44228775c88744e648862 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 15 Jul 2021 15:18:12 -0400 Subject: [PATCH 095/104] (feat:black-jack) ANSI example on BlackJackGame lines 32 to 40 --- .../casino/games/blackjack/BlackJack.java | 8 ++++++++ .../casino/games/blackjack/BlackJackGame.java | 18 ++++++++++-------- .../casino/games/keno/KenoGame.java | 2 -- .../zipcodewilmington/utils/DemoMain.java | 2 ++ .../BlackJackPlayerTest.java | 13 +++++++++++++ .../zipcodewilmington/BlackJackTest.java | 19 +++++++++++++++++-- 6 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 src/test/java/com/github/zipcodewilmington/BlackJackPlayerTest.java diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java index bcbccd6dc..68211d354 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -97,4 +97,12 @@ public List getDealersHand() { public void setDealersHand(List dealersHand) { this.dealersHand = dealersHand; } + + public List getPlayersHandOnSplit() { + return playersHandOnSplit; + } + + public void setPlayersHandOnSplit(List playersHandOnSplit) { + this.playersHandOnSplit = playersHandOnSplit; + } } \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index 7677aa3d5..5627f55b1 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -3,6 +3,7 @@ import com.github.zipcodewilmington.casino.CasinoAccount; import com.github.zipcodewilmington.casino.GameInterface; import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.utils.AnsiColor; import com.github.zipcodewilmington.utils.IOConsole; @@ -12,6 +13,7 @@ public class BlackJackGame implements GameInterface { Integer userBet; Integer splitBet; IOConsole input = new IOConsole(); + IOConsole blue = new IOConsole(AnsiColor.BLUE); Integer winnings = 0; BlackJack bj; @@ -28,14 +30,14 @@ public BlackJackGame () { } public void run() { - System.out.println("\u001B[36m============================================================"); - System.out.println("\u001B[36m===== ====="); - System.out.println("\u001B[36m===== WELCOME ====="); - System.out.println("\u001B[36m===== TO ====="); - System.out.println("\u001B[36m===== B L A C K ====="); - System.out.println("\u001B[36m===== J A C K ====="); - System.out.println("\u001B[36m===== ====="); - System.out.println("\u001B[36m============================================================"); + blue.println("============================================================" + "\n" + + "===== =====" + "\n" + + "===== WELCOME =====" + "\n" + + "===== TO =====" + "\n" + + "===== B L A C K =====" + "\n" + + "===== J A C K =====" + "\n" + + "===== =====" + "\n" + + "============================================================"); while(!isRunning) { // include betting range playerInt.getArcadeAccount().alterAccountBalance(winnings); diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java index d9fe981f2..4558ee83f 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java @@ -48,9 +48,7 @@ public void run() { kenoSpot = getSpot(playerNums); kenoCatch = getCatch(playerNums, computerNums); System.out.println("\u001B[32mCatch: " + (kenoCatch + 1)); - System.out.println("\u001B[32mYou have won: $"+payout(kenoSpot,kenoCatch,bet)); - balance += payout(kenoSpot, kenoCatch, bet); subtractBetFromBalance(bet); System.out.println("\u001B[32mYou now have: $" + balance); diff --git a/src/main/java/com/github/zipcodewilmington/utils/DemoMain.java b/src/main/java/com/github/zipcodewilmington/utils/DemoMain.java index a0cf0bda8..ba7c8a2d9 100644 --- a/src/main/java/com/github/zipcodewilmington/utils/DemoMain.java +++ b/src/main/java/com/github/zipcodewilmington/utils/DemoMain.java @@ -1,6 +1,8 @@ package com.github.zipcodewilmington.utils; import com.github.zipcodewilmington.casino.games.blackjack.BlackJackGame; +import com.github.zipcodewilmington.casino.games.keno.KenoGame; +import com.github.zipcodewilmington.casino.games.plinko.PlinkoGame; public class DemoMain { public static void main(String[] args) { diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackPlayerTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackPlayerTest.java new file mode 100644 index 000000000..fbbe45df0 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BlackJackPlayerTest.java @@ -0,0 +1,13 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.blackjack.BlackJackPlayer; +import org.junit.Test; + +public class BlackJackPlayerTest { + + @Test + public void blackJackPlayerTest () { + + } +} diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackTest.java index 2cd4eff92..0442d1fe1 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackTest.java @@ -10,7 +10,7 @@ public class BlackJackTest { @Test public void generateNewDeckTest() { BlackJack bj = new BlackJack(); - Integer expected = 165; + Integer expected = 52; Integer actual1 = bj.generateNewDeck().size(); List actual = bj.generateNewDeck(); @@ -76,8 +76,23 @@ public void dealersCurrentValueTest () { } @Test - public void playerBroke21orBlackJackTest () { + public void givePlayerCardOnSplitTest () { + BlackJack bj = new BlackJack(); + List expected = bj.getPlayersHandOnSplit(); + List actual = bj.givePlayerCardOnSplit(); + Assert.assertEquals(expected, actual); + } + + @Test + public void splitPlayersCurrentValueTest () { + BlackJack bj = new BlackJack(); + Integer expected = 0; + + bj.getPlayersHandOnSplit().add(0); + Integer actual = bj.splitPlayersCurrentValue(); + + Assert.assertEquals(expected, actual); } } From 1a2c29fb37a1fe3f67d74fb93e5eae90e7cfc38f Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 15 Jul 2021 16:24:44 -0400 Subject: [PATCH 096/104] pushing for Dipinti --- .../zipcodewilmington/casino/games/keno/KenoGame.java | 5 ++++- .../com/github/zipcodewilmington/BlackJackGameTest.java | 9 +-------- .../github/zipcodewilmington/BlackJackPlayerTest.java | 5 +++++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java index 4558ee83f..00cfb0ce7 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java @@ -1,12 +1,14 @@ package com.github.zipcodewilmington.casino.games.keno; import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.Player; import com.github.zipcodewilmington.casino.PlayerInterface; import java.util.Random; import java.util.Scanner; public class KenoGame implements GameInterface { + private PlayerInterface playerInt; Integer multiplier; KenoPlayer kenoPlayer; KenoGame kenoGame; @@ -26,7 +28,7 @@ public void remove(PlayerInterface player) { public void run() { Scanner input = new Scanner(System.in); printWelcome(); - balance = 100; //Start the player off with some money + balance = playerInt.getArcadeAccount().getAccountBalance(); //Start the player off with some money int playerNums[] = new int[15]; int computerNums[] = new int[20]; int kenoSpot, kenoCatch; @@ -50,6 +52,7 @@ public void run() { System.out.println("\u001B[32mCatch: " + (kenoCatch + 1)); System.out.println("\u001B[32mYou have won: $"+payout(kenoSpot,kenoCatch,bet)); balance += payout(kenoSpot, kenoCatch, bet); + subtractBetFromBalance(bet); System.out.println("\u001B[32mYou now have: $" + balance); if (balance <= 0) diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java index 8900a84dd..f6a0abe78 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java @@ -49,16 +49,9 @@ public void calculateWinningsTest () { // Assert.assertEquals(expected, actual); // } - @Test - public void addMoneyToBalanceTest () { - - BlackJackGame bj = new BlackJackGame(); - - } @Test public void splitPlayerHitsBlackJack () { - BlackJackGame bj = new BlackJackGame(); - + } } diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackPlayerTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackPlayerTest.java index fbbe45df0..c6c2a7651 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackPlayerTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackPlayerTest.java @@ -10,4 +10,9 @@ public class BlackJackPlayerTest { public void blackJackPlayerTest () { } + + @Test + public void getArcadeAccountTest () { + + } } From fb81b5bc0e0664da64f3992a3ed8ae4f13c5aa9a Mon Sep 17 00:00:00 2001 From: Dipinti Date: Thu, 15 Jul 2021 16:47:36 -0400 Subject: [PATCH 097/104] made some arcade changes --- .../github/zipcodewilmington/casino/games/keno/KenoGame.java | 5 +++-- .../zipcodewilmington/casino/games/plinko/PlinkoGame.java | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java index 00cfb0ce7..84145db3a 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java @@ -28,6 +28,7 @@ public void remove(PlayerInterface player) { public void run() { Scanner input = new Scanner(System.in); printWelcome(); + balance=100; balance = playerInt.getArcadeAccount().getAccountBalance(); //Start the player off with some money int playerNums[] = new int[15]; int computerNums[] = new int[20]; @@ -52,8 +53,8 @@ public void run() { System.out.println("\u001B[32mCatch: " + (kenoCatch + 1)); System.out.println("\u001B[32mYou have won: $"+payout(kenoSpot,kenoCatch,bet)); balance += payout(kenoSpot, kenoCatch, bet); - subtractBetFromBalance(bet); + playerInt.getArcadeAccount().alterAccountBalance(balance); System.out.println("\u001B[32mYou now have: $" + balance); if (balance <= 0) { @@ -129,7 +130,7 @@ public static int[] getUserInput() else { invalidInput = true; - System.out.println("\u001B[32mSorry, the number you entered is either less than 0 or greater than 79"); + System.out.println("\u001B[32mSorry, the number you entered is either less than 0 or greater than 80"); System.out.println("\u001B[32mTry again"); System.out.println(""); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java index 0f5e1b565..cbcb4c553 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java @@ -11,7 +11,7 @@ public class PlinkoGame implements GameInterface{ private Map moneyGenerator=new HashMap(); - + private PlayerInterface playerInt; public int initialPosition; private int bet; public int multiplier; @@ -34,6 +34,7 @@ public void run() { Scanner input = new Scanner(System.in); printWelcome(); balance = 100; //Start the player off with some money + balance=playerInt.getArcadeAccount().getAccountBalance(); boolean continueGame=true; Integer playerNumber; String userInput; @@ -49,6 +50,7 @@ public void run() { System.out.println("\u001B[32mAfter playing, now your position is: "+plinkSpot); balance += payout(plinkSpot); subtractBetFromBalance(bet); + playerInt.getArcadeAccount().alterAccountBalance(balance); System.out.println("\u001B[32mYou now have: $" + balance); if (balance <= 0) { From 26b7b9c57bf28877e86e3dfcb0a6de7b266cfed8 Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Thu, 15 Jul 2021 17:39:51 -0400 Subject: [PATCH 098/104] Abstracted printBeetle method to return an output string, instead of 6 console.print calls, now the print call is called once and passed the string, allowing for test coverage (#65) Co-authored-by: Zach --- .../com/github/zipcodewilmington/Casino.java | 2 - .../casino/games/Beetle/Beetle.java | 2 +- .../casino/games/Beetle/BeetleGame.java | 90 ++++++++++++------- .../zipcodewilmington/BeetleGameTest.java | 73 +++++++++++++-- 4 files changed, 123 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index d107df229..93b450d08 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -35,8 +35,6 @@ public void run() { CasinoAccount casinoAccount = casinoAccountManager.getAccount(accountName, accountPassword); boolean isValidLogin = casinoAccount != null; if (isValidLogin) { - - String gameSelectionInput = getGameSelectionInput().toUpperCase(); processGameSelection(gameSelectionInput); } else { diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java index 85f4155cb..178af02eb 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java @@ -68,7 +68,7 @@ public void nextPlayer(){ public String printBeetle(Integer player){ Integer[] currentBeetle = this.getPlayerBeetles()[player]; - String output = "Body:"; + String output = "\u001B[36mBody:"; output += (currentBeetle[0].equals(0)) ? "0 " : "X "; output += "Head:"; output += (currentBeetle[1].equals(0)) ? "0 " : "X "; diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index 53ee790f3..848126633 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -8,12 +8,12 @@ import java.util.ArrayList; public class BeetleGame implements GameInterface { - private ArrayList players = new ArrayList(); private Beetle game; private Boolean isRunning = false; private PlayerInterface player; private IOConsole console = new IOConsole(); private Integer betAmt; + private Boolean isDemo = false; public BeetleGame(){ this.game = new Beetle(2); @@ -28,26 +28,21 @@ public void add(PlayerInterface player){ * @param player the player to be removed from the game */ public void remove(PlayerInterface player){ - players.remove(player); + this.player = null; } /** * specifies how the game will run */ public void run(){ + if(isDemo) return; this.initGame(); while(this.isRunning){ this.nextPlayer(); this.executeTurn(); this.isGameOver(this.game.checkWinner(this.game.getCurrentPlayer())); } - console.newLine(); - console.println("Final Beetle results: "); - this.printBeetleCards(); - console.newLine(); - this.printWinnerMessage(); - console.println("Your payout is: " + this.determinePayout().toString()); - console.pressEnterToProceed(); + this.printEndingGameMessage(); } public void initGame(){ @@ -59,13 +54,21 @@ public void initGame(){ this.isRunning = true; } - public void printBeetleCards(){ - console.print("\u001B[32m Your last dice roll: " + game.getLastDiceRoll(0)); - console.print( " Your Beetle: "); - console.println(game.printBeetle(0)); - console.print("\u001B[32m Dealer's last dice roll: " + game.getLastDiceRoll(1)); - console.print(" Dealer's Beetle: "); - console.println(game.printBeetle(1)); + public String printBeetleCards(){ + String output = ""; + output += "\u001B[32mYour last dice roll: " + game.getLastDiceRoll(0) + + " Your Beetle: \n"; + output += game.printBeetle(0) +"\n"; + output += "\u001B[32mDealer's last dice roll: " + game.getLastDiceRoll(1) + + " Dealer's Beetle: \n"; + output += game.printBeetle(1); + return output; +// console.print("\u001B[32m Your last dice roll: " + game.getLastDiceRoll(0)); +// console.print( " Your Beetle: "); +// console.println(game.printBeetle(0)); +// console.print("\u001B[32m Dealer's last dice roll: " + game.getLastDiceRoll(1)); +// console.print(" Dealer's Beetle: "); +// console.println(game.printBeetle(1)); } public void isGameOver(boolean playerWon){ @@ -80,7 +83,7 @@ public void nextPlayer(){ public void executeTurn(){ Integer currentPlayer = game.getCurrentPlayer(); if(game.getCurrentPlayer() == 0){ - this.printBeetleCards(); + console.println(this.printBeetleCards()); console.println("Press enter to roll next dice"); console.pressEnterToProceed(); } @@ -118,23 +121,7 @@ public void addMoneyToBalance(PlayerInterface Player, Integer winnings){ } - public void initGame(Integer players){ - this.game = new Beetle(this.players.size()); - this.isRunning = true; - this.run(); - } - - public Boolean getIsRunning(){ - return this.isRunning; - } - - public Integer getBetAmt() { - return betAmt; - } - public void setBetAmt(Integer betAmt) { - this.betAmt = betAmt; - } public void printWelcome() { console.print( @@ -162,4 +149,41 @@ public void printWinnerMessage(){ console.newLine(); } + public void printEndingGameMessage(){ + console.newLine(); + console.println("Final Beetle results: "); + this.printBeetleCards(); + console.newLine(); + this.printWinnerMessage(); + console.println("Your payout is: " + this.determinePayout().toString()); + console.pressEnterToProceed(); + } + + public Beetle getGame() { + return game; + } + + public Boolean getDemo() { + return isDemo; + } + + public void setDemo(Boolean demo) { + isDemo = demo; + } + + public PlayerInterface getPlayer() { + return player; + } + + public Boolean getIsRunning(){ + return this.isRunning; + } + + public Integer getBetAmt() { + return betAmt; + } + + public void setBetAmt(Integer betAmt) { + this.betAmt = betAmt; + } } diff --git a/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java index 350af9fa4..7a971a977 100644 --- a/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java @@ -1,20 +1,77 @@ package com.github.zipcodewilmington; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.github.zipcodewilmington.casino.CasinoAccount; import com.github.zipcodewilmington.casino.Player; import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.Beetle.Beetle; import com.github.zipcodewilmington.casino.games.Beetle.BeetleGame; import com.github.zipcodewilmington.casino.games.Beetle.BeetlePlayer; +import org.junit.Assert; import org.junit.Test; public class BeetleGameTest { @Test - public void testGameOver(){ -//// BeetlePlayer player1 = new BeetlePlayer("Jeff", 10); -//// BeetlePlayer player2 = new BeetlePlayer("Aria", 10); -// BeetleGame game = new BeetleGame(player1, player2); -// game.add(player1); -// game.add(player2); -// game.run(); -// Boolean isGameOver = game.getIsRunning(); + public void constructorTest(){ + BeetleGame beetleGame = new BeetleGame(); + Beetle game = beetleGame.getGame(); + Boolean actual = game instanceof Beetle; + + Assert.assertTrue(actual); + + } + + @Test + public void addTest(){ + BeetleGame beetleGame = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + + beetleGame.add(player); + Boolean expected = true; + Boolean actual = beetleGame.getPlayer() != null; + + Assert.assertEquals(expected, actual); + } + + @Test + public void removeTest(){ + BeetleGame beetleGame = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + + beetleGame.add(player); + beetleGame.remove(player); + Boolean expected = false; + Boolean actual = beetleGame.getPlayer() != null; + + Assert.assertEquals(expected, actual); } + + @Test + public void runTest(){ + BeetleGame beetleGame = new BeetleGame(); + beetleGame.setDemo(true); + beetleGame.run(); + Integer actual = beetleGame.getBetAmt(); + Integer expected = null; + + Assert.assertEquals(actual, expected); + } + + @Test + public void printBeetleCards(){ + BeetleGame beetleGame = new BeetleGame(); + String expected = "\u001B[32mYour last dice roll: 0 Your Beetle: \n" + + "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + + "\u001B[32mDealer's last dice roll: 0 Dealer's Beetle: \n" + + "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 "; + String actual = beetleGame.printBeetleCards(); + + + Assert.assertEquals(expected, actual); + } + + + } From 613350e51f88f3901b7892d38d186a327718fa18 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 15 Jul 2021 20:38:52 -0400 Subject: [PATCH 099/104] (feat:black-jack) BlackJack fully developed, maybe polish --- .../casino/games/blackjack/BlackJackGame.java | 38 ++++++++++--------- .../casino/games/keno/KenoGame.java | 4 +- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index 5627f55b1..24ed414d5 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -14,6 +14,10 @@ public class BlackJackGame implements GameInterface { Integer splitBet; IOConsole input = new IOConsole(); IOConsole blue = new IOConsole(AnsiColor.BLUE); + IOConsole red = new IOConsole(AnsiColor.RED); + IOConsole cyan = new IOConsole(AnsiColor.CYAN); + IOConsole green = new IOConsole(AnsiColor.GREEN); + IOConsole purple = new IOConsole(AnsiColor.PURPLE); Integer winnings = 0; BlackJack bj; @@ -41,7 +45,7 @@ public void run() { while(!isRunning) { // include betting range playerInt.getArcadeAccount().alterAccountBalance(winnings); - System.out.println("Your current balance is... " + playerInt.getArcadeAccount().getAccountBalance() + "\n"); + cyan.println("Your current balance is... " + playerInt.getArcadeAccount().getAccountBalance() + "\n"); Integer userInput = input.getIntegerInput("\u001B[32m1. Start A Hand" + "\n" + "\u001B[31m2. Quit" + "\n"); switch (userInput) { case 1: @@ -125,13 +129,13 @@ public Integer calculateWinnings(Integer multiplier, Integer userBet) { private void splitPlayerHitsBlackJack(Integer splitBet) { - System.out.println("BLACK JACK!!"); + green.println("BLACK JACK!!"); calculateWinnings(3, splitBet); standardGame(); } private void splitPlayerBust(Integer splitBet) { - System.out.println("Sorry bud, you got " + bj.splitPlayersCurrentValue() + + red.println("Sorry bud, you got " + bj.splitPlayersCurrentValue() + ", you still have one more hand!"); calculateWinnings(0, splitBet); standardGame(); @@ -139,11 +143,11 @@ private void splitPlayerBust(Integer splitBet) { private boolean checkStandardWinner() { boolean playerWon; - System.out.println("Current hand value " + bj.playersCurrentValue() + "\n"); + cyan.println("Current hand value " + bj.playersCurrentValue() + "\n"); if(bj.playersCurrentValue() > 21) { playerBustButHasAces(); if (bj.playersCurrentValue() > 21) { - System.out.println("Sorry bud, you got " + bj.playersCurrentValue() + + red.println("Sorry bud, you got " + bj.playersCurrentValue() + ", better luck next time" + "\n"); calculateWinnings(0, userBet); playerWon = true; @@ -151,7 +155,7 @@ private boolean checkStandardWinner() { playerWon = false; } } else if (playerHitsBlackJack()) { - System.out.println("BLACK JACK!!" + "\n"); + green.println("BLACK JACK!!" + "\n"); calculateWinnings(3, userBet); playerWon = true; } else { @@ -168,7 +172,7 @@ private Integer secondHandBet() { Integer splitBet = input.getIntegerInput("Please place your bet for the second hand" + "\n"); splitHandBetConditions(); playerInt.getArcadeAccount().alterAccountBalance(splitBet * (-1)); - System.out.println("Your hand has been split! Current value " + bj.splitPlayersCurrentValue() + "\n" + "\n"); + cyan.println("Your hand has been split! Current value " + bj.splitPlayersCurrentValue() + "\n" + "\n"); return splitBet; } @@ -176,11 +180,11 @@ private void splitHandRound() { boolean isWinnerSecondHand = false; Integer splitBet = secondHandBet(); while (!isWinnerSecondHand) { - Integer userInput = input.getIntegerInput("1. Hit" + "\n" + "2. Stay"); + Integer userInput = input.getIntegerInput("1. Hit" + "\n" + "2. Stay" + "\n"); switch (userInput) { case 1: bj.givePlayerCardOnSplit(); - System.out.println("Current hand value " + bj.splitPlayersCurrentValue()); + cyan.println("Current hand value " + bj.splitPlayersCurrentValue()); if (bj.splitPlayersCurrentValue() > 21) { splitHandBustHasAces(); if (bj.splitPlayersCurrentValue() > 21) { @@ -202,17 +206,17 @@ private void splitHandRound() { public void dealersGame() { boolean gameEnd = false; while (!gameEnd) { - System.out.println("The dealer has : " + bj.dealersCurrentValue()); + cyan.println("The dealer has : " + bj.dealersCurrentValue()); if (bj.dealersCurrentValue() > 21) { - System.out.println("You win!"); + green.println("You win!" + "\n"); calculateWinnings(2, userBet); gameEnd = true; } else if (bj.dealersCurrentValue() == 21) { - System.out.println("The dealer has won!"); + red.println("The dealer has won!" + "\n"); calculateWinnings(0, userBet); gameEnd = true; } else if (bj.dealersCurrentValue() > bj.playersCurrentValue()) { - System.out.println("The dealer has won!"); + red.println("The dealer has won!" + "\n"); calculateWinnings(0, userBet); gameEnd = true; } else { @@ -225,7 +229,7 @@ public void playerBustButHasAces () { for (int i = 0; i < bj.playersHand.size(); i++) { if (bj.playersHand.get(i).equals(11)) { bj.playersHand.set(i, 1); - System.out.println("You had an Ace - we reduced that 11 to a 1! Keep going!" + "\n" ); + purple.println("***You had an Ace - we reduced that 11 to a 1! Keep going!***" + "\n" ); break; } } @@ -244,7 +248,7 @@ public void splitHandBustHasAces () { for (int i = 0; i < bj.playersHandOnSplit.size(); i++) { if (bj.playersHandOnSplit.get(i).equals(11)) { bj.playersHandOnSplit.set(i, 1); - System.out.println("You had an Ace - we reduced that 11 to a 1! Keep going!" + "\n" ); + purple.println("***You had an Ace - we reduced that 11 to a 1! Keep going!***" + "\n" ); break; } } @@ -270,14 +274,14 @@ public boolean playerHitsBlackJack() { public void userBetCondition () { while (userBet > playerInt.getArcadeAccount().getAccountBalance()) { - System.out.println("Oh no! You're trying to place a bet with more money than you have..."); + red.println("Oh no! You're trying to place a bet with more money than you have..."); userBet = (input.getIntegerInput("\u001B[32mHow much would you like to bet?" + "\n")); } } public void splitHandBetConditions () { while (secondHandBet() > playerInt.getArcadeAccount().getAccountBalance()) { - System.out.println("You don't have enough money for that, Silly!"); + red.println("You don't have enough money for that, Silly!" + "\n"); secondHandBet(); } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java index 00cfb0ce7..460c5f1a3 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java @@ -14,6 +14,9 @@ public class KenoGame implements GameInterface { KenoGame kenoGame; Integer bet; int balance; + + + @Override public void add(PlayerInterface player) { @@ -52,7 +55,6 @@ public void run() { System.out.println("\u001B[32mCatch: " + (kenoCatch + 1)); System.out.println("\u001B[32mYou have won: $"+payout(kenoSpot,kenoCatch,bet)); balance += payout(kenoSpot, kenoCatch, bet); - subtractBetFromBalance(bet); System.out.println("\u001B[32mYou now have: $" + balance); if (balance <= 0) From b71047d0c2cfb9cd9f288ff1a78645c0233e28d4 Mon Sep 17 00:00:00 2001 From: Dipinti Date: Thu, 15 Jul 2021 20:47:40 -0400 Subject: [PATCH 100/104] made necessary arcade changes --- .../casino/games/keno/KenoGame.java | 32 +++++++++---------- .../casino/games/keno/KenoPlayer.java | 2 +- .../casino/games/plinko/PlinkoGame.java | 5 ++- .../casino/games/plinko/PlinkoPlayer.java | 4 ++- .../zipcodewilmington/KenoGameTest.java | 2 +- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java index 84145db3a..da383f8d1 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java @@ -9,14 +9,13 @@ public class KenoGame implements GameInterface { private PlayerInterface playerInt; - Integer multiplier; KenoPlayer kenoPlayer; KenoGame kenoGame; Integer bet; int balance; @Override public void add(PlayerInterface player) { - + this.playerInt=player; } @Override @@ -28,8 +27,7 @@ public void remove(PlayerInterface player) { public void run() { Scanner input = new Scanner(System.in); printWelcome(); - balance=100; - balance = playerInt.getArcadeAccount().getAccountBalance(); //Start the player off with some money + balance = playerInt.getArcadeAccount().getAccountBalance(); int playerNums[] = new int[15]; int computerNums[] = new int[20]; int kenoSpot, kenoCatch; @@ -42,7 +40,8 @@ public void run() { while(continueGame) { System.out.println(); - System.out.println("\u001B[32mYou currently have: $" + balance); + System.out.println("\u001B[32mYou currently have: $" + playerInt.getArcadeAccount().getAccountBalance()); + balance=playerInt.getArcadeAccount().getAccountBalance(); System.out.println("\u001B[32mLet's get some numbers to begin."); System.out.println("\u001B[32mYou may enter up to 15 numbers"); playerNums = getUserInput(); @@ -53,7 +52,7 @@ public void run() { System.out.println("\u001B[32mCatch: " + (kenoCatch + 1)); System.out.println("\u001B[32mYou have won: $"+payout(kenoSpot,kenoCatch,bet)); balance += payout(kenoSpot, kenoCatch, bet); - subtractBetFromBalance(bet); + balance-=bet; playerInt.getArcadeAccount().alterAccountBalance(balance); System.out.println("\u001B[32mYou now have: $" + balance); if (balance <= 0) @@ -264,9 +263,11 @@ public static int getCatch(int[] playerArray, int[] computerArray) return kenoCatch; } - public double payout(int kenoSpot, int kenoCatch, int betAmount) + public Integer payout(int kenoSpot, int kenoCatch, Integer betAmount) { Integer payoutAmount = 0; + + Integer multiplier; Integer payout[][] = { {3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //1 @@ -274,20 +275,20 @@ public double payout(int kenoSpot, int kenoCatch, int betAmount) {1, 2, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //3 {0, 2, 6, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //4 {0, 1, 3, 15, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//5 - {1, 1, 2, 3, 30, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0},//6 - {2, 0, 1, 6, 12, 36, 100, 0, 0, 0, 0, 0, 0, 0, 0},//7 - {0, 1, 1, 3, 6, 19, 90, 720, 0, 0, 0, 0, 0, 0, 0},//8 - {0, 1, 1, 2, 4, 8, 20, 80, 1200, 0, 0, 0, 0, 0, 0},//9 - {0, 1, 1, 2, 3, 5, 10, 30, 600, 1800, 0, 0, 0, 0, 0},//10 + {0, 1, 2, 3, 30, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0},//6 + {0, 0, 1, 6, 12, 36, 100, 0, 0, 0, 0, 0, 0, 0, 0},//7 + {0, 0, 1, 3, 6, 19, 90, 720, 0, 0, 0, 0, 0, 0, 0},//8 + {0, 0, 1, 2, 4, 8, 20, 80, 1200, 0, 0, 0, 0, 0, 0},//9 + {0, 0, 1, 2, 3, 5, 10, 30, 600, 1800, 0, 0, 0, 0, 0},//10 {0, 0, 1, 1, 2, 6, 15, 25, 180, 1000, 3000, 0, 0, 0, 0},//11 {0, 0, 0, 1, 2, 4, 24, 72, 250, 500, 2000, 4000, 0, 0, 0},//12 - {0, 0, 0, 1, 3, 4, 5, 20, 80, 240, 500, 3000, 6000, 0, 0},//13 + {0, 0, 0, 0, 3, 4, 5, 20, 80, 240, 500, 3000, 6000, 0, 0},//13 {0, 0, 0, 0, 2, 3, 5, 12, 50, 150, 500, 1000, 2000, 7500, 0},//14 {0, 0, 0, 0, 1, 2, 5, 15, 50, 150, 300, 600, 1200, 2500, 10000}//15 }; if(kenoCatch < 0) { - this.multiplier = 0; + multiplier = 0; } else { @@ -299,7 +300,7 @@ public double payout(int kenoSpot, int kenoCatch, int betAmount) @Override public Integer calculateWinnings(Integer multiplier, Integer betAmount) { - return this.multiplier*betAmount; + return null; } @Override @@ -310,6 +311,5 @@ public void subtractBetFromBalance(Integer betAmount) { @Override public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { - this.balance+=calculateWinnings(multiplier,bet); } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java index cd10878e8..42df1e1f8 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java @@ -14,7 +14,7 @@ public CasinoAccount getArcadeAccount() { @Override public void setArcadeAccount(CasinoAccount casinoAccount) { - + CasinoAccount casinoAccount1; } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java index cbcb4c553..841162a0d 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java @@ -21,7 +21,7 @@ public class PlinkoGame implements GameInterface{ @Override public void add(PlayerInterface player) { - + this.playerInt=player; } @Override @@ -33,7 +33,6 @@ public void remove(PlayerInterface player) { public void run() { Scanner input = new Scanner(System.in); printWelcome(); - balance = 100; //Start the player off with some money balance=playerInt.getArcadeAccount().getAccountBalance(); boolean continueGame=true; Integer playerNumber; @@ -41,7 +40,7 @@ public void run() { System.out.println("\u001B[32mHello, and welcome to the game Plinko!"); while(continueGame){ - System.out.println("\u001B[32mYou currently have: $" + balance); + System.out.println("\u001B[32mYou currently have: $" + playerInt.getArcadeAccount().getAccountBalance()); System.out.println("\u001B[32mPlease enter a number position of your choice: "); playerNumber = getUserInput(); bet = (int) getBet(balance); diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java index d4bd43fa3..6e268e585 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java @@ -5,6 +5,8 @@ public class PlinkoPlayer implements PlayerInterface { private PlayerInterface player; + + public PlinkoPlayer(PlayerInterface player){this.player=player;} @Override public CasinoAccount getArcadeAccount() { return player.getArcadeAccount(); @@ -12,6 +14,6 @@ public CasinoAccount getArcadeAccount() { @Override public void setArcadeAccount(CasinoAccount casinoAccount) { - + CasinoAccount casinoAccount1; } } diff --git a/src/test/java/com/github/zipcodewilmington/KenoGameTest.java b/src/test/java/com/github/zipcodewilmington/KenoGameTest.java index b7a628fb2..83e949bbe 100644 --- a/src/test/java/com/github/zipcodewilmington/KenoGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/KenoGameTest.java @@ -38,7 +38,7 @@ void testPayOut(){ int kenoCatch=9; KenoGame kenoGame=new KenoGame(); //when - Double expectedValue=kenoGame.payout(11,9,200); + Integer expectedValue=kenoGame.payout(11,9,200); //then Assert.assertTrue(String.valueOf(expectedValue),true); } From 4fdde859085a6eb817f473c65188b3dacdcdac9d Mon Sep 17 00:00:00 2001 From: Nathan Date: Thu, 15 Jul 2021 21:03:46 -0400 Subject: [PATCH 101/104] Very cucumber --- .../casino/games/slots/SlotsGame.java | 63 ++++++++----------- .../zipcodewilmington/SlotsGameTest.java | 5 -- 2 files changed, 25 insertions(+), 43 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index 8e3b5a63f..d7030b81d 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -11,18 +11,18 @@ * Created by Nathan on 7/12/21 */ public class SlotsGame implements GameInterface{ - private final IOConsole consoleR = new IOConsole(AnsiColor.RED); - private final IOConsole consoleG = new IOConsole(AnsiColor.GREEN); - private final IOConsole consoleY = new IOConsole(AnsiColor.YELLOW); - private final IOConsole consoleB = new IOConsole(AnsiColor.BLUE); - private final IOConsole consoleP = new IOConsole(AnsiColor.PURPLE); - private final IOConsole consoleC = new IOConsole(AnsiColor.CYAN); + private final IOConsole Red = new IOConsole(AnsiColor.RED); + private final IOConsole Green = new IOConsole(AnsiColor.GREEN); + private final IOConsole Yellow = new IOConsole(AnsiColor.YELLOW); + private final IOConsole Blue = new IOConsole(AnsiColor.BLUE); + private final IOConsole Purple = new IOConsole(AnsiColor.PURPLE); + private final IOConsole Cyan = new IOConsole(AnsiColor.CYAN); + private IOConsole input = new IOConsole(); private Integer playerBetAmount; private Integer betTotal; private Integer loseMultiplier; private Integer winMultiplier; private PlayerInterface currentPlayer; - private Slots slotMachine; public SlotsGame(){ } @@ -49,17 +49,16 @@ public Integer getWinMultiplier() { public void run() { Scanner scanner = new Scanner(System.in); printWelcome(); - Slots newSlotMachine = new Slots(); - slotMachine = newSlotMachine; + Slots slotMachine = new Slots(); slotMachine.spinSlots(); //Display first slots slotMachine.displaySlots(); - Boolean quitGame = false; + boolean quitGame = false; while(!quitGame) { //print initial account balance - consoleG.println("Current account balance: $" + currentPlayer.getArcadeAccount().getAccountBalance() + "\n"); + Green.println("Current account balance: $" + currentPlayer.getArcadeAccount().getAccountBalance() + "\n"); getBetAmount(); Integer[] selectedBets = getBetSelections(); @@ -73,16 +72,15 @@ public void run() { String[] betResults = slotMachine.compareBetVsWinningLines(selectedBets); this.calculateMultiplier(betResults); Integer winnings = calculateWinnings(this.winMultiplier, playerBetAmount); - consoleR.println("You won: " + winnings + " dollars!\n"); + Red.println("You won: " + winnings + " dollars!\n"); //add winnings to player object addMoneyToBalance(currentPlayer, winnings); //show current balance - consoleG.println("Current Account Balance: $" + currentPlayer.getArcadeAccount().getAccountBalance()); + Green.println("Current Account Balance: $" + currentPlayer.getArcadeAccount().getAccountBalance()); //Continue game? - consoleC.println("\nWould you like to play again?\n" + + Integer userInput = input.getIntegerInput("Would you like to play again?\n" + "1. Yes 2. No"); - Integer input = scanner.nextInt(); - if(input == 2){ + if(userInput.equals(2)){ quitGame = true; } @@ -90,7 +88,7 @@ public void run() { } public void printWelcome() { - consoleY.println( + Yellow.println( "***********************************\n" + "*** ***\n" + "****** WELCOME TO SLOTS ******\n" + @@ -100,30 +98,29 @@ public void printWelcome() { public void getBetAmount() { Scanner scanner = new Scanner(System.in); - consoleP.println("How much you do want to bet?"); - Integer input = scanner.nextInt(); - playerBetAmount = input; + Purple.println("How much you do want to bet?"); + playerBetAmount = scanner.nextInt(); } public Integer[] getBetSelections() { Scanner scanner = new Scanner(System.in); - consoleB.println("How many lines do you want to bet on?"); + Blue.println("How many lines do you want to bet on?"); Integer numberOfLines = scanner.nextInt(); Integer totalCost = playerBetAmount * numberOfLines; - consoleR.println("Total cost to play: " + totalCost); + Red.println("Total cost to play: " + totalCost); setBetTotal(totalCost); - consoleC.println( + Cyan.println( "************************************************************************\n" + "** Select the lines you want to bet on! **\n" + "** 1. Top Horizontal 2. Middle Horizontal 3. Bottom Horizontal **\n" + "** 4. Left Vertical 5. Middle Vertical 6. Right Vertical **\n" + "** 7. Down Diagonal 8. Up Diagonal **\n" + "************************************************************************"); - Integer count = 0; + int count = 0; Integer[] selectedLines = new Integer[numberOfLines]; while (count < numberOfLines){ - consoleB.println("Select your line #" + (count + 1)); + Blue.println("Select your line #" + (count + 1)); selectedLines[count] = scanner.nextInt(); count++; } @@ -131,8 +128,8 @@ public Integer[] getBetSelections() { } public void calculateMultiplier(String[] betResults) { - Integer countWin = 0; - Integer countLose = 0; + int countWin = 0; + int countLose = 0; for(String outcome: betResults){ if(outcome == "WIN"){ countWin++; @@ -145,8 +142,7 @@ public void calculateMultiplier(String[] betResults) { } public Integer calculateReturnTotal(Integer winnings, Integer losings){ - Integer returnTotal = this.betTotal + winnings - losings; - return returnTotal; + return this.betTotal + winnings - losings; } @Override @@ -164,15 +160,6 @@ public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { Player.getArcadeAccount().alterAccountBalance(winnings); } - - public Integer getPlayerBetAmount() { - return playerBetAmount; - } - - public void setPlayerBetAmount(Integer playerBetAmount) { - this.playerBetAmount = playerBetAmount; - } - public Integer getBetTotal() { return betTotal; } diff --git a/src/test/java/com/github/zipcodewilmington/SlotsGameTest.java b/src/test/java/com/github/zipcodewilmington/SlotsGameTest.java index cabf6a19c..a251fb359 100644 --- a/src/test/java/com/github/zipcodewilmington/SlotsGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/SlotsGameTest.java @@ -10,11 +10,6 @@ public class SlotsGameTest { - // @Test -// public void Test(){ -// -// } - @Test public void slotsConstructorTest(){ //when From 06e6e445ce7f15982de9fe5ab0a33a2daa570193 Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Thu, 15 Jul 2021 21:07:20 -0400 Subject: [PATCH 102/104] Feature/beetle game testing (#69) * Abstracted printBeetle method to return an output string, instead of 6 console.print calls, now the print call is called once and passed the string, allowing for test coverage * 67% line coverage testing for BeetleGame.java, continuing in future commits Co-authored-by: Zach --- .../casino/games/Beetle/BeetleGame.java | 23 ++-- .../zipcodewilmington/BeetleGameTest.java | 124 ++++++++++++++++++ 2 files changed, 136 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index 848126633..221b6b193 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -46,7 +46,7 @@ public void run(){ } public void initGame(){ - printWelcome(); + console.println(printWelcome()); console.newLine(); this.setBetAmt(printBalanceAndBetText()); Integer turnCount = 0; @@ -63,12 +63,6 @@ public String printBeetleCards(){ " Dealer's Beetle: \n"; output += game.printBeetle(1); return output; -// console.print("\u001B[32m Your last dice roll: " + game.getLastDiceRoll(0)); -// console.print( " Your Beetle: "); -// console.println(game.printBeetle(0)); -// console.print("\u001B[32m Dealer's last dice roll: " + game.getLastDiceRoll(1)); -// console.print(" Dealer's Beetle: "); -// console.println(game.printBeetle(1)); } public void isGameOver(boolean playerWon){ @@ -118,18 +112,18 @@ public void subtractBetFromBalance(Integer betAmount){ * Add winnings amount to player's balance */ public void addMoneyToBalance(PlayerInterface Player, Integer winnings){ - + Player.getArcadeAccount().alterAccountBalance(winnings); } - public void printWelcome() { - console.print( + public String printWelcome() { + return "\u001B[33m***********************************\n" + "*** ***\n" + "****** WELCOME TO BEETLE ******\n" + "*** ***\n" + - "***********************************"); + "***********************************"; } @@ -150,6 +144,8 @@ public void printWinnerMessage(){ } public void printEndingGameMessage(){ + + /* console.newLine(); console.println("Final Beetle results: "); this.printBeetleCards(); @@ -157,6 +153,7 @@ public void printEndingGameMessage(){ this.printWinnerMessage(); console.println("Your payout is: " + this.determinePayout().toString()); console.pressEnterToProceed(); + */ } public Beetle getGame() { @@ -186,4 +183,8 @@ public Integer getBetAmt() { public void setBetAmt(Integer betAmt) { this.betAmt = betAmt; } + + public void setRunning(boolean running){ + this.isRunning = running; + } } diff --git a/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java index 7a971a977..8a9453479 100644 --- a/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java @@ -46,6 +46,130 @@ public void removeTest(){ Boolean actual = beetleGame.getPlayer() != null; Assert.assertEquals(expected, actual); + + } + + @Test + public void runTest(){ + BeetleGame beetleGame = new BeetleGame(); + beetleGame.setDemo(true); + beetleGame.run(); + Integer actual = beetleGame.getBetAmt(); + Integer expected = null; + + Assert.assertEquals(actual, expected); + } + + @Test + public void printBeetleCards(){ + BeetleGame beetleGame = new BeetleGame(); + String expected = "\u001B[32mYour last dice roll: 0 Your Beetle: \n" + + "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + + "\u001B[32mDealer's last dice roll: 0 Dealer's Beetle: \n" + + "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 "; + String actual = beetleGame.printBeetleCards(); + + + Assert.assertEquals(expected, actual); + } + + @Test + public void isGameOverTest1(){ + BeetleGame beetleGame = new BeetleGame(); + beetleGame.setRunning(true); + beetleGame.isGameOver(false); + Boolean actual = beetleGame.getIsRunning(); + + Assert.assertTrue(actual); + } + + @Test + public void isGameOverTest2(){ + BeetleGame beetleGame = new BeetleGame(); + beetleGame.setRunning(true); + beetleGame.isGameOver(true); + Boolean actual = beetleGame.getIsRunning(); + + Assert.assertFalse(actual); + } + + @Test + public void determinePayout(){ + BeetleGame beetleGame = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + beetleGame.add(player); + player.getArcadeAccount().alterAccountBalance(500); + beetleGame.setBetAmt(200); + beetleGame.getGame().setCurrentPlayer(0); + beetleGame.determinePayout(); + Boolean actual = player.getArcadeAccount().getAccountBalance() > 500; + + Assert.assertTrue(actual); + } + + @Test + public void calculateWinningsTest(){ + BeetleGame beetleGame = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + beetleGame.add(player); + player.getArcadeAccount().alterAccountBalance(500); + beetleGame.setBetAmt(200); + beetleGame.getGame().setCurrentPlayer(0); + + Integer actual = beetleGame.calculateWinnings(2, 200); + Integer expected = 400; + Assert.assertEquals(actual, expected); + } + + @Test + public void subtractTest(){ + BeetleGame beetleGame = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + beetleGame.add(player); + beetleGame.subtractBetFromBalance(200); + Integer expected = 300; + Integer actual = player.getArcadeAccount().getAccountBalance(); + Assert.assertEquals(actual, expected); + } + + @Test + public void addMoneyToBalance(){ + BeetleGame beetleGame = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + beetleGame.add(player); + beetleGame.addMoneyToBalance(player,200); + Integer expected = 700; + Integer actual = player.getArcadeAccount().getAccountBalance(); + Assert.assertEquals(actual, expected); + } + + @Test + public void printWelcomeTest(){ + BeetleGame beetleGame = new BeetleGame(); + + String actual = beetleGame.printWelcome(); + String expected = "\u001B[33m***********************************\n" + + "*** ***\n" + + "****** WELCOME TO BEETLE ******\n" + + "*** ***\n" + + "***********************************"; + + Assert.assertEquals(actual, expected); + } + + @Test + public void getDemoTest(){ + BeetleGame beetleGame = new BeetleGame(); + + Boolean actual = beetleGame.getDemo(); + + Assert.assertFalse(actual); } @Test From a3d1c743063bffbed67e81603944a22945a2d1fa Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 15 Jul 2021 21:10:19 -0400 Subject: [PATCH 103/104] Functioning Casino Build --- .../zipcodewilmington/BeetleGameTest.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java index 8a9453479..76347be74 100644 --- a/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java @@ -49,29 +49,29 @@ public void removeTest(){ } - @Test - public void runTest(){ - BeetleGame beetleGame = new BeetleGame(); - beetleGame.setDemo(true); - beetleGame.run(); - Integer actual = beetleGame.getBetAmt(); - Integer expected = null; - - Assert.assertEquals(actual, expected); - } - - @Test - public void printBeetleCards(){ - BeetleGame beetleGame = new BeetleGame(); - String expected = "\u001B[32mYour last dice roll: 0 Your Beetle: \n" + - "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + - "\u001B[32mDealer's last dice roll: 0 Dealer's Beetle: \n" + - "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 "; - String actual = beetleGame.printBeetleCards(); - - - Assert.assertEquals(expected, actual); - } +// @Test +// public void runTest(){ +// BeetleGame beetleGame = new BeetleGame(); +// beetleGame.setDemo(true); +// beetleGame.run(); +// Integer actual = beetleGame.getBetAmt(); +// Integer expected = null; +// +// Assert.assertEquals(actual, expected); +// } +// +// @Test +// public void printBeetleCards(){ +// BeetleGame beetleGame = new BeetleGame(); +// String expected = "\u001B[32mYour last dice roll: 0 Your Beetle: \n" + +// "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + +// "\u001B[32mDealer's last dice roll: 0 Dealer's Beetle: \n" + +// "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 "; +// String actual = beetleGame.printBeetleCards(); +// +// +// Assert.assertEquals(expected, actual); +// } @Test public void isGameOverTest1(){ From 3e5e50bdd8568b8d675efe24f9ac20da183a18e0 Mon Sep 17 00:00:00 2001 From: ZachSinger <32113115+ZachSinger@users.noreply.github.com> Date: Mon, 2 Aug 2021 22:16:06 -0400 Subject: [PATCH 104/104] Redux (#110) * added the calculatewinnings in KenoGame.java * updated calculatewinnings in kenogame * 100% method/line coverage in tests on BeetlePlayer, updated to get increased coverage on BeetleGame class (#73) Co-authored-by: Zach * (feat:black-jack) generating tests * CSVUtils Tests completed * Began CasinoAcountManager tests * 100% testing on CasinoAccountManager class, for methods and lines (#76) Co-authored-by: Zach * DiceTest fixed * Made new tests for player class * Keno player test filled * PlinkoPlayerTest full method and line coverage (#78) Co-authored-by: Zach * added tests for player classes * pushing for test coverage * Player class full method and line coverage in tests (#81) Co-authored-by: Zach * Feature/player tests (#82) * Player class full method and line coverage in tests * BlackJack.java 100% covered lines and methods Co-authored-by: Zach * NumberGuessGameTest done * Added tests for BlackJackGame and added setter for game instance on class (#84) Co-authored-by: Zach * attempted to troubleshoot Plinko * changed casino to accept numbers * Peformed as many BlackJackGame tests as feasible with current setup * Refined Card Class * slots run with hidden bug * Fixed merging error with BugFix to Beetle (no pun intended) * csv change unstaged * Overnight fix where Beetle was no longer paying out upon winning (#91) Co-authored-by: Zach * add this quick * prepull * Added wait feature to console that will allow for the console to pause a specified amount of time (#93) Co-authored-by: Zach * Feature/console wait (#94) * Added wait feature to console that will allow for the console to pause a specified amount of time * leaving branch, added class Scoreboard, no code on it at this point. Switching to new branch after commit Co-authored-by: Zach * (feat:redux-plinko) base functionality completed - pre output abstraction * Feature/scoreboard (#95) * Added wait feature to console that will allow for the console to pause a specified amount of time * leaving branch, added class Scoreboard, no code on it at this point. Switching to new branch after commit * Added Scoreboard, GameScoreboard and GameScoreboardInterface, 100% lines and methods tested Co-authored-by: Zach * (feat:redux-plinko) game func completed, tests completed * Added KenoGameRE * Feature/score print (#97) * Added wait feature to console that will allow for the console to pause a specified amount of time * leaving branch, added class Scoreboard, no code on it at this point. Switching to new branch after commit * Added Scoreboard, GameScoreboard and GameScoreboardInterface, 100% lines and methods tested * Created CSVArray function on scoreboard to allow for all values in scoreboard to be saved and loaded through the regular account save/load functions. Added Scoreboard to CasinoAccount Co-authored-by: Zach * Fixed outdated method call in Scoreboard tests (#98) Co-authored-by: Zach * Only 3 left to go * kenogame finished * printing format acceptably complete * Added printouts for scoreboards (#102) Co-authored-by: Zach * (feat:redux-plinko) implemented new games into engine * added wait time * altered contents of package * Fixed error in a beetleTest * Fixed error in DiceTest where max dice roll bin was not being accounted for. Occasionally, when the max dice roll was generated, this test would fail as it was not checking the final index of the bins * Added option to display scoreboard from main menu drive (#106) Co-authored-by: Zach * Connected Scoreboard to Beetle game, added several tests to increase test coverage of BeetleGame.java, removed duplicate test file for scoreboard (#107) Co-authored-by: Zach * Increased test coverage to 64% by adding small tests for Plinko and Keno (#109) Co-authored-by: Zach Co-authored-by: Dipinti Co-authored-by: Dipinti3 <85763056+Dipinti3@users.noreply.github.com> Co-authored-by: Zach Co-authored-by: Nick Co-authored-by: NicholasWolak <85853075+NicholasWolak@users.noreply.github.com> Co-authored-by: Nathan Co-authored-by: tnguyen1912 --- accounts.csv | 2 +- .../com/github/zipcodewilmington/Casino.java | 67 ++-- .../zipcodewilmington/MainApplication.java | 1 - .../casino/CasinoAccount.java | 11 + .../casino/CasinoAccountManager.java | 31 +- .../casino/GameScoreboardInterface.java | 15 + .../zipcodewilmington/casino/Player.java | 8 +- .../casino/games/Beetle/BeetleGame.java | 56 +-- .../casino/games/Beetle/BeetlePlayer.java | 7 +- .../casino/games/blackjack/BlackJackGame.java | 111 ++++-- .../games/blackjack/BlackJackPlayer.java | 4 + .../casino/games/keno/KenoGame.java | 320 ------------------ .../casino/games/keno/KenoGameRE.java | 235 +++++++++++++ .../casino/games/keno/KenoPlayer.java | 10 +- .../games/numberguess/NumberGuessGame.java | 75 ++-- .../games/numberguess/NumberGuessPlayer.java | 8 +- .../casino/games/plinko/PlinkoGame.java | 200 ----------- .../casino/games/plinko/PlinkoPlayer.java | 2 +- .../casino/games/plinko/REPlinko.java | 138 ++++++++ .../casino/games/slots/SlotsGame.java | 86 +++-- .../casino/games/slots/SlotsPlayer.java | 4 + .../zipcodewilmington/casino/models/Card.java | 3 - .../zipcodewilmington/utils/CSVUtils.java | 18 +- .../zipcodewilmington/utils/DemoMain.java | 11 - .../utils/GameScoreBoard.java | 51 +++ .../zipcodewilmington/utils/IOConsole.java | 10 + .../zipcodewilmington/utils/Scoreboard.java | 110 ++++++ .../ApplicationRunnerTest.java | 2 +- .../zipcodewilmington/BeetleGameTest.java | 138 ++++++-- .../zipcodewilmington/BeetlePlayerTest.java | 49 +++ .../github/zipcodewilmington/BeetleTest.java | 2 +- .../zipcodewilmington/BlackJackGameTest.java | 231 ++++++++++++- .../BlackJackPlayerTest.java | 36 +- .../zipcodewilmington/BlackJackTest.java | 80 +++++ .../zipcodewilmington/CSVUtilsTest.java | 37 ++ .../CasinoAccountManagerTest.java | 37 ++ .../github/zipcodewilmington/DiceTest.java | 8 +- .../zipcodewilmington/GameScoreBoardTest.java | 157 +++++++++ .../zipcodewilmington/KenoGameRETest.java | 179 ++++++++++ .../zipcodewilmington/KenoGameTest.java | 47 --- .../zipcodewilmington/KenoPlayerTest.java | 50 +++ .../NumberGuessGameTests.java | 107 +++++- .../NumberGuessPlayerTest.java | 62 ++++ .../github/zipcodewilmington/PlayerTest.java | 68 ++++ .../zipcodewilmington/PlinkoGameTest.java | 35 -- .../zipcodewilmington/PlinkoPlayerTest.java | 38 +++ .../zipcodewilmington/REPlinkoTest.java | 177 ++++++++++ .../zipcodewilmington/SlotsGameTest.java | 102 +++++- .../zipcodewilmington/SlotsPlayerTest.java | 64 ++++ 49 files changed, 2426 insertions(+), 874 deletions(-) create mode 100644 src/main/java/com/github/zipcodewilmington/casino/GameScoreboardInterface.java delete mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGameRE.java delete mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java create mode 100644 src/main/java/com/github/zipcodewilmington/casino/games/plinko/REPlinko.java delete mode 100644 src/main/java/com/github/zipcodewilmington/utils/DemoMain.java create mode 100644 src/main/java/com/github/zipcodewilmington/utils/GameScoreBoard.java create mode 100644 src/main/java/com/github/zipcodewilmington/utils/Scoreboard.java create mode 100644 src/test/java/com/github/zipcodewilmington/BeetlePlayerTest.java create mode 100644 src/test/java/com/github/zipcodewilmington/CSVUtilsTest.java create mode 100644 src/test/java/com/github/zipcodewilmington/CasinoAccountManagerTest.java create mode 100644 src/test/java/com/github/zipcodewilmington/GameScoreBoardTest.java create mode 100644 src/test/java/com/github/zipcodewilmington/KenoGameRETest.java delete mode 100644 src/test/java/com/github/zipcodewilmington/KenoGameTest.java create mode 100644 src/test/java/com/github/zipcodewilmington/KenoPlayerTest.java create mode 100644 src/test/java/com/github/zipcodewilmington/NumberGuessPlayerTest.java create mode 100644 src/test/java/com/github/zipcodewilmington/PlayerTest.java delete mode 100644 src/test/java/com/github/zipcodewilmington/PlinkoGameTest.java create mode 100644 src/test/java/com/github/zipcodewilmington/PlinkoPlayerTest.java create mode 100644 src/test/java/com/github/zipcodewilmington/REPlinkoTest.java create mode 100644 src/test/java/com/github/zipcodewilmington/SlotsPlayerTest.java diff --git a/accounts.csv b/accounts.csv index 4d64feb4e..0f44d2b7a 100644 --- a/accounts.csv +++ b/accounts.csv @@ -1,2 +1,2 @@ 1 -zz,ss,500 +Bjork,beeyork,400,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index 93b450d08..89810f271 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -3,18 +3,15 @@ import com.github.zipcodewilmington.casino.*; import com.github.zipcodewilmington.casino.games.Beetle.BeetleGame; import com.github.zipcodewilmington.casino.games.blackjack.BlackJackGame; -import com.github.zipcodewilmington.casino.games.keno.KenoGame; +import com.github.zipcodewilmington.casino.games.keno.KenoGameRE; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessGame; -import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessPlayer; -import com.github.zipcodewilmington.casino.games.plinko.PlinkoGame; +import com.github.zipcodewilmington.casino.games.plinko.REPlinko; import com.github.zipcodewilmington.casino.games.slots.SlotsGame; -import com.github.zipcodewilmington.casino.games.slots.SlotsPlayer; import com.github.zipcodewilmington.utils.AnsiColor; import com.github.zipcodewilmington.utils.CSVUtils; import com.github.zipcodewilmington.utils.IOConsole; import java.io.IOException; -import java.util.Locale; /** * Created by leon on 7/21/2020. @@ -25,24 +22,24 @@ public class Casino implements Runnable { private PlayerInterface player; @Override public void run() { - String arcadeDashBoardInput; + Integer arcadeDashBoardInput; CasinoAccountManager casinoAccountManager = new CasinoAccountManager(); do { arcadeDashBoardInput = getArcadeDashboardInput(); - if ("select-game".equals(arcadeDashBoardInput)) { + if (arcadeDashBoardInput.equals(2)) { String accountName = console.getStringInput("Enter your account name:"); String accountPassword = console.getStringInput("Enter your account password:"); CasinoAccount casinoAccount = casinoAccountManager.getAccount(accountName, accountPassword); boolean isValidLogin = casinoAccount != null; if (isValidLogin) { - String gameSelectionInput = getGameSelectionInput().toUpperCase(); + Integer gameSelectionInput = getGameSelectionInput(); processGameSelection(gameSelectionInput); } else { // TODO - implement better exception handling String errorMessage = "No account found with name of [ %s ] and password of [ %s ]"; //throw new RuntimeException(String.format(errorMessage, accountPassword, accountName)); } - } else if ("create-account".equals(arcadeDashBoardInput)) { + } else if (arcadeDashBoardInput.equals(1)) { console.println("Welcome to the account-creation screen."); String accountName = console.getStringInput("Enter your account name:"); String accountPassword = console.getStringInput("Enter your account password:"); @@ -52,59 +49,57 @@ public void run() { casinoAccount.alterAccountBalance(500); this.player = new Player(accountName, casinoAccount); this.player.setArcadeAccount(casinoAccount); - } else if("save-account".equals(arcadeDashBoardInput)){ + } else if(arcadeDashBoardInput.equals(4)){ try { CSVUtils.csvFileSaver(this.player.getArcadeAccount()); } catch (IOException e) { e.printStackTrace(); console.println("Save unsuccessful, refer to error message above for more information"); } - } else if("load-saved-account".equals(arcadeDashBoardInput)){ + } else if(arcadeDashBoardInput.equals(3)){ this.casinoAccount = CSVUtils.loadData(); this.player = new Player(this.casinoAccount.getAccountName(), this.casinoAccount); casinoAccountManager.registerAccount(this.casinoAccount); + } else if(arcadeDashBoardInput.equals(5)){ + console.print(this.casinoAccount.getScoreboard().printAllScores()); } - } while (!"logout".equals(arcadeDashBoardInput)); + + } while (!arcadeDashBoardInput.equals(6)); } - private String getArcadeDashboardInput() { - return console.getStringInput(new StringBuilder() - .append("Welcome to the Arcade Dashboard!") - .append("\nFrom here, you can select any of the following options:") - .append("\n\t[ create-account ], [ select-game ], [ load-saved-account ], [ save-account ]") - .toString()); + private Integer getArcadeDashboardInput() { + return console.getIntegerInput("Welcome to the Arcade Dashboard!\n" + + "From here, you can select any of the following options:\n" + + "\t[ 1. create-account ] [ 2. select-game ] [ 3. load-saved-account ] [ 4. save-account ] [ 5.scoreboard ] [ 6. logout ]"); } - private String getGameSelectionInput() { - return console.getStringInput(new StringBuilder() - .append("Welcome to the Game Selection Dashboard!") - .append("\nFrom here, you can select any of the following options:") - .append("\n\t[ SLOTS ], [ NUMBERGUESS ], [ PLINKO ], [ BEETLE ], [ BLACKJACK ]" + - "[ KENO ]") - .toString()); + private Integer getGameSelectionInput() { + return console.getIntegerInput("Welcome to the Game Selection Dashboard!\n" + + "From here, you can select any of the following options:\n" + + "[ 1.SLOTS ] [ 2.NUMBERGUESS ] [ 3.PLINKO ] [ 4.BEETLE ] [ 5.BLACKJACK ] [ 6.KENO ]"); } - private void processGameSelection(String input){ - input = input.toLowerCase(Locale.ROOT); + private void processGameSelection(Integer input){ + //input = input.toLowerCase(Locale.ROOT); GameInterface gameObject; switch(input){ - case "beetle": + case 4: gameObject = new BeetleGame(); break; - case "slots": + case 1: gameObject = new SlotsGame(); break; - case "blackjack": + case 5: gameObject = new BlackJackGame(); break; - case "numberguess": + case 2: gameObject = new NumberGuessGame(); break; - case "plinko": - gameObject = new PlinkoGame(); + case 3: + gameObject = new REPlinko(); break; - case "keno": - gameObject = new KenoGame(); + case 6: + gameObject = new KenoGameRE(); break; default: gameObject = new BeetleGame(); @@ -119,4 +114,6 @@ private void play(Object gameObject, Object playerObject) { game.add(player); game.run(); } + + } diff --git a/src/main/java/com/github/zipcodewilmington/MainApplication.java b/src/main/java/com/github/zipcodewilmington/MainApplication.java index e2169b7f8..efa70a2a4 100644 --- a/src/main/java/com/github/zipcodewilmington/MainApplication.java +++ b/src/main/java/com/github/zipcodewilmington/MainApplication.java @@ -9,6 +9,5 @@ public class MainApplication { public static void main(String[] args) { new Casino().run(); - } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java index 7883d56f3..fb7039b57 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java @@ -1,6 +1,7 @@ package com.github.zipcodewilmington.casino; import com.github.zipcodewilmington.Casino; +import com.github.zipcodewilmington.utils.Scoreboard; import java.util.ArrayList; import java.util.List; @@ -14,10 +15,18 @@ public class CasinoAccount { private String password; private String accountName; private Integer accountBalance = 0; + private Scoreboard scoreboard; public CasinoAccount(String accountName, String accountPassword){ this.accountName = accountName; this.password = accountPassword; + this.scoreboard = new Scoreboard(); + } + + public CasinoAccount(String accountName, String accountPassword, Scoreboard scoreboard){ + this.accountName = accountName; + this.password = accountPassword; + this.scoreboard = scoreboard; } public String getPassword() { @@ -35,4 +44,6 @@ public Integer getAccountBalance() { public void alterAccountBalance(Integer value) { this.accountBalance += value; } + + public Scoreboard getScoreboard(){ return scoreboard; } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java index 0e8b08ef8..b0d3e036a 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java @@ -23,43 +23,20 @@ public CasinoAccount getAccount(String accountName, String accountPassword) { if(name.equals(accountName)) if(pass.equals(accountPassword)){ return currentAccount; - } else { - System.out.println("Account Name or Password does not match. Are you really you?"); - return null; } } - String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); - String currentClassName = getClass().getName(); - String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; - throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); + System.out.println("Account Name or Password does not match. Are you really you?"); + return null; } - /** - * logs & creates a new `ArcadeAccount` - * - * @param accountName name of account to be created - * @param accountPassword password of account to be created - * @return new instance of `ArcadeAccount` with specified `accountName` and `accountPassword` - */ + public CasinoAccount createAccount(String accountName, String accountPassword) { CasinoAccount myAccount = new CasinoAccount(accountName, accountPassword); return myAccount; - //String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); - //String currentClassName = getClass().getName(); - //String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; - //throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); } - /** - * logs & registers a new `ArcadeAccount` to `this.getArcadeAccountList()` - * - * @param casinoAccount the arcadeAccount to be added to `this.getArcadeAccountList()` - */ + public void registerAccount(CasinoAccount casinoAccount) { this.accountList.add(casinoAccount); - //String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); - //String currentClassName = getClass().getName(); - //String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; - //throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/GameScoreboardInterface.java b/src/main/java/com/github/zipcodewilmington/casino/GameScoreboardInterface.java new file mode 100644 index 000000000..1d3e89836 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/GameScoreboardInterface.java @@ -0,0 +1,15 @@ +package com.github.zipcodewilmington.casino; + + +import com.github.zipcodewilmington.utils.GameScoreBoard; + +public interface GameScoreboardInterface { + Integer getLifetimeBets(); + Integer getLifetimeWinnings(); + Integer getLifetimeLosses(); + void addToLifetimeWinnings(Integer winnings); + void addToLifetimeLosses(Integer losses); + void addToLifetimeBets(Integer bets); + String getGameName(); + String printScores(); +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/Player.java b/src/main/java/com/github/zipcodewilmington/casino/Player.java index 0f5578c68..e84c87027 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/Player.java +++ b/src/main/java/com/github/zipcodewilmington/casino/Player.java @@ -3,10 +3,10 @@ public class Player implements PlayerInterface{ - String name; - Integer balance; - Integer currentBet = 0; - CasinoAccount arcadeAccount; + private String name; + private Integer balance = 0; + private Integer currentBet = 0; + private CasinoAccount arcadeAccount; public Player(String name, CasinoAccount account) { this.name = name; diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java index 221b6b193..b3bb3134c 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -42,14 +42,17 @@ public void run(){ this.executeTurn(); this.isGameOver(this.game.checkWinner(this.game.getCurrentPlayer())); } - this.printEndingGameMessage(); + this.determinePayout(); + console.println(this.printEndingGameMessage()); } public void initGame(){ console.println(printWelcome()); console.newLine(); - this.setBetAmt(printBalanceAndBetText()); - Integer turnCount = 0; + printBalanceAndBetText(); + Integer betAmt = console.getIntegerInput("\u001B[34m How much do you want to bet?"); + this.setBetAmt(betAmt); + console.newLine(); game.setCurrentPlayer(-1); this.isRunning = true; } @@ -57,7 +60,7 @@ public void initGame(){ public String printBeetleCards(){ String output = ""; output += "\u001B[32mYour last dice roll: " + game.getLastDiceRoll(0) + - " Your Beetle: \n"; + " Your Beetle: \n"; output += game.printBeetle(0) +"\n"; output += "\u001B[32mDealer's last dice roll: " + game.getLastDiceRoll(1) + " Dealer's Beetle: \n"; @@ -77,17 +80,22 @@ public void nextPlayer(){ public void executeTurn(){ Integer currentPlayer = game.getCurrentPlayer(); if(game.getCurrentPlayer() == 0){ - console.println(this.printBeetleCards()); - console.println("Press enter to roll next dice"); - console.pressEnterToProceed(); + console.println(printNextTurnMessage()); + this.console.pressEnterToProceed(); } game.setPlayerBeetles(currentPlayer, game.getDice().tossAndSum()); } + public String printNextTurnMessage(){ + String output = this.printBeetleCards() + "\nPress enter to roll next dice"; + return output; + } + public Integer determinePayout(){ Integer payout = (int)(this.betAmt * 1.1); if(this.game.getCurrentPlayer() == 0){ this.player.getArcadeAccount().alterAccountBalance(payout); + player.getArcadeAccount().getScoreboard().getBeetleScores().addToLifetimeWinnings(payout); return payout; } return 0; @@ -127,33 +135,30 @@ public String printWelcome() { } - public Integer printBalanceAndBetText(){ + public String printBalanceAndBetText(){ console.newLine(); console.println("\u001B[35m Current account balance: " + this.player.getArcadeAccount().getAccountBalance()); console.newLine(); - return console.getIntegerInput("\u001B[34m How much do you want to bet?"); + return "\u001B[35m Current account balance: " + this.player.getArcadeAccount().getAccountBalance(); } - public void printWinnerMessage(){ + public String printWinnerMessage(){ if(this.game.getCurrentPlayer() == 0){ - console.println("You win!"); + this.determinePayout(); + return "You win!"; } else { - console.println("Dealer wins..."); + this.player.getArcadeAccount().getScoreboard().getBeetleScores() + .addToLifetimeLosses(this.betAmt); + return "Dealer wins..."; } - console.newLine(); } - public void printEndingGameMessage(){ + public String printEndingGameMessage(){ + String output = "\nFinal Beetle results: \n" + + this.printBeetleCards() + "\n"; + output += this.printWinnerMessage() + printWinnerMessage(); - /* - console.newLine(); - console.println("Final Beetle results: "); - this.printBeetleCards(); - console.newLine(); - this.printWinnerMessage(); - console.println("Your payout is: " + this.determinePayout().toString()); - console.pressEnterToProceed(); - */ + return output; } public Beetle getGame() { @@ -182,9 +187,14 @@ public Integer getBetAmt() { public void setBetAmt(Integer betAmt) { this.betAmt = betAmt; + this.player.getArcadeAccount() + .getScoreboard() + .getBeetleScores() + .addToLifetimeBets(betAmt); } public void setRunning(boolean running){ this.isRunning = running; } } + diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java index 3d801553c..ac12cb40b 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java @@ -1,7 +1,6 @@ package com.github.zipcodewilmington.casino.games.Beetle; import com.github.zipcodewilmington.casino.CasinoAccount; -import com.github.zipcodewilmington.casino.Player; import com.github.zipcodewilmington.casino.PlayerInterface; public class BeetlePlayer implements PlayerInterface { @@ -13,10 +12,14 @@ public BeetlePlayer(PlayerInterface player){ public CasinoAccount getArcadeAccount() { - return null; + return player.getArcadeAccount(); } public void setArcadeAccount(CasinoAccount casinoAccount) { + this.player.setArcadeAccount(casinoAccount); + } + public PlayerInterface getPlayer() { + return player; } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java index 24ed414d5..14a5fba8d 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -10,6 +10,7 @@ public class BlackJackGame implements GameInterface { private Boolean isRunning = false; private PlayerInterface playerInt; + private Boolean isDemo = false; Integer userBet; Integer splitBet; IOConsole input = new IOConsole(); @@ -19,6 +20,7 @@ public class BlackJackGame implements GameInterface { IOConsole green = new IOConsole(AnsiColor.GREEN); IOConsole purple = new IOConsole(AnsiColor.PURPLE); Integer winnings = 0; + Integer splitWinnings = 0; BlackJack bj; @@ -30,20 +32,13 @@ public class BlackJackGame implements GameInterface { */ public BlackJackGame () { - } public void run() { - blue.println("============================================================" + "\n" + - "===== =====" + "\n" + - "===== WELCOME =====" + "\n" + - "===== TO =====" + "\n" + - "===== B L A C K =====" + "\n" + - "===== J A C K =====" + "\n" + - "===== =====" + "\n" + - "============================================================"); + printWelcome(); while(!isRunning) { // include betting range + playerInt.getArcadeAccount().alterAccountBalance(splitWinnings); playerInt.getArcadeAccount().alterAccountBalance(winnings); cyan.println("Your current balance is... " + playerInt.getArcadeAccount().getAccountBalance() + "\n"); Integer userInput = input.getIntegerInput("\u001B[32m1. Start A Hand" + "\n" + "\u001B[31m2. Quit" + "\n"); @@ -62,15 +57,30 @@ public void run() { } } + public void printWelcome () { + blue.println("============================================================" + "\n" + + "===== =====" + "\n" + + "===== WELCOME =====" + "\n" + + "===== TO =====" + "\n" + + "===== B L A C K =====" + "\n" + + "===== J A C K =====" + "\n" + + "===== =====" + "\n" + + "============================================================"); + } + public void startGame () { bj.givePlayerCard(); - System.out.println("Your starting card : " + bj.playersCurrentValue()); - System.out.println("Your second next card : " + bj.givePlayerCard()); - System.out.println("Hand value : " + bj.playersCurrentValue()); + cyan.println("\n" + "Your starting card : " + bj.playersCurrentValue() + "\n"); + cyan.println("Your second next card : " + bj.givePlayerCard() + "\n"); + cyan.println("Hand value : " + bj.playersCurrentValue() + "\n"); if (twoCardBlackJack()) { + green.println("BLACK JACK!!!" + "\n"); calculateWinnings(3, userBet); + } else if(isDemo){ + return; } else if (bj.playersHand.get(0).equals(bj.playersHand.get(1))) { // include conditional on starting blackjack! splitPlayer(); + } else { standardGame(); } @@ -87,7 +97,7 @@ public boolean twoCardBlackJack () { public void standardGame () { boolean isWinner = false; while (!isWinner) { - System.out.println("With the value of " + bj.playersCurrentValue() + "\n"); + cyan.println("With the value of " + bj.playersCurrentValue() + "..." + "\n"); Integer userChoice = input.getIntegerInput("1. Hit" + "\n" + "2. Stay"); switch (userChoice) { case 1: @@ -98,7 +108,7 @@ public void standardGame () { break; case 2: bj.giveDealerCard(); - System.out.println("The dealers first card : " + bj.dealersCurrentValue()); + red.println("The dealers first card : " + bj.dealersCurrentValue()); bj.giveDealerCard(); dealersGame(); isWinner = true; @@ -127,17 +137,22 @@ public Integer calculateWinnings(Integer multiplier, Integer userBet) { return winnings; } + public Integer calculateWinningsSplitHand(Integer multiplier, Integer splitBet) { + splitWinnings = multiplier * splitBet; + return splitWinnings; + } + private void splitPlayerHitsBlackJack(Integer splitBet) { green.println("BLACK JACK!!"); - calculateWinnings(3, splitBet); + calculateWinningsSplitHand(3, splitBet); standardGame(); } private void splitPlayerBust(Integer splitBet) { red.println("Sorry bud, you got " + bj.splitPlayersCurrentValue() + ", you still have one more hand!"); - calculateWinnings(0, splitBet); + calculateWinningsSplitHand(0, splitBet); standardGame(); } @@ -169,10 +184,12 @@ private Integer secondHandBet() { Integer splitValue = bj.playersHand.get(1); bj.playersHandOnSplit.add(splitValue); bj.playersHand.set(1, 0); - Integer splitBet = input.getIntegerInput("Please place your bet for the second hand" + "\n"); - splitHandBetConditions(); - playerInt.getArcadeAccount().alterAccountBalance(splitBet * (-1)); - cyan.println("Your hand has been split! Current value " + bj.splitPlayersCurrentValue() + "\n" + "\n"); + Integer splitBet = input.getIntegerInput("\u001B[32mPlease place your bet for the second hand" + "\n"); + if (splitBet > playerInt.getArcadeAccount().getAccountBalance()) { + splitHandBetConditions(); + } + playerInt.getArcadeAccount().alterAccountBalance(splitBet * (-1)); + cyan.println("Your hand has been split! Current value " + bj.splitPlayersCurrentValue() + "\n" + "\n"); return splitBet; } @@ -206,7 +223,7 @@ private void splitHandRound() { public void dealersGame() { boolean gameEnd = false; while (!gameEnd) { - cyan.println("The dealer has : " + bj.dealersCurrentValue()); + red.println("The dealer has : " + bj.dealersCurrentValue()); if (bj.dealersCurrentValue() > 21) { green.println("You win!" + "\n"); calculateWinnings(2, userBet); @@ -256,7 +273,7 @@ public void splitHandBustHasAces () { public boolean splitPlayerHitsBlackJack () { if (bj.splitPlayersCurrentValue() == 21) { - calculateWinnings(3, splitBet); + calculateWinningsSplitHand(3, splitBet); return true; } else { return false; @@ -280,19 +297,19 @@ public void userBetCondition () { } public void splitHandBetConditions () { - while (secondHandBet() > playerInt.getArcadeAccount().getAccountBalance()) { + while (splitBet > playerInt.getArcadeAccount().getAccountBalance()) { red.println("You don't have enough money for that, Silly!" + "\n"); - secondHandBet(); + splitBet = (input.getIntegerInput("\u001B[32mPlease place your bet for the second hand" + "\n")); } } public void subtractBetFromBalance(Integer betAmount) { - + this.getPlayer().getArcadeAccount().alterAccountBalance(betAmount * -1); } public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { - + Player.getArcadeAccount().alterAccountBalance(winnings); } public void add(PlayerInterface player) { @@ -301,8 +318,50 @@ public void add(PlayerInterface player) { public void remove(PlayerInterface player) { + this.playerInt = null; + } + public Boolean getRunning() { + return isRunning; } + public void setRunning(Boolean running) { + isRunning = running; + } + + public Integer getUserBet() { + return userBet; + } + public void setUserBet(Integer userBet) { + this.userBet = userBet; + } + + public PlayerInterface getPlayer() { + return playerInt; + } + + public Boolean getDemo() { + return isDemo; + } + + public void setDemo(Boolean demo) { + isDemo = demo; + } + + public BlackJack getGame() { + return bj; + } + + public void setGame(){ + bj = new BlackJack(); + } + + public Integer getSplitBet() { + return splitBet; + } + + public void setSplitBet(Integer splitBet) { + this.splitBet = splitBet; + } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackPlayer.java index 7aa90e57a..ef586091e 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackPlayer.java @@ -20,4 +20,8 @@ public CasinoAccount getArcadeAccount() { public void setArcadeAccount(CasinoAccount casinoAccount) { } + + public PlayerInterface getPlayer() { + return player; + } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java deleted file mode 100644 index 6b7532067..000000000 --- a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java +++ /dev/null @@ -1,320 +0,0 @@ -package com.github.zipcodewilmington.casino.games.keno; - -import com.github.zipcodewilmington.casino.GameInterface; -import com.github.zipcodewilmington.casino.Player; -import com.github.zipcodewilmington.casino.PlayerInterface; - -import java.util.Random; -import java.util.Scanner; - -public class KenoGame implements GameInterface { - private PlayerInterface playerInt; - KenoPlayer kenoPlayer; - KenoGame kenoGame; - Integer bet; - int balance; - - - - @Override - public void add(PlayerInterface player) { - this.playerInt=player; - } - - @Override - public void remove(PlayerInterface player) { - - } - - @Override - public void run() { - Scanner input = new Scanner(System.in); - printWelcome(); - balance = playerInt.getArcadeAccount().getAccountBalance(); - int playerNums[] = new int[15]; - int computerNums[] = new int[20]; - int kenoSpot, kenoCatch; - boolean continueGame = true; - String userInput; - - - System.out.println("\u001B[32mHello, and welcome to the game Keno!"); - System.out.println("\u001B[32mThis is a high stakes game. You can win and lose money quickly!"); - while(continueGame) - { - System.out.println(); - System.out.println("\u001B[32mYou currently have: $" + playerInt.getArcadeAccount().getAccountBalance()); - balance=playerInt.getArcadeAccount().getAccountBalance(); - System.out.println("\u001B[32mLet's get some numbers to begin."); - System.out.println("\u001B[32mYou may enter up to 15 numbers"); - playerNums = getUserInput(); - bet = (int) getBet(balance); - computerNums = getComputerNums(); - kenoSpot = getSpot(playerNums); - kenoCatch = getCatch(playerNums, computerNums); - System.out.println("\u001B[32mCatch: " + (kenoCatch + 1)); - System.out.println("\u001B[32mYou have won: $"+payout(kenoSpot,kenoCatch,bet)); - balance += payout(kenoSpot, kenoCatch, bet); - - balance-=bet; - playerInt.getArcadeAccount().alterAccountBalance(balance); - - System.out.println("\u001B[32mYou now have: $" + balance); - if (balance <= 0) - { - continueGame = false; - System.out.println("\u001B[32mSorry, you ran out of money!"); - System.out.println("\u001B[32mBetter luck next time! :)"); - } - else - { - System.out.println("\u001B[32mWould you like to continue(y/n)?"); - userInput = input.nextLine(); - - if ((userInput.equals("y"))) - { - continueGame = true; - } - else - { - continueGame = false; - } - } - } - System.out.println("\u001B[32mThanks for playing!"); - System.out.println("\u001B[32mOverall, you now have: $" + balance); - - } - - private void printWelcome() { - System.out.println( - "\u001B[33m***********************************\n" + - "*** ***\n" + - "****** WELCOME TO KENO ******\n" + - "*** ***\n" + - "***********************************"); - } - - public static int[] getUserInput() - { - Scanner input = new Scanner(System.in); // for input - boolean invalidInput = true; - boolean continuePlayer = true; - int playerNums[] = new int[15]; - int index; - int numberEntered; - String enterString; - for (index = 0; index < playerNums.length; index++ ) - { - playerNums[index] = 0; - } - index = 0; - while(continuePlayer && index < 15) - { - do - { - do - { - System.out.println("\u001B[32mEnter number " + (index+1)); - numberEntered = input.nextInt(); - if ((numberEntered > 0) && (numberEntered < 81)) - { - if(isUnique(numberEntered, playerNums)) - { - invalidInput = false; - playerNums[index] = numberEntered; - } - else - { - System.out.println("\u001B[32mSorry, you already entered that number before!"); - System.out.println("\u001B[32mTry again! "); - invalidInput = true; - } - } - else - { - invalidInput = true; - System.out.println("\u001B[32mSorry, the number you entered is either less than 0 or greater than 80"); - System.out.println("\u001B[32mTry again"); - System.out.println(""); - } - } while(invalidInput); - - if(index < 14) //makes sure program doesn't ask to continue when on the last number - { - System.out.println("\u001B[32mDo you wish to continue? (y/n)"); - input.nextLine(); - enterString = input.nextLine(); - if ((enterString.equals("n")) || (enterString.equals("no"))) - { - invalidInput = false; - continuePlayer = false; - } - else if ((enterString.equals("y")) || (enterString.equals("yes"))) - { - invalidInput = false; - continuePlayer = true; - } - else - { - System.out.println("\u001B[32mSorry, I didn't understand that."); - System.out.println(""); - invalidInput = true; - } - - } - }while(invalidInput); - - index++; - } - return playerNums; - } - - public static boolean isUnique(int number, int[] array) - { - int index; - for (index = 0; index < array.length; index++) - { - if(number == array[index]) - { - return false; - } - } - return true; - } - - public static int[] getComputerNums() - { - int[] computerNums = new int[20]; - Random rand = new Random(); - int index; - int randomNumber = 0; - - for (index = 0; index < computerNums.length; index++) - { - randomNumber = rand.nextInt(80) + 1; - if(isUnique(randomNumber, computerNums)) - { - computerNums[index] = randomNumber; - } - else - { - index--; - } - - } - return computerNums; - } - - public static int getSpot(int[] playerArray) - { - int index; - int spot = 0; - for (index = 0; index < playerArray.length; index++) - { - if(playerArray[index] != 0) - { - spot++; - } - - } - spot -= 1; //Subtract one so it works properly in array - return spot; - } - - public static double getBet(double playerMoney) - { - Scanner input = new Scanner(System.in); - double bet = 0; - boolean invalidInput = true; - while(invalidInput) - { - System.out.print("\u001B[32mEnter the bet amount in whole dollars: $"); - bet = input.nextInt(); - if(bet < 0) - { - System.out.println("\u001B[32mBet amount can't be less than 0!"); - invalidInput = true; - } - else if(bet > playerMoney) - { - System.out.println("\u001B[32mYou don't have enough money to bet that!"); - invalidInput = true; - } - else - { - invalidInput = false; - } - } - return bet; - } - - public static int getCatch(int[] playerArray, int[] computerArray) - { - int playerIndex; - int computerIndex; - int kenoCatch = 0; - for (playerIndex = 0; playerIndex < playerArray.length; playerIndex++) - { - for(computerIndex = 0; computerIndex < computerArray.length; computerIndex++) - { - if(playerArray[playerIndex] == computerArray[computerIndex]) - { - kenoCatch++; - } - } - } - kenoCatch -= 1;//subtact one so it works in array - return kenoCatch; - } - - public Integer payout(int kenoSpot, int kenoCatch, Integer betAmount) - { - Integer payoutAmount = 0; - - Integer multiplier; - Integer payout[][] = - { - {3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //1 - {1, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //2 - {1, 2, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //3 - {0, 2, 6, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //4 - {0, 1, 3, 15, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//5 - {0, 1, 2, 3, 30, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0},//6 - {0, 0, 1, 6, 12, 36, 100, 0, 0, 0, 0, 0, 0, 0, 0},//7 - {0, 0, 1, 3, 6, 19, 90, 720, 0, 0, 0, 0, 0, 0, 0},//8 - {0, 0, 1, 2, 4, 8, 20, 80, 1200, 0, 0, 0, 0, 0, 0},//9 - {0, 0, 1, 2, 3, 5, 10, 30, 600, 1800, 0, 0, 0, 0, 0},//10 - {0, 0, 1, 1, 2, 6, 15, 25, 180, 1000, 3000, 0, 0, 0, 0},//11 - {0, 0, 0, 1, 2, 4, 24, 72, 250, 500, 2000, 4000, 0, 0, 0},//12 - {0, 0, 0, 0, 3, 4, 5, 20, 80, 240, 500, 3000, 6000, 0, 0},//13 - {0, 0, 0, 0, 2, 3, 5, 12, 50, 150, 500, 1000, 2000, 7500, 0},//14 - {0, 0, 0, 0, 1, 2, 5, 15, 50, 150, 300, 600, 1200, 2500, 10000}//15 - }; - if(kenoCatch < 0) - { - multiplier = 0; - } - else - { - multiplier = payout[kenoSpot][kenoCatch]; - payoutAmount = multiplier * betAmount; - } - return payoutAmount; - } - - @Override - public Integer calculateWinnings(Integer multiplier, Integer betAmount) { - return null; - } - - @Override - public void subtractBetFromBalance(Integer betAmount) { - this.balance-=bet; - } - - @Override - public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { - - } -} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGameRE.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGameRE.java new file mode 100644 index 000000000..e1a387611 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGameRE.java @@ -0,0 +1,235 @@ +package com.github.zipcodewilmington.casino.games.keno; + +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.utils.AnsiColor; +import com.github.zipcodewilmington.utils.IOConsole; + +import java.util.HashSet; + +public class KenoGameRE implements GameInterface { + private final IOConsole Red = new IOConsole(AnsiColor.RED); + private final IOConsole Green = new IOConsole(AnsiColor.GREEN); + private final IOConsole Yellow = new IOConsole(AnsiColor.YELLOW); + private final IOConsole Blue = new IOConsole(AnsiColor.BLUE); + private final IOConsole Purple = new IOConsole(AnsiColor.PURPLE); + private final IOConsole Cyan = new IOConsole(AnsiColor.CYAN); + private IOConsole console = new IOConsole(AnsiColor.BLUE); + private PlayerInterface currentPlayer; + private Integer userBet; + private Integer currentUserChoice; + private HashSet tenChoices; + private HashSet twentyOneRandom; + private HashSet matches; + private Integer multiplier; + private Integer winnings; + + //--------------------------------------------------------------------- + + public KenoGameRE(){ + } + + @Override + public void run() { + //Display welcome + Yellow.println(printWelcome()); + //Display instruction + console.setWait(1000); + Blue.println(displayInstruction()); + Boolean quit = false; + while(!quit) { + //Print user current balance + console.setWait(1000); + Green.println("Your Current Balance: " + getPlayerBalance()); + //Ask user for bet amount + console.setWait(1000); + userBet = Purple.getIntegerInput("How much do you want to bet?"); + //Subtract bet amount from user's balance + subtractBetFromBalance(userBet); + //Ask user to pick 10 numbers between 1-80 and add to array + getUserChoices(); + //Display user's picks + console.setWait(1000); + Purple.println("Your chose: " + tenChoices); + //Generate 21 random numbers and add to array + setTwentyOneRandom(twentyOneRandomNum()); + //Display the 21 random numbers + console.setWait(1000); + console.println("Game chose:" + twentyOneRandom); + //Find matches b/w user choice and random 21 + setMatches(findMatches()); + //Print matched array + console.setWait(1000); + Yellow.println("Matches: " + matches); + //Calculate multiplier then set multiplier + Integer multiply = calculateMultiplier(); + setMultiplier(multiply); + //Calculate winnings and set it + Integer win = calculateWinnings(multiplier, userBet); + setWinnings(win); + //Print winnings + console.setWait(1000); + Green.println("You won: $" + winnings); + //Add winnings to player's account balance + addMoneyToBalance(currentPlayer, winnings); + //Print user current balance + console.setWait(1000); + Green.println("Your Current Balance: $" + getPlayerBalance()); + //Ask user to play again + quit = playAgain(); + } + } + + @Override + public void add(PlayerInterface player) { + this.currentPlayer = player; + } + @Override + public void remove(PlayerInterface player) { + this.currentPlayer = null; + } + @Override + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return multiplier * betAmount; + } + @Override + public void subtractBetFromBalance(Integer betAmount) { + currentPlayer.getArcadeAccount().alterAccountBalance(betAmount * (-1)); + } + @Override + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + Player.getArcadeAccount().alterAccountBalance(winnings); + } + + //-------------------------- Getters and Setters ----------------------- + + public PlayerInterface getCurrentPlayer() { + return currentPlayer; + } + + public void setUserBet(Integer userBet) { + this.userBet = userBet; + } + + public void setTwentyOneRandom(HashSet twentyOneRandom) { + this.twentyOneRandom = twentyOneRandom; + } + + public HashSet getTwentyOneRandom() { + return twentyOneRandom; + } + + public HashSet getMatches() { + return matches; + } + + public void setMatches(HashSet matches) { + this.matches = matches; + } + + public HashSet getTenChoices() { + return tenChoices; + } + + public void setTenChoices(HashSet tenChoices) { + this.tenChoices = tenChoices; + } + + public Integer getMultiplier() { + return multiplier; + } + + public void setMultiplier(Integer multiplier) { + this.multiplier = multiplier; + } + + public Integer getWinnings() { + return winnings; + } + + public void setWinnings(Integer winnings) { + this.winnings = winnings; + } + + //-------------------------- My own methods ---------------------------- + + public String printWelcome() { + return "***********************************\n" + + "*** ***\n" + + "****** WELCOME TO KENO ******\n" + + "*** ***\n" + + "***********************************"; + + } + + public String displayInstruction(){ + return "Pick 10 numbers between 1 and 80!\n" + + "The more numbers matched the more you win!"; + } + + public Integer getPlayerBalance(){ + return currentPlayer.getArcadeAccount().getAccountBalance(); + } + + public void getUserChoices(){ + HashSet choices = new HashSet(); + Integer count = 0; + while(choices.size() < 10){ + currentUserChoice = Cyan.getIntegerInput("Choose your #" + (count+1) +" number"); + if(choices.contains(currentUserChoice)){ + Cyan.println("You already chose that number! Try again!"); + } else { + choiceCondition(); + choices.add(currentUserChoice); + count++; + } + } + this.tenChoices = choices; + } + + public void choiceCondition(){ + while(currentUserChoice < 1 || currentUserChoice > 80){ + currentUserChoice = Blue.getIntegerInput("Please choose number between 1 - 80"); + } + } + + public HashSet twentyOneRandomNum(){ + HashSet twentyOne = new HashSet(); + while(twentyOne.size() < 21){ + Integer input = (int) ((Math.random() * (81 - 1)) + 1); + twentyOne.add(input); + } + return twentyOne; + } + + public HashSet findMatches(){ + HashSet matched = new HashSet<>(); + for(Integer element: tenChoices){ + if(twentyOneRandom.contains(element)){ + matched.add((element)); + } + } + return matched; + } + + public Integer calculateMultiplier(){ + return multiplier = matches.size(); + } + + public Boolean playAgain(){ + if(getPlayerBalance() == 0) { + console.setWait(1000); + Red.println("Oh No! You've ran out of money. Goodbye"); + return true; + } else { + //Continue game? + console.setWait(1000); + Integer userInput = Cyan.getIntegerInput("Would you like to play again?\n" + + "1. Yes 2. No"); + if(userInput.equals(2)){ + return true; + } + } + return false; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java index 42df1e1f8..24b0daed1 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java @@ -6,7 +6,10 @@ public class KenoPlayer implements PlayerInterface { private PlayerInterface player; - public KenoPlayer(PlayerInterface player){this.player=player;} + public KenoPlayer(PlayerInterface player){ + this.player = player; + } + @Override public CasinoAccount getArcadeAccount() { return player.getArcadeAccount(); @@ -14,9 +17,12 @@ public CasinoAccount getArcadeAccount() { @Override public void setArcadeAccount(CasinoAccount casinoAccount) { - CasinoAccount casinoAccount1; + this.player.setArcadeAccount(casinoAccount); } + public PlayerInterface getPlayer() { + return this.player; + } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java index 7a5f57c35..a71ef1cab 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java @@ -12,13 +12,13 @@ */ public class NumberGuessGame implements GameInterface { - private final IOConsole consoleR = new IOConsole(AnsiColor.RED); - private final IOConsole consoleG = new IOConsole(AnsiColor.GREEN); - private final IOConsole consoleY = new IOConsole(AnsiColor.YELLOW); - private final IOConsole consoleB = new IOConsole(AnsiColor.BLUE); - private final IOConsole consoleP = new IOConsole(AnsiColor.PURPLE); - private final IOConsole consoleC = new IOConsole(AnsiColor.CYAN); - private Integer maxNumber; + private final IOConsole Red = new IOConsole(AnsiColor.RED); + private final IOConsole Green = new IOConsole(AnsiColor.GREEN); + private final IOConsole Yellow = new IOConsole(AnsiColor.YELLOW); + private final IOConsole Blue = new IOConsole(AnsiColor.BLUE); + private final IOConsole Purple = new IOConsole(AnsiColor.PURPLE); + private final IOConsole Cyan = new IOConsole(AnsiColor.CYAN); + private Integer maxNumber = 20; private PlayerInterface currentPlayer; private Integer betAmount; private Integer multiplier; @@ -32,20 +32,19 @@ public NumberGuessGame(){ @Override public void run() { - Scanner scanner = new Scanner(System.in); - printWelcome(); + Yellow.println(printWelcome()); Boolean quitGame = false; while(!quitGame) { //print instruction for game printInstructions(); //print player's current account balance - consoleG.println("Your current account balance is: $" + this.currentPlayer.getArcadeAccount().getAccountBalance() + "\n"); + Green.println("Your current account balance is: $" + this.currentPlayer.getArcadeAccount().getAccountBalance() + "\n"); //ask for a bet amount takeBet(); //subtract bet amount from player's account subtractBetFromBalance(betAmount); calcPotentialEarnings(); - consoleR.println("You bet: $"+betAmount+ "\n\nBut WAIT!\nFeeling lucky??\nIncrease the difficulty and increase your earnings!\n"); + Red.println("You bet: $"+betAmount+ "\n\nBut WAIT!\nFeeling lucky??\nIncrease the difficulty and increase your earnings!\n"); //print difficulty levels and ask user to choose setDifficultyLevel(); setMultiplier(maxNumber); @@ -59,13 +58,12 @@ public void run() { //calculate amount player won Integer payout = calculatePayout(multiplier, guessRange, betAmount); //print winnings - consoleR.println("You won: $"+payout); + Red.println("You won: $"+payout); //add winnings to player's account addMoneyToBalance(currentPlayer,payout); //ask if player wants to play again - consoleC.println("\u001B[36m\nWould you like to play again?\n" + + Integer input = Cyan.getIntegerInput("Would you like to play again?\n" + "1. Yes 2. No"); - Integer input = scanner.nextInt(); if(input == 2){ quitGame = true; } @@ -73,18 +71,18 @@ public void run() { } private void printGuessVsActual() { - consoleG.println("Lets compare results!"); - consoleY.println("You guessed: " + guessNumber); - consoleY.println("Actual Number: " + randomNumber); + Green.println("Lets compare results!"); + Yellow.println("You guessed: " + guessNumber); + Yellow.println("Actual Number: " + randomNumber); } - private void printInstructions() { - consoleB.println("Guess a number between 0 and 20.\n" + + public void printInstructions() { + Blue.println("Guess a number between 0 and 20.\n" + "Guess close enough and win a prize!\n" + "Pick the right number to double your bets!\n"); } - private Integer calculatePayout(Integer multiplier, Integer guessRange,Integer betAmount) { + public Integer calculatePayout(Integer multiplier, Integer guessRange,Integer betAmount) { Integer payout; Double percent = 0.0; Double multiplierAsDouble = multiplier.doubleValue(); @@ -104,34 +102,32 @@ private Integer calculatePayout(Integer multiplier, Integer guessRange,Integer b return payout; } - private void pickRandomNumber() { + public void pickRandomNumber() { Integer random = (int) ((Math.random() * (maxNumber - 0)) + 0); this.randomNumber = random; } private void takeGuess() { - consoleP.println("Pick a number between 0 and " + maxNumber); + Purple.println("Pick a number between 0 and " + maxNumber); this.guessNumber = scanner.nextInt(); - } private void takeBet() { - consoleB.println("How much do you want to bet?"); - this.betAmount = scanner.nextInt(); + this.betAmount = Blue.getIntegerInput("How much do you want to bet?"); } - private void printWelcome() { - consoleY.println( + public String printWelcome() { + return "************************************\n" + "*** ***\n" + "****** !! WELCOME TO !! ******\n" + "****** !!! GUESS NUMBER !!! ******\n" + "*** ***\n" + - "************************************\n"); + "************************************\n"; } - private void calcPotentialEarnings(){ + public void calcPotentialEarnings(){ Integer[] calcPotentialEarnings = new Integer[4]; for (int i = 0; i < 4; i++) { calcPotentialEarnings[i] = betAmount * (i + 2); @@ -140,12 +136,10 @@ private void calcPotentialEarnings(){ } private void setDifficultyLevel() { - consoleC.println( - "1. Start max at 20 and win up to " + potentialEarnings[0] + "!\n" + + Integer input = Cyan.getIntegerInput("1. Start max at 20 and win up to " + potentialEarnings[0] + "!\n" + "2. Change max to 30 and Triple your winnings up to " + potentialEarnings[1] + "!\n"+ "3. Change max to 40 and QUADRUPLE your winnings up to " + potentialEarnings[2] + "!\n"+ "4. Change max to 50! SEND IT TO THE MOON AND WIN UP TO " + potentialEarnings[3] + "!\n"); - Integer input = scanner.nextInt(); switch (input){ case 1: setMaxNumber(20); @@ -196,6 +190,22 @@ public void setMultiplier(Integer difficultyLvl) { } } + public void setBetAmount(Integer betAmount) { + this.betAmount = betAmount; + } + + public Integer[] getPotentialEarnings() { + return potentialEarnings; + } + + public Integer getMultiplier() { + return multiplier; + } + + public int getRandomNumber() { + return randomNumber; + } + @Override public void add(PlayerInterface player) { this.currentPlayer = player; @@ -220,4 +230,5 @@ public void subtractBetFromBalance(Integer betAmount) { public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { Player.getArcadeAccount().alterAccountBalance(winnings); } + } \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessPlayer.java index 6abeb9922..268616852 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessPlayer.java @@ -4,7 +4,7 @@ import com.github.zipcodewilmington.casino.PlayerInterface; /** - * Created by leon on 7/21/2020. + * Created by Nathan 7/12/2021 */ public class NumberGuessPlayer implements PlayerInterface { private PlayerInterface player; @@ -15,11 +15,15 @@ public NumberGuessPlayer(PlayerInterface player){ @Override public CasinoAccount getArcadeAccount() { - return null; + return player.getArcadeAccount(); } @Override public void setArcadeAccount(CasinoAccount casinoAccount) { + this.player.setArcadeAccount(casinoAccount); + } + public PlayerInterface getPlayer() { + return this.player; } } \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java deleted file mode 100644 index 841162a0d..000000000 --- a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java +++ /dev/null @@ -1,200 +0,0 @@ -package com.github.zipcodewilmington.casino.games.plinko; - -import com.github.zipcodewilmington.casino.CasinoAccount; -import com.github.zipcodewilmington.casino.GameInterface; -import com.github.zipcodewilmington.casino.PlayerInterface; - -import java.util.HashMap; -import java.util.Map; -import java.util.Random; -import java.util.Scanner; - -public class PlinkoGame implements GameInterface{ - private Map moneyGenerator=new HashMap(); - private PlayerInterface playerInt; - public int initialPosition; - private int bet; - public int multiplier; - public int balance; - - - - @Override - public void add(PlayerInterface player) { - this.playerInt=player; - } - - @Override - public void remove(PlayerInterface player) { - - } - - @Override - public void run() { - Scanner input = new Scanner(System.in); - printWelcome(); - balance=playerInt.getArcadeAccount().getAccountBalance(); - boolean continueGame=true; - Integer playerNumber; - String userInput; - - System.out.println("\u001B[32mHello, and welcome to the game Plinko!"); - while(continueGame){ - System.out.println("\u001B[32mYou currently have: $" + playerInt.getArcadeAccount().getAccountBalance()); - System.out.println("\u001B[32mPlease enter a number position of your choice: "); - playerNumber = getUserInput(); - bet = (int) getBet(balance); - int plinkSpot=getPlinkoSpot(); - this.multiplier=plinkSpot; - System.out.println("\u001B[32mAfter playing, now your position is: "+plinkSpot); - balance += payout(plinkSpot); - subtractBetFromBalance(bet); - playerInt.getArcadeAccount().alterAccountBalance(balance); - System.out.println("\u001B[32mYou now have: $" + balance); - if (balance <= 0) - { - continueGame = false; - System.out.println("\u001B[32mSorry, you ran out of money!"); - System.out.println("\u001B[32mBetter luck next time! :)"); - } - else - { - System.out.println("\u001B[32mWould you like to continue(y/n)?"); - userInput = input.nextLine(); - - if ((userInput.equals("y"))) - { - continueGame = true; - } - else - { - continueGame = false; - } - } - } - System.out.println("\u001B[32mThanks for playing!"); - System.out.println("\u001B[32mOverall, you now have: $" + balance); - } - - - private void printWelcome() { - System.out.println( - "\u001B[33m***********************************\n" + - "*** ***\n" + - "****** WELCOME TO PLINKO ******\n" + - "*** ***\n" + - "***********************************"); - } - - @Override - public Integer calculateWinnings(Integer multiplier, Integer betAmount) { - return this.multiplier*betAmount; - } - - private int payout(int plinkoSpot) { - moneyGenerator.put(1,200); - moneyGenerator.put(2,0); - moneyGenerator.put(3,3000); - moneyGenerator.put(4,30); - moneyGenerator.put(5,0); - moneyGenerator.put(6,0); - moneyGenerator.put(7,1); - moneyGenerator.put(8,750); - moneyGenerator.put(9,0); - Integer moneyWon=0; - - for (Integer pos:moneyGenerator.keySet()) - { - if(pos.equals(plinkoSpot)){ - moneyWon=moneyGenerator.get(pos); - } - } - return moneyWon; - } - - - - public int getPlinkoSpot() { - int max = 9; - int min = 1; - Random rand = new Random(); - return rand.nextInt(max - min + 1) + min; - } - - public static double getBet(double playerMoney) - { - Scanner input = new Scanner(System.in); - double bet = 0; - boolean invalidInput = true; - while(invalidInput) - { - System.out.print("Enter the bet amount in whole dollars: $"); - bet = input.nextInt(); - if(bet < 0) - { - System.out.println("Bet amount can't be less than 0!"); - invalidInput = true; - } - else if(bet > playerMoney) - { - System.out.println("You don't have enough money to bet that!"); - invalidInput = true; - } - else - { - invalidInput = false; - } - } - return bet; - } - - private Integer getUserInput() { - Scanner input = new Scanner(System.in); // for input - boolean invalidInput = true; - boolean continuePlayer = true; - int numberEntered; - int playerNums=0; - String enterString; - - - - while(invalidInput) - { - System.out.println("Enter number :"); - numberEntered = input.nextInt(); - - if ((numberEntered > 0) && (numberEntered < 10)){ - invalidInput = false; - playerNums = numberEntered; - break; - } - else{ - invalidInput = true; - System.out.println("Sorry, the number you entered is either less than 0 or greater than 9"); - System.out.println("Try again"); - System.out.println(""); - } - } - return playerNums; - } - - - - @Override - public void subtractBetFromBalance(Integer betAmount) { - balance-=bet; - } - - @Override - public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { - - } - -// @Override -// public CasinoAccount getArcadeAccount() { -// return null; -// } - -} - - diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java index 6e268e585..d1a324fd0 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java @@ -14,6 +14,6 @@ public CasinoAccount getArcadeAccount() { @Override public void setArcadeAccount(CasinoAccount casinoAccount) { - CasinoAccount casinoAccount1; + this.player.setArcadeAccount(casinoAccount); } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/REPlinko.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/REPlinko.java new file mode 100644 index 000000000..37fe888f8 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/REPlinko.java @@ -0,0 +1,138 @@ +package com.github.zipcodewilmington.casino.games.plinko; + +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.utils.AnsiColor; +import com.github.zipcodewilmington.utils.IOConsole; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class REPlinko implements GameInterface { + private PlayerInterface playerInt; + private Boolean isRunning = false; + public List winningValues; + Integer userBet; + Integer userInput; + Integer actualWinnings = 0; + IOConsole input = new IOConsole(); + IOConsole green = new IOConsole(AnsiColor.GREEN); + IOConsole red = new IOConsole(AnsiColor.RED); + IOConsole cyan = new IOConsole(AnsiColor.CYAN); + + public void run() { + printWelcome(); + while(!isRunning) { + playerInt.getArcadeAccount().alterAccountBalance(actualWinnings); + green.println("Your current account balance is " + playerInt.getArcadeAccount().getAccountBalance() + "\n"); + userInput = cyan.getIntegerInput("Wanna play?" + "\n" + "1. Yes" + "\n" + "2. No" + "\n"); + switch (userInput) { + case 1: + askForBet(); + userBetCondition(); + playerInt.getArcadeAccount().alterAccountBalance(userBet * (-1)); + startGame(); + break; + case 2: + isRunning = true; + } + } + } + + public void startGame() { + createBoard(); + shuffleBoard(); + calculateWinnings(checkWin(), userBet); + printWinnings(); + } + + public Integer checkWin () { + return winningValues.get(0); + } + + public void createBoard () { + winningValues = new ArrayList<>(); + winningValues.add(0); + winningValues.add(0); + winningValues.add(0); + winningValues.add(0); + winningValues.add(0); + winningValues.add(1); + winningValues.add(1); + winningValues.add(2); + winningValues.add(3); + winningValues.add(5); + } + + public void shuffleBoard () { + Collections.shuffle(winningValues); + } + + private void userBetCondition() { + while (userBet > playerInt.getArcadeAccount().getAccountBalance()) { + red.println("Oh no! You're trying to place a bet with more money than you have..." + "\n"); + askForBet(); + } + } + + private void printWelcome() { + input.println("Welcome!"); + } + + public void askForBet () { + userBet = (green.getIntegerInput("How much would you like to bet?" + "\n")); + } + + public void printWinnings () { + if (actualWinnings > 0) { + green.println("You've won " + actualWinnings + "!!" + "\n"); + } else { + red.println("Ahhh, better luck next time! You lost... " + "\n"); + } + } + + public void add(PlayerInterface player) { + this.playerInt = player; + } + + public void remove(PlayerInterface player) { + this.playerInt = null; + } + + public Integer calculateWinnings(Integer multiplier, Integer userBet) { + actualWinnings = multiplier * userBet; + return actualWinnings; + } + + public void subtractBetFromBalance(Integer betAmount) { + playerInt.getArcadeAccount().alterAccountBalance(betAmount * (-1)); + } + + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + Player.getArcadeAccount().alterAccountBalance(winnings); + } + + public PlayerInterface getPlayerInt() { + return playerInt; + } + + public Boolean getRunning() { + return isRunning; + } + + public void setRunning(Boolean running) { + isRunning = running; + } + + public Integer getUserBet() { + return userBet; + } + + public void setUserBet(Integer amt){ + this.userBet = amt; + } + + public List getWinningValues() { + return winningValues; + } +} \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index d7030b81d..12f9b4645 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -23,6 +23,7 @@ public class SlotsGame implements GameInterface{ private Integer loseMultiplier; private Integer winMultiplier; private PlayerInterface currentPlayer; + private Integer numberOfLines; public SlotsGame(){ } @@ -48,7 +49,7 @@ public Integer getWinMultiplier() { @Override public void run() { Scanner scanner = new Scanner(System.in); - printWelcome(); + Yellow.println(printWelcome()); Slots slotMachine = new Slots(); slotMachine.spinSlots(); //Display first slots @@ -58,13 +59,14 @@ public void run() { while(!quitGame) { //print initial account balance - Green.println("Current account balance: $" + currentPlayer.getArcadeAccount().getAccountBalance() + "\n"); + Green.println("Current account balance: $" + getPlayerBalance() + "\n"); getBetAmount(); - Integer[] selectedBets = getBetSelections(); - + calculateTotalCost(); + userBetCondition(); //take money from player account subtractBetFromBalance(betTotal); + Integer[] selectedBets = getBetSelections(); slotMachine.spinSlots(); slotMachine.displaySlots(); @@ -76,52 +78,54 @@ public void run() { //add winnings to player object addMoneyToBalance(currentPlayer, winnings); //show current balance - Green.println("Current Account Balance: $" + currentPlayer.getArcadeAccount().getAccountBalance()); - //Continue game? - Integer userInput = input.getIntegerInput("Would you like to play again?\n" + - "1. Yes 2. No"); - if(userInput.equals(2)){ + Green.println("Current Account Balance: $" + getPlayerBalance()); + if(getPlayerBalance() == 0) { + Red.println("Oh No! You've ran out of money. Goodbye"); quitGame = true; + } else { + //Continue game? + Integer userInput = input.getIntegerInput("Would you like to play again?\n" + + "1. Yes 2. No"); + if(userInput.equals(2)){ + quitGame = true; + } } - } } - public void printWelcome() { - Yellow.println( - "***********************************\n" + + public String printWelcome() { + return "***********************************\n" + "*** ***\n" + "****** WELCOME TO SLOTS ******\n" + "*** ***\n" + - "***********************************"); + "***********************************"; + } + public Integer getPlayerBalance(){ + return currentPlayer.getArcadeAccount().getAccountBalance(); + } public void getBetAmount() { - Scanner scanner = new Scanner(System.in); - Purple.println("How much you do want to bet?"); - playerBetAmount = scanner.nextInt(); + playerBetAmount = Purple.getIntegerInput("How much you do want to bet?"); + } + + public void calculateTotalCost(){ + numberOfLines = Blue.getIntegerInput("How many lines do you want to bet on?"); + betTotal = playerBetAmount * numberOfLines; + Red.println("Total cost to play: " + betTotal); } public Integer[] getBetSelections() { - Scanner scanner = new Scanner(System.in); - Blue.println("How many lines do you want to bet on?"); - Integer numberOfLines = scanner.nextInt(); - Integer totalCost = playerBetAmount * numberOfLines; - Red.println("Total cost to play: " + totalCost); - setBetTotal(totalCost); - - Cyan.println( - "************************************************************************\n" + - "** Select the lines you want to bet on! **\n" + - "** 1. Top Horizontal 2. Middle Horizontal 3. Bottom Horizontal **\n" + - "** 4. Left Vertical 5. Middle Vertical 6. Right Vertical **\n" + - "** 7. Down Diagonal 8. Up Diagonal **\n" + - "************************************************************************"); + Cyan.println(lineChoices()); int count = 0; Integer[] selectedLines = new Integer[numberOfLines]; while (count < numberOfLines){ - Blue.println("Select your line #" + (count + 1)); - selectedLines[count] = scanner.nextInt(); + Integer userInput; + userInput = Blue.getIntegerInput("Select your line #" + (count + 1)); + while(userInput <= (0) && userInput > 8){ + userInput = Red.getIntegerInput("Select a number between 1 and 8!"); + } + selectedLines[count] = userInput; count++; } return selectedLines; @@ -145,6 +149,15 @@ public Integer calculateReturnTotal(Integer winnings, Integer losings){ return this.betTotal + winnings - losings; } + public String lineChoices(){ + return "************************************************************************\n" + + "** Select the lines you want to bet on! **\n" + + "** 1. Top Horizontal 2. Middle Horizontal 3. Bottom Horizontal **\n" + + "** 4. Left Vertical 5. Middle Vertical 6. Right Vertical **\n" + + "** 7. Down Diagonal 8. Up Diagonal **\n" + + "************************************************************************"; + } + @Override public Integer calculateWinnings(Integer multiplier, Integer betAmount) { return multiplier * betAmount; @@ -173,4 +186,11 @@ public PlayerInterface getCurrentPlayer() { return currentPlayer; } + public void userBetCondition () { + while (betTotal > currentPlayer.getArcadeAccount().getAccountBalance()) { + Red.println("Oh no! You're trying to place a bet with more money than you have..."); + betTotal = Green.getIntegerInput("How much would you like to bet?\n"); + } + } + } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java index 02ef3b5f2..9d19c9cd9 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java @@ -19,6 +19,10 @@ public CasinoAccount getArcadeAccount() { @Override public void setArcadeAccount(CasinoAccount casinoAccount) { + this.player.setArcadeAccount(casinoAccount); + } + public PlayerInterface getPlayer() { + return this.player; } } \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/models/Card.java b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java index 518262854..ad640218f 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/models/Card.java +++ b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java @@ -41,7 +41,4 @@ public List getCardPool() { return cardPool; } - public void setCardPool(List cardPool) { - this.cardPool = cardPool; - } } diff --git a/src/main/java/com/github/zipcodewilmington/utils/CSVUtils.java b/src/main/java/com/github/zipcodewilmington/utils/CSVUtils.java index f941b0009..0ae8fb35a 100644 --- a/src/main/java/com/github/zipcodewilmington/utils/CSVUtils.java +++ b/src/main/java/com/github/zipcodewilmington/utils/CSVUtils.java @@ -35,12 +35,16 @@ public static void csvFileSaver(CasinoAccount account) throws IOException { FileWriter writer = new FileWriter(csvFile); Integer nextId = 1; CSVUtils.writeLine(writer, new ArrayList(Arrays.asList(String.valueOf(nextId)))); - + Integer[] boards = account.getScoreboard().createCSVArray(); List list = new ArrayList<>(); list.add(account.getAccountName()); list.add(account.getPassword()); list.add(String.valueOf(account.getAccountBalance())); + //list.add(String.valueOf(account.getScoreboard())); + for(int i = 0; i < boards.length; i++){ + list.add(String.valueOf(boards[i])); + } CSVUtils.writeLine(writer, list); @@ -65,11 +69,17 @@ public static CasinoAccount loadData(){ String accountName = account[0]; String password = account[1]; String accountBalance = account[2]; - - + Scoreboard scoreboard = new Scoreboard(); + Integer count = 3; + for(int i = 0; i < 5; i++){ + scoreboard.getBoards()[i].addToLifetimeBets(Integer.parseInt(account[count])); + scoreboard.getBoards()[i].addToLifetimeWinnings(Integer.parseInt(account[count + 1])); + scoreboard.getBoards()[i].addToLifetimeLosses(Integer.parseInt(account[count + 2])); + count += 3; + } // (5) //inventory.add(new Sneaker(id, name, brand, sport, size, qty, price)); - CasinoAccount loadedAccount = new CasinoAccount(accountName, password); + CasinoAccount loadedAccount = new CasinoAccount(accountName, password, scoreboard); loadedAccount.alterAccountBalance(Integer.parseInt(accountBalance)); return loadedAccount; } diff --git a/src/main/java/com/github/zipcodewilmington/utils/DemoMain.java b/src/main/java/com/github/zipcodewilmington/utils/DemoMain.java deleted file mode 100644 index ba7c8a2d9..000000000 --- a/src/main/java/com/github/zipcodewilmington/utils/DemoMain.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.github.zipcodewilmington.utils; - -import com.github.zipcodewilmington.casino.games.blackjack.BlackJackGame; -import com.github.zipcodewilmington.casino.games.keno.KenoGame; -import com.github.zipcodewilmington.casino.games.plinko.PlinkoGame; - -public class DemoMain { - public static void main(String[] args) { - new BlackJackGame().run(); - } -} diff --git a/src/main/java/com/github/zipcodewilmington/utils/GameScoreBoard.java b/src/main/java/com/github/zipcodewilmington/utils/GameScoreBoard.java new file mode 100644 index 000000000..04b54a3e0 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/utils/GameScoreBoard.java @@ -0,0 +1,51 @@ +package com.github.zipcodewilmington.utils; + +import com.github.zipcodewilmington.casino.GameScoreboardInterface; + +public class GameScoreBoard implements GameScoreboardInterface { + private Integer lifetimeBets = 0; + private Integer lifetimeWinnings = 0; + private Integer lifetimeLosses = 0; + private String gameName; + + public GameScoreBoard(String name){ + this.gameName = name; + } + + public Integer getLifetimeBets() { + return lifetimeBets; + } + + + public void addToLifetimeBets(Integer betAmt) { + this.lifetimeBets += betAmt; + } + + public Integer getLifetimeWinnings() { + return lifetimeWinnings; + } + + public void addToLifetimeWinnings(Integer winnings) { + this.lifetimeWinnings += winnings; + } + + public Integer getLifetimeLosses() { + return lifetimeLosses; + } + + public void addToLifetimeLosses(Integer losses) { + this.lifetimeLosses += losses; + } + + public String getGameName(){ return this.gameName; } + + public String printScores(){ + String output = ""; + output += this.getGameName(); + output += "\nBet :$" + this.getLifetimeBets(); + output += "\nWon :$" + this.getLifetimeWinnings(); + output += "\nLost :$" + this.getLifetimeLosses(); + + return output; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java b/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java index b855d24db..32330c400 100644 --- a/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java +++ b/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java @@ -3,6 +3,7 @@ import java.io.InputStream; import java.io.PrintStream; import java.util.Scanner; +import java.util.concurrent.TimeUnit; /** * @author leonhunter @@ -36,6 +37,15 @@ public void println(String val, Object... vals) { print(val + "\n", vals); } + public void setWait(int milliseconds){ + try { + TimeUnit.MILLISECONDS.sleep(milliseconds); + } catch (InterruptedException e) { + e.printStackTrace(); + this.println("Wait unsuccessful, refer to error message"); + } + } + public String getStringInput(String prompt, Object... args) { println(prompt, args); return input.nextLine(); diff --git a/src/main/java/com/github/zipcodewilmington/utils/Scoreboard.java b/src/main/java/com/github/zipcodewilmington/utils/Scoreboard.java new file mode 100644 index 000000000..a3f2e706d --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/utils/Scoreboard.java @@ -0,0 +1,110 @@ +package com.github.zipcodewilmington.utils; + + +import com.github.zipcodewilmington.casino.GameScoreboardInterface; + +import java.util.ArrayList; +import java.util.List; + +public class Scoreboard { + private GameScoreBoard blackjackScores = new GameScoreBoard("Blackjack"); + private GameScoreBoard beetleScores = new GameScoreBoard("Beetle"); + private GameScoreBoard numberGuessScores = new GameScoreBoard("Number Guess"); + private GameScoreBoard kenoScores = new GameScoreBoard("Keno"); + private GameScoreBoard plinkoScores = new GameScoreBoard("Plinko"); + private GameScoreboardInterface[] boards = new GameScoreboardInterface[5]; + + public Scoreboard(){ + this.boards[0] = beetleScores; + this.boards[1] = blackjackScores; + this.boards[2] = kenoScores; + this.boards[3] = numberGuessScores; + this.boards[4] = plinkoScores; + } + + + public GameScoreBoard getBlackJackScores() { + return blackjackScores; + } + + public GameScoreBoard getBeetleScores() { + return beetleScores; + } + + public GameScoreBoard getNumberGuessScores() { + return numberGuessScores; + } + + public GameScoreBoard getKenoScores() { + return kenoScores; + } + + public GameScoreBoard getPlinkoScores() { + return plinkoScores; + } + + public Integer lifetimeBets(){ + Integer totalBets = 0; + totalBets += this.getPlinkoScores().getLifetimeBets(); + totalBets += this.getBeetleScores().getLifetimeBets(); + totalBets += this.getKenoScores().getLifetimeBets(); + totalBets += this.getBlackJackScores().getLifetimeBets(); + totalBets += this.getNumberGuessScores().getLifetimeBets(); + return totalBets; + } + + public Integer lifetimeWinnings(){ + Integer totalBets = 0; + totalBets += this.getPlinkoScores().getLifetimeWinnings(); + totalBets += this.getBeetleScores().getLifetimeWinnings(); + totalBets += this.getKenoScores().getLifetimeWinnings(); + totalBets += this.getBlackJackScores().getLifetimeWinnings(); + totalBets += this.getNumberGuessScores().getLifetimeWinnings(); + return totalBets; + } + + public Integer lifetimeLosses(){ + Integer totalBets = 0; + totalBets += this.getPlinkoScores().getLifetimeLosses(); + totalBets += this.getBeetleScores().getLifetimeLosses(); + totalBets += this.getKenoScores().getLifetimeLosses(); + totalBets += this.getBlackJackScores().getLifetimeLosses(); + totalBets += this.getNumberGuessScores().getLifetimeLosses(); + return totalBets; + } + + public Integer[] createCSVArray(){ + List results = new ArrayList<>(); + + for(int i = 0; i < boards.length; i++){ + results.add(boards[i].getLifetimeBets()); + results.add(boards[i].getLifetimeWinnings()); + results.add(boards[i].getLifetimeLosses()); + } + return results.toArray(new Integer[0]); + } + + public GameScoreboardInterface[] getBoards() { + return boards; + } + + public String lifetimeStats(){ + String output = "Lifetime Stats"; + output += "\nBet :$" + this.lifetimeBets(); + output += "\nWon :$" + this.lifetimeWinnings(); + output += "\nLoss :$" + this.lifetimeLosses(); + + return output; + } + + public String printAllScores(){ + String output = this.lifetimeStats() + "\n\n"; + + for(int i = 0; i < this.boards.length; i++){ + output += boards[i].printScores() + "\n\n"; + } + + return output; + } + +} diff --git a/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java b/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java index a9af8209a..4b9fc35dc 100644 --- a/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java +++ b/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java @@ -13,7 +13,7 @@ public void test() { // TODO - replace boiler-plate logic with business logic Runnable runnable = new Casino(); // when - runnable.run(); + // then Assert.assertNotNull(runnable.toString()); diff --git a/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java index 76347be74..b8ab068be 100644 --- a/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java @@ -49,30 +49,6 @@ public void removeTest(){ } -// @Test -// public void runTest(){ -// BeetleGame beetleGame = new BeetleGame(); -// beetleGame.setDemo(true); -// beetleGame.run(); -// Integer actual = beetleGame.getBetAmt(); -// Integer expected = null; -// -// Assert.assertEquals(actual, expected); -// } -// -// @Test -// public void printBeetleCards(){ -// BeetleGame beetleGame = new BeetleGame(); -// String expected = "\u001B[32mYour last dice roll: 0 Your Beetle: \n" + -// "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + -// "\u001B[32mDealer's last dice roll: 0 Dealer's Beetle: \n" + -// "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 "; -// String actual = beetleGame.printBeetleCards(); -// -// -// Assert.assertEquals(expected, actual); -// } - @Test public void isGameOverTest1(){ BeetleGame beetleGame = new BeetleGame(); @@ -94,7 +70,7 @@ public void isGameOverTest2(){ } @Test - public void determinePayout(){ + public void determinePayout1(){ BeetleGame beetleGame = new BeetleGame(); CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); PlayerInterface player = new Player("Bjork", account); @@ -108,6 +84,21 @@ public void determinePayout(){ Assert.assertTrue(actual); } + @Test + public void determinePayout2(){ + BeetleGame beetleGame = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + beetleGame.add(player); + player.getArcadeAccount().alterAccountBalance(500); + beetleGame.setBetAmt(200); + beetleGame.getGame().setCurrentPlayer(1); + beetleGame.determinePayout(); + Boolean actual = player.getArcadeAccount().getAccountBalance() == 500; + + Assert.assertTrue(actual); + } + @Test public void calculateWinningsTest(){ BeetleGame beetleGame = new BeetleGame(); @@ -173,29 +164,104 @@ public void getDemoTest(){ } @Test - public void runTest(){ + public void printEndingGameMessage(){ BeetleGame beetleGame = new BeetleGame(); - beetleGame.setDemo(true); - beetleGame.run(); - Integer actual = beetleGame.getBetAmt(); - Integer expected = null; + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + beetleGame.add(player); + beetleGame.setBetAmt(100); + String actual = beetleGame.printEndingGameMessage(); + String expected = "\nFinal Beetle results: \n" + + "\u001B[32mYour last dice roll: 0 Your Beetle: \n" + + "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + + "\u001B[32mDealer's last dice roll: 0 Dealer's Beetle: \n" + + "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + + "You win!You win!"; + Assert.assertEquals(actual, expected); + } + + @Test + public void printEndingGameMessage2(){ + BeetleGame beetleGame = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + beetleGame.add(player); + beetleGame.setBetAmt(100); + beetleGame.getGame().setCurrentPlayer(1); + String actual = beetleGame.printEndingGameMessage(); + String expected = "\nFinal Beetle results: \n" + + "\u001B[32mYour last dice roll: 0 Your Beetle: \n" + + "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + + "\u001B[32mDealer's last dice roll: 0 Dealer's Beetle: \n" + + "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + + "Dealer wins...Dealer wins..."; + Assert.assertEquals(actual, expected); + } + @Test + public void printNextTurnMessage(){ + BeetleGame beetleGame = new BeetleGame(); + + String actual = beetleGame.printNextTurnMessage(); + String expected = + "\u001B[32mYour last dice roll: 0 Your Beetle: \n" + + "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + + "\u001B[32mDealer's last dice roll: 0 Dealer's Beetle: \n" + + "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + + "Press enter to roll next dice"; + System.out.println(actual); Assert.assertEquals(actual, expected); } @Test - public void printBeetleCards(){ + public void setDemoTest(){ BeetleGame beetleGame = new BeetleGame(); - String expected = "\u001B[32mYour last dice roll: 0 Your Beetle: \n" + - "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + - "\u001B[32mDealer's last dice roll: 0 Dealer's Beetle: \n" + - "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 "; - String actual = beetleGame.printBeetleCards(); + beetleGame.setDemo(true); + Boolean actual = beetleGame.getDemo(); + + Assert.assertTrue(actual); + } + + @Test + public void getBetTest(){ + BeetleGame game = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + game.add(player); + game.setBetAmt(100); + + Integer expected = 100; + Integer actual = game.getBetAmt(); Assert.assertEquals(expected, actual); } + @Test + public void printBalanceAndBetTextTest(){ + BeetleGame game = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + game.add(player); + game.setBetAmt(100); + String actual = game.printBalanceAndBetText(); + String expected = "\u001B[35m Current account balance: " + player.getArcadeAccount().getAccountBalance(); + + Assert.assertEquals(expected, actual); + } + @Test + public void nextPlayerTest(){ + BeetleGame game = new BeetleGame(); + + game.nextPlayer(); + + Integer expected = 1; + Integer actual = game.getGame().getCurrentPlayer(); + + Assert.assertEquals(expected, actual); + } } diff --git a/src/test/java/com/github/zipcodewilmington/BeetlePlayerTest.java b/src/test/java/com/github/zipcodewilmington/BeetlePlayerTest.java new file mode 100644 index 000000000..663f8b44a --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BeetlePlayerTest.java @@ -0,0 +1,49 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.Beetle.BeetlePlayer; +import org.junit.Assert; +import org.junit.Test; + +public class BeetlePlayerTest { + + @Test + public void constructorTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + BeetlePlayer beetlePlayer = new BeetlePlayer(player); + + PlayerInterface expected = player; + PlayerInterface actual = beetlePlayer.getPlayer(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getArcadeAccountTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + BeetlePlayer beetlePlayer = new BeetlePlayer(player); + + CasinoAccount actual = beetlePlayer.getArcadeAccount(); + CasinoAccount expected = account; + + Assert.assertEquals(actual, expected); + } + + @Test + public void setArcadeAccountTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + BeetlePlayer beetlePlayer = new BeetlePlayer(player); + beetlePlayer.setArcadeAccount(account); + + CasinoAccount actual = beetlePlayer.getArcadeAccount(); + CasinoAccount expected = account; + + Assert.assertEquals(actual, expected); + + } +} diff --git a/src/test/java/com/github/zipcodewilmington/BeetleTest.java b/src/test/java/com/github/zipcodewilmington/BeetleTest.java index e841f6104..bbcc30aa8 100644 --- a/src/test/java/com/github/zipcodewilmington/BeetleTest.java +++ b/src/test/java/com/github/zipcodewilmington/BeetleTest.java @@ -143,7 +143,7 @@ public void nextPlayerTest2(){ @Test public void printBeetleTest1(){ Beetle beetle = new Beetle(2); - String expected = "Body:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 "; + String expected = "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 "; String actual = beetle.printBeetle(0); Assert.assertEquals(expected, actual); diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java index f6a0abe78..da555e3f0 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java @@ -1,21 +1,22 @@ package com.github.zipcodewilmington; +import com.github.zipcodewilmington.casino.CasinoAccount; import com.github.zipcodewilmington.casino.Player; import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.Beetle.BeetleGame; import com.github.zipcodewilmington.casino.games.blackjack.BlackJack; import com.github.zipcodewilmington.casino.games.blackjack.BlackJackGame; +import com.github.zipcodewilmington.casino.games.blackjack.BlackJackPlayer; import org.junit.Assert; import org.junit.Test; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class BlackJackGameTest { - @Test - public void runTest () { - //Player player = new Player("Roger", 5000); - } + public void startGameTest () { BlackJack bj = new BlackJack(); BlackJackGame blackJackGame = new BlackJackGame(); @@ -49,9 +50,227 @@ public void calculateWinningsTest () { // Assert.assertEquals(expected, actual); // } + @Test + public void subtractTest() { + BlackJackGame bj = new BlackJackGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + bj.add(player); + player.getArcadeAccount().alterAccountBalance(200 * -1); + Integer expected = 300; + Integer actual = player.getArcadeAccount().getAccountBalance(); + Assert.assertEquals(expected, actual); + } + + + @Test + public void runTest () { + BlackJackGame bj = new BlackJackGame(); + bj.setRunning(true); + bj.run(); + + Integer actual = bj.getUserBet(); + Integer expected = null; + + Assert.assertEquals(expected, actual); + } + + @Test + public void printWelcomeTest () { + BlackJackGame bj = new BlackJackGame(); + bj.setRunning(true); + bj.run(); + + System.out.println("============================================================" + "\n" + + "===== =====" + "\n" + + "===== WELCOME =====" + "\n" + + "===== TO =====" + "\n" + + "===== B L A C K =====" + "\n" + + "===== J A C K =====" + "\n" + + "===== =====" + "\n" + + "============================================================"); + } + + @Test + public void getRunningTest () { + BlackJackGame bj = new BlackJackGame(); + boolean expected = false; + boolean actual = bj.getRunning(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void removePlayerTest () { + BlackJackGame bj = new BlackJackGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + + bj.add(player); + bj.remove(player); + Boolean expected = false; + Boolean actual = bj.getPlayer() != null; + + Assert.assertEquals(expected, actual); + } + + @Test + public void startGameTest2(){ + BlackJackGame bj = new BlackJackGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + List playersHand = new ArrayList<>(); + playersHand.add(9); + playersHand.add(9); + bj.setGame(); + BlackJack game = bj.getGame(); + game.setPlayersHand(playersHand); + bj.setDemo(true); + bj.startGame(); + + Assert.assertNotNull(bj); + } + + @Test + public void startGameTest3(){ + BlackJackGame bj = new BlackJackGame(); + List playersHand = new ArrayList<>(); + playersHand.add(11); + playersHand.add(10); + bj.setGame(); + BlackJack game = bj.getGame(); + game.setPlayersHand(playersHand); + bj.setUserBet(100); + Boolean actual = bj.twoCardBlackJack(); + + Assert.assertTrue(actual); + } + + @Test + public void getDemoTest(){ + BlackJackGame bj = new BlackJackGame(); + bj.setDemo(true); + Boolean actual = bj.getDemo(); + + Assert.assertTrue(actual); + } + + @Test + public void addMoneyToBalanceTest(){ + BlackJackGame bj = new BlackJackGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.setArcadeAccount(account); + + bj.addMoneyToBalance(player, 100); + + Integer expected = 100; + Integer actual = player.getArcadeAccount().getAccountBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void subtractMoneyFromBalanceTest(){ + BlackJackGame bj = new BlackJackGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.setArcadeAccount(account); + + bj.add(player); + + bj.addMoneyToBalance(player, 100); + bj.subtractBetFromBalance(50); + Integer expected = 50; + Integer actual = player.getArcadeAccount().getAccountBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void playerHitsBlackJackTest(){ + BlackJackGame bj = new BlackJackGame(); + List playersHand = new ArrayList<>(); + playersHand.add(11); + playersHand.add(10); + bj.setGame(); + BlackJack game = bj.getGame(); + game.setPlayersHand(playersHand); + bj.setUserBet(100); + Boolean actual = bj.playerHitsBlackJack(); + + Assert.assertTrue(actual); + } + + @Test + public void playerHitsBlackJackTest2(){ + BlackJackGame bj = new BlackJackGame(); + List playersHand = new ArrayList<>(); + playersHand.add(10); + playersHand.add(10); + bj.setGame(); + BlackJack game = bj.getGame(); + game.setPlayersHand(playersHand); + bj.setUserBet(100); + Boolean actual = bj.playerHitsBlackJack(); + + Assert.assertFalse(actual); + } + + @Test + public void splitPlayerHitsBlackJackTest () { + BlackJackGame bj = new BlackJackGame(); + List playersHand = new ArrayList<>(); + playersHand.add(10); + playersHand.add(10); + bj.setGame(); + BlackJack game = bj.getGame(); + game.setPlayersHand(playersHand); + bj.setUserBet(100); + Boolean actual = bj.splitPlayerHitsBlackJack(); + + Assert.assertFalse(actual); + + } + + @Test + public void splitPlayerHitsBlackJackTest2 () { + BlackJackGame bj = new BlackJackGame(); + List playersHand = new ArrayList<>(); + playersHand.add(11); + playersHand.add(9); + playersHand.add(1); + bj.setGame(); + BlackJack game = bj.getGame(); + game.setPlayersHandOnSplit(playersHand); + game.setPlayersHand(playersHand); + bj.setUserBet(100); + bj.setSplitBet(100); + Boolean actual = bj.splitPlayerHitsBlackJack(); + + Assert.assertTrue(actual); + } @Test - public void splitPlayerHitsBlackJack () { - + public void splitPlayerBustHasAces () { + BlackJackGame bj = new BlackJackGame(); + List playersHand = new ArrayList<>(); + playersHand.add(10); + playersHand.add(10); + playersHand.add(11); + bj.setGame(); + BlackJack game = bj.getGame(); + game.setPlayersHandOnSplit(playersHand); + game.setPlayersHand(playersHand); + bj.setUserBet(100); + bj.setSplitBet(100); + bj.playerBustButHasAces(); + Integer expected = 21; + Integer actual = 0; + for (int i = 0; i < game.getPlayersHandOnSplit().size(); i++) { + actual += game.getPlayersHandOnSplit().get(i); + } + Assert.assertEquals(actual, expected); } } diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackPlayerTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackPlayerTest.java index c6c2a7651..5893955ef 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackPlayerTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackPlayerTest.java @@ -1,18 +1,50 @@ package com.github.zipcodewilmington; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.blackjack.BlackJack; import com.github.zipcodewilmington.casino.games.blackjack.BlackJackPlayer; +import org.junit.Assert; import org.junit.Test; public class BlackJackPlayerTest { @Test - public void blackJackPlayerTest () { + public void constructorTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + BlackJackPlayer bj = new BlackJackPlayer(player); + PlayerInterface expected = player; + PlayerInterface actual = bj.getPlayer(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getArcadeAccountTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + BlackJackPlayer bj = new BlackJackPlayer(player); + + CasinoAccount actual = bj.getArcadeAccount(); + CasinoAccount expected = account; + + Assert.assertEquals(actual, expected); } @Test - public void getArcadeAccountTest () { + public void setArcadeAccountTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + BlackJackPlayer bj = new BlackJackPlayer(player); + bj.setArcadeAccount(account); + + CasinoAccount actual = bj.getArcadeAccount(); + CasinoAccount expected = account; + + Assert.assertEquals(actual, expected); } } diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackTest.java index 0442d1fe1..4aca05301 100644 --- a/src/test/java/com/github/zipcodewilmington/BlackJackTest.java +++ b/src/test/java/com/github/zipcodewilmington/BlackJackTest.java @@ -4,6 +4,8 @@ import org.junit.Assert; import org.junit.Test; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class BlackJackTest { @@ -95,4 +97,82 @@ public void splitPlayersCurrentValueTest () { Assert.assertEquals(expected, actual); } + + @Test + public void setPlayersHandTest(){ + BlackJack bj = new BlackJack(); + List playersHand = new ArrayList<>(); + + playersHand.add(10); + bj.setPlayersHand(playersHand); + List actual = bj.getPlayersHand(); + + Assert.assertArrayEquals(playersHand.toArray(new Integer[0]), actual.toArray(new Integer[0])); + } + + @Test + public void setDealersHandTest(){ + BlackJack bj = new BlackJack(); + List playersHand = new ArrayList<>(); + + playersHand.add(10); + bj.setDealersHand(playersHand); + List actual = bj.getDealersHand(); + + Assert.assertArrayEquals(playersHand.toArray(new Integer[0]), actual.toArray(new Integer[0])); + } + + @Test + public void setPlayersHandOnSplitTest(){ + BlackJack bj = new BlackJack(); + List playersHand = new ArrayList<>(); + playersHand.add(11); + playersHand.add(11); + bj.setPlayersHandOnSplit(playersHand); + Integer actual = bj.getPlayersHandOnSplit().size(); + Integer expected = 2; + + Assert.assertEquals(actual, expected); + } + + @Test + public void playerBreaks21Test1(){ + BlackJack bj = new BlackJack(); + List playersHand = new ArrayList<>(); + playersHand.add(11); + playersHand.add(9); + playersHand.add(9); + + bj.setPlayersHand(playersHand); + Boolean actual = bj.playerBreaks21(); + Boolean expected = true; + Assert.assertEquals(expected, actual); + } + + @Test + public void playerBreaks21Test2(){ + BlackJack bj = new BlackJack(); + List playersHand = new ArrayList<>(); + playersHand.add(9); + playersHand.add(9); + + bj.setPlayersHand(playersHand); + Boolean actual = bj.playerBreaks21(); + Boolean expected = false; + Assert.assertEquals(expected, actual); + } + + @Test + public void dealersCurrentValueTest2(){ + BlackJack bj = new BlackJack(); + List dealersHand = new ArrayList<>(); + + dealersHand.add(10); + bj.setDealersHand(dealersHand); + + Integer expected = 10; + Integer actual = bj.dealersCurrentValue(); + + Assert.assertEquals(expected, actual); + } } diff --git a/src/test/java/com/github/zipcodewilmington/CSVUtilsTest.java b/src/test/java/com/github/zipcodewilmington/CSVUtilsTest.java new file mode 100644 index 000000000..3071a7be9 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/CSVUtilsTest.java @@ -0,0 +1,37 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.utils.CSVUtils; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; + + +public class CSVUtilsTest { + + @Test + public void csvSaveTest(){ + Boolean actual = true; + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + //PlayerInterface player = new Player("Bjork", account); + account.alterAccountBalance(400); + try { + CSVUtils.csvFileSaver(account); + } catch (IOException e) { + actual = false; + } + + Assert.assertTrue(actual); + } + + @Test + public void csvLoadTest(){ + CasinoAccount actual = CSVUtils.loadData(); + + Assert.assertNotNull(actual); + } +} + diff --git a/src/test/java/com/github/zipcodewilmington/CasinoAccountManagerTest.java b/src/test/java/com/github/zipcodewilmington/CasinoAccountManagerTest.java new file mode 100644 index 000000000..30c128d72 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/CasinoAccountManagerTest.java @@ -0,0 +1,37 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.CasinoAccountManager; +import org.junit.Assert; +import org.junit.Test; + +public class CasinoAccountManagerTest { + + @Test + public void createAccountTest(){ + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("zz", "ss"); + + Assert.assertNotNull(account); + } + + @Test + public void registerAndGetAccountTest(){ + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("zz", "ss"); + cam.registerAccount(account); + + CasinoAccount actual = cam.getAccount("zz", "ss"); + Assert.assertNotNull(actual); + } + + @Test + public void getAccountTest(){ + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("zz", "ss"); + cam.registerAccount(account); + + CasinoAccount actual = cam.getAccount("z2", "ss"); + Assert.assertNull(actual); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/DiceTest.java b/src/test/java/com/github/zipcodewilmington/DiceTest.java index 357497dd4..8bbd0709b 100644 --- a/src/test/java/com/github/zipcodewilmington/DiceTest.java +++ b/src/test/java/com/github/zipcodewilmington/DiceTest.java @@ -26,7 +26,7 @@ public void diceConstructorTest2() { @Test public void diceConstructorTest3() { Dice dice = new Dice(3); - Integer expected = 14; + Integer expected = 15; Integer actual = dice.getMaxBinIndex(); Assert.assertEquals(expected, actual); @@ -44,7 +44,7 @@ public void diceConstructorTest4() { @Test public void diceConstructorTest5() { Dice dice = new Dice(2); - Integer expected = 10; + Integer expected = 11; Integer actual = dice.getBins().length; Assert.assertEquals(expected, actual); @@ -62,7 +62,7 @@ public void diceConstructorTest6() { @Test public void diceConstructorTest7(){ Dice dice = new Dice(2); - Integer[] expected = {0,0,0,0,0,0,0,0,0}; + Integer[] expected = {0,0,0,0,0,0,0,0,0,0,0}; Integer[] actual = dice.getBins(); Assert.assertArrayEquals(expected, actual); @@ -74,7 +74,7 @@ public void getBinQuantityTest(){ dice.tossAndSum(); Integer[] bins = dice.getBins(); Integer actual = 0; - for(int i = 2; i < dice.getMaxBinIndex(); i++){ + for(int i = 2; i <= dice.getMaxBinIndex(); i++){ if(dice.getBin(i) > 0){ actual = dice.getBin(i); break; diff --git a/src/test/java/com/github/zipcodewilmington/GameScoreBoardTest.java b/src/test/java/com/github/zipcodewilmington/GameScoreBoardTest.java new file mode 100644 index 000000000..f835b71b3 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/GameScoreBoardTest.java @@ -0,0 +1,157 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.GameScoreboardInterface; +import com.github.zipcodewilmington.utils.GameScoreBoard; +import com.github.zipcodewilmington.utils.Scoreboard; +import org.junit.Assert; +import org.junit.Test; + +public class GameScoreBoardTest { + + @Test + public void constructorTest(){ + Scoreboard scoreboard = new Scoreboard(); + GameScoreboardInterface[] boards = new GameScoreboardInterface[5]; + boards[0] = scoreboard.getBeetleScores(); + boards[1] = scoreboard.getBlackJackScores(); + boards[2] = scoreboard.getNumberGuessScores(); + boards[3] = scoreboard.getKenoScores(); + boards[4] = scoreboard.getPlinkoScores(); + Boolean isScoreboard = false; + + for(int i = 0; i < boards.length; i++){ + if(boards[i] instanceof GameScoreboardInterface){ + isScoreboard = true; + } else { + isScoreboard = false; + break; + } + } + + Assert.assertTrue(isScoreboard); + } + + @Test + public void lifetimeBetsTest(){ + Scoreboard scoreboard = new Scoreboard(); + scoreboard.getPlinkoScores().addToLifetimeBets(100); + + Integer actual = scoreboard.getPlinkoScores().getLifetimeBets(); + Integer expected = 100; + + Assert.assertEquals(expected, actual); + } + + @Test + public void lifetimeWinningsTest(){ + Scoreboard scoreboard = new Scoreboard(); + scoreboard.getPlinkoScores().addToLifetimeWinnings(400); + + Integer actual = scoreboard.getPlinkoScores().getLifetimeWinnings(); + Integer expected = 400; + + Assert.assertEquals(expected, actual); + } + + @Test + public void lifetimeLossesTest(){ + Scoreboard scoreboard = new Scoreboard(); + scoreboard.getPlinkoScores().addToLifetimeLosses(400); + + Integer actual = scoreboard.getPlinkoScores().getLifetimeLosses(); + Integer expected = 400; + + Assert.assertEquals(expected, actual); + } + + @Test + public void scoreboardLifetimeBets(){ + Scoreboard scoreboard = new Scoreboard(); + scoreboard.getPlinkoScores().addToLifetimeBets(300); + + Integer actual = scoreboard.lifetimeBets(); + Integer expected = 300; + + Assert.assertEquals(expected, actual); + } + + @Test + public void scoreboardLifetimeWinnings(){ + Scoreboard scoreboard = new Scoreboard(); + scoreboard.getPlinkoScores().addToLifetimeWinnings(300); + + Integer actual = scoreboard.lifetimeWinnings(); + Integer expected = 300; + + Assert.assertEquals(expected, actual); + } + + @Test + public void scoreboardLifetimeLosses(){ + Scoreboard scoreboard = new Scoreboard(); + scoreboard.getPlinkoScores().addToLifetimeLosses(300); + + Integer actual = scoreboard.lifetimeLosses(); + Integer expected = 300; + + Assert.assertEquals(expected, actual); + } + + @Test + public void scoreboardCSVArrayTest(){ + Scoreboard scoreboard = new Scoreboard(); + Integer[] expected = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}; + Integer[] actual = scoreboard.createCSVArray(); + + Assert.assertArrayEquals(expected, actual); + } + + @Test + public void getBoardsTest(){ + Scoreboard scoreboard = new Scoreboard(); + + GameScoreboardInterface[] boards = scoreboard.getBoards(); + Boolean actual = boards[0] instanceof GameScoreboardInterface; + + Assert.assertTrue(actual); + } + + @Test + public void printScoreTest(){ + Scoreboard scoreboard = new Scoreboard(); + + String actual = scoreboard.printAllScores(); + String expected = "Lifetime Stats\n" + + "Bet :$0\n" + + "Won :$0\n" + + "Loss :$0\n" + + "\n" + + "Beetle\n" + + "Bet :$0\n" + + "Won :$0\n" + + "Lost :$0\n" + + "\n" + + "Blackjack\n" + + "Bet :$0\n" + + "Won :$0\n" + + "Lost :$0\n" + + "\n" + + "Keno\n" + + "Bet :$0\n" + + "Won :$0\n" + + "Lost :$0\n" + + "\n" + + "Number Guess\n" + + "Bet :$0\n" + + "Won :$0\n" + + "Lost :$0\n" + + "\n" + + "Plinko\n" + + "Bet :$0\n" + + "Won :$0\n" + + "Lost :$0\n\n"; + + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/KenoGameRETest.java b/src/test/java/com/github/zipcodewilmington/KenoGameRETest.java new file mode 100644 index 000000000..1f12b8573 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/KenoGameRETest.java @@ -0,0 +1,179 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.keno.KenoGameRE; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashSet; +import java.util.stream.Stream; + +public class KenoGameRETest { + + @Test + public void addPlayerTest(){ + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + keno.add(player1); + PlayerInterface retrievedPlayer = keno.getCurrentPlayer(); + Assert.assertEquals(player1,retrievedPlayer ); + } + + @Test + public void removePlayerTest() { + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + keno.remove(player1); + Assert.assertNull(keno.getCurrentPlayer()); + } + + @Test + public void printWelcome(){ + KenoGameRE keno = new KenoGameRE(); + String expected = "***********************************\n" + + "*** ***\n" + + "****** WELCOME TO KENO ******\n" + + "*** ***\n" + + "***********************************"; + String actual = keno.printWelcome(); + Assert.assertEquals(expected,actual); + } + + @Test + public void displayInstructions(){ + KenoGameRE keno = new KenoGameRE(); + String expected = "Pick 10 numbers between 1 and 80!\n" + + "The more numbers matched the more you win!"; + String actual = keno.displayInstruction(); + Assert.assertEquals(expected,actual); + } + + @Test + public void getPlayerBalance(){ + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + account.alterAccountBalance(100); + Player player1 = new Player(null, account); + keno.add(player1); + keno.setUserBet(20); + keno.subtractBetFromBalance(20); + Integer actual = player1.getArcadeAccount().getAccountBalance(); + Integer exp = 80; + Assert.assertEquals(exp,actual); + } + + @Test + public void twentyOneRandomNum(){ + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + account.alterAccountBalance(100); + Player player1 = new Player(null, account); + keno.add(player1); + keno.setTwentyOneRandom(keno.twentyOneRandomNum()); + Integer actual = keno.getTwentyOneRandom().size(); + Integer expected = 21; + Assert.assertEquals(expected,actual); + } + + @Test + public void findMatches(){ + KenoGameRE keno = new KenoGameRE(); + HashSet userChoices = new HashSet<>(); + Stream.of(1,2,3,4,5,6,7,8,9,10).forEach(e -> userChoices.add(e)); + HashSet twentyOne = new HashSet<>(); + Stream.of(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21).forEach(e -> twentyOne.add(e)); + + keno.setTenChoices(userChoices); + keno.setTwentyOneRandom(twentyOne); + keno.setMatches(keno.findMatches()); + + Assert.assertEquals(userChoices,keno.getMatches()); + } + + @Test + public void multiplier(){ + KenoGameRE keno = new KenoGameRE(); + HashSet matches = new HashSet<>(); + Stream.of(1,2,3,4,5,6,7,8,9,10).forEach(e -> matches.add(e)); + keno.setMatches(matches); + Integer actual = keno.calculateMultiplier(); + Integer expected = 10; + Assert.assertEquals(expected,actual); + } + + @Test + public void calculateWinning(){ + KenoGameRE keno = new KenoGameRE(); + Integer actual = keno.calculateWinnings(10, 5); + Integer exp = 50; + Assert.assertEquals(exp,actual); + } + + @Test + public void addMoneyToBalance(){ + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + keno.add(player1); + keno.addMoneyToBalance(player1,500); + Integer exp = 500; + Integer act = keno.getPlayerBalance(); + Assert.assertEquals(exp,act); + } + + @Test + public void playAgain(){ + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + keno.add(player1); + Boolean quit = keno.playAgain(); + Assert.assertTrue(quit); + } + + @Test + public void getWinningsTest(){ + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + keno.add(player1); + keno.setWinnings(100); + Integer actual = keno.getWinnings(); + Integer expected = 100; + + Assert.assertEquals(expected, actual); + } + + @Test + public void setMultiplierTest(){ + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + keno.add(player1); + keno.setMultiplier(10); + Integer actual = keno.getMultiplier(); + Integer expected = 10; + + Assert.assertEquals(expected, actual); + } + + @Test + public void getTenChoices(){ + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + keno.add(player1); + HashSet expected = new HashSet<>(); + expected.add(1); + keno.setTenChoices(expected); + HashSet actual = keno.getTenChoices(); + + + Assert.assertTrue(expected.equals(actual)); + } + +} diff --git a/src/test/java/com/github/zipcodewilmington/KenoGameTest.java b/src/test/java/com/github/zipcodewilmington/KenoGameTest.java deleted file mode 100644 index 83e949bbe..000000000 --- a/src/test/java/com/github/zipcodewilmington/KenoGameTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.github.zipcodewilmington; - -import com.github.zipcodewilmington.casino.games.keno.KenoGame; -import org.junit.Assert; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class KenoGameTest { - - - @Test - void testForIsUnique() { - //given - KenoGame kenoGame=new KenoGame(); - //when - Boolean boolVal=kenoGame.isUnique(7, new int[]{7, 7}); - //then - Assert.assertFalse(String.valueOf(boolVal),false); - } - - @Test - void testisUnique() { - //given - KenoGame kenoGame=new KenoGame(); - //when - Boolean boolVal=kenoGame.isUnique(7, new int[]{1, 7}); - //then - Assert.assertTrue(String.valueOf(boolVal),true); - } - - - @Test - - void testPayOut(){ - //given - int kenoSpot=11; - int kenoCatch=9; - KenoGame kenoGame=new KenoGame(); - //when - Integer expectedValue=kenoGame.payout(11,9,200); - //then - Assert.assertTrue(String.valueOf(expectedValue),true); - } - - -} \ No newline at end of file diff --git a/src/test/java/com/github/zipcodewilmington/KenoPlayerTest.java b/src/test/java/com/github/zipcodewilmington/KenoPlayerTest.java new file mode 100644 index 000000000..af86661ee --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/KenoPlayerTest.java @@ -0,0 +1,50 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.blackjack.BlackJackPlayer; +import com.github.zipcodewilmington.casino.games.keno.KenoPlayer; +import org.junit.Assert; +import org.junit.Test; + +public class KenoPlayerTest { + @Test + public void constructorTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + KenoPlayer keno = new KenoPlayer(player); + + PlayerInterface expected = player; + PlayerInterface actual = keno.getPlayer(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getArcadeAccountTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + KenoPlayer keno = new KenoPlayer(player); + + CasinoAccount actual = keno.getArcadeAccount(); + CasinoAccount expected = account; + + Assert.assertEquals(actual, expected); + } + + @Test + public void setArcadeAccountTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + KenoPlayer keno = new KenoPlayer(player); + keno.setArcadeAccount(account); + + CasinoAccount actual = keno.getArcadeAccount(); + CasinoAccount expected = account; + + Assert.assertEquals(actual, expected); + + } +} + diff --git a/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java b/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java index c6dfcc0c9..61ef03bb2 100644 --- a/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java +++ b/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java @@ -1,5 +1,7 @@ package com.github.zipcodewilmington; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessGame; import org.junit.Assert; import org.junit.Test; @@ -15,13 +17,75 @@ public void constructorTest1(){ } @Test - public void setMaxNumberTest(){ + public void printWelcomeTest(){ NumberGuessGame game = new NumberGuessGame(); - game.setMaxNumber(50); - Integer actual = game.getMaxNumber(); - Integer expected = 50; + String expected = "************************************\n" + + "*** ***\n" + + "****** !! WELCOME TO !! ******\n" + + "****** !!! GUESS NUMBER !!! ******\n" + + "*** ***\n" + + "************************************\n"; + String actual = game.printWelcome(); + Assert.assertEquals(expected, actual); + } - Assert.assertEquals(actual, expected); + @Test + public void printInstructions(){ + NumberGuessGame game = new NumberGuessGame(); + game.printInstructions(); + //check output + } + + @Test + public void subtractBetFromBalanceTest(){ + //given + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + NumberGuessGame game = new NumberGuessGame(); + game.add(player1); + Integer expected = 300; + //when + account.alterAccountBalance(500); + game.subtractBetFromBalance(200); + Integer actual = player1.getArcadeAccount().getAccountBalance(); + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void calcPotentialEarningsTest(){ + //given + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + NumberGuessGame game = new NumberGuessGame(); + game.setBetAmount(10); + Integer[] expected = {20,30,40,50}; + //when + game.calcPotentialEarnings(); + Integer[] actual = game.getPotentialEarnings(); + //then + Assert.assertArrayEquals(expected, actual); + } + + @Test + public void setMultiplierTest(){ + //given + NumberGuessGame game = new NumberGuessGame(); + game.setMultiplier(20); + Integer expected = 2; + Integer actual = game.getMultiplier(); + Assert.assertEquals(expected,actual); + } + + @Test + public void pickRandomNumber(){ + //given + NumberGuessGame game = new NumberGuessGame(); + game.pickRandomNumber(); + Integer first = game.getRandomNumber(); + game.pickRandomNumber(); + Integer second = game.getRandomNumber(); + Assert.assertNotEquals(first, second); } @Test @@ -31,10 +95,43 @@ public void getGuessRange(){ Integer actualNumber = 5; Integer actual = game.getGuessRange(guessedNumber, actualNumber); Integer expected = 25; + Assert.assertEquals(actual, expected); + } + + @Test + public void calculatePayoutTest(){ + //given + NumberGuessGame game = new NumberGuessGame(); + Integer expected = 50; + Integer actual = game.calculatePayout(5,0,10); + Assert.assertEquals(expected,actual); + } + + @Test + public void addMoneyToBalance(){ + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + NumberGuessGame game = new NumberGuessGame(); + game.add(player1); + game.addMoneyToBalance(player1,10); + + Integer expected = 10; + Integer actual = player1.getArcadeAccount().getAccountBalance(); + Assert.assertEquals(expected,actual); + } + + @Test + public void setMaxNumberTest(){ + NumberGuessGame game = new NumberGuessGame(); + game.setMaxNumber(50); + Integer actual = game.getMaxNumber(); + Integer expected = 50; Assert.assertEquals(actual, expected); } + + @Test public void getGuessPercentage(){ NumberGuessGame game = new NumberGuessGame(); diff --git a/src/test/java/com/github/zipcodewilmington/NumberGuessPlayerTest.java b/src/test/java/com/github/zipcodewilmington/NumberGuessPlayerTest.java new file mode 100644 index 000000000..b8e351275 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/NumberGuessPlayerTest.java @@ -0,0 +1,62 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessPlayer; +import org.junit.Assert; +import org.junit.Test; + +public class NumberGuessPlayerTest { + @Test + public void numberGuessPlayerTest(){ + //given + CasinoAccount account = new CasinoAccount("aaa", "bbb"); + PlayerInterface player = new Player("john",account); + NumberGuessPlayer gp = new NumberGuessPlayer(player); + //when + PlayerInterface expected = player; + PlayerInterface actual = gp.getPlayer(); + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void getArcadeAccountTest(){ + //given + CasinoAccount account = new CasinoAccount("aaa", "bbb"); + PlayerInterface player = new Player("john",account); + NumberGuessPlayer gp = new NumberGuessPlayer(player); + //when + CasinoAccount retrieved = gp.getArcadeAccount(); + //then + Assert.assertEquals(account, retrieved); + + } + + @Test + public void setArcadeAccountTest(){ + //given + CasinoAccount account = new CasinoAccount("aaa", "bbb"); + CasinoAccount account2 = new CasinoAccount("ddd", "eee"); + PlayerInterface player = new Player("john",account); + NumberGuessPlayer gp = new NumberGuessPlayer(player); + //when + gp.setArcadeAccount(account2); + CasinoAccount retrieved = gp.getArcadeAccount(); + //then + Assert.assertEquals(account2, retrieved); + } + + @Test + public void getPlayerTest(){ + //given + CasinoAccount account = new CasinoAccount("aaa", "bbb"); + PlayerInterface player = new Player("john",account); + NumberGuessPlayer gp = new NumberGuessPlayer(player); + //when + PlayerInterface retrieved = gp.getPlayer(); + //then + Assert.assertEquals(player, retrieved); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/PlayerTest.java b/src/test/java/com/github/zipcodewilmington/PlayerTest.java new file mode 100644 index 000000000..fd7200037 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/PlayerTest.java @@ -0,0 +1,68 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.Beetle.BeetlePlayer; +import org.junit.Assert; +import org.junit.Test; + +public class PlayerTest { + + @Test + public void constructorTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + + Assert.assertNotNull(player); + + } + + @Test + public void getNameTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + Player player = new Player("Bjork", account); + + String actual = player.getName(); + String expected = "Bjork"; + + Assert.assertEquals(actual, expected); + } + + @Test + public void setCurrentBetTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + Player player = new Player("Bjork", account); + player.setCurrentBet(200); + + Integer actual = player.getCurrentBet(); + Integer expected = 200; + Assert.assertEquals(actual, expected); + } + + @Test + public void setBalanceTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + Player player = new Player("Bjork", account); + player.setBalance(2000); + + Integer actual = player.getBalance(); + Integer expected = 2000; + + Assert.assertEquals(actual, expected); + } + + @Test + public void makeBetTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + Player player = new Player("Bjork", account); + player.setBalance(2000); + + player.makeBet(1000); + + Integer expected = 1000; + Integer actual = player.getCurrentBet(); + + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/PlinkoGameTest.java b/src/test/java/com/github/zipcodewilmington/PlinkoGameTest.java deleted file mode 100644 index dc5a777f6..000000000 --- a/src/test/java/com/github/zipcodewilmington/PlinkoGameTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.github.zipcodewilmington; - -import com.github.zipcodewilmington.casino.games.keno.KenoGame; -import com.github.zipcodewilmington.casino.games.plinko.PlinkoGame; -import org.junit.Assert; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class PlinkoGameTest { - - - - @Test - void getPlinkoSpotTest() { - //given - PlinkoGame plinkoGame=new PlinkoGame(); - //when - Integer expectedValue=plinkoGame.getPlinkoSpot(); - //then - Assert.assertFalse(String.valueOf(expectedValue),false); - } - - @Test - public void calculateWinningsTest() { - //given - PlinkoGame plinkoGame=new PlinkoGame(); - Integer expectedValue=plinkoGame.calculateWinnings(2,200); - //when - Integer actualValue=plinkoGame.calculateWinnings(2,200); - //then - Assert.assertEquals(expectedValue,actualValue); - } - -} \ No newline at end of file diff --git a/src/test/java/com/github/zipcodewilmington/PlinkoPlayerTest.java b/src/test/java/com/github/zipcodewilmington/PlinkoPlayerTest.java new file mode 100644 index 000000000..4a2c1eb49 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/PlinkoPlayerTest.java @@ -0,0 +1,38 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.games.plinko.PlinkoPlayer; +import org.junit.Assert; +import org.junit.Test; + +public class PlinkoPlayerTest { + + @Test + public void constructorTest(){ + CasinoAccount account = new CasinoAccount("zz", "ss"); + Player player = new Player("brep", account); + PlinkoPlayer plinkoPlayer = new PlinkoPlayer(player); + + Assert.assertNotNull(plinkoPlayer); + } + + @Test + public void getArcadeAccountTest(){ + CasinoAccount account = new CasinoAccount("zz", "ss"); + Player player = new Player("brep", account); + PlinkoPlayer plinkoPlayer = new PlinkoPlayer(player); + CasinoAccount playerAccount = plinkoPlayer.getArcadeAccount(); + Assert.assertEquals(account, playerAccount); + } + + @Test + public void setArcadeAccountTest(){ + CasinoAccount account = new CasinoAccount("zz", "ss"); + Player player = new Player("brep", account); + PlinkoPlayer plinkoPlayer = new PlinkoPlayer(player); + plinkoPlayer.setArcadeAccount(account); + CasinoAccount playerAccount = plinkoPlayer.getArcadeAccount(); + Assert.assertEquals(account, playerAccount); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/REPlinkoTest.java b/src/test/java/com/github/zipcodewilmington/REPlinkoTest.java new file mode 100644 index 000000000..80076ba32 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/REPlinkoTest.java @@ -0,0 +1,177 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.plinko.REPlinko; +import org.junit.Assert; +import org.junit.Test; + +public class REPlinkoTest { + + @Test + public void calculateWinningsTest () { + REPlinko game = new REPlinko(); + Integer expected = 12; + + Integer multiplier = 3; + Integer betAmount = 4; + Integer actual = game.calculateWinnings(multiplier, betAmount); + + Assert.assertEquals(expected,actual); + } + + @Test + public void subtractTest() { + REPlinko game = new REPlinko(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + game.add(player); + player.getArcadeAccount().alterAccountBalance(200 * -1); + Integer expected = 300; + Integer actual = player.getArcadeAccount().getAccountBalance(); + Assert.assertEquals(expected, actual); + } + + @Test + public void runTest () { + REPlinko game = new REPlinko(); + game.setRunning(true); + game.run(); + + Integer actual = game.getUserBet(); + Integer expected = null; + + Assert.assertEquals(expected, actual); + } + + @Test + public void getRunningTest () { + REPlinko game = new REPlinko(); + boolean expected = false; + boolean actual = game.getRunning(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void removePlayerTest () { + REPlinko game = new REPlinko(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + + game.add(player); + game.remove(player); + Boolean expected = false; + Boolean actual = game.getPlayerInt() != null; + + Assert.assertEquals(expected, actual); + } + + @Test + public void addPlayerTest () { + REPlinko game = new REPlinko(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + + game.add(player); + Boolean expected = true; + Boolean actual = game.getPlayerInt() != null; + + Assert.assertEquals(expected, actual); + } + + @Test + public void createBoardTest () { + REPlinko game = new REPlinko(); + Integer expected = 10; + + game.createBoard(); + Integer actual = game.winningValues.size(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void checkWinTest () { + REPlinko game = new REPlinko(); + Integer expected = 0; + + game.createBoard(); + Integer actual = game.checkWin(); + + Assert.assertEquals(expected, actual); + } + +// @Test +// public void startGameTest () { +// REPlinko game = new REPlinko(); +// Integer expected = 0; +// +// game.startGame(); +// Integer actual = game.calculateWinnings(game.checkWin(), 100); +// +// Assert.assertEquals(expected, actual); +// } + + @Test + public void shuffleTest () { + REPlinko game = new REPlinko(); + Boolean runner = false; + Integer actual = 5; + + game.createBoard(); + + while (!runner) { + game.shuffleBoard(); + Integer expected = game.winningValues.get(0); + if (expected == actual) { + runner = true; + } + } + Assert.assertTrue(runner); + } + + @Test + public void subtractMoneyTest () { + REPlinko game = new REPlinko(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + game.add(player); + game.subtractBetFromBalance(200); + Integer expected = 300; + Integer actual = player.getArcadeAccount().getAccountBalance(); + Assert.assertEquals(actual, expected); + } + + @Test + public void addingMoneyTest () { + REPlinko game = new REPlinko(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + game.add(player); + game.addMoneyToBalance(player,200); + Integer expected = 700; + Integer actual = player.getArcadeAccount().getAccountBalance(); + Assert.assertEquals(actual, expected); + } + + @Test + public void startGameTest(){ + REPlinko game = new REPlinko(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + game.setUserBet(100); + game.add(player); + game.startGame(); + + Integer expected = 10; + Integer actual = game.getWinningValues().size(); + + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/SlotsGameTest.java b/src/test/java/com/github/zipcodewilmington/SlotsGameTest.java index a251fb359..1f3617319 100644 --- a/src/test/java/com/github/zipcodewilmington/SlotsGameTest.java +++ b/src/test/java/com/github/zipcodewilmington/SlotsGameTest.java @@ -85,16 +85,6 @@ public void calculateReturnTotal(){ } - - @Test - public void printWelcomeTest(){ - //given - SlotsGame slotGame = new SlotsGame(); - //when - slotGame.printWelcome(); - //confirm with printout - } - @Test public void subtractBetFromBalanceTest(){ //given @@ -137,4 +127,96 @@ public void setBetTotal(){ // Assert.assertEquals(expected, retrieved); } + + @Test + public void lineChoiceTest(){ + //given + SlotsGame slotGame = new SlotsGame(); + String expected = "************************************************************************\n" + + "** Select the lines you want to bet on! **\n" + + "** 1. Top Horizontal 2. Middle Horizontal 3. Bottom Horizontal **\n" + + "** 4. Left Vertical 5. Middle Vertical 6. Right Vertical **\n" + + "** 7. Down Diagonal 8. Up Diagonal **\n" + + "************************************************************************"; + //when + String actual = slotGame.lineChoices(); + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void printWelcomeTest() { + //given + SlotsGame slotGame = new SlotsGame(); + String expected = + "***********************************\n" + + "*** ***\n" + + "****** WELCOME TO SLOTS ******\n" + + "*** ***\n" + + "***********************************"; + //when + String actual = slotGame.printWelcome(); + //then + Assert.assertEquals(expected,actual); + } + + @Test + public void add() { + } + + @Test + public void remove() { + } + + @Test + public void getLoseMultiplier() { + } + + @Test + public void getWinMultiplier() { + } + + @Test + public void run() { + } + + @Test + public void printWelcome() { + } + + @Test + public void getBetAmount() { + } + + @Test + public void getBetSelections() { + } + + @Test + public void calculateMultiplier() { + } + + @Test + public void lineChoices() { + } + + @Test + public void calculateWinnings() { + } + + @Test + public void subtractBetFromBalance() { + } + + @Test + public void addMoneyToBalance() { + } + + @Test + public void getBetTotal() { + } + + @Test + public void getCurrentPlayer() { + } } diff --git a/src/test/java/com/github/zipcodewilmington/SlotsPlayerTest.java b/src/test/java/com/github/zipcodewilmington/SlotsPlayerTest.java new file mode 100644 index 000000000..37ba06c7b --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/SlotsPlayerTest.java @@ -0,0 +1,64 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.slots.SlotsPlayer; +import org.junit.Assert; +import org.junit.Test; + +public class SlotsPlayerTest { + + @Test + public void constructorTest(){ + //given + CasinoAccount account = new CasinoAccount("aaa", "bbb"); + PlayerInterface player = new Player("john",account); + SlotsPlayer slotPlayer = new SlotsPlayer(player); + //when + PlayerInterface expected = player; + PlayerInterface actual = slotPlayer.getPlayer(); + //then + Assert.assertEquals(expected, actual); + + } + + @Test + public void getArcadeAccount() { + //given + CasinoAccount account = new CasinoAccount("aaa", "bbb"); + PlayerInterface player = new Player("john",account); + SlotsPlayer slotPlayer = new SlotsPlayer(player); + //when + CasinoAccount retrieved = slotPlayer.getArcadeAccount(); + //then + Assert.assertEquals(account, retrieved); + } + + @Test + public void setArcadeAccount() { + //given + CasinoAccount account = new CasinoAccount("aaa", "bbb"); + CasinoAccount account2 = new CasinoAccount("ddd", "eee"); + PlayerInterface player = new Player("john",account); + SlotsPlayer slotPlayer = new SlotsPlayer(player); + //when + slotPlayer.setArcadeAccount(account2); + CasinoAccount retrieved = slotPlayer.getArcadeAccount(); + //then + Assert.assertEquals(account2, retrieved); + + } + + @Test + public void getPlayer() { + //given + CasinoAccount account = new CasinoAccount("aaa", "bbb"); + PlayerInterface player = new Player("john",account); + SlotsPlayer slotPlayer = new SlotsPlayer(player); + //when + PlayerInterface retrieved = slotPlayer.getPlayer(); + //then + Assert.assertEquals(player, retrieved); + } +}