|
@ -3,10 +3,16 @@ package de.hsfulda.onses.models; |
|
|
import de.hsfulda.onses.services.GameService; |
|
|
import de.hsfulda.onses.services.GameService; |
|
|
import de.hsfulda.onses.services.PlayerService; |
|
|
import de.hsfulda.onses.services.PlayerService; |
|
|
|
|
|
|
|
|
|
|
|
import java.beans.PropertyChangeSupport; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
|
public class Game { |
|
|
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 GameService gameService; |
|
|
private PlayerService playerService; |
|
|
private PlayerService playerService; |
|
|
|
|
|
|
|
@ -22,7 +28,9 @@ public class Game { |
|
|
lastPlayedCard.setColor(color); |
|
|
lastPlayedCard.setColor(color); |
|
|
} |
|
|
} |
|
|
public Game setLastPlayedCard(Card lastPlayedCard) { |
|
|
public Game setLastPlayedCard(Card lastPlayedCard) { |
|
|
|
|
|
final Card oldLastPlayedCard = this.lastPlayedCard; |
|
|
this.lastPlayedCard = lastPlayedCard; |
|
|
this.lastPlayedCard = lastPlayedCard; |
|
|
|
|
|
this.firePropertyChange(PROPERTY_LAST_PLAYED_CARD, oldLastPlayedCard, lastPlayedCard); |
|
|
return this; |
|
|
return this; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -31,7 +39,9 @@ public class Game { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void addCardToDrawCardDeck(Card card) { |
|
|
public void addCardToDrawCardDeck(Card card) { |
|
|
|
|
|
final ArrayList<Card> oldCards = new ArrayList<>(this.drawCardDeck); |
|
|
drawCardDeck.add(card); |
|
|
drawCardDeck.add(card); |
|
|
|
|
|
this.firePropertyChange(PROPERTY_DRAW_CARD_DECK, oldCards, drawCardDeck); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public GameService getGameService() { |
|
|
public GameService getGameService() { |
|
@ -56,4 +66,19 @@ public class Game { |
|
|
{ |
|
|
{ |
|
|
this.playerService = new PlayerService().setGame(this); |
|
|
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; |
|
|
|
|
|
} |
|
|
} |
|
|
} |