/** Handles the key press event. */ private void handleKeyPress(String key) { if (key.equals("enter")) { handleStartGame(); } else { passwordInputLabel.handleKeyPress(key); if (passwordInputLabel.wasTextChanged()) { String password = passwordInputLabel.getText(); if (password.length() > 0) { checkPassword(password); } } } }
/** Initializes the screen. */ public void initScreen() { gameScreen.setCurrentLevelNumber(1); // reset level gameScreen.setBackground("start_screen.png"); startGameButton = new Button("Start Game", 130, 30, GameScreen.FONT_M); startGameButton.setBorderColor(Color.RED); startGameButton.setIcon(GameScreen.ICON_START); startGameButton.setBackgroundColor(new Color(255, 205, 205)); gameScreen.addObject(startGameButton, GameScreen.WIDTH_IN_CELLS / 2, 10); if (MyKara.HIGHSCORE_ENABLED) { highscoreButton = new Button("Highscore", 130, 30, GameScreen.FONT_M); highscoreButton.setBorderColor(Color.RED); highscoreButton.setIcon(GameScreen.ICON_HIGHSCORE); highscoreButton.setBackgroundColor(new Color(255, 205, 205)); gameScreen.addObject(highscoreButton, GameScreen.WIDTH_IN_CELLS / 2, 12); } Label enterPasswordLabel = new Label("Enter Level Password With Keyboard:", 230, 21, GameScreen.FONT_S); enterPasswordLabel.setBackgroundColor(Color.BLACK); enterPasswordLabel.setTextColor(new Color(255, 205, 205)); gameScreen.addObject(enterPasswordLabel, GameScreen.WIDTH_IN_CELLS / 2, 14); passwordInputLabel = new InputLabel("", 180, 21, GameScreen.FONT_M); passwordInputLabel.setBorderColor(null); passwordInputLabel.setBackgroundColor(new Color(255, 205, 205)); // passwordInputLabel.setMaxLength(10); gameScreen.addObject(passwordInputLabel, GameScreen.WIDTH_IN_CELLS / 2, 15); passwordOkLabel = new Label(95, 24, GameScreen.ICON_LOCKED); passwordOkLabel.setBackgroundTransparency(0); passwordOkLabel.setTextColor(new Color(255, 205, 205)); passwordOkLabel.setFont(GameScreen.FONT_S); passwordOkLabel.setIconVisible(true); passwordOkLabel.setAlign(Label.ALIGN_LEFT); gameScreen.addObject(passwordOkLabel, GameScreen.WIDTH_IN_CELLS / 2 + 5, 15); }