@Override public void actionPerformed(ActionEvent e) { switch (e.getActionCommand()) { case "Cancel": screen.show("menu"); break; case "Create": Game startGame = new Game(); startGame.setName(screen.getStartGamePanel().getGameName()); startGame.setMapSize(25); Gamer opponent = new Gamer(); // For-loop kører brugerne igennem og viser dem i en comboBox // 1. if tjekker værdien af hvad der er valgt i comboBoxen og sammenligner med de brugere // som for-loopet kører igennem for (User u : users) { if (u.getUsername().equals(screen.getStartGamePanel().getSelectedUSer())) { opponent.setId(u.getId()); } } // If tjekker om hosten vil udfordre sig selv og giver fejlmeddelelse og ellers er spillet // oprettet. if (opponent.getId() == currentUser.getId()) { JOptionPane.showMessageDialog( screen, "Error: You need to choose a different opponent than yourself"); } else { Gamer host = new Gamer(); host.setId(currentUser.getId()); host.setControls(screen.getStartGamePanel().getControlsToSnake()); startGame.setHost(host); startGame.setOpponent(opponent); String message = api.createGame(startGame); JOptionPane.showMessageDialog(screen, message); screen.show("menu"); } break; } }
@Override public void actionPerformed(ActionEvent e) { switch (e.getActionCommand()) { case "Cancel": screen.show("menu"); break; case "Delete game": Game deleteGame = new Game(); deleteGame.setName(screen.getDeleteGamePanel().getSelectedGame()); for (Game g : deleteGames) { if (g.getName().equals(screen.getDeleteGamePanel().getSelectedGame())) { deleteGame = g; } } // Besked om at spillet er slettet String message = api.deleteGame(deleteGame.getGameId()); JOptionPane.showMessageDialog(screen, message); if (message.equals("Game was deleted")) { screen.getDeleteGamePanel().removeGame(); } break; } }