package test;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Random;
public class Test {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Random rand = new Random();
String[] cards = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
String[] suits = {" of Hearts", " of Diamonds", " of Spades", " of Clubs"};
ArrayList checkCards = new ArrayList();
String currentCard, getCard;
int shuffleCards, shuffleSuits, playerPoints, dealerPoints, playerTotal, dealerTotal, wins, loses, pushes;
String play, anotherCard, showCard, playAgain, score;
StringBuilder PSB = new StringBuilder();
StringBuilder selectedCard = new StringBuilder();
showCard = "";
playAgain = "y";
score = "";
playerTotal = 0;
playerPoints = 0;
dealerPoints = 0;
dealerTotal = 0;
wins = loses = pushes = 0;
System.out.println("Welcome to Thirty3\n");
System.out.print("Would you like to play (Y/Q)? ");
play = scan.nextLine();
if(play.equalsIgnoreCase("y"))
{
while(playAgain.equalsIgnoreCase("y"))
{
System.out.println();
System.out.print("Your cards: ");
for(int a=1; a<=3; a++)
{
// shuffleCards = rand.nextInt(cards.length-1) + 0;
// shuffleSuits = rand.nextInt(suits.length-1) + 0;
shuffleCards = 0;
shuffleSuits = 0;
selectedCard.append(cards[shuffleCards].concat(suits[shuffleSuits]));
// selectedCard = cards[shuffleCards].concat(suits[shuffleSuits]);
currentCard = cards[shuffleCards].concat(suits[shuffleSuits]);
// System.out.println("current card" + currentCard);
checkCards.add(currentCard);
// System.out.println("currentCard " + checkCards);
for(int x=0; x<checkCards.toArray().length; x++)
{
// getCard = (String) checkCards.get(x);
if(currentCard.matches(selectedCard.toString()))
{
shuffleCards = rand.nextInt(cards.length-1) + 0;
shuffleSuits = rand.nextInt(suits.length-1) + 0;
// System.out.println("That card already selected!");
}
// System.out.println("getCard["+x+"] = " + (String) checkCards.get(x));
}
System.out.print(cards[shuffleCards] + suits[shuffleSuits] + ", ");
if(shuffleCards == 1)
{
playerPoints = 2;
}
if(shuffleCards == 2)
{
playerPoints = 3;
}
if(shuffleCards == 3)
{
playerPoints = 4;
}
if(shuffleCards == 4)
{
playerPoints = 5;
}
if(shuffleCards == 5)
{
playerPoints = 6;
}
if(shuffleCards == 6)
{
playerPoints = 7;
}
if(shuffleCards == 7)
{
playerPoints = 8;
}
if(shuffleCards == 8)
{
playerPoints = 9;
}
if(shuffleCards == 9 || shuffleCards == 10 || shuffleCards == 11 || shuffleCards == 12)
{
playerPoints = 10;
}
if((shuffleCards == 10 && shuffleSuits == 2 )|| (shuffleCards == 10 && shuffleSuits == 0) || (shuffleCards == 12 && shuffleSuits == 1))
{
playerPoints = 13;
}
if(shuffleCards == 2 && shuffleSuits == 3)
{
playerPoints = 0;
}
if(shuffleCards == 0 && (playerTotal <= 22))
{
playerPoints = 11;
}
if(shuffleCards == 0 && (playerTotal > 22))
{
playerPoints = 1;
}
playerTotal = playerPoints + playerTotal;
showCard = showCard.concat(cards[shuffleCards]).concat(suits[shuffleSuits].concat(", "));
}
System.out.print("(Total " + playerTotal + ")");
System.out.println();
System.out.print("Would you like another card (Y/N)? ");
anotherCard = scan.nextLine();
while(anotherCard.equalsIgnoreCase("y"))
{
System.out.print("Your cards: " + showCard);
shuffleCards = rand.nextInt(cards.length-1) + 0;
shuffleSuits = rand.nextInt(suits.length-1) + 0;
PSB.append(cards[shuffleCards].concat(suits[shuffleSuits]).concat(", ")); // dashes done here
System.out.print(PSB.toString());
if(shuffleCards == 1)
{
playerPoints = 2;
}
if(shuffleCards == 2)
{
playerPoints = 3;
}
if(shuffleCards == 3)
{
playerPoints = 4;
}
if(shuffleCards == 4)
{
playerPoints = 5;
}
if(shuffleCards == 5)
{
playerPoints = 6;
}
if(shuffleCards == 6)
{
playerPoints = 7;
}
if(shuffleCards == 7)
{
playerPoints = 8;
}
if(shuffleCards == 8)
{
playerPoints = 9;
}
if(shuffleCards == 9 || shuffleCards == 10 || shuffleCards == 11 || shuffleCards == 12)
{
playerPoints = 10;
}
if(shuffleCards == 10 && shuffleSuits == 2 || shuffleCards == 10 && shuffleSuits == 0 || shuffleCards == 12 && shuffleSuits == 1)
{
playerPoints = 13;
}
if(shuffleCards == 2 && shuffleSuits == 3)
{
playerPoints = 0;
}
if(shuffleCards == 0 && (playerTotal <= 22))
{
playerPoints = 11;
}
if(shuffleCards == 0 && (playerTotal > 22))
{
playerPoints = 1;
}
playerTotal = playerPoints + playerTotal;
System.out.print("(Total " + playerTotal + ")");
System.out.println();
System.out.print("Would you like another card (Y/N)? ");
anotherCard = scan.nextLine();
}
System.out.println();
System.out.print("The dealer drew: ");
while(dealerTotal <= 26)
{
shuffleCards = rand.nextInt(cards.length-1) + 0;
shuffleSuits = rand.nextInt(suits.length-1) + 0;
if(shuffleCards == 1)
{
dealerPoints = 2;
}
if(shuffleCards == 2)
{
dealerPoints = 3;
}
if(shuffleCards == 3)
{
dealerPoints = 4;
}
if(shuffleCards == 4)
{
dealerPoints = 5;
}
if(shuffleCards == 5)
{
dealerPoints = 6;
}
if(shuffleCards == 6)
{
dealerPoints = 7;
}
if(shuffleCards == 7)
{
dealerPoints = 8;
}
if(shuffleCards == 8)
{
dealerPoints = 9;
}
if(shuffleCards == 9 || shuffleCards == 10 || shuffleCards == 11 || shuffleCards == 12)
{
dealerPoints = 10;
}
if((shuffleCards == 10 && shuffleSuits == 2 )|| (shuffleCards == 10 && shuffleSuits == 0) || (shuffleCards == 12 && shuffleSuits == 1))
{
dealerPoints = 13;
}
if(shuffleCards == 2 && shuffleSuits == 3)
{
dealerPoints = 0;
}
if(shuffleCards == 0 && (dealerTotal <= 22))
{
dealerPoints = 11;
}
if(shuffleCards == 0 && (dealerTotal > 22))
{
dealerPoints = 1;
}
dealerTotal = dealerPoints + dealerTotal;
System.out.print(cards[shuffleCards] + suits[shuffleSuits].concat(", "));
}
System.out.println("(Total " + dealerTotal + ")");
System.out.println();
if((33 - playerTotal < 33 - dealerTotal) && playerTotal <= 33 || dealerTotal > 33)
{
score = "win!";
wins++;
}
if((33 - playerTotal > 33 - dealerTotal) && dealerTotal <= 33 || playerTotal > 33)
{
score = "lose!";
loses++;
}
if(playerTotal == dealerTotal)
{
score = "tied!";
pushes++;
}
System.out.println("You " + score + " - Current Total - Wins - " + wins + " Ties - " + pushes + " Loses - " + loses);
System.out.println();
System.out.print("Would you like to play again (Y/Q)? ");
playAgain = scan.nextLine();
if(playAgain.equalsIgnoreCase("y"))
{
playerTotal = 0;
dealerTotal = 0;
playerPoints = 0;
dealerPoints = 0;
PSB.delete(0, PSB.length());
showCard = "";
}
}
}
}
}