[Cruce-commit] SF.net SVN: cruce:[98] Java/trunk/src/prc/bubulina/cruce
Status: Beta
Brought to you by:
caiusb
|
From: <hor...@us...> - 2010-04-07 13:12:51
|
Revision: 98
http://cruce.svn.sourceforge.net/cruce/?rev=98&view=rev
Author: horiaradu
Date: 2010-04-07 13:12:45 +0000 (Wed, 07 Apr 2010)
Log Message:
-----------
Am implementat partea de start game si de join game, cat am stiut din ea. Sa te uiti peste ce am facut, cum am facut. Am nelamurire la cum ajunge Serverul sa stie de clienti (ClientInterface). Am facut modificat metoda joinGame, dar nu cred ca e ok. O sa ma mai uit peste restul, sa fac cat mai mult din ce stiu.
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/remote/Card.java
Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java
Java/trunk/src/prc/bubulina/cruce/remote/Color.java
Java/trunk/src/prc/bubulina/cruce/remote/Player.java
Java/trunk/src/prc/bubulina/cruce/remote/Score.java
Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java
Added Paths:
-----------
Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java
Java/trunk/src/prc/bubulina/cruce/server/PlayerFactory.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/Card.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-07 12:39:23 UTC (rev 97)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-07 13:12:45 UTC (rev 98)
@@ -1,34 +1,28 @@
package prc.bubulina.cruce.remote;
-public class Card
-{
+public class Card {
private int value;
private Color color;
private static Color tromf;
-
- public Card(int value, Color color)
- {
+
+ public Card(int value, Color color) {
this.color = color;
this.value = value;
}
- public int getValue()
- {
+ public int getValue() {
return value;
}
- public Color getColor()
- {
+ public Color getColor() {
return color;
}
-
- public static void setTromf(Color tromf)
- {
+
+ public static void setTromf(Color tromf) {
Card.tromf = tromf;
}
-
- public boolean isTromf()
- {
+
+ public boolean isTromf() {
return color.equals(tromf);
}
}
Modified: Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java 2010-04-07 12:39:23 UTC (rev 97)
+++ Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java 2010-04-07 13:12:45 UTC (rev 98)
@@ -4,64 +4,73 @@
import java.rmi.RemoteException;
import java.util.ArrayList;
-public interface ClientInterface extends Remote
-{
+public interface ClientInterface extends Remote {
/**
- * A method to receive informations from the server
+ * A method to receive informations from the server
+ *
* @param information
* @throws RemoteException
*/
public void inform(String information) throws RemoteException;
-
+
/**
* Through this method the client will receive the cards at the beginning of
- * the round
- * @param cards The list of card sent by the server
- * @return True in case the client accepts the cars. False in case the client rejects the
- * cards
+ * the round
+ *
+ * @param cards
+ * The list of card sent by the server
+ * @return True in case the client accepts the cars. False in case the
+ * client rejects the cards
* @throws RemoteException
*/
public boolean receiveCards(ArrayList<Card> cards) throws RemoteException;
-
+
/**
- * This method forces a client to receive a list of cards
- * @param cards
+ * This method forces a client to receive a list of cards
+ *
+ * @param cards
* @throws RemoteException
*/
public void forceReceive(ArrayList<Card> cards) throws RemoteException;
-
+
/**
- * Tells the client to bid
+ * Tells the client to bid
+ *
* @return The amount the client has bidded
* @throws RemoteException
*/
public int bid() throws RemoteException;
-
+
/**
- * Tells the client that he can start sending cards to the server
+ * Tells the client that he can start sending cards to the server
+ *
* @throws RemoteException
*/
public void hit() throws RemoteException;
-
+
/**
- * Informs the player about the tromf
+ * Informs the player about the tromf
+ *
* @param tromf
* @throws RemoteException
*/
- public void setTromf(Color tromf) throws RemoteException;
-
+ public void setTromf(Color tromf) throws RemoteException;
+
/**
* Informs the player about the score at the end of the round
+ *
* @param score
* @throws RemoteException
*/
public void receiveRoundScore(Score score) throws RemoteException;
-
+
/**
- * Informs the player that the game has ended and also sends the overall score
+ * Informs the player that the game has ended and also sends the overall
+ * score
+ *
* @param score
* @throws RemoteException
*/
- public void endGame(Score score) throws RemoteException;
-
+ public void endGame(Score score) throws RemoteException;
+
}
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Color.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Color.java 2010-04-07 12:39:23 UTC (rev 97)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Color.java 2010-04-07 13:12:45 UTC (rev 98)
@@ -1,9 +1,5 @@
package prc.bubulina.cruce.remote;
-public enum Color
-{
- ROSU,
- DUBA,
- VERDE,
- GHINDA
+public enum Color {
+ ROSU, DUBA, VERDE, GHINDA
}
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Player.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Player.java 2010-04-07 12:39:23 UTC (rev 97)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Player.java 2010-04-07 13:12:45 UTC (rev 98)
@@ -1,25 +1,20 @@
package prc.bubulina.cruce.remote;
-public class Player
-{
+public class Player {
private String name;
private int id;
-
- public Player(String name, int ID)
- {
+
+ public Player(String name, int ID) {
this.name = name;
this.id = ID;
}
- public String getName()
- {
+ public String getName() {
return name;
}
- public int getID()
- {
+ public int getID() {
return id;
}
-
-
+
}
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Score.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Score.java 2010-04-07 12:39:23 UTC (rev 97)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Score.java 2010-04-07 13:12:45 UTC (rev 98)
@@ -4,25 +4,23 @@
/**
* This class will be a container for a name value pair "player-score"
+ *
* @author alinposho
- *
+ *
*/
-public class Score
-{
+public class Score {
private Map<Player, Integer> score;
-
- public Score(Map<Player, Integer> score)
- {
+
+ public Score(Map<Player, Integer> score) {
this.score = score;
}
-
+
/**
*
* @param player
* @return The score of the player identified by the argument
*/
- public int getYourScore(Player player)
- {
+ public int getYourScore(Player player) {
return score.get(player);
}
}
Modified: Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java 2010-04-07 12:39:23 UTC (rev 97)
+++ Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java 2010-04-07 13:12:45 UTC (rev 98)
@@ -3,47 +3,56 @@
import java.rmi.Remote;
import java.rmi.RemoteException;
-public interface ServerInterface extends Remote
-{
-
- public Player joinGame(String name) throws RemoteException;
-
+public interface ServerInterface extends Remote {
+
+ public Player joinGame(String name, ClientInterface client) throws RemoteException;
+
public void startGame(Player sender) throws RemoteException;
-
+
/**
* Though this method the server receives a card sent by the client
- * @param sender The player who sent the card
- * @param card The card sent by the player
- * @return true in case the card sent is according to the rules of the game, false otherwise
+ *
+ * @param sender
+ * The player who sent the card
+ * @param card
+ * The card sent by the player
+ * @return true in case the card sent is according to the rules of the game,
+ * false otherwise
* @throws RemoteException
*/
public boolean acceptCard(Player sender, Card card) throws RemoteException;
-
+
/**
- * This method is used to sent a card and an anunt to the server for validation and
- * storage
- * @param sender The client who sent the card
- * @param card
- * @param anunt The value of the anunt
- * @return True in case the card and the anunt are sent according to the rules of the
- * game
+ * This method is used to sent a card and an anunt to the server for
+ * validation and storage
+ *
+ * @param sender
+ * The client who sent the card
+ * @param card
+ * @param anunt
+ * The value of the anunt
+ * @return True in case the card and the anunt are sent according to the
+ * rules of the game
* @throws RemoteException
*/
- public boolean acceptCard(Player sender, Card card, int anunt) throws RemoteException;
-
+ public boolean acceptCard(Player sender, Card card, int anunt)
+ throws RemoteException;
+
/**
*
- * @return The overall score of the game
+ * @return The overall score of the game
* @throws RemoteException
*/
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
+ * 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;
-
+ public void registerForNotifications(ClientInterface callback)
+ throws RemoteException;
+
}
Added: Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java 2010-04-07 13:12:45 UTC (rev 98)
@@ -0,0 +1,13 @@
+package prc.bubulina.cruce.server;
+
+import java.util.List;
+
+public class GameLogic {
+ private List<Team> teams;
+ public void startGame(List<Team> teams) {
+ this.teams = teams;
+ }
+ public void startBid() {
+
+ }
+}
\ No newline at end of file
Added: Java/trunk/src/prc/bubulina/cruce/server/PlayerFactory.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/PlayerFactory.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/server/PlayerFactory.java 2010-04-07 13:12:45 UTC (rev 98)
@@ -0,0 +1,10 @@
+package prc.bubulina.cruce.server;
+
+import prc.bubulina.cruce.remote.Player;
+
+public class PlayerFactory {
+ private static int val = 0;
+ public static Player getPlayer(String name) {
+ return new Player(name, val++);
+ }
+}
\ No newline at end of file
Added: Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java 2010-04-07 13:12:45 UTC (rev 98)
@@ -0,0 +1,42 @@
+package prc.bubulina.cruce.server;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import prc.bubulina.cruce.remote.ClientInterface;
+import prc.bubulina.cruce.remote.Player;
+
+public class PlayerMap {
+ private Map<Player, ServerSidePlayer> data;
+ private Map<Player, ClientInterface> clients;
+ private static PlayerMap instance;
+ private 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);
+ }
+ public ServerSidePlayer getServerSidePlayer(Player player) {
+ return data.get(player);
+ }
+ public ClientInterface getClient(Player player) {
+ return clients.get(player);
+ }
+ public Player getPlayer(ClientInterface client) {
+ for (Entry<Player, ClientInterface> e : clients.entrySet())
+ if (e.getValue().equals(client))
+ return e.getKey();
+ return null;
+ }
+ public void reset() {
+ data.clear();
+ }
+}
\ No newline at end of file
Added: Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-07 13:12:45 UTC (rev 98)
@@ -0,0 +1,47 @@
+package prc.bubulina.cruce.server;
+
+import java.rmi.RemoteException;
+import java.util.LinkedList;
+import java.util.List;
+
+import prc.bubulina.cruce.remote.Card;
+import prc.bubulina.cruce.remote.ClientInterface;
+import prc.bubulina.cruce.remote.Player;
+import prc.bubulina.cruce.remote.Score;
+import prc.bubulina.cruce.remote.ServerInterface;
+
+public class ServerImplementation implements ServerInterface {
+ private List<Team> teams = new LinkedList<Team>();
+ private List<ClientInterface> clients = new LinkedList<ClientInterface>();
+ private StartGameLogic startGameLogic;
+ private GameLogic gameLogic;
+ public boolean acceptCard(Player sender, Card card) throws RemoteException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+ public boolean acceptCard(Player sender, Card card, int anunt) throws RemoteException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+ public Score getOverallScore() throws RemoteException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ public Player joinGame(String name, ClientInterface client) throws RemoteException {
+ ServerSidePlayer ssplayer = startGameLogic.setupPlayer(name, client);
+ if (ssplayer != null)
+ return ssplayer.getInfo();
+ return null;
+ }
+ public void registerForNotifications(ClientInterface callback) throws RemoteException {
+ clients.add(callback);
+ }
+ public void startGame(Player sender) throws RemoteException {
+ startGameLogic.playerReady();
+ if (startGameLogic.gameReady()) {
+ for (ClientInterface client : clients)
+ client.inform("The game will start in a moment...");
+ gameLogic.startGame(teams);
+ }
+ }
+}
\ No newline at end of file
Added: Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java 2010-04-07 13:12:45 UTC (rev 98)
@@ -0,0 +1,56 @@
+package prc.bubulina.cruce.server;
+
+import java.util.List;
+
+import prc.bubulina.cruce.remote.Card;
+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)
+ return true;
+ else {
+ int searchValue = 7 - card.getValue();
+ for (Card c : cards)
+ if (c.getValue() == searchValue && c.getColor().equals(card.getColor()))
+ return true;
+ return false;
+ }
+ }
+ public boolean checkHit(Card card, Card[] cardsDown) {
+ if (this.hasCard(card) == false)
+ return false;
+ if (cardsDown.length == 0)
+ return true;
+ if (card.getColor().equals(cardsDown[0].getColor()))
+ return true;
+ else {
+ for (Card c : cards)
+ if (c.getColor().equals(cardsDown[0].getColor()))
+ return false;
+ if (card.isTromf())
+ return true;
+ for (Card c : cards)
+ if (c.isTromf())
+ return false;
+ }
+ return true;
+ }
+ public Player getInfo() {
+ return player;
+ }
+}
\ No newline at end of file
Added: Java/trunk/src/prc/bubulina/cruce/server/StartGameLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/StartGameLogic.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/server/StartGameLogic.java 2010-04-07 13:12:45 UTC (rev 98)
@@ -0,0 +1,42 @@
+package prc.bubulina.cruce.server;
+
+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;
+ teams = new LinkedList<Team>();
+ teams.add(new Team());
+ teams.add(new Team());
+ }
+ public ServerSidePlayer setupPlayer(String name, ClientInterface client) {
+ if (joinedPlayers < 4) {
+ Player player = PlayerFactory.getPlayer(name);
+ ServerSidePlayer ssplayer = new ServerSidePlayer(player);
+ PlayerMap.getInstance().put(ssplayer, client);
+ joinedPlayers++;
+ int teamIndex = player.getID() % 2;
+ teams.get(teamIndex).addPlayer(ssplayer);
+ return ssplayer;
+ }
+ return null;
+ }
+ public boolean playerReady() {
+ if (readyPlayers < 4) {
+ readyPlayers++;
+ return true;
+ }
+ return false;
+ }
+ public boolean gameReady() {
+ return readyPlayers == 4;
+ }
+}
\ No newline at end of file
Added: Java/trunk/src/prc/bubulina/cruce/server/Team.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/Team.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/server/Team.java 2010-04-07 13:12:45 UTC (rev 98)
@@ -0,0 +1,14 @@
+package prc.bubulina.cruce.server;
+
+import java.util.LinkedList;
+import java.util.List;
+
+public class Team {
+ private List<ServerSidePlayer> players;
+ public Team() {
+ players = new LinkedList<ServerSidePlayer>();
+ }
+ public void addPlayer(ServerSidePlayer player) {
+ players.add(player);
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|