|
|
@@ -1,15 +1,19 @@
|
|
|
package model.state;
|
|
|
|
|
|
+import java.awt.Color;
|
|
|
import java.awt.Font;
|
|
|
import java.awt.Graphics2D;
|
|
|
import java.awt.event.KeyEvent;
|
|
|
+import java.util.Arrays;
|
|
|
|
|
|
-import main.Window;
|
|
|
import model.GameStateManager;
|
|
|
import resources.image.Images;
|
|
|
import resources.image.Images.ImageType;
|
|
|
|
|
|
public class MenuState extends State {
|
|
|
+
|
|
|
+ public static String name = "Guest" + Math.round((Math.random()*1000));
|
|
|
+ private static int[] not_allowed = {KeyEvent.VK_COMMA, KeyEvent.VK_SEMICOLON, KeyEvent.VK_PERIOD, KeyEvent.VK_QUOTE, KeyEvent.VK_QUOTEDBL, KeyEvent.VK_SHIFT};
|
|
|
|
|
|
public MenuState(GameStateManager gsm) {
|
|
|
super("menu", gsm);
|
|
|
@@ -18,6 +22,7 @@ public class MenuState extends State {
|
|
|
/* INIT AND EXIT */
|
|
|
@Override
|
|
|
public void init() {
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -33,10 +38,20 @@ public class MenuState extends State {
|
|
|
@Override
|
|
|
public void paint(Graphics2D g2) {
|
|
|
g2.drawImage(Images.getImage(ImageType.BACKGROUND_MENU), 0,0,null);
|
|
|
- g2.drawString("Fill in your name and press ENTER to start the game", Window.WIDTH / 2, Window.HEIGHT / 2);
|
|
|
+ g2.drawImage(Images.getImage(ImageType.PLAYER1).getSubimage(38, 0, 40, 54), 610, 550, null);
|
|
|
+ g2.drawImage(Images.getImage(ImageType.PLAYER2).getSubimage(38, 0, 40, 54), 670, 550, null);
|
|
|
+
|
|
|
+ g2.setColor(Color.WHITE);
|
|
|
+
|
|
|
+ g2.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
|
|
+ g2.drawString("Type your name and press ENTER to start the game", 20, 690);
|
|
|
+
|
|
|
+ g2.setFont(new Font("Segoe UI", Font.BOLD, 30));
|
|
|
+ g2.drawString(name.toString(), 20, 730);
|
|
|
+ g2.drawRect(15, 702, 380, 36);
|
|
|
|
|
|
g2.setFont(new Font("Segoe UI", Font.BOLD, 80));
|
|
|
- g2.drawString("Bubble Trouble", 100, 100);
|
|
|
+ g2.drawString("Bubble Trouble", 100, 150);
|
|
|
}
|
|
|
|
|
|
/* EVENTS */
|
|
|
@@ -45,14 +60,21 @@ public class MenuState extends State {
|
|
|
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
|
|
gsm.setState("play");
|
|
|
}
|
|
|
+
|
|
|
+ if(e.getKeyCode() == KeyEvent.VK_BACK_SPACE && name.length() > 0)
|
|
|
+ {
|
|
|
+ name = name.substring(0, name.length()-1);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void keyReleased(KeyEvent e) {
|
|
|
-
|
|
|
+ if(name.length() <= 15 && e.getKeyCode() != KeyEvent.VK_BACK_SPACE && !Arrays.asList(not_allowed).contains(e.getKeyCode()))
|
|
|
+ {
|
|
|
+ name += e.getKeyChar();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void keyTyped(KeyEvent e) {
|
|
|
- }
|
|
|
+ public void keyTyped(KeyEvent e) {}
|
|
|
}
|