[Cruce-commit] SF.net SVN: cruce:[102] Java/trunk/src/prc/bubulina/cruce
Status: Beta
Brought to you by:
caiusb
|
From: <ali...@us...> - 2010-04-07 16:38:24
|
Revision: 102
http://cruce.svn.sourceforge.net/cruce/?rev=102&view=rev
Author: alinposho
Date: 2010-04-07 16:38:07 +0000 (Wed, 07 Apr 2010)
Log Message:
-----------
Modificari:
1) PlayerMap nu mai este singleton(singleton-urile sunt dificil de testat si in cazul nostru nu prea este necesar). In cazul in care trebuie il putem adauga.
2) Am scos metoda "registerForNotifications()" din interfata serverului. Clientii se vor inregistra la server apeland joinGame(). Un client nu poate juca daca nu este inregistrat pentru a primi mesaje de la server asa ca inregistrarea clientilor este obligatorie.
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java
Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java
Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java
Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java
Java/trunk/src/prc/bubulina/cruce/server/StartGameLogic.java
Java/trunk/src/prc/bubulina/cruce/server/Team.java
Modified: Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java 2010-04-07 15:39:48 UTC (rev 101)
+++ Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java 2010-04-07 16:38:07 UTC (rev 102)
@@ -5,8 +5,22 @@
public interface ServerInterface extends Remote {
+ /**
+ * Method used by the client to join a game of cards and to
+ * register itself to the server in order to be able to receive notifications
+ * Precondition: NO player will call joinGame() more than once
+ *@param name
+ *@param client
+ * @throws RemoteException
+ */
public Player joinGame(String name, ClientInterface client) throws RemoteException;
+ /**
+ * This will inform the server that a player is willing to start the game
+ * Precondition: No player shell call this method more than once
+ * @param sender
+ * @throws RemoteException
+ */
public void startGame(Player sender) throws RemoteException;
/**
@@ -45,14 +59,4 @@
*/
public Score getOverallScore() throws RemoteException;
- /**
- * Method used by the client to register itself to the server in order to be
- * able to receive notifications
- *
- * @param callback
- * @throws RemoteException
- */
- public void registerForNotifications(ClientInterface callback)
- throws RemoteException;
-
}
Modified: Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java 2010-04-07 15:39:48 UTC (rev 101)
+++ Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java 2010-04-07 16:38:07 UTC (rev 102)
@@ -3,14 +3,17 @@
import java.util.List;
public class GameLogic {
+
private List<Team> teams;
private RoundLogic roundLogic;
+
public void startGame(List<Team> teams) {
this.teams = teams;
roundLogic = new RoundLogic(teams);
while (endOfGame() == false)
roundLogic.startRound();
}
+
public boolean endOfGame() {
for (Team t : teams)
if (t.getOverallScore() >= 15)
Modified: Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java 2010-04-07 15:39:48 UTC (rev 101)
+++ Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java 2010-04-07 16:38:07 UTC (rev 102)
@@ -10,19 +10,14 @@
public class PlayerMap {
private Map<Player, ServerSidePlayer> data;
private Map<Player, ClientInterface> clients;
- private static PlayerMap instance;
+
- private PlayerMap() {
+ public PlayerMap() {
+
data = new HashMap<Player, ServerSidePlayer>();
clients = new HashMap<Player, ClientInterface>();
- }
+ }
- public static PlayerMap getInstance() {
- if (instance == null)
- instance = new PlayerMap();
- return instance;
- }
-
public void put(ServerSidePlayer ssplayer, ClientInterface client) {
data.put(ssplayer.getInfo(), ssplayer);
clients.put(ssplayer.getInfo(), client);
Modified: Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-07 15:39:48 UTC (rev 101)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-07 16:38:07 UTC (rev 102)
@@ -14,7 +14,10 @@
private static ServerImplementation instance;
- private ServerImplementation() {}
+ private ServerImplementation() {
+
+ super();
+ }
public synchronized static ServerImplementation getInstance() {
if (instance == null)
@@ -26,9 +29,10 @@
private List<ClientInterface> clients = new LinkedList<ClientInterface>();
private StartGameLogic startGameLogic;
private GameLogic gameLogic;
+ private PlayerMap playerMap = new PlayerMap();
public synchronized boolean sendCards(List<Card> cards, ServerSidePlayer player) {
- ClientInterface client = PlayerMap.getInstance().getClient(player.getInfo());
+ ClientInterface client = playerMap.getClient(player.getInfo());
try {
if (client.receiveCards(cards) == false) {
@@ -63,16 +67,13 @@
public synchronized Player joinGame(String name, ClientInterface client) throws RemoteException {
- ServerSidePlayer ssplayer = startGameLogic.setupPlayer(name, client);
+ ServerSidePlayer ssplayer = startGameLogic.setupPlayer(name);
+ playerMap.put(ssplayer, client);
if (ssplayer != null)
return ssplayer.getInfo();
return null;
}
-
- public synchronized void registerForNotifications(ClientInterface callback) throws RemoteException {
- clients.add(callback);
- }
-
+
public synchronized void startGame(Player sender) throws RemoteException {
startGameLogic.playerReady();
if (startGameLogic.gameReady()) {
Modified: Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java 2010-04-07 15:39:48 UTC (rev 101)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java 2010-04-07 16:38:07 UTC (rev 102)
@@ -6,19 +6,25 @@
import prc.bubulina.cruce.remote.Player;
public class ServerSidePlayer {
+
private Player player;
private List<Card> cards;
private int order;
+
public ServerSidePlayer(Player player) {
this.player = player;
}
+
public List<Card> getCards() {
return cards;
}
+
public boolean hasCard(Card card) {
return cards.contains(card);
}
+
public boolean hasAnunt(Card card, int anunt) {
+
if (anunt == 40 && card.isTromf() == false)
return false;
else if (anunt == 20 && card.isTromf() == true)
@@ -31,6 +37,7 @@
return false;
}
}
+
public boolean checkHit(Card card, Card[] cardsDown) {
if (this.hasCard(card) == false)
return false;
@@ -50,6 +57,7 @@
}
return true;
}
+
public Player getInfo() {
return player;
}
Modified: Java/trunk/src/prc/bubulina/cruce/server/StartGameLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/StartGameLogic.java 2010-04-07 15:39:48 UTC (rev 101)
+++ Java/trunk/src/prc/bubulina/cruce/server/StartGameLogic.java 2010-04-07 16:38:07 UTC (rev 102)
@@ -3,13 +3,14 @@
import java.util.LinkedList;
import java.util.List;
-import prc.bubulina.cruce.remote.ClientInterface;
import prc.bubulina.cruce.remote.Player;
public class StartGameLogic {
+
private int joinedPlayers;
private int readyPlayers;
private List<Team> teams;
+
public StartGameLogic() {
joinedPlayers = 0;
readyPlayers = 0;
@@ -17,25 +18,31 @@
teams.add(new Team());
teams.add(new Team());
}
- public ServerSidePlayer setupPlayer(String name, ClientInterface client) {
+
+ public ServerSidePlayer setupPlayer(String name) {
+
if (joinedPlayers < 4) {
+
Player player = PlayerFactory.getPlayer(name);
- ServerSidePlayer ssplayer = new ServerSidePlayer(player);
- PlayerMap.getInstance().put(ssplayer, client);
+ ServerSidePlayer ssplayer = new ServerSidePlayer(player);
joinedPlayers++;
int teamIndex = player.getID() % 2;
teams.get(teamIndex).addPlayer(ssplayer);
+
return ssplayer;
}
+
return null;
}
- public boolean playerReady() {
+
+ public boolean playerReady() {
if (readyPlayers < 4) {
readyPlayers++;
return true;
}
return false;
}
+
public boolean gameReady() {
return readyPlayers == 4;
}
Modified: Java/trunk/src/prc/bubulina/cruce/server/Team.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/Team.java 2010-04-07 15:39:48 UTC (rev 101)
+++ Java/trunk/src/prc/bubulina/cruce/server/Team.java 2010-04-07 16:38:07 UTC (rev 102)
@@ -11,6 +11,7 @@
private int goal;
private List<Card> cardsTaken;
private int overallScore;
+
public Team() {
players = new LinkedList<ServerSidePlayer>();
cardsTaken = new LinkedList<Card>();
@@ -18,12 +19,15 @@
goal = 0;
overallScore = 0;
}
+
public void addPlayer(ServerSidePlayer player) {
players.add(player);
}
+
public List<ServerSidePlayer> getPlayers() {
return players;
}
+
public void addCard(Card card) {
cardsTaken.add(card);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|