Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.event.KeyEvent;
- import java.awt.event.MouseEvent;
- public class main_menu extends state
- {
- private String title;
- private String play;
- private String quit;
- private int selected;
- public main_menu()
- {
- this.title = "Saper";
- this.play = "Play";
- this.quit = "Quit";
- this.selected = 0;
- }
- public void Update(KeyEvent e, app a, MouseEvent m)
- {
- if(m == null) {
- switch(e.getKeyCode())
- {
- case 40:
- this.selected += 1;
- break;
- case 38:
- this.selected -= 1;
- break;
- case 32:
- if(this.selected == 0)
- a.coreState = new game(a);
- else if(this.selected == 1)
- System.exit(0);
- break;
- }
- if (this.selected > 1)
- {
- this.selected = 0;
- }
- if (this.selected < 0)
- {
- this.selected = 1;
- }
- a.repaint();
- }
- }
- public void Render(Graphics g, app a) {
- Image img = a.createImage(a.getSize().width, a.getSize().height);
- Graphics2D g2 =(Graphics2D)img.getGraphics();
- g2.setFont(new Font("Arial",Font.BOLD,64));
- g2.setColor(Color.black.darker());
- g2.drawString(this.title, a.getSize().width / 2 - (this.title.length()) / 2 * 50, 120);
- g2.setFont(new Font("Arial",Font.BOLD,32));
- if(this.selected == 0)
- {
- g2.setColor(Color.green.darker());
- g2.drawString(this.play, a.getSize().width / 2 - this.play.length() / 2 * 22, a.getSize().height / 2);
- g2.setColor(Color.black.darker());
- g2.drawString(this.quit, a.getSize().width / 2 - this.quit.length() / 2 * 22, 520);
- }
- else if(this.selected == 1)
- {
- g2.setColor(Color.black.darker());
- g2.drawString(this.play, a.getSize().width / 2 - this.play.length() / 2 * 22, a.getSize().height / 2);
- g2.setColor(Color.green.darker());
- g2.drawString(this.quit, a.getSize().width / 2 - this.quit.length() / 2 * 22, 520);
- }
- g.drawImage(img, 0, 0, a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment