22
33import java .awt .Color ;
44import java .awt .Graphics ;
5+ import java .awt .event .MouseListener ;
6+ import java .awt .event .MouseMotionListener ;
57import java .awt .image .BufferStrategy ;
68
79import com .redomar .game .lib .Font ;
10+ import com .redomar .game .lib .Mouse ;
811
912
1013
@@ -15,18 +18,24 @@ public class Menu implements Runnable{
1518 private static final int SCALE = 3 ;
1619 private static final String NAME = "Menu" ;
1720
18- private DedicatedJFrame frame = new DedicatedJFrame (WIDTH , HEIGHT , SCALE , NAME );
21+ private static boolean running = false ;
22+ private static boolean selectedStart = false ;
23+ private static boolean selectedExit = false ;
24+ private static boolean gameOver = false ;
25+
26+ private static DedicatedJFrame frame = new DedicatedJFrame (WIDTH , HEIGHT , SCALE , NAME );
1927 private Font font = new Font ();
28+ private MouseListener Mouse = new Mouse ();
2029
21- private boolean running = false ;
22- private boolean selected = true ;
30+ private Color selected = new Color ( 0xFFFF8800 ) ;
31+ private Color deSelected = new Color ( 0xFFCC5500 ) ;
2332
2433 public synchronized void start () {
2534 running = true ;
26- new Thread (this ).start ();
35+ new Thread (this , "MENU" ).start ();
2736 }
2837
29- public synchronized void stop () {
38+ public static synchronized void stop () {
3039 running = false ;
3140 }
3241
@@ -74,6 +83,8 @@ public void run() {
7483
7584 private void render () {
7685 //frame.getFrame().getContentPane().setBackground(Color.GREEN);
86+ frame .addMouseMotionListener ((MouseMotionListener ) Mouse );
87+ frame .addMouseListener (Mouse );
7788 BufferStrategy bs = frame .getBufferStrategy ();
7889 if (bs == null ) {
7990 frame .createBufferStrategy (3 );
@@ -82,29 +93,50 @@ private void render() {
8293 Graphics g = bs .getDrawGraphics ();
8394 g .setColor (Color .BLACK );
8495 g .fillRect (0 , 0 , frame .getWidth (), frame .getHeight ());
96+ g .setColor (new Color (0xFF660000 ));
97+ g .fillRect (12 , 12 , (WIDTH *3 )-30 , (HEIGHT *3 )-53 );
8598 g .setColor (new Color (0xFFFF9900 ));
8699 g .setFont (font .getArial ());
87- //g.drawString("Testing Phase...",40,30);
100+ if (isGameOver ()){
101+ g .drawString ("GAME OVER... What will you do now?" ,35 ,30 );
102+ }else {
103+ g .drawString ("Welcome to JavaGame" ,35 ,30 );
104+ }
105+ g .drawLine (10 , (HEIGHT *3 )-40 , 10 , 10 );
106+ g .drawLine (10 , 10 , (WIDTH *3 )-17 , 10 );
107+ g .drawLine ((WIDTH *3 )-17 , 10 , (WIDTH *3 )-17 , (HEIGHT *3 )-40 );
108+ g .drawLine (10 , (HEIGHT *3 )-40 , (WIDTH *3 )-17 , (HEIGHT *3 )-40 );
88109 //(LEFT,DOWN,WIDTH,HEIGHT)
89- if (selected == true ){
110+ if (isSelectedStart () == true ){
90111 //START
91- g .setColor (new Color ( 0xFFFF8800 ));
112+ g .setColor (getSelected ( ));
92113 g .fillRect (35 , 35 , (frame .getWidth ()-70 ), 90 );
93114 g .setColor (Color .BLACK );
94115 g .drawString ("Start" , 220 , 85 );
95116 //EXIT
96- g .setColor (new Color ( 0xFFFF8800 ));
117+ g .setColor (getDeSelected ( ));
97118 g .fillRect (35 , 160 , (frame .getWidth ()-70 ), 90 );
98119 g .setColor (Color .BLACK );
99120 g .drawString ("Exit" , 220 , 210 );
100- } else {
121+ } else if ( isSelectedExit () == true ) {
101122 //START
102- g .setColor (new Color ( 0xFFFF8833 ));
123+ g .setColor (getDeSelected ( ));
103124 g .fillRect (35 , 35 , (frame .getWidth ()-70 ), 90 );
104125 g .setColor (Color .BLACK );
105126 g .drawString ("Start" , 220 , 85 );
106127 //EXIT
107- g .setColor (new Color (0xFFFF8833 ));
128+ g .setColor (getSelected ());
129+ g .fillRect (35 , 160 , (frame .getWidth ()-70 ), 90 );
130+ g .setColor (Color .BLACK );
131+ g .drawString ("Exit" , 220 , 210 );
132+ }else {
133+ //START
134+ g .setColor (getDeSelected ());
135+ g .fillRect (35 , 35 , (frame .getWidth ()-70 ), 90 );
136+ g .setColor (Color .BLACK );
137+ g .drawString ("Start" , 220 , 85 );
138+ //EXIT
139+ g .setColor (getDeSelected ());
108140 g .fillRect (35 , 160 , (frame .getWidth ()-70 ), 90 );
109141 g .setColor (Color .BLACK );
110142 g .drawString ("Exit" , 220 , 210 );
@@ -117,5 +149,69 @@ private void render() {
117149 public static void main (String [] args ) {
118150 new Menu ().start ();
119151 }
152+
153+ public static DedicatedJFrame getFrame () {
154+ return Menu .frame ;
155+ }
156+
157+ public static void setFrame (DedicatedJFrame frame ) {
158+ Menu .frame = frame ;
159+ }
160+
161+ public static boolean isRunning () {
162+ return running ;
163+ }
164+
165+ public static void setRunning (boolean running ) {
166+ Menu .running = running ;
167+ }
168+
169+ public static boolean isSelectedStart () {
170+ return selectedStart ;
171+ }
172+
173+ public static void setSelectedStart (boolean selectedStart ) {
174+ Menu .selectedStart = selectedStart ;
175+ }
176+
177+ public static boolean isSelectedExit () {
178+ return selectedExit ;
179+ }
180+
181+ public static void setSelectedExit (boolean selectedExit ) {
182+ Menu .selectedExit = selectedExit ;
183+ }
184+
185+ public Color getSelected () {
186+ return selected ;
187+ }
188+
189+ public void setSelected (Color selected ) {
190+ this .selected = selected ;
191+ }
192+
193+ public Color getDeSelected () {
194+ return deSelected ;
195+ }
196+
197+ public void setDeSelected (Color deSelected ) {
198+ this .deSelected = deSelected ;
199+ }
200+
201+ public static int getWidth () {
202+ return WIDTH ;
203+ }
204+
205+ public static int getHeight () {
206+ return HEIGHT ;
207+ }
208+
209+ public static boolean isGameOver () {
210+ return gameOver ;
211+ }
212+
213+ public static void setGameOver (boolean gameOver ) {
214+ Menu .gameOver = gameOver ;
215+ }
120216
121217}
0 commit comments