started on uebung04

This commit is contained in:
Johannes Schmelz 2024-05-06 22:26:56 +02:00
parent 7ac35f607a
commit cbeca1b3c0
8 changed files with 82 additions and 7 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,4 +2,20 @@ package uebung04;
public class ByeGame extends Game{ public class ByeGame extends Game{
private String player1;
public ByeGame(String player1, Game player2){
this.player1 = player1;
this.player2 = player2;
}
public String getPlayer1(){return player1;}
public ??? getPlayer2(){
return player2.getAllPlayers();
}
} }

View File

@ -1,23 +1,23 @@
package uebung04; package uebung04;
import java.util.List; import java.util.ArrayList;
public abstract class Game { public abstract class Game {
protected static int counter = 0; protected static int counter = 0;
protected final int id; protected final int id;
protected String player1; protected T player1 = null;
protected String player2; protected String player2 = null;
protected String winner; protected String winner = null;
public Game(){ protected Game(){
id = counter; id = counter;
counter++; counter++;
} }
public int getId() {return id;} public int getId() {return id;}
public String getWinner(){return winner;} protected String getWinner(){return winner;}
public void setWinner(int player){ public void setWinner(int player){
if (player == 1) { if (player == 1) {
@ -28,7 +28,8 @@ public abstract class Game {
} }
public abstract String getPlayer1(); public abstract String getPlayer1();
public abstract String getPlayer2(); public abstract String getPlayer2();
public abstract List<String> getAllPlayers(); public abstract ArrayList<String> getAllPlayers();
} }

View File

@ -1,5 +1,32 @@
package uebung04; package uebung04;
import java.util.ArrayList;
public class OrdinaryGame extends Game{ public class OrdinaryGame extends Game{
private final int id;
public OrdinaryGame(Game player1, Game player2){
this.player1 = player1;
this.player2 = player2;
id = counter;
counter++;
}
public ArrayList<String> getPlayer1(){
return player1.getAllPlayers();
}
public ArrayList<String> getPlayer2(){
return player2.getAllPlayers();
}
public ArrayList<String> getAllPlayers(){
ArrayList<String> rtn = player1.getAllPlayers();
rtn.addAll(player2.getAllPlayers());
return rtn;
}
} }

View File

@ -1,5 +1,36 @@
package uebung04; package uebung04;
import java.util.ArrayList;
public class SeededGame extends Game{ public class SeededGame extends Game{
private String player1;
private String player2;
private int id;
public SeededGame(String player1, String player2){
this.player1 = player1;
this.player2 = player2;
// super();
id = counter;
counter++;
}
@Override
public String getPlayer1(){
return player1;
}
@Override
public String getPlayer2(){
return player2;
}
@Override
public ArrayList<String> getAllPlayers(){
ArrayList<String> e = new ArrayList<String>();
e.add(player1);
e.add(player2);
return e;
}
} }