From b7bd1c0756162fb20321a2ed120a58ee4df6981e Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 12 Jul 2021 21:47:00 -0400 Subject: [PATCH 01/89] 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 02/89] 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 03/89] 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 04/89] 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 05/89] 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 06/89] 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 07/89] 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 08/89] 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 09/89] 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 10/89] 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 11/89] 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 12/89] 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 13/89] 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 14/89] 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 15/89] 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 16/89] 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 17/89] 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 18/89] 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 19/89] 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 20/89] 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 21/89] 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 22/89] 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 23/89] 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 24/89] 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 25/89] 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 26/89] 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 27/89] 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 28/89] 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 29/89] 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 30/89] 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 31/89] 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 32/89] 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 33/89] 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 34/89] 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 35/89] (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 36/89] 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 37/89] 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 38/89] (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 39/89] 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 40/89] 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 41/89] 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 42/89] 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 43/89] 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 44/89] (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 45/89] 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 46/89] 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 47/89] 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 48/89] 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 49/89] 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 50/89] 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 51/89] 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 52/89] 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 53/89] 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 54/89] 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 55/89] 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 56/89] 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 57/89] 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 58/89] (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 59/89] 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 60/89] 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 61/89] 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 62/89] 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 63/89] (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 64/89] 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 65/89] 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 66/89] 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 67/89] (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 68/89] 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 69/89] 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 70/89] (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 71/89] 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 72/89] 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 73/89] 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 74/89] (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 75/89] (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 76/89] 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 77/89] 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 78/89] 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 79/89] 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 80/89] 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 81/89] 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 82/89] 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 83/89] 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 84/89] 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 85/89] 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 86/89] (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 87/89] 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 cc93126c9e29cde8834448eefd1fe4938c1e8a04 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 15 Jul 2021 13:10:32 -0400 Subject: [PATCH 88/89] (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 89/89] 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)); - } -} -