/*
	For: Poker
	
	Created by Travis Roe
*/
import java.util.*;

public class Game{

	private Deck deck;
	private Hand human, computer;
	
	public Game(){
		//initialize the scanner for reading input from the screen
		Scanner scanner = new Scanner(System.in);
		
		//initialize the components of the game
		deck = new Deck();
		human = new Hand();
		computer = new Hand();
		
		dealCards();
		
		System.out.println(	"Welcome to Poker Player!\n" +
									"\n" +
									"Here are the cards you have been dealt:\n" + 
									human + "\n" + 
									"\n" + 
									"How many cards would you like to discard?");
		
		//get the number of cards 
		int numDiscard = scanner.nextInt();
		
		/*
			This line uses a turinary if. Turinary ifs are in-line if statements
			that returns the value associated with result of the condition.
			Syntax is as follows:
				(condition? resultIfTrue : resultIfFalse)
			
			Also, when mixing in variables and strings when printing, don't
			forget the spaces.
		*/
		System.out.println("Indicate which " + numDiscard + " card" + (numDiscard > 1? "s ":" ") + "with their numbers(1-5):");
		
		for(int x = 0; x < numDiscard; x++){
			/*
				index reduced by one because each picture's number is one higher
				than actual index
			*/
			int cardNumToReplace = scanner.nextInt() - 1;
			human.replace(cardNumToReplace - 1, deck.deal());
		}
		
		/*
			compare the human to the computer.
			If the human wins, display "You win!"
			Otherwise, if the computer wins, print "you lose!"
			Or, if there's a tie, print "You and the comptuer are tied!"
			
			Then, print out the cards of both teams
		*/
		int winner = human.compareTo(computer);
		if(winner > 0) System.out.println("\nYou win!\n");
		else if(winner < 0) System.out.println("\nSorry, you lose!\n");
		else System.out.println("\nYou and the computer tied!\n");
		
		System.out.println(	"Here are your final cards:\n" +
									"\n" +
									human + "\n" +
									"\n" +
									"Here are the computer's final cards:\n" + 
									"\n" +
									computer + "\n" );
	}
	
	
	/*
		Just like in a real game of poker, each player recieves a card
		one after the other. To simulate that, the human receives a card,
		then the computer receives a card.
	*/
	public void dealCards(){
		for(int x = 0; x < 5; x++){
			human.add(deck.deal());
			computer.add(deck.deal());
		}
	}
	
	/*
		public static void main is the method called when java is run on
		this class. Therefore, we need to tell java to start our game.
	*/
	public static void main(String[] args){
		Game game = new Game();
	}
}