52 lines
1.2 KiB
Java
52 lines
1.2 KiB
Java
package tournament;
|
|
|
|
import java.util.List;
|
|
|
|
public abstract class Game {
|
|
private static int counter = 0;
|
|
protected final int id;
|
|
//null nicht notwendig
|
|
protected String winner = null;
|
|
|
|
|
|
protected Game() {
|
|
this.id = counter++;
|
|
}
|
|
|
|
public int getId(){
|
|
return this.id;
|
|
}
|
|
|
|
public String getWinner(){
|
|
return this.winner;
|
|
}
|
|
|
|
public void setWinner(String winner) {
|
|
if (this.winner != null)
|
|
throw new IllegalStateException("winner already set");
|
|
if (getPlayer1() == null || getPlayer2() == null)
|
|
throw new IllegalStateException("Opponents are not yet known");
|
|
if (getPlayer1().equals(winner) || getPlayer2().equals(winner))
|
|
this.winner = winner;
|
|
else
|
|
throw new IllegalArgumentException("Unknown player " + winner);
|
|
}
|
|
|
|
|
|
public abstract String getPlayer1();
|
|
|
|
public abstract String getPlayer2();
|
|
|
|
public abstract List<String> getAllPlayers();
|
|
|
|
public abstract List<String> getRemaningPlayers();
|
|
|
|
public abstract List<Game> getAllGames();
|
|
|
|
public String toString(){
|
|
return "Game: " + getId() + " Player: "+ getPlayer1()+ " vs Player: " + getPlayer2() + "Winner is: "+ getWinner();
|
|
}
|
|
|
|
|
|
}
|