|
|
@ -3,10 +3,16 @@ package de.hsfulda.onses.models; |
|
|
|
import de.hsfulda.onses.services.GameService; |
|
|
|
import de.hsfulda.onses.services.PlayerService; |
|
|
|
|
|
|
|
import java.beans.PropertyChangeSupport; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
public class Game { |
|
|
|
|
|
|
|
public final static String PROPERTY_LAST_PLAYED_CARD = "lastPlayedCard"; |
|
|
|
public final static String PROPERTY_DRAW_CARD_DECK = "drawCardDeck"; |
|
|
|
|
|
|
|
protected PropertyChangeSupport listeners; |
|
|
|
|
|
|
|
private GameService gameService; |
|
|
|
private PlayerService playerService; |
|
|
|
|
|
|
@ -22,7 +28,9 @@ public class Game { |
|
|
|
lastPlayedCard.setColor(color); |
|
|
|
} |
|
|
|
public Game setLastPlayedCard(Card lastPlayedCard) { |
|
|
|
final Card oldLastPlayedCard = this.lastPlayedCard; |
|
|
|
this.lastPlayedCard = lastPlayedCard; |
|
|
|
this.firePropertyChange(PROPERTY_LAST_PLAYED_CARD, oldLastPlayedCard, lastPlayedCard); |
|
|
|
return this; |
|
|
|
} |
|
|
|
|
|
|
@ -31,7 +39,9 @@ public class Game { |
|
|
|
} |
|
|
|
|
|
|
|
public void addCardToDrawCardDeck(Card card) { |
|
|
|
final ArrayList<Card> oldCards = new ArrayList<>(this.drawCardDeck); |
|
|
|
drawCardDeck.add(card); |
|
|
|
this.firePropertyChange(PROPERTY_DRAW_CARD_DECK, oldCards, drawCardDeck); |
|
|
|
} |
|
|
|
|
|
|
|
public GameService getGameService() { |
|
|
@ -56,4 +66,19 @@ public class Game { |
|
|
|
{ |
|
|
|
this.playerService = new PlayerService().setGame(this); |
|
|
|
} |
|
|
|
|
|
|
|
public PropertyChangeSupport listeners() { |
|
|
|
if(this.listeners == null) { |
|
|
|
this.listeners = new PropertyChangeSupport(this); |
|
|
|
} |
|
|
|
return this.listeners; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean firePropertyChange(String propertyName, Object oldValue, Object newValue) { |
|
|
|
if(this.listeners != null) { |
|
|
|
this.listeners.firePropertyChange(propertyName, oldValue, newValue); |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |