Compare commits
2 Commits
136be17443
...
e7f7a20ea6
Author | SHA1 | Date | |
---|---|---|---|
e7f7a20ea6 | |||
703097ad4d |
@ -8,7 +8,7 @@ public class ByeGame extends Game{
|
||||
private final String player1;
|
||||
private final Game ref;
|
||||
|
||||
ByeGame(String player1, Game ref){
|
||||
ByeGame(String player1, Game ref) {
|
||||
super();
|
||||
this.ref = ref;
|
||||
this.player1 = player1;
|
||||
@ -38,16 +38,22 @@ public class ByeGame extends Game{
|
||||
|
||||
|
||||
@Override
|
||||
public List<Game> getAllGames()
|
||||
{
|
||||
List<Game> temp = new ArrayList(Arrays.asList(this.getId()));
|
||||
public List<Game> getAllGames() {
|
||||
List<Game> temp = new ArrayList<>();
|
||||
temp.add(this);
|
||||
temp.addAll(ref.getAllGames());
|
||||
return temp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRemaningPlayers() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getRemaningPlayers'");
|
||||
if (winner != null) {
|
||||
return Arrays.asList(winner);
|
||||
} else {
|
||||
List<String> players = new ArrayList<>();
|
||||
players.add(player1);
|
||||
players.addAll(ref.getRemaningPlayers());
|
||||
return players;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,45 +3,49 @@ package tournament;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Game {
|
||||
private static int counter = 0;
|
||||
private final int id;
|
||||
//null nicht notwendig
|
||||
private String winner = null;
|
||||
|
||||
private static int counter = 0;
|
||||
protected final int id;
|
||||
//null nicht notwendig
|
||||
protected String winner = null;
|
||||
|
||||
|
||||
protected Game() {
|
||||
this.id = counter++;
|
||||
}
|
||||
protected Game() {
|
||||
this.id = counter++;
|
||||
}
|
||||
|
||||
public int getId(){
|
||||
return this.id;
|
||||
}
|
||||
public int getId(){
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getWinner(){
|
||||
return this.winner;
|
||||
}
|
||||
public String getWinner(){
|
||||
return this.winner;
|
||||
}
|
||||
|
||||
public void setWinner(String winner) {
|
||||
String player1 = getPlayer1();
|
||||
System.out.println("Player 1: " + player1);
|
||||
String player2 = getPlayer2();
|
||||
System.out.println("Player 2: " + player2);
|
||||
this.winner = this.winner == null && player1 != null && player2 != null && (winner == player1 || winner == player2) ? this.winner = winner : 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 String getPlayer1();
|
||||
|
||||
public abstract List<String> getAllPlayers();
|
||||
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();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Game: " + getId() + " Player: "+ getPlayer1()+ " vs Player: " + getPlayer2() + "Winner is: "+ getWinner();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,45 +5,46 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class OrdinaryGame extends Game{
|
||||
|
||||
private Game Player1;
|
||||
private Game Player2;
|
||||
public OrdinaryGame(Game Player1, Game Player2)
|
||||
{
|
||||
|
||||
public OrdinaryGame(Game Player1, Game Player2) {
|
||||
this.Player1 = Player1;
|
||||
this.Player2 = Player2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayer1()
|
||||
{
|
||||
public String getPlayer1() {
|
||||
return Player1.getWinner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayer2()
|
||||
{
|
||||
public String getPlayer2() {
|
||||
return Player2.getWinner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllPlayers()
|
||||
{
|
||||
List<String> temp = new ArrayList();
|
||||
public List<String> getAllPlayers() {
|
||||
List<String> temp = new ArrayList<>();
|
||||
temp.addAll(Player1.getAllPlayers());
|
||||
temp.addAll(Player2.getAllPlayers());
|
||||
return temp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRemaningPlayers()
|
||||
{
|
||||
public List<String> getRemaningPlayers() {
|
||||
if(this.getWinner() != null)
|
||||
return new ArrayList<>(Arrays.asList(this.getWinner()));
|
||||
List<String> temp = new ArrayList();
|
||||
List<String> temp = new ArrayList<>();
|
||||
temp.addAll(Player1.getRemaningPlayers());
|
||||
temp.addAll(Player2.getRemaningPlayers());
|
||||
return temp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Game> getAllGames()
|
||||
{
|
||||
List<Game> temp = new ArrayList(Arrays.asList(this.getId()));
|
||||
public List<Game> getAllGames() {
|
||||
List<Game> temp = new ArrayList<>();
|
||||
temp.addAll(Player1.getAllGames());
|
||||
temp.addAll(Player2.getAllGames());
|
||||
return temp;
|
||||
|
@ -6,6 +6,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class SeededGame extends Game{
|
||||
|
||||
private String player1;
|
||||
private String player2;
|
||||
|
||||
@ -16,35 +17,32 @@ public class SeededGame extends Game{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayer1()
|
||||
{
|
||||
public String getPlayer1() {
|
||||
return player1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayer2()
|
||||
{
|
||||
public String getPlayer2() {
|
||||
return player2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllPlayers()
|
||||
{
|
||||
public List<String> getAllPlayers() {
|
||||
//return new ArrayList<String>(Arrays.asList(player1, player2));
|
||||
return List.of(player1, player2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRemaningPlayers()
|
||||
{
|
||||
if(this.getWinner() != null)
|
||||
public List<String> getRemaningPlayers() {
|
||||
if(this.getWinner() != null) {
|
||||
return new ArrayList<>(Arrays.asList(this.getWinner()));
|
||||
List<String> temp = new ArrayList(Arrays.asList(player1,player2));
|
||||
return temp;
|
||||
}
|
||||
|
||||
return List.of(player1, player2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Game> getAllGames()
|
||||
{
|
||||
public List<Game> getAllGames() {
|
||||
return List.of(this);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user