//Name: Gorski
//Date: October 15, 2021
//Purpose: To demonstrate a complex task for the RPG

public class BottleRiddle {
	public static void main(String args[]) {
		new BottleRiddle();
	}
	public BottleRiddle() {
		BottleGame();
	}

	public void BottleGame() {
		//Plays the bottle game; user needs to get 4L from 3L & 5L bottle
		
		//Instructions
		System.out.println("You have a 3L bottle and a 5L bottle.");
		System.out.println("You need to use them to get exactly 4L of water.");
		//both bottles start at 0
		int threeL=0;
		int fiveL=0;

		//Loop until the user wins, or they get 4L in the 5L bottle.
		while(fiveL!=4) {
			drawBottle(threeL, fiveL);
			//Display options
			System.out.println("You can:");
			System.out.println("(a) fill the 3L bottle");
			System.out.println("(b) empty the 3L bottle");
			System.out.println("(c) fill the 5L bottle");
			System.out.println("(d) empty the 5L bottle");
			System.out.println("(e) pour the 3L bottle in the 5L bottle");
			//Process choice
			char choice = IO.inputChar(">> ");
			if(choice=='a')
				threeL=3;
			else if(choice=='b')
				threeL=0;
			else if(choice=='c')
				fiveL=5;
			else if (choice=='d')
				fiveL=0;
			else if(choice=='e') {
				int left = 5-fiveL;
				if(threeL<=left) {
					fiveL=fiveL+threeL;
					threeL=0;
				}else {
					fiveL = fiveL+left;
					threeL = threeL-left;
				}
			}//end choice e
		}//end game while loop

		//They have won!
		System.out.println("\nYou win! ");
		drawBottle(threeL, fiveL);
		System.out.println("Great work!");
	}


	public void drawBottle(int n, int m) {
		//draws the 3L and 5L bottle on the screen, properly filled

		System.out.println("\n                [_ ]");
		System.out.println("              .-'. '-.");
		System.out.println(" _[_]_       /:;/ _.-'\\");
		//draw top line in 5L bottle
		if(m>=5)
			System.out.println("/_   _\\      |:.____.-|");
		else
			System.out.println("/_   _\\      |:.    .-|");

		//draw 4L line in 5L bottle
		if(m>=4)
			System.out.println(")_``'_(      |:._____ |");
		else
			System.out.println(")_``'_(      |:.      |");

		//draw 3L line in each bottle
		if(m>=3 && n>=3)
			System.out.println("|;:___|      |:._____ |");
		else if(m>=3)
			System.out.println("|;    |      |:._____ |");
		else if(n>=3)
			System.out.println("|;:___|      |:.      |");
		else
			System.out.println("|;    |      |:.      |");

		//draw 2L line in each bottle
		if(m>=2 && n>=2)
			System.out.println("|;:___|      |:._____ |");
		else if(m>=2)
			System.out.println("|;    |      |:._____ |");
		else if(n>=2)
			System.out.println("|;:___|      |:.      |");
		else
			System.out.println("|;    |      |:.      |");

		//draw 1L line in each bottle
		if(m>=1 && n>=1)
			System.out.println("|;:___|      |:._____ |");
		else if(m>=1)
			System.out.println("|;    |      |:._____ |");
		else if(n>=1)
			System.out.println("|;:___|      |:.      |");
		else
			System.out.println("|;    |      |:.      |");

		//draw bottom
		System.out.println("`-...-'      `-.____.-'  ");  
		System.out.println("3L has "+n+"L    5L has "+m+"L");
	}

}
