/* * Handle events common to all views. * Returns false if no action was taken. */ protected final void keyPressed(int keyCode) { if (modal != null) { if (modal.keyPressed(keyCode, this)) { if ((modal == menu) && (menu.execute())) { menuAction(menu.getAction()); } modal = modal.parentModal; } this.repaint(); System.out.println("repaint"); return; } switch (keyCode) { case -7: case KEY_POUND: modal = menu; this.repaint(); return; case -6: case KEY_STAR: case KEY_NUM0: // Convenience key when developing viewNavigator.ShowNext(); return; } keyPressedView(keyCode); // Let the current view handle this keypress }
public void play() { String[] keys = this.menu.keys(); int option = -1; LimitedIntDialog optionDialog = new LimitedIntDialog("Opcion: ", 1, exitOption); do { tableauView.show(); this.showMenu(keys); option = optionDialog.read(); if (option == exitOption) { MoveController.EXIT_FLAG = true; } else { menu.execute(keys[option - 1]); // index 0..N-1 vs 1..N } } while (!moveController.endOfTheGame() && !MoveController.EXIT_FLAG); IO.write("Gracias por jugar!!"); }