diff --git a/Java/Array.java b/Java/Array.java new file mode 100644 index 0000000000..e51bd200db --- /dev/null +++ b/Java/Array.java @@ -0,0 +1,154 @@ +public class Array { + private int count; + private String array[]; + + // Constructor initialzing array and its length + public Array(int length) { + this.array = new String[length]; + } + + // Method which prints the array + // And skips any index with val of null + public void printArray() { + for(int i =0; i < count; i++) { + // checking if the index is a valid card (not null) + if (array[i] != null) { + System.out.print(array[i] + " "); + } + } + } + + public String getCard(int index) { + return array[index]; + } + + public int cardValue(String card) { + if (card.equals("King") != true && card.equals("Queen") != true && card.equals("Jack") != true && card.equals("Ace") != true ) { + return Integer.parseInt(card); + } + else if (card.equals("King") == true) { + return 13; + } + else if (card.equals("Queen") == true) { + return 12; + } + else if (card.equals("Jack") == true) { + return 11; + } + else if (card.equals("Ace") == true) { + return 14; + } + else { + return -1; + } + } + + public int cardValue(int index) { + String card = getCard(index); + if (card.equals("King") != true && card.equals("Queen") != true && card.equals("Jack") != true && card.equals("Ace") != true ) { + return Integer.parseInt(card); + } + else if (card.equals("King") == true) { + return 13; + } + else if (card.equals("Queen") == true) { + return 12; + } + else if (card.equals("Jack") == true) { + return 11; + } + else if (card.equals("Ace") == true) { + return 14; + } + else { + return -1; + } + } + + public int getLength() { + return count; + } + + // Method which gets the index of a specified card + public int getIndex(String cardName) { + // loops through every element in the array + for(int i = 0; i < array.length; i++) { + // Stops when the first card equaling the search + // parameter is found + if(array[i] == cardName) { + return i; + } + } + // returns -1 if none are found + return -1; + } + + // Method which adds a card onto the end of the array + // Can expand the array dynamically if needed + public void insertCard(String card) { + // checking if the length of the array is equal to + // the amount of cards in the array (count) + if (array.length == count) { + // creating a new array that's twice the size + String[] newArray = new String[count*2]; + // for loop which copies the array onto a dif array + // then replaces the original array with the new one + for(int i=0; i= 1 && computerDeck.getLength() >= 1) { + + playerCardIndex = rand.nextInt(playerDeck.getLength()); + computerCardIndex = rand.nextInt(computerDeck.getLength()); + + String playerCard = playerDeck.getCard(playerCardIndex); + String computerCard = computerDeck.getCard(computerCardIndex); + + if (playerDeck.cardValue(playerCard) > computerDeck.cardValue(computerCard)) { + computerDeck.removeCard(computerCard); + playerDeck.insertCard(computerCard); + System.out.print(green+" Player wins the round! \n (P) " + playerCard + " vs (C) " + computerCard); + System.out.println(" | Player Deck: " + playerDeck.getLength() + " Computer Deck: " + computerDeck.getLength() + clearLine); + Thread.sleep(1300); + } + else if (playerDeck.cardValue(playerCard) < computerDeck.cardValue(computerCard)) { + playerDeck.removeCard(playerCard); + computerDeck.insertCard(playerCard); + System.out.print(red+" Computer wins the round! \n (P) " + playerCard + " vs (C) " + computerCard); + System.out.println(" | Player Deck: " + playerDeck.getLength() + " Computer Deck: " + computerDeck.getLength() + "\n"); + Thread.sleep(1300); + } + // Draw mechanic + else if (playerDeck.cardValue(playerCard) == computerDeck.cardValue(computerCard)) { + + int removedCards = 0; + while (playerCard == computerCard) { + System.out.print(textColor+" Draw, this means war! "); + Thread.sleep(650); + System.out.print("Lay out 3 extra cards"); + Thread.sleep(750); + System.out.print("."); + Thread.sleep(750); + System.out.print("."); + Thread.sleep(750); + System.out.println("."); + Thread.sleep(500); + + removedCards += 3; + playerCardIndex = rand.nextInt(playerDeck.getLength()); + computerCardIndex = rand.nextInt(computerDeck.getLength()); + + playerCard = playerDeck.getCard(playerCardIndex); + computerCard = computerDeck.getCard(computerCardIndex); + + if (playerDeck.cardValue(playerCard) > computerDeck.cardValue(computerCard)) { + computerDeck.removeCard(computerCard); + playerDeck.insertCard(computerCard); + for(int i =0; i < removedCards; i++) { + if (computerDeck.getLength() > 0) { + computerCardIndex = rand.nextInt(computerDeck.getLength()); + computerCard = computerDeck.getCard(computerCardIndex); + computerDeck.removeCard(computerCard); + playerDeck.insertCard(computerCard); + } + } + System.out.print(green+"Player wins the war!!! \n (P) " + playerCard + " vs (C) " + computerCard); + System.out.println(" | Player Deck: " + playerDeck.getLength() + " Computer Deck: " + computerDeck.getLength() + "\n"); + Thread.sleep(1300); + + } + + else if (playerDeck.cardValue(playerCard) < computerDeck.cardValue(computerCard)) { + playerDeck.removeCard(playerCard); + computerDeck.insertCard(playerCard); + + for(int i =0; i < removedCards; i++) { + if (playerDeck.getLength() > 0) { + playerCardIndex = rand.nextInt(playerDeck.getLength()); + playerCard = playerDeck.getCard(playerCardIndex); + playerDeck.removeCard(playerCard); + computerDeck.insertCard(playerCard); + } + } + System.out.print(red+" Computer wins the war!!! \n (P) " + playerCard + " vs (C) " + computerCard); + System.out.println(" | Player Deck: " + playerDeck.getLength() + " Computer Deck: " + computerDeck.getLength() + "\n"); + Thread.sleep(1300); + } + + } + } + } + + if (playerDeck.getLength() > computerDeck.getLength()) { + System.out.println("Player wins!!"); + } + else if (playerDeck.getLength() < computerDeck.getLength()) { + System.out.println("Computer wins :("); + } + + + } + + public static void sleepy() { + + } + + public static void clearScreen() { + System.out.print("\033[H\033[2J"); + } +} + + + + +/* + Start Sequence - done + Player Setup - done + Deck setup - Done + Rounds - done but not pretty (it is now pretty) + Subtracting/adding cards - Done + Card draw condition - done + Win Condition - done + Done!!!!!!!!!!!1 +*/ \ No newline at end of file diff --git a/README.md b/Other/README.md similarity index 100% rename from README.md rename to Other/README.md