This commit is contained in:
Andrin Fassbind 2022-05-13 23:57:31 +02:00
parent b598eb660b
commit 30afecb379
1 changed files with 54 additions and 2 deletions

View File

@ -1,29 +1,51 @@
package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView; package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView;
import ch.zhaw.projekt2.turnierverwaltung.*; import ch.zhaw.projekt2.turnierverwaltung.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* This Class is used by the GameController for additional functionality and holds the listeners and the Model Game
*/
public class GameDecorator implements IsObservable{ public class GameDecorator implements IsObservable{
private Game game; private Game game;
private List<IsObserver> listener = new ArrayList<>(); private List<IsObserver> listener = new ArrayList<>();
/**
* Setup the GameDecorator
*
* @param game Model for the Controller
*/
public GameDecorator (Game game) { public GameDecorator (Game game) {
this.game = game; this.game = game;
} }
/**
* Method adds a new Listener to the listener list
*
* @param observer that is being added to the Listener List
*/
@Override @Override
public void addListener(IsObserver observer) { public void addListener(IsObserver observer) {
listener.add(observer); listener.add(observer);
} }
/**
* Removes a Listener from the Listener List
*
* @param observer the Listener to be removed
*/
@Override @Override
public void removeListener(IsObserver observer) { public void removeListener(IsObserver observer) {
listener.remove(observer); listener.remove(observer);
} }
/**
* Saves the Gameresult in the model
*
* @param points1 points achieved in textfield one
* @param points2 points achieved in textfield two
*/
public void saveGameResult(String points1, String points2){ public void saveGameResult(String points1, String points2){
if(points1.length() > 0){ if(points1.length() > 0){
game.setPoints1(Integer.parseInt(points1)); game.setPoints1(Integer.parseInt(points1));
@ -38,19 +60,35 @@ public class GameDecorator implements IsObservable{
informListener(); informListener();
} }
/**
* Saves the Place in the Model
*
* @param place
*/
public void saveGamePlace(Place place){ public void saveGamePlace(Place place){
game.setPlace(place); game.setPlace(place);
informListener(); informListener();
} }
/**
* @return game points from player one
*/
public String getPoints1() { public String getPoints1() {
return String.valueOf(game.getPoints1()); return String.valueOf(game.getPoints1());
} }
/**
*
*@return game points from player two
*/
public String getPoints2() { public String getPoints2() {
return String.valueOf(game.getPoints2()); return String.valueOf(game.getPoints2());
} }
/**
*
* @return returns Gameparticipant one
*/
public String getParticipantOne() { public String getParticipantOne() {
if (game.getParticipant1() != null) { if (game.getParticipant1() != null) {
return game.getParticipant1().toString(); return game.getParticipant1().toString();
@ -58,6 +96,10 @@ public class GameDecorator implements IsObservable{
return "1"; return "1";
} }
/**
*
* @return returns Gameparticipant two
*/
public String getParticipantTwo() { public String getParticipantTwo() {
if (game.getParticipant2() != null) { if (game.getParticipant2() != null) {
return game.getParticipant2().toString(); return game.getParticipant2().toString();
@ -65,15 +107,25 @@ public class GameDecorator implements IsObservable{
return "2"; return "2";
} }
/**
* calls method in model to refresh participant
*/
public void refreshParticipants(){ public void refreshParticipants(){
game.refreshParticipants(); game.refreshParticipants();
informListener(); informListener();
} }
/**
*
* @return place
*/
public Place getPlace() { public Place getPlace() {
return game.getPlace(); return game.getPlace();
} }
/**
* Method that informs all listeners of an update.
*/
public void informListener() { public void informListener() {
for(IsObserver observer : listener) { for(IsObserver observer : listener) {
observer.update(); observer.update();