From 4be46e184a328bc1e6670dfb32a04dca1916820d Mon Sep 17 00:00:00 2001 From: sgoudham Date: Sat, 17 Oct 2020 00:17:30 +0100 Subject: [PATCH] Just returning to avoid errors --- Personal/Cards/src/Sevens.java | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/Personal/Cards/src/Sevens.java b/Personal/Cards/src/Sevens.java index aee9317..3b50714 100644 --- a/Personal/Cards/src/Sevens.java +++ b/Personal/Cards/src/Sevens.java @@ -44,7 +44,7 @@ public class Sevens extends Deck { String[] splitCard = userCard.split(" "); if (splitCard.length != 2) - askPlayer(playerCounter, player, tableHand, in); + return new String[0]; return splitCard; } @@ -63,39 +63,38 @@ public class Sevens extends Deck { } Hand userSuitHand = tableHand.getSevensTableHand().get(userSuitInTableHand); - canBePlayed(cardToBePlayed, userSuitHand, userSuitInTableHand, tableHand, player); - - playACard(userSuitHand, cardToBePlayed, tableHand, userSuitInTableHand, player); } public void canBePlayed(Card cardToBePlayed, Hand userSuitHand, Suits userSuitInTableHand, TableHand tableHand, Player player) { - int minimumValueInUserSuitHand = userSuitHand.getListOfCards().get(0).getFace(); - int sizeOfUserSuitHand = userSuitHand.getListOfCards().size(); - int maximumValueInUserSuitHand = userSuitHand.getListOfCards().get(sizeOfUserSuitHand - 1).getFace(); - if (userSuitHand.getListOfCards().size() == 0) { if (cardToBePlayed.getFace() == 7) { - playACard(userSuitHand, cardToBePlayed, tableHand, userSuitInTableHand, player); + playACard(userSuitHand, cardToBePlayed, 0, tableHand, userSuitInTableHand, player); } else { System.out.println("Card Played Was Not A Face of 7 in Empty Suit! Try again!"); return; } } else { - if (cardToBePlayed.getFace() == (minimumValueInUserSuitHand - 1)) { + int minimumValueInUserSuitHand = userSuitHand.getListOfCards().get(0).getFace(); + int sizeOfUserSuitHand = userSuitHand.getListOfCards().size(); + int maximumValueInUserSuitHand = userSuitHand.getListOfCards().get(sizeOfUserSuitHand - 1).getFace(); + if (cardToBePlayed.getFace() == (minimumValueInUserSuitHand - 1)) { + playACard(userSuitHand, cardToBePlayed, 0, tableHand, userSuitInTableHand, player); + } else if (cardToBePlayed.getFace() == (maximumValueInUserSuitHand + 1)) { + playACard(userSuitHand, cardToBePlayed, sizeOfUserSuitHand, tableHand, userSuitInTableHand, player); } } } - public void playACard(Hand userSuitHand, Card playingCard, TableHand tableHand, Suits userSuitInTableHand, - Player player) { + public void playACard(Hand userSuitHand, Card playingCard, int indexToInsertCard, TableHand tableHand, + Suits userSuitInTableHand, Player player) { + + userSuitHand.addCard(indexToInsertCard, playingCard); - userSuitHand.addCard(playingCard); - tableHand.getSevensTableHand().put(userSuitInTableHand, userSuitHand); player.getHand().removeCard(playingCard); } }