package game_state;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;


public class MenuState extends AbstractGameState {
	
	private String title;
	private String[] options;
	private Font title_font;
	private Font options_font;
	
	private int selectedOption;
	
	
	
	/**
	 * Constructor of main menu
	 */
	public MenuState(GameStateManager gsm) {
		this.gsm = gsm;
		this.title = "PONG";
		
		this.options = new String[3];
		this.options[0] = "Start Game";
		this.options[1] = "Option";
		this.options[2] = "Exit";
		
		this.title_font = new Font("Century Gothic", Font.PLAIN, 70);
		this.options_font = new Font("Century Gothic", Font.PLAIN, 30);
		this.selectedOption = 0;
	}

	@Override
	public void init() {}

	@Override
	public void update() {}

	
	@Override
	public void draw(Graphics2D g) {
		// title :
		g.setColor(Color.white);
		g.setFont(title_font);
		g.drawString(title, 400, 150);
		
		// options :
		g.setFont(options_font);
		for(int i = 0; i<options.length; i++) {
			if(i == selectedOption)
				g.setColor(Color.yellow);
			else 
				g.setColor(Color.white);
			
			g.drawString(options[i], 400, 250+35*i);
		}
	}
	

	@Override
	public void keyPressed(KeyEvent key) {
		if(key.getKeyCode() == KeyEvent.VK_DOWN) {
			if(selectedOption >= options.length-1) 
				selectedOption = 0;
			else
				selectedOption++;
		}
		
		else if(key.getKeyCode() == KeyEvent.VK_UP) {
			if(selectedOption <= 0 ) 
				selectedOption = options.length-1;
			else
				selectedOption--;
		}
		
		else if(key.getKeyCode() == KeyEvent.VK_ENTER) {
			switch(selectedOption) {
			case 0: // Start game
				gsm.setCurrentState(GameStateManager.GAME);
				break;
			case 1: // Option
				gsm.setCurrentState(GameStateManager.OPTIONS);
				break;
			case 2: // EXit
				break;
			}
		}
	}

	@Override
	public void keyReleased(KeyEvent key) {}
}












@@ -179,29 +179,120 @@
 %0A%09%0A%09
-private String title;
+/** Game title to display */%0A%09private String title;%0A%09/** table of options like %22start game%22, %22option%22, %22exit%22 */
 %0A%09pr
@@ -315,16 +315,39 @@
 ptions;%0A
+%09/** the title font */%0A
 %09private
@@ -364,16 +364,41 @@
 e_font;%0A
+%09/** the options font */%0A
 %09private
@@ -418,16 +418,52 @@
 _font;%0A%09
+/** current selected option index */
 %0A%09privat
@@ -899,24 +899,26 @@
 on = 0;%0A%09%7D%0A%0A
+%09%0A
 %09@Override%0A%09
@@ -939,17 +939,16 @@
 it() %7B%7D%0A
-%0A
 %09@Overri
@@ -1412,16 +1412,19 @@
  key) %7B%0A
+%09%09%0A
 %09%09if(key
@@ -1982,12 +1982,32 @@
 // E
-X
+x
 it%0A
+%09%09%09%09System.exit(0);%0A
 %09%09%09%09
@@ -2026,16 +2026,18 @@
 %09%09%7D%0A%09%7D%0A%0A
+%09%0A
 %09@Overri

Exit option OK