
// Ashok Sivakumar			 		6.030  Final Project
// 12/04/99

package breakout;

import java.awt.*;
import java.awt.event.*;

/*  This class implements the frame unto which the canvas of the game is held.
	The frame is unique in that it has a pull-down menu with options including 
	Start a 1 or 2 player game, Pause and Quit.  The Conclusion graphics that 
	occur during a quit are also part of this class.   */


public class BreakOutFrame extends Frame implements ActionListener
{

	protected ScreenCanvas screenCan;
	
	//constructor: takes a Screen Canvas and sets field
	public BreakOutFrame(ScreenCanvas sc)
	{
		super("KATAKANA !!!"); // name of game so stays as name of frame
		this.screenCan = sc;
		
		this.pack();
		
		this.setLayout(new BorderLayout());
		
	}
	
	/* The next method is the frame's initialization method. This has a text field to give
	   user directions, sets the size of the frame, and sets up the menu bar.            */
	    
	   
	public void init()
	{
		this.add(this.screenCan);
		this.add("North", new Label("Put Num Locks on or get Mouse Hand ready and choose START", Label.CENTER));
		
		this.setSize(800, 700);
		this.setLocation(100, 20);  // centers the frame
		MenuBar myMenuBar = new MenuBar();
		this.makeOptionMenu(myMenuBar);
		this.setMenuBar(myMenuBar);
		this.show();
	}
	
	/* The next method is used in the following method to add the different
		options to the menu     */
	
	
	protected void addItem(Menu m, String s)
	{
		MenuItem mi = new MenuItem(s);
		mi.addActionListener(this);
		m.add(mi);
	}
	
	/* This method creates the actual option menu and adds this menu to the menu bar   */
	
	public void makeOptionMenu(MenuBar mb)
	{
		Menu optionMenu = new Menu("Options");
		this.addItem(optionMenu, "Start 1 Player Game");
		this.addItem(optionMenu, "Start 2 Player Game");  // different options in menu
		this.addItem(optionMenu, "Pause");
		this.addItem(optionMenu, "Quit");
		mb.add(optionMenu);
	}
	
	/* This method dispatches on the value of which menu item was selected  */
	
	public void actionPerformed(ActionEvent ae)
	{
		
		String command = ae.getActionCommand();
		if (command.equals("Start 1 Player Game")) start1Player();
		else if (command.equals("Start 2 Player Game")) start2Player();
		else if (command.equals("Pause")) pause();
		else if (command.equals("Quit"))  quit();
	}
	
	/* This method is initiated when user selects 1-Player option and sets certain
	   variables so game can begin under correct conditions               */

	public void start1Player()
	{
		System.out.println("Starting Katakana for 1 Player !!! ");
		this.screenCan.pause = false;
		this.screenCan.numberOfPlayers = 0;  // needed for correct running of code
		
	}
	
	/* This method is initiated when user selects 2-Player option and sets certain
	   variables so game can begin under correct conditions               */
	
	public void start2Player()
	{
		System.out.println("Starting Katakana for  2 Players !!! ");
		this.screenCan.pause = false;
		this.screenCan.numberOfPlayers = 1;  // needed for correct running of code
		
	}
	
	/* This method "pauses"  or "unpauses" the game by changing the pause boolean in
	   Class screenCanvas - it is run when user selects pause option     */
	
	public void pause()
	{
		
		System.out.println("We are in pause method");
		this.screenCan.pause = !this.screenCan.pause;
	}
	
	/* This is the method that quits the game. A new ImageCanvas is created. 
	   A fun concluding frame will pop up after the game has been quit. 
	   The size and location of the frame is set.*/
	 
	public void quit()
	{
		System.out.println("GAME OVER - Play Again !");
			
		/* Statements to create final frame - see ImageCanvas class for details  */
			
		ImageCanvas im = new ImageCanvas();
		MyFrame f = new MyFrame(im);
		f.setSize(800, 700);
		f.setLocation(100, 30);
		f.show();
		f.repaint();
		
		System.out.println("YOUR SCORE was =  " + this.screenCan.myScore);  // show of total score
		
		System.exit(0);   // closes all open frames and ends everything running
	
	}
		
}