javadoc
This commit is contained in:
		
							parent
							
								
									b598eb660b
								
							
						
					
					
						commit
						30afecb379
					
				| 
						 | 
				
			
			@ -1,29 +1,51 @@
 | 
			
		|||
package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView;
 | 
			
		||||
 | 
			
		||||
import ch.zhaw.projekt2.turnierverwaltung.*;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
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{
 | 
			
		||||
    private Game game;
 | 
			
		||||
    private List<IsObserver> listener = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Setup the GameDecorator
 | 
			
		||||
     *
 | 
			
		||||
     * @param game Model for the Controller
 | 
			
		||||
     */
 | 
			
		||||
    public GameDecorator (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
 | 
			
		||||
    public void addListener(IsObserver observer) {
 | 
			
		||||
        listener.add(observer);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Removes a Listener from the Listener List
 | 
			
		||||
     *
 | 
			
		||||
     * @param observer the Listener to be removed
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void removeListener(IsObserver 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){
 | 
			
		||||
        if(points1.length() > 0){
 | 
			
		||||
            game.setPoints1(Integer.parseInt(points1));
 | 
			
		||||
| 
						 | 
				
			
			@ -38,19 +60,35 @@ public class GameDecorator implements IsObservable{
 | 
			
		|||
        informListener();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Saves the Place in the Model
 | 
			
		||||
     *
 | 
			
		||||
     * @param place
 | 
			
		||||
     */
 | 
			
		||||
    public void saveGamePlace(Place place){
 | 
			
		||||
        game.setPlace(place);
 | 
			
		||||
        informListener();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return game points from player one
 | 
			
		||||
     */
 | 
			
		||||
    public String getPoints1() {
 | 
			
		||||
       return String.valueOf(game.getPoints1());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     *
 | 
			
		||||
     *@return game points from player two
 | 
			
		||||
     */
 | 
			
		||||
    public String getPoints2() {
 | 
			
		||||
        return String.valueOf(game.getPoints2());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     *
 | 
			
		||||
     * @return returns Gameparticipant one
 | 
			
		||||
     */
 | 
			
		||||
    public String getParticipantOne() {
 | 
			
		||||
        if (game.getParticipant1() != null) {
 | 
			
		||||
            return game.getParticipant1().toString();
 | 
			
		||||
| 
						 | 
				
			
			@ -58,6 +96,10 @@ public class GameDecorator implements IsObservable{
 | 
			
		|||
        return "1";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     *
 | 
			
		||||
     * @return returns Gameparticipant two
 | 
			
		||||
     */
 | 
			
		||||
    public String getParticipantTwo() {
 | 
			
		||||
        if (game.getParticipant2() != null) {
 | 
			
		||||
            return game.getParticipant2().toString();
 | 
			
		||||
| 
						 | 
				
			
			@ -65,15 +107,25 @@ public class GameDecorator implements IsObservable{
 | 
			
		|||
        return "2";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * calls method in model to refresh participant
 | 
			
		||||
     */
 | 
			
		||||
    public void refreshParticipants(){
 | 
			
		||||
        game.refreshParticipants();
 | 
			
		||||
        informListener();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     *
 | 
			
		||||
     * @return place
 | 
			
		||||
     */
 | 
			
		||||
    public Place getPlace() {
 | 
			
		||||
        return game.getPlace();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Method that informs all listeners of an update.
 | 
			
		||||
     */
 | 
			
		||||
    public void informListener() {
 | 
			
		||||
        for(IsObserver observer : listener) {
 | 
			
		||||
            observer.update();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue