package application.domain;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Serializable;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import application.services.SaveGameDAO;
import application.util.Logger;
import application.util.Logger.Verbosity;
// TODO: Auto-generated Javadoc
/**
* The Class GameImpl.
*
* @author Sanchez
*/
public class GameImpl extends UnicastRemoteObject implements Reinitializable, Game, Serializable {
private static final long serialVersionUID = -2852281344739846301L;
private GameState gameState;
private transient Registry registry;
private PlayingFieldImpl playingField;
private int currentPlayerIdx;
private int roundNr;
private int maxPlayers;
private boolean reserveCardInventoryFull;
private List<Player> players; // Contains a list of PlayerImpl on server
private Player winningPlayer;
private transient Map<GameObserver, Player> observers;
private EndTurnImpl endTurn;
/**
* Instantiates a new game impl.
*
* @param maxPlayers the max players
* @throws RemoteException the remote exception
*/
public GameImpl(int maxPlayers) throws RemoteException {
this.maxPlayers = maxPlayers;
this.roundNr = 0;
this.currentPlayerIdx = -1;
this.players = new ArrayList<Player>();
this.observers = new LinkedHashMap<GameObserver, Player>();
//this.debugCreate4Players();
this.playingField = new PlayingFieldImpl(this.maxPlayers);
this.endTurn = new EndTurnImpl(this);
}
/* (non-Javadoc)
* @see application.domain.Game#nextTurn()
*/
public void nextTurn() throws RemoteException
{
System.out.println("[DEBUG] GameImpl::nextTurn()::Next turn started");
currentPlayerIdx++;
if(currentPlayerIdx >= players.size() || currentPlayerIdx < 0) {
currentPlayerIdx = 0;
}
roundNr++;
try {
playingField.newTurn();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.playingField.getTempHand().updatePlayer(this.getCurrentPlayer());
System.out.printf("[DEBUG] GameImpl::nextTurn()::Current player: %s(ID: %d)\n", this.getCurrentPlayer().getName(), currentPlayerIdx);
this.notifyObservers();
}
/* (non-Javadoc)
* @see application.domain.Game#isDisabled(application.domain.GameObserver)
*/
public boolean isDisabled(GameObserver o) throws RemoteException
{
Player player = observers.get(o);
return !(player.getName().equals(this.getCurrentPlayer().getName()));
}
/* (non-Javadoc)
* @see application.domain.Game#saveGame()
*/
@Override
public void saveGame() throws RemoteException
{
try {
SaveGameDAO.getInstance().saveGameToFile(this);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/* (non-Javadoc)
* @see application.domain.Game#findSelectableCards(application.domain.MoveType)
*/
@Override
public void findSelectableCards(MoveType moveType) throws RemoteException {
this.playingField.getTempHand().setMoveType(moveType);
if(moveType == MoveType.PURCHASE_CARD) {
this.getCurrentPlayer().findSelectableCardsFromReserve();
}
playingField.findSelectableCardsFromField();
}
/* (non-Javadoc)
* @see application.domain.Game#reserveCardInventoryFull()
*/
//TODO not yet tested
public boolean reserveCardInventoryFull() throws RemoteException
{
System.out.println("reserve card inventory full aantal: " + this.getCurrentPlayer().getReservedCards().size());
if(this.getCurrentPlayer().getReservedCards().size() == 3)
{
reserveCardInventoryFull = true;
}
else
{
reserveCardInventoryFull = false;
}
return reserveCardInventoryFull;
}
/* (non-Javadoc)
* @see application.domain.Game#setTokensSelectable(application.domain.MoveType)
*/
@Override
public void setTokensSelectable(MoveType moveType) throws RemoteException {
this.playingField.setTokensSelectable(moveType);
}
/* (non-Javadoc)
* @see application.domain.Game#getCurrentPlayerIdx()
*/
public int getCurrentPlayerIdx() throws RemoteException {
return currentPlayerIdx;
}
/* (non-Javadoc)
* @see application.domain.Game#getRoundNr()
*/
public int getRoundNr() throws RemoteException {
return roundNr;
}
/* (non-Javadoc)
* @see application.domain.Game#getPlayers()
*/
public List<Player> getPlayers() throws RemoteException {
return players;
}
/**
* Sets the players.
*
* @param players the new players
*/
public void setPlayers(List<Player> players) {
this.players = players;
}
/* (non-Javadoc)
* @see application.domain.Game#getPlayingField()
*/
public PlayingField getPlayingField() throws RemoteException {
return playingField;
}
/* (non-Javadoc)
* @see application.domain.Game#getCurrentPlayer()
*/
public Player getCurrentPlayer() throws RemoteException {
return players.get(currentPlayerIdx);
}
/**
* Gets the max players.
*
* @return the max players
* @throws RemoteException the remote exception
*/
public int getMaxPlayers() throws RemoteException {
return maxPlayers;
}
/**
* Gets the game state.
*
* @return GameSate
* @throws RemoteException the remote exception
*/
public GameState getGameState() throws RemoteException {
return gameState;
}
/**
* Notify observers.
*
* @throws RemoteException the remote exception
*/
public synchronized void notifyObservers() throws RemoteException
{
System.out.println("[DEBUG] GameImpl::notifyObservers()::Notifying all game observers of change");
for(GameObserver o : observers.keySet())
{
try {
o.modelChanged(this);
} catch (RemoteException e) {
Logger.log(String.format("GameImpl::notifyObservers()::Lost connection to observer: %s", o.toString()), Verbosity.DEBUG);
this.observers.remove(o);
this.terminateGame();
}
}
}
/* (non-Javadoc)
* @see application.domain.Game#addObserver(application.domain.GameObserver)
*/
@Override
public synchronized void addObserver(GameObserver o, Player player) throws RemoteException {
this.observers.put(o, player);
this.notifyObservers();
}
/* (non-Javadoc)
* @see application.domain.Game#removeObserver(application.domain.GameObserver)
*/
@Override
public synchronized void removeObserver(GameObserver o) throws RemoteException {
this.observers.remove(o);
this.notifyObservers();
}
/* (non-Javadoc)
* @see application.domain.Game#updatePlayingFieldAndPlayerView()
*/
@Override
public void cleanUpTurn() throws RemoteException {
playingField.getTempHand().emptyHand();
}
/* (non-Javadoc)
* @see application.domain.Game#updatePlayingFieldAndPlayerView()
*/
public void updatePlayingFieldAndPlayerView() throws RemoteException {
for(CardRow cardRow : playingField.getCardRows()) {
cardRow.updateView();
}
this.getCurrentPlayer().updatePlayerView();
}
/* (non-Javadoc)
* @see application.domain.Game#cleanUpSelections()
*/
@Override
public void cleanUpSelections() throws RemoteException {
this.playingField.getTempHand().emptyHand();
for(CardRow cardRow : playingField.getCardRows()) {
cardRow.clearSelectableCards();
}
playingField.newTurn();
this.getCurrentPlayer().clearSelectableCards();
this.notifyObservers();
}
/* (non-Javadoc)
* @see application.domain.Game#addCardToTempFromReserve(application.domain.Card)
*/
@Override
public void reserveCardFromDeck(int cardRowIdx)
没有合适的资源?快使用搜索试试~ 我知道了~
iipsen:用Java编写的多人纸牌游戏Splendor。 文件->
共408个文件
html:233个
java:79个
png:47个
需积分: 10 3 下载量 2 浏览量
2021-05-12
07:52:08
上传
评论
收藏 51.98MB ZIP 举报
温馨提示
辉煌-IIPSEN项目 近年来,越来越多的不同类型的棋盘游戏已经发布。 越来越多的人设计游戏并可以发布它,所以现在市场上有很多游戏,其中很多都不是很知名。 这些游戏可以数字化方式制作,并提供给更广泛的受众。 棋盘游戏的数字版本也具有更多优势。 可以添加游戏功能来帮助肢体残障人士,使他们在玩游戏时不会或不会感到不适。 同样,由于它是数字的,因此可以与世界各地的人们一起玩游戏。 例如,祖母可以在自己几英里外的床上舒适地与孙女一起玩游戏。 由于采用了数字分配,因此在生产和交付中也消除了许多成本。 无需再打印和切割卡片,或将箱子运送到商店和其他国家/地区。 因此,游戏的价格也可能与实体棋盘游戏有所不同,这是2020年游戏的决定。
资源详情
资源评论
资源推荐
收起资源包目录
iipsen:用Java编写的多人纸牌游戏Splendor。 文件-> (408个子文件)
.classpath 596B
stylesheet.css 13KB
application.css 4KB
application_deployed.css 4KB
cards.csv 3KB
nobles.csv 209B
build.fxbuild 299B
.gitignore 2KB
.gitignore 70B
GameImpl.html 61KB
index-7.html 58KB
LobbyImpl.html 52KB
Gem.html 52KB
PlayingFieldImpl.html 51KB
PlayerImpl.html 51KB
Card.html 39KB
TempHandImpl.html 37KB
GameView.html 37KB
index-3.html 35KB
PlayerView.html 34KB
index-16.html 34KB
PlayingFieldView.html 34KB
index-17.html 34KB
Player.html 33KB
CardRowImpl.html 33KB
constant-values.html 32KB
Game.html 30KB
Player.html 29KB
LobbyView.html 29KB
serialized-form.html 27KB
OpponentView.html 27KB
CardDeckImpl.html 27KB
PlayingField.html 26KB
EndTurnImpl.html 26KB
Lobby.html 25KB
Noble.html 25KB
index-1.html 24KB
PlayerSlotImpl.html 24KB
ReturnTokens.html 24KB
CardImpl.html 24KB
overview-tree.html 24KB
GameController.html 23KB
Token.html 23KB
LobbyObserver.html 22KB
TempHand.html 21KB
package-use.html 21KB
CardRowView.html 20KB
index-15.html 20KB
index-2.html 19KB
MainMenuView.html 19KB
NobleView.html 18KB
FrontCardView.html 18KB
index-19.html 18KB
NobleImpl.html 17KB
ReturnTokensView.html 17KB
TestLobby.html 17KB
index-18.html 17KB
TempHand.html 17KB
CardsReader.html 17KB
NoblesReader.html 16KB
index-12.html 16KB
TokenView.html 16KB
TestPlayingField.html 16KB
MainMenuController.html 16KB
GemView.html 16KB
index-9.html 16KB
LobbyController.html 16KB
CardRow.html 16KB
MoveType.html 16KB
index-13.html 16KB
CardRow.html 16KB
Game.html 16KB
index-11.html 15KB
SaveGameDAO.html 15KB
CardLevel.html 15KB
CardDeck.html 15KB
package-summary.html 15KB
CardLevel.html 15KB
Gem.html 15KB
NobleDeck.html 15KB
ColorBlindModes.html 15KB
DeckFactory.html 14KB
TokenList.html 14KB
package-tree.html 14KB
Logger.Verbosity.html 14KB
CardView.html 14KB
PlayerSlot.html 14KB
PlayingField.html 14KB
TestLobby.LobbyStates.html 14KB
StageManager.html 14KB
TestOpslaanSpel.html 13KB
AlertDialog.html 13KB
RearCardView.html 13KB
CardDeckView.html 13KB
MoveType.html 13KB
LobbyImpl.LobbyStates.html 13KB
TokenImpl.html 13KB
Lobby.html 13KB
TestToken.html 13KB
ReturnTokens.ReturnTokenState.html 13KB
共 408 条
- 1
- 2
- 3
- 4
- 5
吃肥皂吐泡沫
- 粉丝: 28
- 资源: 4587
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0