import java.io.*;

public class Casino {
	
	//fields
	private String name;
	// 100 = max number of slot machines in the casino
	private SlotMachine [] slotMachines = new SlotMachine[100]; 
	private int numOfSlotMachines = 0;

	// constructor
	public Casino(String n) {
		name = n;
	}
	
	public void addSlotMachine(String n, int wf) {
		if ( numOfSlotMachines < 100 ) {
			slotMachines[numOfSlotMachines++] = new SlotMachine(n, wf);
		} else {
			System.out.println("Can't add any more slot machines!");
		}
	}
	
	public void addFancySlotMachine(String n, int wf) {
		if ( numOfSlotMachines < 100 ) {
			slotMachines[numOfSlotMachines++] = new FancySlotMachine(n, wf);
		} else {
			System.out.println("Can't add any more slot machines!");
		}
	}
	
	public void playAllSlotMachines(int numberOfTokens) throws IOException {
		
		java.io.BufferedReader stndin;
		stndin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
		String answer = "";  // to hold the user's reply to play again	
		
		// keep playing all the machines one at a time, until the user
		// wants to quit or runs out of tokens
		while ( true ) {
		    // for every slot machine, play it if the user wants to.....
			for ( int i = 0; i < numOfSlotMachines; i++ ) {
				if ( numberOfTokens == 0 ) {
					System.out.println("Sorry you've run out of tokens!");
					return;
				} else { 
					System.out.println(
						"Keep playing ("+ numberOfTokens + " tokens left)? y/n");
					answer = stndin.readLine();	
					if (answer.equalsIgnoreCase("y") ) {
						numberOfTokens--; 
						numberOfTokens += slotMachines[i].playSlotMachine();
					} else {
						return;
					} // inner if
				} // outer if
			} // for	
		} // while			
	}
	
	// tester for this class
	public static void main ( String args[]){
		
		Casino ourCasino = new Casino ("Casino Royale");
		// add the regular machines
		ourCasino.addSlotMachine("Huey", 2);
		ourCasino.addSlotMachine("Louie", 3);
		ourCasino.addSlotMachine("Dewey", 4);
		// add the fancy machines
		ourCasino.addFancySlotMachine("Super Huey", 2);
		ourCasino.addFancySlotMachine("Super Louie", 3);
		ourCasino.addFancySlotMachine("Super Dewey", 4);
	
		// need to get the player's number of tokens before we can start playing!
		System.out.println("Hi Welcome to " + ourCasino.name + ", how many tokens do you have!");
		java.io.BufferedReader stndin;
		stndin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
		int answer = 0;  // to hold the user's reply to play again	
		try {
			answer = Integer.valueOf(stndin.readLine()).intValue();
			ourCasino.playAllSlotMachines(answer);
		} catch  (IOException e) {	
			System.out.println("caught an input exception!");
		}

		System.out.println("Goodbye");
			
	}
	
}