fixed Exception handling
This commit is contained in:
		| @@ -40,14 +40,21 @@ public class ByeGame extends Game{ | |||||||
|     @Override |     @Override | ||||||
|     public List<Game> getAllGames() |     public List<Game> getAllGames() | ||||||
|     { |     { | ||||||
|         List<Game> temp = new ArrayList(Arrays.asList(this.getId())); |         List<Game> temp = new ArrayList<>(); | ||||||
|  |         temp.add(this); | ||||||
|         temp.addAll(ref.getAllGames()); |         temp.addAll(ref.getAllGames()); | ||||||
|         return temp; |         return temp; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public List<String> getRemaningPlayers() { |     public List<String> getRemaningPlayers() { | ||||||
|         // TODO Auto-generated method stub |         if (winner != null) { | ||||||
|         throw new UnsupportedOperationException("Unimplemented method 'getRemaningPlayers'"); |             return Arrays.asList(winner); | ||||||
|  |         } else { | ||||||
|  |             List<String> players = new ArrayList<>(); | ||||||
|  |             players.add(player1); | ||||||
|  |             players.addAll(ref.getRemaningPlayers()); | ||||||
|  |             return players; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,9 +4,9 @@ import java.util.List; | |||||||
|  |  | ||||||
| public abstract class Game { | public abstract class Game { | ||||||
|    private static int counter = 0; |    private static int counter = 0; | ||||||
|    private final int id; |    protected final int id; | ||||||
|    //null nicht notwendig |    //null nicht notwendig | ||||||
|    private String winner = null; |    protected String winner = null; | ||||||
|  |  | ||||||
|  |  | ||||||
|    protected Game() { |    protected Game() { | ||||||
| @@ -22,13 +22,17 @@ public abstract class Game { | |||||||
|    } |    } | ||||||
|  |  | ||||||
|    public void setWinner(String winner) { |    public void setWinner(String winner) { | ||||||
|        String player1 = getPlayer1(); |         if (this.winner != null) | ||||||
|        System.out.println("Player 1: " + player1); |             throw new IllegalStateException("winner already set"); | ||||||
|        String player2 = getPlayer2(); |         if (getPlayer1() == null || getPlayer2() == null) | ||||||
|        System.out.println("Player 2: " + player2); |             throw new IllegalStateException("Opponents are not yet known"); | ||||||
|         this.winner = this.winner == null && player1 != null && player2 != null && (winner == player1 || winner == player2) ? this.winner = winner : this.winner; |         if (getPlayer1().equals(winner) || getPlayer2().equals(winner)) | ||||||
|  |             this.winner = winner; | ||||||
|  |         else | ||||||
|  |             throw new IllegalArgumentException("Unknown player " + winner); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|    public abstract String getPlayer1(); |    public abstract String getPlayer1(); | ||||||
|  |  | ||||||
|    public abstract String getPlayer2(); |    public abstract String getPlayer2(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user