Thread: [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.
|
|
From: <hor...@us...> - 2010-04-07 14:12:19
|
Revision: 99
http://cruce.svn.sourceforge.net/cruce/?rev=99&view=rev
Author: horiaradu
Date: 2010-04-07 14:12:12 +0000 (Wed, 07 Apr 2010)
Log Message:
-----------
Am facut si logica de sendCards.
Pt Alin:
Eu m-as opri acuma si te invit sa verifici ce am facut, sa te uiti si sa completezi unde e de completat. Apoi sa ma anunti ce ai facut, sau ce anume te gandesti sa faci.
Daca nu intelegi ceva, call me!
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/server/GameLogic.java
Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
Java/trunk/src/prc/bubulina/cruce/server/Team.java
Added Paths:
-----------
Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Card.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-07 13:12:45 UTC (rev 98)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-07 14:12:12 UTC (rev 99)
@@ -1,5 +1,7 @@
package prc.bubulina.cruce.remote;
+import java.util.Random;
+
public class Card {
private int value;
private Color color;
@@ -25,4 +27,13 @@
public boolean isTromf() {
return color.equals(tromf);
}
+ public static Card getRandomCard() {
+ int i = new Random().nextInt(6);
+ if (i == 1)
+ i = 11;
+ else if (i == 5)
+ i = 10;
+ Color c = Color.values()[new Random().nextInt(4)];
+ return new Card(i, c);
+ }
}
Modified: Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java 2010-04-07 13:12:45 UTC (rev 98)
+++ Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java 2010-04-07 14:12:12 UTC (rev 99)
@@ -2,7 +2,7 @@
import java.rmi.Remote;
import java.rmi.RemoteException;
-import java.util.ArrayList;
+import java.util.List;
public interface ClientInterface extends Remote {
/**
@@ -23,7 +23,7 @@
* client rejects the cards
* @throws RemoteException
*/
- public boolean receiveCards(ArrayList<Card> cards) throws RemoteException;
+ public boolean receiveCards(List<Card> cards) throws RemoteException;
/**
* This method forces a client to receive a list of cards
@@ -31,7 +31,7 @@
* @param cards
* @throws RemoteException
*/
- public void forceReceive(ArrayList<Card> cards) throws RemoteException;
+ public void forceReceive(List<Card> cards) throws RemoteException;
/**
* Tells the client to bid
Modified: Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java 2010-04-07 13:12:45 UTC (rev 98)
+++ Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java 2010-04-07 14:12:12 UTC (rev 99)
@@ -4,10 +4,17 @@
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 void startBid() {
-
+ public boolean endOfGame() {
+ for (Team t : teams)
+ if (t.getOverallScore() >= 15)
+ return true;
+ return false;
}
}
\ No newline at end of file
Added: Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-07 14:12:12 UTC (rev 99)
@@ -0,0 +1,44 @@
+package prc.bubulina.cruce.server;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import prc.bubulina.cruce.remote.Card;
+
+public class RoundLogic {
+ private List<Team> teams;
+ private Map<Integer, ServerSidePlayer> playerOrder;
+ public RoundLogic(List<Team> teams) {
+ this.teams = teams;
+ int i = 0;
+ for (Team t : teams)
+ for (ServerSidePlayer p : t.getPlayers())
+ playerOrder.put(i++, p);
+ }
+ private Team getTeam(ServerSidePlayer player) {
+ for (Team t : teams)
+ if (t.getPlayers().contains(player))
+ return t;
+ return null;
+ }
+ public void startRound() {
+ sendCards();
+ }
+ private void sendCards() {
+ List<Card> givenCards = new LinkedList<Card>();
+ for (int i = 0; i < 4; i++) {
+ ServerSidePlayer player = playerOrder.get(i);
+ List<Card> cards = new LinkedList<Card>();
+ for (int j = 0; j < 6; j++) {
+ Card card;
+ do {
+ card = Card.getRandomCard();
+ } while (givenCards.contains(card));
+ givenCards.add(card);
+ cards.add(card);
+ }
+ ServerImplementation.getInstance().sendCards(cards, player);
+ }
+ }
+}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-07 13:12:45 UTC (rev 98)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-07 14:12:12 UTC (rev 99)
@@ -11,10 +11,34 @@
import prc.bubulina.cruce.remote.ServerInterface;
public class ServerImplementation implements ServerInterface {
+ private static ServerImplementation instance;
+ private ServerImplementation() {}
+ public static ServerImplementation getInstance() {
+ if (instance == null)
+ instance = new ServerImplementation();
+ return instance;
+ }
private List<Team> teams = new LinkedList<Team>();
private List<ClientInterface> clients = new LinkedList<ClientInterface>();
private StartGameLogic startGameLogic;
private GameLogic gameLogic;
+ public boolean sendCards(List<Card> cards, ServerSidePlayer player) {
+ ClientInterface client = PlayerMap.getInstance().getClient(player.getInfo());
+ try {
+ if (client.receiveCards(cards) == false) {
+ int sum = 0;
+ for (Card c : cards)
+ sum += c.getValue();
+ if (sum >= 11)
+ client.forceReceive(cards);
+ else
+ return false;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return true;
+ }
public boolean acceptCard(Player sender, Card card) throws RemoteException {
// TODO Auto-generated method stub
return false;
Modified: Java/trunk/src/prc/bubulina/cruce/server/Team.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/Team.java 2010-04-07 13:12:45 UTC (rev 98)
+++ Java/trunk/src/prc/bubulina/cruce/server/Team.java 2010-04-07 14:12:12 UTC (rev 99)
@@ -3,12 +3,49 @@
import java.util.LinkedList;
import java.util.List;
+import prc.bubulina.cruce.remote.Card;
+
public class Team {
private List<ServerSidePlayer> players;
+ private int anunturi;
+ private int goal;
+ private List<Card> cardsTaken;
+ private int overallScore;
public Team() {
players = new LinkedList<ServerSidePlayer>();
+ cardsTaken = new LinkedList<Card>();
+ anunturi = 0;
+ 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);
+ }
+ public void setGoal(int goal) {
+ this.goal = goal;
+ }
+ public int computeScore() {
+ int result = anunturi;
+ for (Card card : cardsTaken)
+ result += card.getValue();
+ result /= 33;
+ if (result < goal)
+ result *= -1;
+ overallScore += result;
+ return result;
+ }
+ public int getOverallScore() {
+ return overallScore;
+ }
+ public void resetRound() {
+ anunturi = 0;
+ goal = 0;
+ cardsTaken.clear();
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|
|
From: <ali...@us...> - 2010-04-07 18:09:24
|
Revision: 104
http://cruce.svn.sourceforge.net/cruce/?rev=104&view=rev
Author: alinposho
Date: 2010-04-07 18:09:17 +0000 (Wed, 07 Apr 2010)
Log Message:
-----------
Am adaugat teste pentru computeScore() din clasa Team. De asemenea in clasa Team am adaugat metoda addAnunt(int value) pentru a adauga anunturi echipei. De asemenea metoda este si testata.
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/remote/Card.java
Java/trunk/src/prc/bubulina/cruce/server/Team.java
Java/trunk/src/prc/bubulina/cruce/tests/server/StartGameLogicTest.java
Added Paths:
-----------
Java/trunk/src/prc/bubulina/cruce/tests/server/TeamTest.java
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Card.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-07 17:31:52 UTC (rev 103)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-07 18:09:17 UTC (rev 104)
@@ -8,7 +8,13 @@
private static Color tromf;
public Card(int value, Color color) {
- this.color = color;
+ this.color = color;
+ if(value != 0 && value != 2 && value != 3 && value != 4 && value != 10 &&
+ value != 11)
+ {
+ throw new IllegalArgumentException("Card value is not within the set: " +
+ "{0 , 2, 3, 4, 10, 11}!\n");
+ }
this.value = value;
}
Modified: Java/trunk/src/prc/bubulina/cruce/server/Team.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/Team.java 2010-04-07 17:31:52 UTC (rev 103)
+++ Java/trunk/src/prc/bubulina/cruce/server/Team.java 2010-04-07 18:09:17 UTC (rev 104)
@@ -36,6 +36,16 @@
this.goal = goal;
}
+ public void addAnunt(int value)
+ {
+ if(value != 40 && value != 20)
+ {
+ throw new IllegalArgumentException("The value filed is not one of 20 or 40!\n");
+ }
+
+ anunturi += value;
+ }
+
public int computeScore() {
int result = anunturi;
@@ -61,4 +71,5 @@
goal = 0;
cardsTaken.clear();
}
+
}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/tests/server/StartGameLogicTest.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/tests/server/StartGameLogicTest.java 2010-04-07 17:31:52 UTC (rev 103)
+++ Java/trunk/src/prc/bubulina/cruce/tests/server/StartGameLogicTest.java 2010-04-07 18:09:17 UTC (rev 104)
@@ -8,7 +8,6 @@
import org.junit.Before;
import org.junit.Test;
-import prc.bubulina.cruce.remote.Player;
import prc.bubulina.cruce.server.ServerSidePlayer;
import prc.bubulina.cruce.server.StartGameLogic;
import prc.bubulina.cruce.server.Team;
@@ -127,10 +126,4 @@
}
}
- @Test
- public void testPlayerReady()
- {
- fail("Not yet implemented");
- }
-
}
Added: Java/trunk/src/prc/bubulina/cruce/tests/server/TeamTest.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/tests/server/TeamTest.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/tests/server/TeamTest.java 2010-04-07 18:09:17 UTC (rev 104)
@@ -0,0 +1,157 @@
+package prc.bubulina.cruce.tests.server;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import prc.bubulina.cruce.remote.Card;
+import prc.bubulina.cruce.remote.Color;
+import prc.bubulina.cruce.server.Team;
+
+public class TeamTest
+{
+ private Team team;
+ private List<Card> cardsTaken;
+ private int goal;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ team = new Team();
+ cardsTaken = new ArrayList<Card>();
+ }
+
+ @Test
+ public void testComputeScore_NoAnunt_NoCardsTAken_NoGoal()
+ {
+ assertEquals(0, team.computeScore());
+ assertEquals(goal, team.getOverallScore());
+ }
+
+ @Test
+ public void testComputeScore_NoAnunt_NoCardsTAken_WithGoalUnfulfilled()
+ {
+ goal = 10;
+ team.setGoal(goal);
+ assertEquals(-goal, team.computeScore());
+ assertEquals(-goal, team.getOverallScore());
+ }
+
+ @Test
+ public void testComputeScore_NoAnunt_CardsTaken_WithGoalUnfulfilled()
+ {
+ goal = 2;
+ team.setGoal(goal);
+
+ int takenCardsValue = 0;
+
+ for(int i = 0; i < 11; i++)
+ {
+ Card card;
+ try
+ {
+ card = new Card(i * 2 % 3, Color.ROSU);
+ }
+ catch (IllegalArgumentException e)
+ {
+ card = new Card(0, Color.ROSU);
+ }
+
+ takenCardsValue += card.getValue();
+ team.addCard(card);
+ }
+
+ //Precondition check
+ assertTrue(takenCardsValue < 66);
+
+ //actual test
+ assertEquals(-goal, team.computeScore());
+ assertEquals(-goal, team.getOverallScore());
+ }
+
+ @Test
+ public void testComputeScore_Anunturi_CardsTaken_WithGoalFulfilled()
+ {
+ //set up
+ goal = 6;
+ team.setGoal(goal);
+
+ int takenCardsValue = 0;
+
+ //adding some cards to the team
+ for(int i = 0; i < 66; i++)
+ {
+ Card card;
+ try
+ {
+ card = new Card(i * 2 % 12, Color.ROSU);
+ }
+ catch (IllegalArgumentException e)
+ {
+ card = new Card(0, Color.ROSU);
+ }
+
+ takenCardsValue += card.getValue();
+ team.addCard(card);
+ }
+
+ //adding some anunturi - Notice how we do not check for only one 40 and
+ //maximum 3 20's
+ team.addAnunt(40);
+ takenCardsValue += 40;
+ team.addAnunt(20);
+ takenCardsValue += 20;
+ team.addAnunt(40);
+ takenCardsValue += 40;
+ team.addAnunt(20);
+ takenCardsValue += 20;
+ team.addAnunt(20);
+ takenCardsValue += 20;
+ team.addAnunt(40);
+ takenCardsValue += 40;
+
+ //Precondition check
+ assertTrue(takenCardsValue >= 33 * 6);
+
+ //actual test
+ int actual = team.computeScore();
+ assertTrue(goal <= actual);
+ assertEquals(takenCardsValue / 33, actual);
+ assertEquals(takenCardsValue / 33, team.getOverallScore());
+ }
+
+ @Test
+ public void testAddAnunt()
+ {
+ //trying to add an invalid anunt
+ try
+ {
+ team.addAnunt(100);
+ fail("100 is an invalid anunt value so an exception should have been raised.");
+ }
+ catch (IllegalArgumentException e)
+ {
+ String expected = "The value filed is not one of 20 or 40!\n";
+ assertEquals(expected, e.getMessage());
+ }
+
+ //Adding a 40 and a 20 anunt
+ team.addAnunt(40);
+ team.addAnunt(20);
+
+ //Notice how we can add more that one 40 and 3 20's
+ team = new Team();
+ team.addAnunt(40);
+ team.addAnunt(20);
+ team.addAnunt(20);
+ team.addAnunt(20);
+ team.addAnunt(40);
+ team.addAnunt(20);
+
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-04-08 06:13:04
|
Revision: 106
http://cruce.svn.sourceforge.net/cruce/?rev=106&view=rev
Author: alinposho
Date: 2010-04-08 06:12:57 +0000 (Thu, 08 Apr 2010)
Log Message:
-----------
Clasele Card, Player si Score implementeaza interfata Serializable pentru a putea fi serializate. Este necesar pentru ca ele apar ca parametrii in metodele interfetelor la distanta.
Clasa ServerImplementation extinde UnicastRemoteObject pentru a fi un server rmi.
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/remote/Card.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/server/GameLogic.java
Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java
Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Card.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-07 18:20:12 UTC (rev 105)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-08 06:12:57 UTC (rev 106)
@@ -1,8 +1,15 @@
package prc.bubulina.cruce.remote;
+import java.io.Serializable;
import java.util.Random;
-public class Card {
+public class Card implements Serializable{
+
+ /**
+ * Needed serialization for RMI parameter
+ */
+ private static final long serialVersionUID = 243254958971908105L;
+
private int value;
private Color color;
private static Color tromf;
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Player.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Player.java 2010-04-07 18:20:12 UTC (rev 105)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Player.java 2010-04-08 06:12:57 UTC (rev 106)
@@ -1,6 +1,14 @@
package prc.bubulina.cruce.remote;
-public class Player {
+import java.io.Serializable;
+
+public class Player implements Serializable{
+
+ /**
+ * Needed for serialization serialization
+ */
+ private static final long serialVersionUID = -2446467001127293964L;
+
private String name;
private int id;
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Score.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Score.java 2010-04-07 18:20:12 UTC (rev 105)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Score.java 2010-04-08 06:12:57 UTC (rev 106)
@@ -1,14 +1,18 @@
package prc.bubulina.cruce.remote;
+import java.io.Serializable;
import java.util.Map;
/**
* This class will be a container for a name value pair "player-score"
*
- * @author alinposho
- *
*/
-public class Score {
+public class Score implements Serializable{
+
+ /**
+ * Needed for serialization(auto generated)
+ */
+ private static final long serialVersionUID = 1214550626496444804L;
private Map<Player, Integer> score;
public Score(Map<Player, Integer> score) {
Modified: Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java 2010-04-07 18:20:12 UTC (rev 105)
+++ Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java 2010-04-08 06:12:57 UTC (rev 106)
@@ -5,11 +5,11 @@
public class GameLogic {
private List<Team> teams;
- private RoundLogic roundLogic;
+ private RoundLogic roundLogic;
- public void startGame(List<Team> teams) {
+ public void startGame(List<Team> teams, ServerImplementation server) {
this.teams = teams;
- roundLogic = new RoundLogic(teams);
+ roundLogic = new RoundLogic(teams, server);
while (endOfGame() == false)
roundLogic.startRound();
}
Modified: Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-07 18:20:12 UTC (rev 105)
+++ Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-08 06:12:57 UTC (rev 106)
@@ -7,10 +7,14 @@
import prc.bubulina.cruce.remote.Card;
public class RoundLogic {
+
private List<Team> teams;
private Map<Integer, ServerSidePlayer> playerOrder;
+ private ServerImplementation server;
- public RoundLogic(List<Team> teams) {
+ public RoundLogic(List<Team> teams, ServerImplementation server) {
+
+ this.server = server;
this.teams = teams;
int i = 0;
for (Team t : teams)
@@ -45,7 +49,7 @@
givenCards.add(card);
cards.add(card);
}
- ServerImplementation.getInstance().sendCards(cards, player);
+ server.sendCards(cards, player);
}
}
}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-07 18:20:12 UTC (rev 105)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-08 06:12:57 UTC (rev 106)
@@ -1,6 +1,7 @@
package prc.bubulina.cruce.server;
import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
import java.util.LinkedList;
import java.util.List;
@@ -10,16 +11,21 @@
import prc.bubulina.cruce.remote.Score;
import prc.bubulina.cruce.remote.ServerInterface;
-public class ServerImplementation implements ServerInterface {
+public class ServerImplementation extends UnicastRemoteObject implements ServerInterface {
+ /**
+ * Needed for serialization
+ */
+ private static final long serialVersionUID = 6398777327639353025L;
+
private static ServerImplementation instance;
- private ServerImplementation() {
+ private ServerImplementation() throws RemoteException {
super();
}
- public synchronized static ServerImplementation getInstance() {
+ public synchronized static ServerImplementation getInstance() throws RemoteException {
if (instance == null)
instance = new ServerImplementation();
return instance;
@@ -79,7 +85,7 @@
if (startGameLogic.gameReady()) {
for (ClientInterface client : clients)
client.inform("The game will start in a moment...");
- gameLogic.startGame(teams);
+ gameLogic.startGame(teams, this);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-04-09 09:18:54
|
Revision: 108
http://cruce.svn.sourceforge.net/cruce/?rev=108&view=rev
Author: alinposho
Date: 2010-04-09 09:18:48 +0000 (Fri, 09 Apr 2010)
Log Message:
-----------
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/server/OrderKeeper.java
Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java
Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java
Java/trunk/src/prc/bubulina/cruce/tests/server/OrderKeeperTest.java
Modified: Java/trunk/src/prc/bubulina/cruce/server/OrderKeeper.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/OrderKeeper.java 2010-04-08 16:35:52 UTC (rev 107)
+++ Java/trunk/src/prc/bubulina/cruce/server/OrderKeeper.java 2010-04-09 09:18:48 UTC (rev 108)
@@ -5,6 +5,18 @@
import java.util.Map.Entry;
public class OrderKeeper extends HashMap<Integer, ServerSidePlayer> {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -8527789594990649607L;
+
+ /**
+ * This will reorder the values stored in the HashMap so that the
+ * argument is the first followed by the value after it and so on.
+ * The keys will be always be fist key 0, second key one, and so one
+ * @param firstPlayer
+ */
public void resetOrder(ServerSidePlayer firstPlayer) {
int oldPosition = this.getOrder(firstPlayer);
Map<Integer, ServerSidePlayer> newPlayerOrder = new HashMap<Integer, ServerSidePlayer>();
@@ -20,10 +32,12 @@
this.clear();
this.putAll(newPlayerOrder);
}
+
public int getOrder(ServerSidePlayer player) {
for (Entry<Integer, ServerSidePlayer> p : this.entrySet())
if (p.getValue().equals(player))
return p.getKey();
return -1;
}
+
}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-08 16:35:52 UTC (rev 107)
+++ Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-09 09:18:48 UTC (rev 108)
@@ -54,7 +54,10 @@
do {
card = Card.getRandomCard();
} while (givenCards.contains(card));
-
+
+ //in order for givenCards.contains(card) to work properly you have to
+ //override equals(Object o) in Card
+
givenCards.add(card);
cards.add(card);
}
Modified: Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java 2010-04-08 16:35:52 UTC (rev 107)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java 2010-04-09 09:18:48 UTC (rev 108)
@@ -9,7 +9,6 @@
private Player player;
private List<Card> cards;
- private int order;
public ServerSidePlayer(Player player) {
this.player = player;
Modified: Java/trunk/src/prc/bubulina/cruce/tests/server/OrderKeeperTest.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/tests/server/OrderKeeperTest.java 2010-04-08 16:35:52 UTC (rev 107)
+++ Java/trunk/src/prc/bubulina/cruce/tests/server/OrderKeeperTest.java 2010-04-09 09:18:48 UTC (rev 108)
@@ -1,13 +1,17 @@
package prc.bubulina.cruce.tests.server;
+import static org.junit.Assert.assertEquals;
+
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
+import java.util.Set;
+import java.util.Map.Entry;
import org.junit.Before;
import org.junit.Test;
import prc.bubulina.cruce.server.OrderKeeper;
-import prc.bubulina.cruce.server.RoundLogic;
import prc.bubulina.cruce.server.ServerSidePlayer;
import prc.bubulina.cruce.server.StartGameLogic;
import prc.bubulina.cruce.server.Team;
@@ -28,16 +32,61 @@
p2 = startGameLogic.setupPlayer("P2");
p3 = startGameLogic.setupPlayer("P3");
p4 = startGameLogic.setupPlayer("P4");
+ //Notice how the HashMap does't care about the team of the players
o.put(0, p1);
o.put(1, p2);
o.put(2, p3);
o.put(3, p4);
}
+ /**
+ * This will test the method resetOrder(ServerSydePlayer) with the number of the
+ * player to be set first given as an argument
+ * @param players
+ * @param firstPlayer The number of the player who shell be the first in the HashMap
+ */
+ private void testResetOrder(ServerSidePlayer[] players, int firstPlayer)
+ {
+ Set<Entry<Integer, ServerSidePlayer>> set = o.entrySet();
+ Iterator<Entry<Integer, ServerSidePlayer>> iterator = set.iterator();
+ int i = 0;
+
+ //Precondition check
+ while (iterator.hasNext())
+ {
+ Entry<Integer, ServerSidePlayer> entry = iterator.next();
+ assertEquals(i, (int) entry.getKey());
+ assertEquals(players[i], entry.getValue());
+ i++;
+ }
+
+ //Actual test
+ o.resetOrder(players[firstPlayer]);
+
+ set = o.entrySet();
+ iterator = set.iterator();
+ i = firstPlayer;
+ int j = 0;
+ //Precondition check
+ while (iterator.hasNext())
+ {
+ Entry<Integer, ServerSidePlayer> entry = iterator.next();
+ assertEquals(j, (int) entry.getKey());
+ assertEquals(players[i], entry.getValue());
+ i = (i + 1) % 4;
+ j++;
+ }
+ }
+
@Test
public void testResetOrder() {
- System.out.println(o);
- o.resetOrder(p3);
- System.out.println(o);
- }
+
+ for(int i = 0; i < 4; i++)
+ {
+ setUp();
+ ServerSidePlayer[] players = {p1, p2, p3, p4};
+ testResetOrder(players, i);
+ }
+ }
+
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <hor...@us...> - 2010-04-12 16:21:43
|
Revision: 112
http://cruce.svn.sourceforge.net/cruce/?rev=112&view=rev
Author: horiaradu
Date: 2010-04-12 16:21:25 +0000 (Mon, 12 Apr 2010)
Log Message:
-----------
Am facut sa mearga join & start game. Am adaugat ClientRun (ala care porneste clientul) si Server (ala care porneste serverul).
Mai trebe partea cu flush input la askBinaryQuestion.
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/client/Client.java
Java/trunk/src/prc/bubulina/cruce/remote/Player.java
Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java
Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
Added Paths:
-----------
Java/trunk/src/prc/bubulina/cruce/client/ClientRun.java
Java/trunk/src/prc/bubulina/cruce/server/Server.java
Java/trunk/src/prc/bubulina/cruce/tests/server/PlayerTest.java
Modified: Java/trunk/src/prc/bubulina/cruce/client/Client.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/Client.java 2010-04-12 09:12:08 UTC (rev 111)
+++ Java/trunk/src/prc/bubulina/cruce/client/Client.java 2010-04-12 16:21:25 UTC (rev 112)
@@ -1,6 +1,9 @@
package prc.bubulina.cruce.client;
+import java.io.Serializable;
+import java.net.MalformedURLException;
import java.rmi.Naming;
+import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.List;
@@ -12,7 +15,7 @@
import prc.bubulina.cruce.remote.Score;
import prc.bubulina.cruce.remote.ServerInterface;
-public class Client extends UnicastRemoteObject implements ClientInterface {
+public class Client extends UnicastRemoteObject implements ClientInterface, Serializable {
/**
*
@@ -41,12 +44,31 @@
this.game = game;
//TODO instantiate server
- //server = (ServerInterface) Naming.lookup(url);
+ try {
+ server = (ServerInterface) Naming.lookup(url);
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NotBoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
// TODO this looks weird
- if (game.joinGame())
+ try {
+ if (game.joinGame()) {
player = server.joinGame(game.getPlayerName(), this);
- if (game.startGame())
+ System.out.println(player.getName());
+ System.out.println(player);
+ }
+ game.joinGame();
+ game.joinGame();
+ if (game.startGame()) {
+ System.out.println("Yes");
server.startGame(player);
+ }
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
}
@Override
Added: Java/trunk/src/prc/bubulina/cruce/client/ClientRun.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/ClientRun.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/client/ClientRun.java 2010-04-12 16:21:25 UTC (rev 112)
@@ -0,0 +1,16 @@
+package prc.bubulina.cruce.client;
+
+import java.rmi.RemoteException;
+
+public class ClientRun {
+ public static void main(String[] args) {
+ UI ui = new TextUI();
+ Game game = new Game("bubu", ui);
+ try {
+ Client c = new Client(game, "localhost", "CruceServer");
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Player.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Player.java 2010-04-12 09:12:08 UTC (rev 111)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Player.java 2010-04-12 16:21:25 UTC (rev 112)
@@ -2,7 +2,7 @@
import java.io.Serializable;
-public class Player implements Serializable{
+public class Player implements Serializable {
/**
* Needed for serialization serialization
@@ -24,5 +24,15 @@
public int getID() {
return id;
}
-
+
+ public boolean equals(Object o) {
+ if (o instanceof Player)
+ if (((Player)o).name.equals(name) && ((Player)o).id == id)
+ return true;
+ return false;
+ }
+
+ public int hashCode() {
+ return id;
+ }
}
Modified: Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java 2010-04-12 09:12:08 UTC (rev 111)
+++ Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java 2010-04-12 16:21:25 UTC (rev 112)
@@ -44,4 +44,7 @@
public void reset() {
data.clear();
}
+ public String toString() {
+ return data.toString() + "\n" + clients.toString();
+ }
}
\ No newline at end of file
Added: Java/trunk/src/prc/bubulina/cruce/server/Server.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/Server.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/server/Server.java 2010-04-12 16:21:25 UTC (rev 112)
@@ -0,0 +1,16 @@
+package prc.bubulina.cruce.server;
+
+import java.rmi.Naming;
+
+import prc.bubulina.cruce.remote.ServerInterface;
+
+public class Server {
+ public static void main(String[] args) {
+ try {
+ ServerInterface server = new ServerImplementation();
+ Naming.rebind("CruceServer", server);
+ System.out.println("Server running");
+ } catch (Exception e) {
+ }
+ }
+}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-12 09:12:08 UTC (rev 111)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-12 16:21:25 UTC (rev 112)
@@ -28,8 +28,37 @@
public ServerImplementation() throws RemoteException {
super();
+ teams = new LinkedList<Team>();
+ teams.add(new Team());
+ teams.add(new Team());
+ startGameLogic = new StartGameLogic(teams);
+ gameLogic = new GameLogic();
}
+
+ public synchronized Player joinGame(String name, ClientInterface client) throws RemoteException {
+ System.out.println(name + " joined the game");
+ client.inform("welcome to the game");
+ ServerSidePlayer ssplayer = startGameLogic.setupPlayer(name);
+ clients.add(client);
+ playerMap.put(ssplayer, client);
+ if (ssplayer != null)
+ return ssplayer.getInfo();
+ return null;
+ }
+ public synchronized void startGame(Player sender) throws RemoteException {
+ System.out.println(sender.getName() + " is ready to start the game");
+ startGameLogic.playerReady();
+ if (startGameLogic.gameReady()) {
+ for (ClientInterface client : clients)
+ client.inform("The game will start in a moment...");
+ gameLogic.startGame(teams, this);
+ } else {
+ playerMap.getClient(sender).inform("waiting for other players");
+ System.out.println("need more players");
+ }
+ }
+
public synchronized boolean sendCards(List<Card> cards, ServerSidePlayer player) {
ClientInterface client = playerMap.getClient(player.getInfo());
@@ -91,21 +120,4 @@
// TODO Auto-generated method stub
return null;
}
-
- public synchronized Player joinGame(String name, ClientInterface client) throws RemoteException {
- ServerSidePlayer ssplayer = startGameLogic.setupPlayer(name);
- playerMap.put(ssplayer, client);
- if (ssplayer != null)
- return ssplayer.getInfo();
- return null;
- }
-
- public synchronized 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, this);
- }
- }
}
\ No newline at end of file
Added: Java/trunk/src/prc/bubulina/cruce/tests/server/PlayerTest.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/tests/server/PlayerTest.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/tests/server/PlayerTest.java 2010-04-12 16:21:25 UTC (rev 112)
@@ -0,0 +1,32 @@
+package prc.bubulina.cruce.tests.server;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+
+import org.junit.Test;
+
+import prc.bubulina.cruce.remote.Player;
+
+public class PlayerTest {
+ @Test
+ public void testEquals() {
+ Player p1 = new Player("Horia", 0);
+ Player p2 = new Player("Horia", 0);
+ assertTrue(p1.equals(p2));
+ assertEquals(p1, p2);
+ }
+ @Test
+ public void testEqualsInList() {
+ HashMap<Player, Integer> l = new HashMap<Player, Integer>();
+ Player p1 = new Player("Horia", 0);
+ Player p2 = new Player("Horia", 0);
+ Player p3 = new Player("Alin", 1);
+ l.put(p3, 0);
+ l.put(p1, 1);
+ Integer i = l.get(p2);
+ System.out.println(i);
+ assertEquals(i, new Integer(1));
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ca...@us...> - 2010-04-24 13:42:18
|
Revision: 130
http://cruce.svn.sourceforge.net/cruce/?rev=130&view=rev
Author: caiusb
Date: 2010-04-24 13:42:11 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
Am rezolvat problema cu anuntul
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/client/TextUI.java
Java/trunk/src/prc/bubulina/cruce/remote/Anunt.java
Modified: Java/trunk/src/prc/bubulina/cruce/client/TextUI.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/TextUI.java 2010-04-24 09:29:39 UTC (rev 129)
+++ Java/trunk/src/prc/bubulina/cruce/client/TextUI.java 2010-04-24 13:42:11 UTC (rev 130)
@@ -60,16 +60,19 @@
@Override
public Hitable playCard() {
int cardNo = 0, anunt = 0;
+ String anuntString;
+ byte[] data = new byte[2];
System.out.println("Carti disponibile:");
showAvailableCards();
try {
+ System.out.println("Da-ti cartea jucata (1-" + cards.size() + "): ");
System.in.skip(System.in.available());
- System.out.println("Da-ti cartea jucata (1-" + cards.size() + "): ");
cardNo = System.in.read() - '0';
+ System.out.println("Anunt? (20/40): ");
System.in.skip(System.in.available());
- //System.out.println("Anunt? (20/40): ");
- //anunt = System.in.read();
- //TODO AICI TRE FACUT SA CITESTI CORECT DE LA TASTATURA
+ System.in.read(data);
+ anuntString = new String(data);
+ anunt = Integer.parseInt(anuntString);
System.in.skip(System.in.available());
} catch (IOException e) {
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Anunt.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Anunt.java 2010-04-24 09:29:39 UTC (rev 129)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Anunt.java 2010-04-24 13:42:11 UTC (rev 130)
@@ -1,6 +1,14 @@
package prc.bubulina.cruce.remote;
-public class Anunt implements Hitable {
+import java.io.Serializable;
+
+public class Anunt implements Serializable, Hitable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -1263862604372844721L;
+
public Card card;
public int value;
public Anunt(Card card, int value) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <hor...@us...> - 2010-04-24 18:38:59
|
Revision: 131
http://cruce.svn.sourceforge.net/cruce/?rev=131&view=rev
Author: horiaradu
Date: 2010-04-24 18:38:53 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
Acum merge si partea cu cititul anuntului
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/client/Client.java
Java/trunk/src/prc/bubulina/cruce/client/ClientRun.java
Java/trunk/src/prc/bubulina/cruce/client/TextUI.java
Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java
Java/trunk/src/prc/bubulina/cruce/server/Server.java
Modified: Java/trunk/src/prc/bubulina/cruce/client/Client.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/Client.java 2010-04-24 13:42:11 UTC (rev 130)
+++ Java/trunk/src/prc/bubulina/cruce/client/Client.java 2010-04-24 18:38:53 UTC (rev 131)
@@ -79,8 +79,6 @@
@Override
public Hitable hit() throws RemoteException {
Hitable card = game.hit();
- System.out.println(card);
- System.out.println("AAA");
System.out.println("CLIENT: " + player.getName() + ": " + card);
return card;
}
Modified: Java/trunk/src/prc/bubulina/cruce/client/ClientRun.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/ClientRun.java 2010-04-24 13:42:11 UTC (rev 130)
+++ Java/trunk/src/prc/bubulina/cruce/client/ClientRun.java 2010-04-24 18:38:53 UTC (rev 131)
@@ -4,10 +4,17 @@
public class ClientRun {
public static void main(String[] args) {
+ if (args.length != 3) {
+ System.out.println("Eroare la nr de parametrii.\n1 - username | 2 - server ip | 3 - server name");
+ System.exit(0);
+ }
+ String username = args[0];
+ String ip = args[1];
+ String servername = args[2];
UI ui = new TextUI();
- Game game = new Game("bubu", ui);
+ Game game = new Game(username, ui);
try {
- Client c = new Client(game, "localhost", "CruceServer");
+ Client c = new Client(game, ip, servername);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Modified: Java/trunk/src/prc/bubulina/cruce/client/TextUI.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/TextUI.java 2010-04-24 13:42:11 UTC (rev 130)
+++ Java/trunk/src/prc/bubulina/cruce/client/TextUI.java 2010-04-24 18:38:53 UTC (rev 131)
@@ -1,6 +1,8 @@
package prc.bubulina.cruce.client;
+import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.List;
import prc.bubulina.cruce.remote.Anunt;
@@ -65,17 +67,26 @@
System.out.println("Carti disponibile:");
showAvailableCards();
try {
- System.out.println("Da-ti cartea jucata (1-" + cards.size() + "): ");
- System.in.skip(System.in.available());
- cardNo = System.in.read() - '0';
- System.out.println("Anunt? (20/40): ");
- System.in.skip(System.in.available());
- System.in.read(data);
- anuntString = new String(data);
- anunt = Integer.parseInt(anuntString);
- System.in.skip(System.in.available());
+ boolean ok = true;
+ do {
+ ok = true;
+ System.out.println("Da-ti cartea jucata (1-" + cards.size() + ") si eventual anuntul: ");
+ BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+ System.in.skip(System.in.available());
+ String input;
+ while ((input = in.readLine()) == null);
+ String delims = "[ ]+";
+ String[] tokens = input.split(delims);
+ cardNo = Integer.parseInt(tokens[0]);
+ if (tokens.length == 2)
+ anunt = Integer.parseInt(tokens[1]);
+ if (cardNo <=0 || cardNo > 6)
+ ok = false;
+ else if (anunt != 0 && anunt != 20 && anunt != 40)
+ ok = false;
+ } while (ok == false);
- } catch (IOException e) {
+ } catch (Exception e) {
e.printStackTrace();
}
if (anunt != 0)
Modified: Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-24 13:42:11 UTC (rev 130)
+++ Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-24 18:38:53 UTC (rev 131)
@@ -108,8 +108,13 @@
ok = acceptCard(p, card);
if (ok == false)
server.inform(p.getInfo(), "Ai dat gresit. Mai da o data");
- else
+ else {
server.informAll(p.getInfo() + " a dat " + card);
+ if (handNr == 0 && i == 0) {
+ Card.setTromf(card.getColor());
+ server.informAll("Tromful este: " + card.getColor());
+ }
+ }
} else {
Card card = ((Anunt) hitResult).card;
int anunt = ((Anunt) hitResult).value;
@@ -158,8 +163,6 @@
System.out.println(player.getInfo().getName() + ": " + card);
if (player.checkHit(card, cardsDown) == true) {
cardsDown.put(playerOrder.getOrder(player), card);
- if (handNr == 0)
- Card.setTromf(card.getColor());
player.removeCard(card);
server.updateCards(player, card);
return true;
@@ -175,8 +178,6 @@
if (player.checkHit(card, cardsDown) == true) {
cardsDown.put(playerOrder.getOrder(player), card);
this.getTeam(player).addAnunt(anunt);
- if (handNr == 0)
- Card.setTromf(card.getColor());
player.removeCard(card);
server.updateCards(player, card);
return true;
Modified: Java/trunk/src/prc/bubulina/cruce/server/Server.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/Server.java 2010-04-24 13:42:11 UTC (rev 130)
+++ Java/trunk/src/prc/bubulina/cruce/server/Server.java 2010-04-24 18:38:53 UTC (rev 131)
@@ -6,9 +6,14 @@
public class Server {
public static void main(String[] args) {
+ if (args.length != 1) {
+ System.out.println("Eroare la nr de argumente.\n1 - server name");
+ System.exit(0);
+ }
+ String serverName = args[0];
try {
ServerInterface server = new ServerImplementation();
- Naming.rebind("CruceServer", server);
+ Naming.rebind(serverName, server);
System.out.println("Server running");
} catch (Exception e) {
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <hor...@us...> - 2010-04-08 16:35:58
|
Revision: 107
http://cruce.svn.sourceforge.net/cruce/?rev=107&view=rev
Author: horiaradu
Date: 2010-04-08 16:35:52 +0000 (Thu, 08 Apr 2010)
Log Message:
-----------
Am facut partea de playHand, mai putin informarea playerilor cu privire la scor.
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/remote/Card.java
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/PlayerFactory.java
Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java
Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.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
Java/trunk/src/prc/bubulina/cruce/tests/server/StartGameLogicTest.java
Java/trunk/src/prc/bubulina/cruce/tests/server/TeamTest.java
Added Paths:
-----------
Java/trunk/src/prc/bubulina/cruce/server/OrderKeeper.java
Java/trunk/src/prc/bubulina/cruce/tests/server/OrderKeeperTest.java
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Card.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-08 06:12:57 UTC (rev 106)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-08 16:35:52 UTC (rev 107)
@@ -15,12 +15,12 @@
private static Color tromf;
public Card(int value, Color color) {
- this.color = color;
- if(value != 0 && value != 2 && value != 3 && value != 4 && value != 10 &&
- value != 11)
- {
- throw new IllegalArgumentException("Card value is not within the set: " +
- "{0 , 2, 3, 4, 10, 11}!\n");
+ this.color = color;
+ if (value != 0 && value != 2 && value != 3 && value != 4 && value != 10
+ && value != 11) {
+ throw new IllegalArgumentException(
+ "Card value is not within the set: "
+ + "{0 , 2, 3, 4, 10, 11}!\n");
}
this.value = value;
}
@@ -40,6 +40,7 @@
public boolean isTromf() {
return color.equals(tromf);
}
+
public static Card getRandomCard() {
int i = new Random().nextInt(6);
if (i == 1)
Modified: Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java 2010-04-08 06:12:57 UTC (rev 106)
+++ Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java 2010-04-08 16:35:52 UTC (rev 107)
@@ -6,18 +6,21 @@
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
+ * 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;
+ 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
*/
@@ -39,6 +42,7 @@
/**
* This method is used to sent a card and an anunt to the server for
* validation and storage
+ * Clintul tre sa apeleze asta pana ii da true!
*
* @param sender
* The client who sent the card
Modified: Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java 2010-04-08 06:12:57 UTC (rev 106)
+++ Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java 2010-04-08 16:35:52 UTC (rev 107)
@@ -3,17 +3,17 @@
import java.util.List;
public class GameLogic {
-
+
private List<Team> teams;
private RoundLogic roundLogic;
-
+
public void startGame(List<Team> teams, ServerImplementation server) {
this.teams = teams;
roundLogic = new RoundLogic(teams, server);
while (endOfGame() == false)
roundLogic.startRound();
}
-
+
public boolean endOfGame() {
for (Team t : teams)
if (t.getOverallScore() >= 15)
Added: Java/trunk/src/prc/bubulina/cruce/server/OrderKeeper.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/OrderKeeper.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/server/OrderKeeper.java 2010-04-08 16:35:52 UTC (rev 107)
@@ -0,0 +1,29 @@
+package prc.bubulina.cruce.server;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+public class OrderKeeper extends HashMap<Integer, ServerSidePlayer> {
+ public void resetOrder(ServerSidePlayer firstPlayer) {
+ int oldPosition = this.getOrder(firstPlayer);
+ Map<Integer, ServerSidePlayer> newPlayerOrder = new HashMap<Integer, ServerSidePlayer>();
+ for (Entry<Integer, ServerSidePlayer> p : this.entrySet()) {
+ int newPosition;
+ if (p.getKey() >= oldPosition)
+ newPosition = p.getKey() - oldPosition;
+ else
+ newPosition = p.getKey() - oldPosition + 4;
+ ServerSidePlayer player = p.getValue();
+ newPlayerOrder.put(newPosition, player);
+ }
+ this.clear();
+ this.putAll(newPlayerOrder);
+ }
+ public int getOrder(ServerSidePlayer player) {
+ for (Entry<Integer, ServerSidePlayer> p : this.entrySet())
+ if (p.getValue().equals(player))
+ return p.getKey();
+ return -1;
+ }
+}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/server/PlayerFactory.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/PlayerFactory.java 2010-04-08 06:12:57 UTC (rev 106)
+++ Java/trunk/src/prc/bubulina/cruce/server/PlayerFactory.java 2010-04-08 16:35:52 UTC (rev 107)
@@ -3,9 +3,9 @@
import prc.bubulina.cruce.remote.Player;
public class PlayerFactory {
-
+
private int val = 0;
-
+
public Player getPlayer(String name) {
return new Player(name, val++);
}
Modified: Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java 2010-04-08 06:12:57 UTC (rev 106)
+++ Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java 2010-04-08 16:35:52 UTC (rev 107)
@@ -1,5 +1,6 @@
package prc.bubulina.cruce.server;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -11,26 +12,24 @@
private Map<Player, ServerSidePlayer> data;
private Map<Player, ClientInterface> clients;
-
public PlayerMap() {
-
data = new HashMap<Player, ServerSidePlayer>();
clients = new HashMap<Player, ClientInterface>();
- }
-
+ }
+
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))
@@ -38,6 +37,10 @@
return null;
}
+ public Collection<ClientInterface> getClients() {
+ return clients.values();
+ }
+
public void reset() {
data.clear();
}
Modified: Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-08 06:12:57 UTC (rev 106)
+++ Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-08 16:35:52 UTC (rev 107)
@@ -1,5 +1,6 @@
package prc.bubulina.cruce.server;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -9,11 +10,15 @@
public class RoundLogic {
private List<Team> teams;
- private Map<Integer, ServerSidePlayer> playerOrder;
+ private OrderKeeper playerOrder;
private ServerImplementation server;
-
+ private Map<Integer, Card> cardsDown;
+ private String hitInfoMessage;
+ private int handNr;
+
public RoundLogic(List<Team> teams, ServerImplementation server) {
+ playerOrder = new OrderKeeper();
this.server = server;
this.teams = teams;
int i = 0;
@@ -21,35 +26,148 @@
for (ServerSidePlayer p : t.getPlayers())
playerOrder.put(i++, p);
}
-
+
public Team getTeam(ServerSidePlayer player) {
for (Team t : teams)
if (t.getPlayers().contains(player))
return t;
return null;
}
-
+
public void startRound() {
sendCards();
+ startBid();
+ for (handNr = 0; handNr < 6; handNr++)
+ playHand();
+ //de bagat cu scorul!
}
-
+
private void sendCards() {
List<Card> givenCards = new LinkedList<Card>();
- for (int i = 0; i < 4; i++) {
+ int i;
+ for (i = 0; i < 4; i++) {
ServerSidePlayer player = playerOrder.get(i);
List<Card> cards = new LinkedList<Card>();
for (int j = 0; j < 6; j++) {
Card card;
-
+
do {
card = Card.getRandomCard();
- }
- while (givenCards.contains(card));
-
+ } while (givenCards.contains(card));
+
givenCards.add(card);
- cards.add(card);
+ cards.add(card);
}
- server.sendCards(cards, player);
+ boolean ok = server.sendCards(cards, player);
+ if (ok == false) {
+ i = -1;
+ givenCards.clear();
+ }
}
}
+
+ private void startBid() {
+ int max = 0;
+ ServerSidePlayer winner = null;
+ for (int i = 0; i < 4; i++) {
+ ServerSidePlayer player = playerOrder.get(i);
+ int amount = server.bid(player);
+ if (amount > max) {
+ max = amount;
+ winner = player;
+ }
+ server.informAll(player.getInfo().getName() + " a zis " + amount);
+ }
+ getTeam(winner).setGoal(max);
+ playerOrder.resetOrder(winner);
+ }
+
+ /*private void resetOrder(ServerSidePlayer firstPlayer) {
+ int oldPosition = 0;
+ for (Entry<Integer, ServerSidePlayer> p : playerOrder.entrySet())
+ if (p.getValue().equals(firstPlayer))
+ oldPosition = p.getKey();
+ Map<Integer, ServerSidePlayer> newPlayerOrder = new HashMap<Integer, ServerSidePlayer>();
+ for (Entry<Integer, ServerSidePlayer> p : playerOrder.entrySet()) {
+ int newPosition;
+ if (p.getKey() >= oldPosition)
+ newPosition = p.getKey() - oldPosition;
+ else
+ newPosition = p.getKey() - oldPosition + 4;
+ ServerSidePlayer player = p.getValue();
+ newPlayerOrder.put(newPosition, player);
+ }
+ playerOrder = newPlayerOrder;
+ }*/
+
+ private void playHand() {
+ cardsDown = new HashMap<Integer, Card>();
+ for (int i = 0; i < 4; i++) {
+ ServerSidePlayer p = playerOrder.get(i);
+ server.hit(p);
+ server.informAll(hitInfoMessage);
+ }
+ int maxIndex = getMaxCard(cardsDown);
+ Team t = this.getTeam(playerOrder.get(maxIndex));
+ for (Card c : cardsDown.values())
+ t.addCard(c);
+ ServerSidePlayer winner = playerOrder.get(maxIndex);
+ playerOrder.resetOrder(winner);
+ }
+
+ private int getMaxCard(Map<Integer, Card> cards) {
+ int maxIndex = 0;
+ Card max = cards.get(0);
+ for (int i = 1; i < 4; i++) {
+ if (cards.get(i).isTromf()) {
+ if (max.isTromf()) {
+ if (max.getValue() < cards.get(i).getValue()) {
+ maxIndex = i;
+ max = cards.get(i);
+ }
+ } else {
+ maxIndex = i;
+ max = cards.get(i);
+ }
+ } else {
+ if (cards.get(i).getColor().equals(max.getColor()))
+ if (max.getValue() < cards.get(i).getValue()) {
+ maxIndex = i;
+ max = cards.get(i);
+ }
+ }
+ }
+ return maxIndex;
+ }
+
+ public boolean acceptCard(ServerSidePlayer player, Card card) {
+ Card[] c = (Card[]) cardsDown.values().toArray();
+ if (player.checkHit(card, c) == true) {
+ cardsDown.put(playerOrder.getOrder(player), card);
+ hitInfoMessage = player.getInfo().getName() + " a dat " + c;
+ if (handNr == 0)
+ Card.setTromf(card.getColor());
+ player.removeCard(card);
+ return true;
+ }
+ return false;
+ }
+
+ public boolean acceptCard(ServerSidePlayer player, Card card, int anunt) {
+ if (player.hasAnunt(card, anunt) == false)
+ return false;
+ if (playerOrder.getOrder(player) != 0)
+ return false;
+ Card[] c = (Card[]) cardsDown.values().toArray();
+ if (player.checkHit(card, c) == true) {
+ cardsDown.put(playerOrder.getOrder(player), card);
+ hitInfoMessage = player.getInfo().getName() + " a dat " + c + " anuntand " + anunt;
+ this.getTeam(player).addAnunt(anunt);
+ if (handNr == 0)
+ Card.setTromf(card.getColor());
+ player.removeCard(card);
+ return true;
+ }
+ return false;
+ }
}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-08 06:12:57 UTC (rev 106)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-08 16:35:52 UTC (rev 107)
@@ -12,34 +12,34 @@
import prc.bubulina.cruce.remote.ServerInterface;
public class ServerImplementation extends UnicastRemoteObject implements ServerInterface {
-
+
/**
* Needed for serialization
*/
private static final long serialVersionUID = 6398777327639353025L;
private static ServerImplementation instance;
-
+
private ServerImplementation() throws RemoteException {
-
super();
}
-
+
public synchronized static ServerImplementation getInstance() throws RemoteException {
if (instance == null)
instance = new ServerImplementation();
return instance;
}
-
+
private List<Team> teams = new LinkedList<Team>();
private List<ClientInterface> clients = new LinkedList<ClientInterface>();
private StartGameLogic startGameLogic;
- private GameLogic gameLogic;
+ private GameLogic gameLogic;
+ private RoundLogic roundLogic;
private PlayerMap playerMap = new PlayerMap();
-
+
public synchronized boolean sendCards(List<Card> cards, ServerSidePlayer player) {
ClientInterface client = playerMap.getClient(player.getInfo());
-
+
try {
if (client.receiveCards(cards) == false) {
int sum = 0;
@@ -47,7 +47,7 @@
sum += c.getValue();
if (sum >= 11)
client.forceReceive(cards);
- else
+ else
return false;
}
} catch (Exception e) {
@@ -56,30 +56,57 @@
return true;
}
+ public int bid(ServerSidePlayer player) {
+ ClientInterface client = playerMap.getClient(player.getInfo());
+ try {
+ int amount = client.bid();
+ return amount;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return 0;
+ }
+
+ public void hit(ServerSidePlayer player) {
+ ClientInterface client = playerMap.getClient(player.getInfo());
+ try {
+ client.hit();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void informAll(String message) {
+ for (ClientInterface c : playerMap.getClients()) {
+ try {
+ c.inform(message);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
public synchronized boolean acceptCard(Player sender, Card card) throws RemoteException {
- // TODO Auto-generated method stub
- return false;
+ return roundLogic.acceptCard(playerMap.getServerSidePlayer(sender), card);
}
-
+
public synchronized boolean acceptCard(Player sender, Card card, int anunt) throws RemoteException {
- // TODO Auto-generated method stub
- return false;
+ return roundLogic.acceptCard(playerMap.getServerSidePlayer(sender), card, anunt);
}
-
+
public synchronized Score getOverallScore() throws RemoteException {
// TODO Auto-generated method stub
return null;
}
-
+
public synchronized Player joinGame(String name, ClientInterface client) throws RemoteException {
-
ServerSidePlayer ssplayer = startGameLogic.setupPlayer(name);
playerMap.put(ssplayer, client);
if (ssplayer != null)
return ssplayer.getInfo();
return null;
}
-
+
public synchronized void startGame(Player sender) throws RemoteException {
startGameLogic.playerReady();
if (startGameLogic.gameReady()) {
@@ -88,5 +115,4 @@
gameLogic.startGame(teams, this);
}
}
-
}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java 2010-04-08 06:12:57 UTC (rev 106)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java 2010-04-08 16:35:52 UTC (rev 107)
@@ -6,25 +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)
@@ -32,12 +32,13 @@
else {
int searchValue = 7 - card.getValue();
for (Card c : cards)
- if (c.getValue() == searchValue && c.getColor().equals(card.getColor()))
+ 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;
@@ -57,8 +58,12 @@
}
return true;
}
-
+
public Player getInfo() {
return player;
}
+
+ public void removeCard(Card card) {
+ this.cards.remove(card);
+ }
}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/server/StartGameLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/StartGameLogic.java 2010-04-08 06:12:57 UTC (rev 106)
+++ Java/trunk/src/prc/bubulina/cruce/server/StartGameLogic.java 2010-04-08 16:35:52 UTC (rev 107)
@@ -5,47 +5,48 @@
import prc.bubulina.cruce.remote.Player;
public class StartGameLogic {
-
+
private int joinedPlayers;
private int readyPlayers;
private List<Team> teams;
private PlayerFactory factory;
-
+
public StartGameLogic(List<Team> teams) {
-
+
joinedPlayers = 0;
readyPlayers = 0;
factory = new PlayerFactory();
-
- this.teams = teams;
+
+ this.teams = teams;
}
-
+
public ServerSidePlayer setupPlayer(String name) {
-
+
if (joinedPlayers < 4) {
-
+
Player player = factory.getPlayer(name);
- ServerSidePlayer ssplayer = new ServerSidePlayer(player);
+ ServerSidePlayer ssplayer = new ServerSidePlayer(player);
joinedPlayers++;
- //First two players are added to team one and the next two to team 2
+ // First two players are added to team one and the next two to team
+ // 2
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-08 06:12:57 UTC (rev 106)
+++ Java/trunk/src/prc/bubulina/cruce/server/Team.java 2010-04-08 16:35:52 UTC (rev 107)
@@ -11,7 +11,7 @@
private int goal;
private List<Card> cardsTaken;
private int overallScore;
-
+
public Team() {
players = new LinkedList<ServerSidePlayer>();
cardsTaken = new LinkedList<Card>();
@@ -19,53 +19,51 @@
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);
}
-
+
public void setGoal(int goal) {
this.goal = goal;
}
-
- public void addAnunt(int value)
- {
- if(value != 40 && value != 20)
- {
- throw new IllegalArgumentException("The value filed is not one of 20 or 40!\n");
+
+ public void addAnunt(int value) {
+ if (value != 40 && value != 20) {
+ throw new IllegalArgumentException(
+ "The value filed is not one of 20 or 40!\n");
}
-
+
anunturi += value;
}
-
+
public int computeScore() {
-
+
int result = anunturi;
for (Card card : cardsTaken)
result += card.getValue();
result /= 33;
- if (result < goal)
- {
- result = -goal;
+ if (result < goal) {
+ result = -goal;
}
-
+
overallScore += result;
-
+
return result;
}
-
+
public int getOverallScore() {
return overallScore;
}
-
+
public void resetRound() {
anunturi = 0;
goal = 0;
Added: Java/trunk/src/prc/bubulina/cruce/tests/server/OrderKeeperTest.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/tests/server/OrderKeeperTest.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/tests/server/OrderKeeperTest.java 2010-04-08 16:35:52 UTC (rev 107)
@@ -0,0 +1,43 @@
+package prc.bubulina.cruce.tests.server;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import prc.bubulina.cruce.server.OrderKeeper;
+import prc.bubulina.cruce.server.RoundLogic;
+import prc.bubulina.cruce.server.ServerSidePlayer;
+import prc.bubulina.cruce.server.StartGameLogic;
+import prc.bubulina.cruce.server.Team;
+
+public class OrderKeeperTest {
+ private OrderKeeper o;
+ private List<Team> teams;
+ private ServerSidePlayer p1, p2, p3, p4;
+
+ @Before
+ public void setUp() {
+ o = new OrderKeeper();
+ teams = new ArrayList<Team>();
+ teams.add(new Team());
+ teams.add(new Team());
+ StartGameLogic startGameLogic = new StartGameLogic(teams);
+ p1 = startGameLogic.setupPlayer("P1");
+ p2 = startGameLogic.setupPlayer("P2");
+ p3 = startGameLogic.setupPlayer("P3");
+ p4 = startGameLogic.setupPlayer("P4");
+ o.put(0, p1);
+ o.put(1, p2);
+ o.put(2, p3);
+ o.put(3, p4);
+ }
+
+ @Test
+ public void testResetOrder() {
+ System.out.println(o);
+ o.resetOrder(p3);
+ System.out.println(o);
+ }
+}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/tests/server/StartGameLogicTest.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/tests/server/StartGameLogicTest.java 2010-04-08 06:12:57 UTC (rev 106)
+++ Java/trunk/src/prc/bubulina/cruce/tests/server/StartGameLogicTest.java 2010-04-08 16:35:52 UTC (rev 107)
@@ -12,15 +12,13 @@
import prc.bubulina.cruce.server.StartGameLogic;
import prc.bubulina.cruce.server.Team;
-public class StartGameLogicTest
-{
+public class StartGameLogicTest {
- private StartGameLogic startGameLogic;
+ private StartGameLogic startGameLogic;
private List<Team> teams;
-
+
@Before
- public void setUp() throws Exception
- {
+ public void setUp() throws Exception {
teams = new ArrayList<Team>();
teams.add(new Team());
teams.add(new Team());
@@ -28,102 +26,96 @@
}
@Test
- public void testSetupPlayer_OnePlayer_BestCaseScenario()
- {
+ public void testSetupPlayer_OnePlayer_BestCaseScenario() {
String playerName = "Player1";
teams.clear();
teams.add(new Team());
-
- //Actual test
+
+ // Actual test
ServerSidePlayer actual = startGameLogic.setupPlayer(playerName);
ServerSidePlayer expected = teams.get(0).getPlayers().get(0);
assertEquals(expected, actual);
assertEquals(1, teams.size());
assertEquals(1, teams.get(0).getPlayers().size());
- assertEquals(playerName, actual.getInfo().getName());
+ assertEquals(playerName, actual.getInfo().getName());
}
-
+
@Test
- public void testSetupPlayer_FourPlayers_BestCaseScenario()
- {
- String[] playerName = {"Player1", "Player2", "Player3", "Player4"};
-
- //Actual test
- for (int i = 0; i < playerName.length; i++)
- {
+ public void testSetupPlayer_FourPlayers_BestCaseScenario() {
+ String[] playerName = { "Player1", "Player2", "Player3", "Player4" };
+
+ // Actual test
+ for (int i = 0; i < playerName.length; i++) {
ServerSidePlayer actual = startGameLogic.setupPlayer(playerName[i]);
- ServerSidePlayer expected = teams.get(i / 2).getPlayers().get(i % 2);
+ ServerSidePlayer expected = teams.get(i / 2).getPlayers()
+ .get(i % 2);
assertEquals(expected, actual);
assertEquals(2, teams.size());
assertEquals((i % 2 + 1), teams.get(i / 2).getPlayers().size());
assertEquals(playerName[i], actual.getInfo().getName());
}
}
-
+
@Test
- public void testSetupPlayer_FivePlayers_BestCaseScenario()
- {
- String[] playerName = {"Player1", "Player2", "Player3", "Player4", "Player5"};
-
- //Actual test
- for (int i = 0; i < playerName.length - 1; i++)
- {
+ public void testSetupPlayer_FivePlayers_BestCaseScenario() {
+ String[] playerName = { "Player1", "Player2", "Player3", "Player4",
+ "Player5" };
+
+ // Actual test
+ for (int i = 0; i < playerName.length - 1; i++) {
ServerSidePlayer actual = startGameLogic.setupPlayer(playerName[i]);
- ServerSidePlayer expected = teams.get(i / 2).getPlayers().get(i % 2);
+ ServerSidePlayer expected = teams.get(i / 2).getPlayers()
+ .get(i % 2);
assertEquals(expected, actual);
assertEquals(2, teams.size());
assertEquals((i % 2 + 1), teams.get(i / 2).getPlayers().size());
assertEquals(playerName[i], actual.getInfo().getName());
}
-
+
ServerSidePlayer actual = startGameLogic.setupPlayer(playerName[4]);
assertNull(actual);
- //Checking if the player was added to a team
- for(Team team : teams)
- {
- for (ServerSidePlayer player : team.getPlayers())
- {
+ // Checking if the player was added to a team
+ for (Team team : teams) {
+ for (ServerSidePlayer player : team.getPlayers()) {
assertNotSame(playerName[4], player.getInfo().getName());
}
}
}
-
+
@Test
- public void testSetupPlayer_TwoPlayersWithTheSameName()
- {
- String[] playerName = {"Player1", "Player1"};
-
+ public void testSetupPlayer_TwoPlayersWithTheSameName() {
+ String[] playerName = { "Player1", "Player1" };
+
assertEquals(playerName[0], playerName[1]);
-
- //Actual test
- for (int i = 0; i < playerName.length - 1; i++)
- {
+
+ // Actual test
+ for (int i = 0; i < playerName.length - 1; i++) {
ServerSidePlayer actual = startGameLogic.setupPlayer(playerName[i]);
- ServerSidePlayer expected = teams.get(i / 2).getPlayers().get(i % 2);
+ ServerSidePlayer expected = teams.get(i / 2).getPlayers()
+ .get(i % 2);
assertEquals(expected, actual);
assertEquals(2, teams.size());
assertEquals((i % 2 + 1), teams.get(i / 2).getPlayers().size());
assertEquals(playerName[i], actual.getInfo().getName());
assertEquals(playerName[0], actual.getInfo().getName());
- }
+ }
}
-
+
@Test
- public void testSetupPlayer_AllPlayersWithTheSameName()
- {
- String[] playerName = {"Player1", "Player1", "Player1", "Player1"};
-
- //Actual test
- for (int i = 0; i < playerName.length - 1; i++)
- {
+ public void testSetupPlayer_AllPlayersWithTheSameName() {
+ String[] playerName = { "Player1", "Player1", "Player1", "Player1" };
+
+ // Actual test
+ for (int i = 0; i < playerName.length - 1; i++) {
ServerSidePlayer actual = startGameLogic.setupPlayer(playerName[i]);
- ServerSidePlayer expected = teams.get(i / 2).getPlayers().get(i % 2);
+ ServerSidePlayer expected = teams.get(i / 2).getPlayers()
+ .get(i % 2);
assertEquals(expected, actual);
assertEquals(2, teams.size());
assertEquals((i % 2 + 1), teams.get(i / 2).getPlayers().size());
assertEquals(playerName[i], actual.getInfo().getName());
assertEquals(playerName[0], actual.getInfo().getName());
- }
+ }
}
}
Modified: Java/trunk/src/prc/bubulina/cruce/tests/server/TeamTest.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/tests/server/TeamTest.java 2010-04-08 06:12:57 UTC (rev 106)
+++ Java/trunk/src/prc/bubulina/cruce/tests/server/TeamTest.java 2010-04-08 16:35:52 UTC (rev 107)
@@ -11,93 +11,79 @@
import prc.bubulina.cruce.remote.Color;
import prc.bubulina.cruce.server.Team;
-public class TeamTest
-{
- private Team team;
+public class TeamTest {
+ private Team team;
private int goal;
-
+
@Before
- public void setUp() throws Exception
- {
- team = new Team();
+ public void setUp() throws Exception {
+ team = new Team();
}
-
+
@Test
- public void testComputeScore_NoAnunt_NoCardsTAken_NoGoal()
- {
+ public void testComputeScore_NoAnunt_NoCardsTAken_NoGoal() {
assertEquals(0, team.computeScore());
assertEquals(goal, team.getOverallScore());
}
@Test
- public void testComputeScore_NoAnunt_NoCardsTAken_WithGoalUnfulfilled()
- {
+ public void testComputeScore_NoAnunt_NoCardsTAken_WithGoalUnfulfilled() {
goal = 10;
team.setGoal(goal);
assertEquals(-goal, team.computeScore());
assertEquals(-goal, team.getOverallScore());
}
-
+
@Test
- public void testComputeScore_NoAnunt_CardsTaken_WithGoalUnfulfilled()
- {
+ public void testComputeScore_NoAnunt_CardsTaken_WithGoalUnfulfilled() {
goal = 2;
team.setGoal(goal);
-
+
int takenCardsValue = 0;
-
- for(int i = 0; i < 11; i++)
- {
+
+ for (int i = 0; i < 11; i++) {
Card card;
- try
- {
- card = new Card(i * 2 % 3, Color.ROSU);
+ try {
+ card = new Card(i * 2 % 3, Color.ROSU);
+ } catch (IllegalArgumentExcept...
[truncated message content] |
|
From: <ali...@us...> - 2010-04-09 09:33:51
|
Revision: 109
http://cruce.svn.sourceforge.net/cruce/?rev=109&view=rev
Author: alinposho
Date: 2010-04-09 09:33:41 +0000 (Fri, 09 Apr 2010)
Log Message:
-----------
Am suprascris metoda equals() in clasa Card.
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/remote/Card.java
Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Card.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-09 09:18:48 UTC (rev 108)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-09 09:33:41 UTC (rev 109)
@@ -50,4 +50,18 @@
Color c = Color.values()[new Random().nextInt(4)];
return new Card(i, c);
}
+
+ @Override
+ public boolean equals(Object object)
+ {
+ if(!(object instanceof Card))
+ {
+ return false;
+ }
+
+ Card card = (Card)object;
+
+ return color.equals(card.getColor()) && value == card.getValue();
+ }
+
}
Modified: Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-09 09:18:48 UTC (rev 108)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-09 09:33:41 UTC (rev 109)
@@ -18,25 +18,18 @@
*/
private static final long serialVersionUID = 6398777327639353025L;
- private static ServerImplementation instance;
-
- private ServerImplementation() throws RemoteException {
- super();
- }
-
- public synchronized static ServerImplementation getInstance() throws RemoteException {
- if (instance == null)
- instance = new ServerImplementation();
- return instance;
- }
-
private List<Team> teams = new LinkedList<Team>();
private List<ClientInterface> clients = new LinkedList<ClientInterface>();
private StartGameLogic startGameLogic;
private GameLogic gameLogic;
private RoundLogic roundLogic;
private PlayerMap playerMap = new PlayerMap();
+
+ public ServerImplementation() throws RemoteException {
+ super();
+ }
+
public synchronized boolean sendCards(List<Card> cards, ServerSidePlayer player) {
ClientInterface client = playerMap.getClient(player.getInfo());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <hor...@us...> - 2010-04-23 17:27:13
|
Revision: 126
http://cruce.svn.sourceforge.net/cruce/?rev=126&view=rev
Author: horiaradu
Date: 2010-04-23 17:27:07 +0000 (Fri, 23 Apr 2010)
Log Message:
-----------
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/client/Client.java
Java/trunk/src/prc/bubulina/cruce/client/Game.java
Java/trunk/src/prc/bubulina/cruce/client/TextUI.java
Java/trunk/src/prc/bubulina/cruce/remote/Card.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
Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.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/Team.java
Modified: Java/trunk/src/prc/bubulina/cruce/client/Client.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/Client.java 2010-04-23 09:51:21 UTC (rev 125)
+++ Java/trunk/src/prc/bubulina/cruce/client/Client.java 2010-04-23 17:27:07 UTC (rev 126)
@@ -15,8 +15,7 @@
import prc.bubulina.cruce.remote.Score;
import prc.bubulina.cruce.remote.ServerInterface;
-public class Client extends UnicastRemoteObject implements ClientInterface,
- Serializable {
+public class Client extends UnicastRemoteObject implements ClientInterface, Serializable {
/**
*
@@ -37,8 +36,7 @@
* the name of the used game server
* @throws RemoteException
*/
- public Client(Game game, String gameServerAddress, String gameServerName)
- throws RemoteException {
+ public Client(Game game, String gameServerAddress, String gameServerName) throws RemoteException {
super();
String url = "rmi://" + gameServerAddress + "/" + gameServerName;
@@ -82,8 +80,11 @@
boolean accepted = false;
while (!accepted) {
Card card = game.hit();
+ System.out.println(card);
try {
+ System.out.println("AAA");
accepted = server.acceptCard(player, card);
+ System.out.println("BBB");
} catch (RemoteException e) {
e.printStackTrace();
}
Modified: Java/trunk/src/prc/bubulina/cruce/client/Game.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/Game.java 2010-04-23 09:51:21 UTC (rev 125)
+++ Java/trunk/src/prc/bubulina/cruce/client/Game.java 2010-04-23 17:27:07 UTC (rev 126)
@@ -56,7 +56,7 @@
*/
public Card hit() {
Card card = ui.playCard();
- return null;
+ return card;
}
/**
@@ -99,7 +99,7 @@
}
public void inform(String information) {
- ui.sendMessage(information);
+ ui.sendMessage(information);
}
public void setRoundScore(int score) {
@@ -107,6 +107,6 @@
}
public void setGameScore(int score) {
- ui.sendMessage("Scorul jocului este" + score);
+ ui.sendMessage("Scorul jocului este" + score);
}
}
Modified: Java/trunk/src/prc/bubulina/cruce/client/TextUI.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/TextUI.java 2010-04-23 09:51:21 UTC (rev 125)
+++ Java/trunk/src/prc/bubulina/cruce/client/TextUI.java 2010-04-23 17:27:07 UTC (rev 126)
@@ -62,14 +62,13 @@
showAvailableCards();
try {
System.in.skip(System.in.available());
- System.out
- .println("Da-ti cartea jucata (1-" + cards.size() + "): ");
- cardNo = System.in.read();
+ System.out.println("Da-ti cartea jucata (1-" + cards.size() + "): ");
+ cardNo = System.in.read() - '0';
System.in.skip(System.in.available());
} catch (IOException e) {
e.printStackTrace();
}
- return cards.get(cardNo-1);
+ return cards.get(cardNo - 1);
}
@Override
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Card.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-23 09:51:21 UTC (rev 125)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-23 17:27:07 UTC (rev 126)
@@ -3,24 +3,21 @@
import java.io.Serializable;
import java.util.Random;
-public class Card implements Serializable{
-
+public class Card implements Serializable {
+
/**
- * Needed serialization for RMI parameter
+ * Needed serialization for RMI parameter
*/
private static final long serialVersionUID = 243254958971908105L;
-
+
private int value;
private Color color;
private static Color tromf;
public Card(int value, Color color) {
this.color = color;
- if (value != 0 && value != 2 && value != 3 && value != 4 && value != 10
- && value != 11) {
- throw new IllegalArgumentException(
- "Card value is not within the set: "
- + "{0 , 2, 3, 4, 10, 11}!\n");
+ if (value != 0 && value != 2 && value != 3 && value != 4 && value != 10 && value != 11) {
+ throw new IllegalArgumentException("Card value is not within the set: " + "{0 , 2, 3, 4, 10, 11}!\n");
}
this.value = value;
}
@@ -50,18 +47,20 @@
Color c = Color.values()[new Random().nextInt(4)];
return new Card(i, c);
}
-
+
@Override
- public boolean equals(Object object)
- {
- if(!(object instanceof Card))
- {
+ public boolean equals(Object object) {
+ if (!(object instanceof Card)) {
return false;
}
-
- Card card = (Card)object;
-
- return color.equals(card.getColor()) && value == card.getValue();
+
+ Card card = (Card) object;
+
+ return color.equals(card.getColor()) && value == card.getValue();
}
+ public String toString() {
+ return color + " " + value;
+ }
+
}
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Player.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Player.java 2010-04-23 09:51:21 UTC (rev 125)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Player.java 2010-04-23 17:27:07 UTC (rev 126)
@@ -3,12 +3,12 @@
import java.io.Serializable;
public class Player implements Serializable {
-
+
/**
* Needed for serialization serialization
*/
private static final long serialVersionUID = -2446467001127293964L;
-
+
private String name;
private int id;
private String teamName;
@@ -25,22 +25,22 @@
public int getID() {
return id;
}
-
+
public void setTeamName(String teamName) {
this.teamName = teamName;
}
-
+
public String getTeamName() {
return teamName;
}
-
+
public boolean equals(Object o) {
if (o instanceof Player)
- if (((Player)o).name.equals(name) && ((Player)o).id == id)
+ if (((Player) o).name.equals(name) && ((Player) o).id == id)
return true;
return false;
}
-
+
public int hashCode() {
return id;
}
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Score.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Score.java 2010-04-23 09:51:21 UTC (rev 125)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Score.java 2010-04-23 17:27:07 UTC (rev 126)
@@ -7,10 +7,10 @@
* This class will be a container for a name value pair "player-score"
*
*/
-public class Score implements Serializable{
-
+public class Score implements Serializable {
+
/**
- * Needed for serialization(auto generated)
+ * Needed for serialization(auto generated)
*/
private static final long serialVersionUID = 1214550626496444804L;
private Map<Player, Integer> score;
Modified: Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java 2010-04-23 09:51:21 UTC (rev 125)
+++ Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java 2010-04-23 17:27:07 UTC (rev 126)
@@ -14,8 +14,7 @@
*@param client
* @throws RemoteException
*/
- public Player joinGame(String name, ClientInterface 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
@@ -41,8 +40,7 @@
/**
* This method is used to sent a card and an anunt to the server for
- * validation and storage
- * Clintul tre sa apeleze asta pana ii da true!
+ * validation and storage Clintul tre sa apeleze asta pana ii da true!
*
* @param sender
* The client who sent the card
@@ -53,8 +51,7 @@
* 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;
/**
*
Modified: Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-23 09:51:21 UTC (rev 125)
+++ Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-23 17:27:07 UTC (rev 126)
@@ -146,6 +146,7 @@
}
public boolean acceptCard(ServerSidePlayer player, Card card) {
+ System.out.println(player.getInfo().getName() + ": " + card);
Card[] c = (Card[]) cardsDown.values().toArray();
if (player.checkHit(card, c) == true) {
cardsDown.put(playerOrder.getOrder(player), card);
@@ -166,8 +167,7 @@
Card[] c = (Card[]) cardsDown.values().toArray();
if (player.checkHit(card, c) == true) {
cardsDown.put(playerOrder.getOrder(player), card);
- hitInfoMessage = player.getInfo().getName() + " a dat " + c
- + " anuntand " + anunt;
+ hitInfoMessage = player.getInfo().getName() + " a dat " + c + " anuntand " + anunt;
this.getTeam(player).addAnunt(anunt);
if (handNr == 0)
Card.setTromf(card.getColor());
Modified: Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-23 09:51:21 UTC (rev 125)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-23 17:27:07 UTC (rev 126)
@@ -11,8 +11,7 @@
import prc.bubulina.cruce.remote.Score;
import prc.bubulina.cruce.remote.ServerInterface;
-public class ServerImplementation extends UnicastRemoteObject implements
- ServerInterface {
+public class ServerImplementation extends UnicastRemoteObject implements ServerInterface {
/**
* Needed for serialization
@@ -35,14 +34,12 @@
gameLogic = new GameLogic();
}
- public synchronized Player joinGame(String name, ClientInterface client)
- throws RemoteException {
+ public synchronized Player joinGame(String name, ClientInterface client) throws RemoteException {
System.out.println(name + " joined the game");
client.inform("welcome to the game");
ServerSidePlayer ssplayer = startGameLogic.setupPlayer(name);
client.inform("you are in team " + ssplayer.getInfo().getTeamName());
- this.informAll(ssplayer.getInfo().getName() + " from "
- + ssplayer.getInfo().getTeamName() + " joined the game");
+ this.informAll(ssplayer.getInfo().getName() + " from " + ssplayer.getInfo().getTeamName() + " joined the game");
clients.add(client);
playerMap.put(ssplayer, client);
if (ssplayer != null)
@@ -63,8 +60,7 @@
}
}
- public synchronized boolean sendCards(List<Card> cards,
- ServerSidePlayer player) {
+ public synchronized boolean sendCards(List<Card> cards, ServerSidePlayer player) {
ClientInterface client = playerMap.getClient(player.getInfo());
try {
@@ -114,16 +110,14 @@
}
}
- public synchronized boolean acceptCard(Player sender, Card card)
- throws RemoteException {
- return roundLogic.acceptCard(playerMap.getServerSidePlayer(sender),
- card);
+ public synchronized boolean acceptCard(Player sender, Card card) throws RemoteException {
+ System.out.println("X");
+ return roundLogic.acceptCard(playerMap.getServerSidePlayer(sender), card);
}
- public synchronized boolean acceptCard(Player sender, Card card, int anunt)
- throws RemoteException {
- return roundLogic.acceptCard(playerMap.getServerSidePlayer(sender),
- card, anunt);
+ public synchronized boolean acceptCard(Player sender, Card card, int anunt) throws RemoteException {
+ System.out.println("Y");
+ return roundLogic.acceptCard(playerMap.getServerSidePlayer(sender), card, anunt);
}
public synchronized Score getOverallScore() throws RemoteException {
Modified: Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java 2010-04-23 09:51:21 UTC (rev 125)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java 2010-04-23 17:27:07 UTC (rev 126)
@@ -31,8 +31,7 @@
else {
int searchValue = 7 - card.getValue();
for (Card c : cards)
- if (c.getValue() == searchValue
- && c.getColor().equals(card.getColor()))
+ if (c.getValue() == searchValue && c.getColor().equals(card.getColor()))
return true;
return false;
}
Modified: Java/trunk/src/prc/bubulina/cruce/server/Team.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/Team.java 2010-04-23 09:51:21 UTC (rev 125)
+++ Java/trunk/src/prc/bubulina/cruce/server/Team.java 2010-04-23 17:27:07 UTC (rev 126)
@@ -40,8 +40,7 @@
public void addAnunt(int value) {
if (value != 40 && value != 20) {
- throw new IllegalArgumentException(
- "The value filed is not one of 20 or 40!\n");
+ throw new IllegalArgumentException("The value filed is not one of 20 or 40!\n");
}
anunturi += value;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <hor...@us...> - 2010-04-24 07:41:13
|
Revision: 127
http://cruce.svn.sourceforge.net/cruce/?rev=127&view=rev
Author: horiaradu
Date: 2010-04-24 07:41:06 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/client/Client.java
Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java
Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
Modified: Java/trunk/src/prc/bubulina/cruce/client/Client.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/Client.java 2010-04-23 17:27:07 UTC (rev 126)
+++ Java/trunk/src/prc/bubulina/cruce/client/Client.java 2010-04-24 07:41:06 UTC (rev 127)
@@ -83,6 +83,7 @@
System.out.println(card);
try {
System.out.println("AAA");
+ System.out.println("CLIENT: " + player.getName() + ": " + card);
accepted = server.acceptCard(player, card);
System.out.println("BBB");
} catch (RemoteException e) {
Modified: Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-23 17:27:07 UTC (rev 126)
+++ Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-24 07:41:06 UTC (rev 127)
@@ -13,7 +13,7 @@
private OrderKeeper playerOrder;
private ServerImplementation server;
private Map<Integer, Card> cardsDown;
- private String hitInfoMessage;
+ private String hitInfoMessage = new String();
private int handNr;
public RoundLogic(List<Team> teams, ServerImplementation server) {
@@ -110,6 +110,7 @@
for (int i = 0; i < 4; i++) {
ServerSidePlayer p = playerOrder.get(i);
server.hit(p);
+ System.out.println("XXYY " + hitInfoMessage);
server.informAll(hitInfoMessage);
}
int maxIndex = getMaxCard(cardsDown);
@@ -146,6 +147,7 @@
}
public boolean acceptCard(ServerSidePlayer player, Card card) {
+ System.out.println("AAAAAAAAAAAAAAAAAAAAAA");
System.out.println(player.getInfo().getName() + ": " + card);
Card[] c = (Card[]) cardsDown.values().toArray();
if (player.checkHit(card, c) == true) {
Modified: Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-23 17:27:07 UTC (rev 126)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-24 07:41:06 UTC (rev 127)
@@ -95,6 +95,7 @@
ClientInterface client = playerMap.getClient(player.getInfo());
try {
client.hit();
+ wait();
} catch (Exception e) {
e.printStackTrace();
}
@@ -111,8 +112,10 @@
}
public synchronized boolean acceptCard(Player sender, Card card) throws RemoteException {
- System.out.println("X");
- return roundLogic.acceptCard(playerMap.getServerSidePlayer(sender), card);
+ System.out.println("SERVER: " + sender.getName() + " " + card);
+ boolean result = roundLogic.acceptCard(playerMap.getServerSidePlayer(sender), card);
+ notifyAll();
+ return result;
}
public synchronized boolean acceptCard(Player sender, Card card, int anunt) throws RemoteException {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <hor...@us...> - 2010-04-24 09:05:26
|
Revision: 128
http://cruce.svn.sourceforge.net/cruce/?rev=128&view=rev
Author: horiaradu
Date: 2010-04-24 09:05:19 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
Am rezolvat problemele de la hit() si acceptcard schimband logica si modul de apelare. Acum mai fac partea cu anuntul si gata
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/client/Client.java
Java/trunk/src/prc/bubulina/cruce/client/Game.java
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/Score.java
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/RoundLogic.java
Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java
Added Paths:
-----------
Java/trunk/src/prc/bubulina/cruce/remote/Anunt.java
Java/trunk/src/prc/bubulina/cruce/remote/Hitable.java
Modified: Java/trunk/src/prc/bubulina/cruce/client/Client.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/Client.java 2010-04-24 07:41:06 UTC (rev 127)
+++ Java/trunk/src/prc/bubulina/cruce/client/Client.java 2010-04-24 09:05:19 UTC (rev 128)
@@ -67,7 +67,7 @@
@Override
public void endGame(Score score) throws RemoteException {
- game.setGameScore(score.getYourScore(player));
+ game.setGameScore(score);
}
@Override
@@ -76,20 +76,12 @@
}
@Override
- public void hit() throws RemoteException {
- boolean accepted = false;
- while (!accepted) {
- Card card = game.hit();
- System.out.println(card);
- try {
- System.out.println("AAA");
- System.out.println("CLIENT: " + player.getName() + ": " + card);
- accepted = server.acceptCard(player, card);
- System.out.println("BBB");
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
+ public Card hit() throws RemoteException {
+ Card card = game.hit();
+ System.out.println(card);
+ System.out.println("AAA");
+ System.out.println("CLIENT: " + player.getName() + ": " + card);
+ return card;
}
@Override
@@ -103,13 +95,17 @@
}
@Override
- public void receiveRoundScore(Score score) throws RemoteException {
- game.setRoundScore(score.getYourScore(player));
- }
-
- @Override
public void setTromf(Color tromf) throws RemoteException {
game.setTromf(tromf);
}
+
+ public void removeCard(Card card) {
+ game.removeCard(card);
+ }
+ @Override
+ public void sendScore(Score overallScore) {
+ game.setGameScore(overallScore);
+ }
+
}
Modified: Java/trunk/src/prc/bubulina/cruce/client/Game.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/Game.java 2010-04-24 07:41:06 UTC (rev 127)
+++ Java/trunk/src/prc/bubulina/cruce/client/Game.java 2010-04-24 09:05:19 UTC (rev 128)
@@ -102,11 +102,15 @@
ui.sendMessage(information);
}
- public void setRoundScore(int score) {
+ public void setRoundScore(Score score) {
ui.sendMessage("Scorul rundei este: " + score);
}
- public void setGameScore(int score) {
+ public void setGameScore(Score score) {
ui.sendMessage("Scorul jocului este" + score);
}
+
+ public void removeCard(Card card) {
+ cardsInHand.remove(card);
+ }
}
Added: Java/trunk/src/prc/bubulina/cruce/remote/Anunt.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Anunt.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Anunt.java 2010-04-24 09:05:19 UTC (rev 128)
@@ -0,0 +1,10 @@
+package prc.bubulina.cruce.remote;
+
+public class Anunt implements Hitable {
+ public Card card;
+ public int value;
+ public Anunt(Card card, int value) {
+ this.value = value;
+ this.card = card;
+ }
+}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Card.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-24 07:41:06 UTC (rev 127)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-24 09:05:19 UTC (rev 128)
@@ -3,7 +3,7 @@
import java.io.Serializable;
import java.util.Random;
-public class Card implements Serializable {
+public class Card implements Serializable, Hitable {
/**
* Needed serialization for RMI parameter
Modified: Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java 2010-04-24 07:41:06 UTC (rev 127)
+++ Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java 2010-04-24 09:05:19 UTC (rev 128)
@@ -46,7 +46,7 @@
*
* @throws RemoteException
*/
- public void hit() throws RemoteException;
+ public Card hit() throws RemoteException;
/**
* Informs the player about the tromf
@@ -62,7 +62,7 @@
* @param score
* @throws RemoteException
*/
- public void receiveRoundScore(Score score) throws RemoteException;
+ public void sendScore(Score overallScore) throws RemoteException;
/**
* Informs the player that the game has ended and also sends the overall
@@ -73,4 +73,6 @@
*/
public void endGame(Score score) throws RemoteException;
+ public void removeCard(Card card) throws RemoteException;
+
}
Added: Java/trunk/src/prc/bubulina/cruce/remote/Hitable.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Hitable.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Hitable.java 2010-04-24 09:05:19 UTC (rev 128)
@@ -0,0 +1,5 @@
+package prc.bubulina.cruce.remote;
+
+public interface Hitable {
+
+}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Score.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Score.java 2010-04-24 07:41:06 UTC (rev 127)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Score.java 2010-04-24 09:05:19 UTC (rev 128)
@@ -1,7 +1,9 @@
package prc.bubulina.cruce.remote;
import java.io.Serializable;
+import java.util.HashMap;
import java.util.Map;
+import java.util.Map.Entry;
/**
* This class will be a container for a name value pair "player-score"
@@ -14,9 +16,11 @@
*/
private static final long serialVersionUID = 1214550626496444804L;
private Map<Player, Integer> score;
+ private Map<String, Integer> teamScore;
- public Score(Map<Player, Integer> score) {
+ public Score(Map<Player, Integer> score, Map<String, Integer> teamScore) {
this.score = score;
+ this.teamScore = teamScore;
}
/**
@@ -27,4 +31,11 @@
public int getYourScore(Player player) {
return score.get(player);
}
+
+ public String toString() {
+ String result = new String();
+ for (Entry<String, Integer> e : teamScore.entrySet())
+ result += e.getKey() + " : " + e.getValue() + "\n";
+ return result;
+ }
}
Modified: Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java 2010-04-24 07:41:06 UTC (rev 127)
+++ Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java 2010-04-24 09:05:19 UTC (rev 128)
@@ -26,35 +26,7 @@
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
- * @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 Clintul tre sa apeleze asta pana ii da true!
- *
- * @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;
-
- /**
- *
* @return The overall score of the game
* @throws RemoteException
*/
Modified: Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java 2010-04-24 07:41:06 UTC (rev 127)
+++ Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java 2010-04-24 09:05:19 UTC (rev 128)
@@ -15,8 +15,16 @@
public void startGame(List<Team> teams, ServerImplementation server) {
this.teams = teams;
roundLogic = new RoundLogic(teams, server);
- while (endOfGame() == false)
+ while (endOfGame() == false) {
+ for (Team t : teams)
+ t.resetRound();
roundLogic.startRound();
+ server.informAll("S-a terminat runda");
+ server.sendScore(getRoundScore());
+ server.sendScore(getOverallScore());
+ }
+ server.informAll("S-a terminat jocul");
+ server.sendScore(getOverallScore());
}
public boolean endOfGame() {
@@ -28,10 +36,25 @@
public Score getOverallScore() {
Map<Player, Integer> scoreMap = new HashMap<Player, Integer>();
- for (Team t : teams)
+ Map<String, Integer> teamScore = new HashMap<String, Integer>();
+ for (Team t : teams) {
for (ServerSidePlayer p : t.getPlayers())
scoreMap.put(p.getInfo(), t.getOverallScore());
+ teamScore.put(t.getName(), t.getOverallScore());
+ }
- return new Score(scoreMap);
+ return new Score(scoreMap, teamScore);
}
+
+ public Score getRoundScore() {
+ Map<Player, Integer> scoreMap = new HashMap<Player, Integer>();
+ Map<String, Integer> teamScore = new HashMap<String, Integer>();
+ for (Team t : teams) {
+ for (ServerSidePlayer p : t.getPlayers())
+ scoreMap.put(p.getInfo(), t.computeScore());
+ teamScore.put(t.getName(), t.computeScore());
+ }
+
+ return new Score(scoreMap, teamScore);
+ }
}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-24 07:41:06 UTC (rev 127)
+++ Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-24 09:05:19 UTC (rev 128)
@@ -13,7 +13,6 @@
private OrderKeeper playerOrder;
private ServerImplementation server;
private Map<Integer, Card> cardsDown;
- private String hitInfoMessage = new String();
private int handNr;
public RoundLogic(List<Team> teams, ServerImplementation server) {
@@ -45,7 +44,6 @@
startBid();
for (handNr = 0; handNr < 6; handNr++)
playHand();
- // de bagat cu scorul!
}
private void sendCards() {
@@ -72,6 +70,8 @@
if (ok == false) {
i = -1;
givenCards.clear();
+ } else {
+ player.setCards(cards);
}
}
}
@@ -92,26 +92,19 @@
playerOrder.resetOrder(winner);
}
- /*
- * private void resetOrder(ServerSidePlayer firstPlayer) { int oldPosition =
- * 0; for (Entry<Integer, ServerSidePlayer> p : playerOrder.entrySet()) if
- * (p.getValue().equals(firstPlayer)) oldPosition = p.getKey(); Map<Integer,
- * ServerSidePlayer> newPlayerOrder = new HashMap<Integer,
- * ServerSidePlayer>(); for (Entry<Integer, ServerSidePlayer> p :
- * playerOrder.entrySet()) { int newPosition; if (p.getKey() >= oldPosition)
- * newPosition = p.getKey() - oldPosition; else newPosition = p.getKey() -
- * oldPosition + 4; ServerSidePlayer player = p.getValue();
- * newPlayerOrder.put(newPosition, player); } playerOrder = newPlayerOrder;
- * }
- */
-
private void playHand() {
cardsDown = new HashMap<Integer, Card>();
for (int i = 0; i < 4; i++) {
ServerSidePlayer p = playerOrder.get(i);
- server.hit(p);
- System.out.println("XXYY " + hitInfoMessage);
- server.informAll(hitInfoMessage);
+ boolean ok = false;
+ while (ok == false) {
+ Card card = server.hit(p);
+ ok = acceptCard(p, card);
+ if (ok == false)
+ server.inform(p.getInfo(), "Ai dat gresit. Mai da o data");
+ else
+ server.informAll(p.getInfo() + " a dat " + card);
+ }
}
int maxIndex = getMaxCard(cardsDown);
Team t = this.getTeam(playerOrder.get(maxIndex));
@@ -147,15 +140,13 @@
}
public boolean acceptCard(ServerSidePlayer player, Card card) {
- System.out.println("AAAAAAAAAAAAAAAAAAAAAA");
System.out.println(player.getInfo().getName() + ": " + card);
- Card[] c = (Card[]) cardsDown.values().toArray();
- if (player.checkHit(card, c) == true) {
+ if (player.checkHit(card, cardsDown) == true) {
cardsDown.put(playerOrder.getOrder(player), card);
- hitInfoMessage = player.getInfo().getName() + " a dat " + c;
if (handNr == 0)
Card.setTromf(card.getColor());
player.removeCard(card);
+ server.updateCards(player, card);
return true;
}
return false;
@@ -166,16 +157,16 @@
return false;
if (playerOrder.getOrder(player) != 0)
return false;
- Card[] c = (Card[]) cardsDown.values().toArray();
- if (player.checkHit(card, c) == true) {
+ if (player.checkHit(card, cardsDown) == true) {
cardsDown.put(playerOrder.getOrder(player), card);
- hitInfoMessage = player.getInfo().getName() + " a dat " + c + " anuntand " + anunt;
this.getTeam(player).addAnunt(anunt);
if (handNr == 0)
Card.setTromf(card.getColor());
player.removeCard(card);
+ server.updateCards(player, card);
return true;
}
return false;
}
+
}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-24 07:41:06 UTC (rev 127)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-24 09:05:19 UTC (rev 128)
@@ -91,14 +91,15 @@
return 0;
}
- public void hit(ServerSidePlayer player) {
+ public Card hit(ServerSidePlayer player) {
ClientInterface client = playerMap.getClient(player.getInfo());
+ Card card = null;
try {
- client.hit();
- wait();
+ card = client.hit();
} catch (Exception e) {
e.printStackTrace();
}
+ return card;
}
public void informAll(String message) {
@@ -110,20 +111,35 @@
}
}
}
+
+ public void inform(Player p, String message) {
+ try {
+ playerMap.getClient(p).inform(message);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
- public synchronized boolean acceptCard(Player sender, Card card) throws RemoteException {
- System.out.println("SERVER: " + sender.getName() + " " + card);
- boolean result = roundLogic.acceptCard(playerMap.getServerSidePlayer(sender), card);
- notifyAll();
- return result;
+ public synchronized Score getOverallScore() throws RemoteException {
+ return gameLogic.getOverallScore();
}
- public synchronized boolean acceptCard(Player sender, Card card, int anunt) throws RemoteException {
- System.out.println("Y");
- return roundLogic.acceptCard(playerMap.getServerSidePlayer(sender), card, anunt);
+ public void updateCards(ServerSidePlayer player, Card card) {
+ try {
+ playerMap.getClient(player.getInfo()).removeCard(card);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
}
- public synchronized Score getOverallScore() throws RemoteException {
- return gameLogic.getOverallScore();
+ public void sendScore(Score overallScore) {
+ for (ClientInterface c : playerMap.getClients()) {
+ try {
+ c.sendScore(overallScore);
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
}
}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java 2010-04-24 07:41:06 UTC (rev 127)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerSidePlayer.java 2010-04-24 09:05:19 UTC (rev 128)
@@ -1,6 +1,9 @@
package prc.bubulina.cruce.server;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import prc.bubulina.cruce.remote.Card;
import prc.bubulina.cruce.remote.Player;
@@ -17,8 +20,13 @@
public List<Card> getCards() {
return cards;
}
+
+ public void setCards(List<Card> cards) {
+ this.cards = new LinkedList<Card>(cards);
+ }
public boolean hasCard(Card card) {
+ System.out.println(cards + " -> " + card);
return cards.contains(card);
}
@@ -37,16 +45,20 @@
}
}
- public boolean checkHit(Card card, Card[] cardsDown) {
+ public boolean checkHit(Card card, Map<Integer, Card> cardsDown) {
+ Card[] givenCards = new Card[cardsDown.size()];
+ for (Entry<Integer, Card> e : cardsDown.entrySet())
+ givenCards[e.getKey()] = e.getValue();
+
if (this.hasCard(card) == false)
return false;
- if (cardsDown.length == 0)
+ if (givenCards.length == 0)
return true;
- if (card.getColor().equals(cardsDown[0].getColor()))
+ if (card.getColor().equals(givenCards[0].getColor()))
return true;
else {
for (Card c : cards)
- if (c.getColor().equals(cardsDown[0].getColor()))
+ if (c.getColor().equals(givenCards[0].getColor()))
return false;
if (card.isTromf())
return true;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <hor...@us...> - 2010-04-24 09:29:45
|
Revision: 129
http://cruce.svn.sourceforge.net/cruce/?rev=129&view=rev
Author: horiaradu
Date: 2010-04-24 09:29:39 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
Gata. Merge totul, mai putin partea cu anuntul deoarece nu stiu si nu mai vreau sa vad cum sa citesc de la tastatura.
Cineva sa faca partea aia pana dupamasa.
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/client/Client.java
Java/trunk/src/prc/bubulina/cruce/client/Game.java
Java/trunk/src/prc/bubulina/cruce/client/TextUI.java
Java/trunk/src/prc/bubulina/cruce/client/UI.java
Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java
Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java
Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java
Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
Java/trunk/src/prc/bubulina/cruce/server/Team.java
Modified: Java/trunk/src/prc/bubulina/cruce/client/Client.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/Client.java 2010-04-24 09:05:19 UTC (rev 128)
+++ Java/trunk/src/prc/bubulina/cruce/client/Client.java 2010-04-24 09:29:39 UTC (rev 129)
@@ -11,6 +11,7 @@
import prc.bubulina.cruce.remote.Card;
import prc.bubulina.cruce.remote.ClientInterface;
import prc.bubulina.cruce.remote.Color;
+import prc.bubulina.cruce.remote.Hitable;
import prc.bubulina.cruce.remote.Player;
import prc.bubulina.cruce.remote.Score;
import prc.bubulina.cruce.remote.ServerInterface;
@@ -76,8 +77,8 @@
}
@Override
- public Card hit() throws RemoteException {
- Card card = game.hit();
+ public Hitable hit() throws RemoteException {
+ Hitable card = game.hit();
System.out.println(card);
System.out.println("AAA");
System.out.println("CLIENT: " + player.getName() + ": " + card);
Modified: Java/trunk/src/prc/bubulina/cruce/client/Game.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/Game.java 2010-04-24 09:05:19 UTC (rev 128)
+++ Java/trunk/src/prc/bubulina/cruce/client/Game.java 2010-04-24 09:29:39 UTC (rev 129)
@@ -1,13 +1,12 @@
package prc.bubulina.cruce.client;
-import java.rmi.Naming;
import java.util.ArrayList;
import java.util.List;
import prc.bubulina.cruce.remote.Card;
import prc.bubulina.cruce.remote.Color;
+import prc.bubulina.cruce.remote.Hitable;
import prc.bubulina.cruce.remote.Score;
-import prc.bubulina.cruce.remote.ServerInterface;
public class Game {
private int bidAmount;
@@ -54,8 +53,8 @@
*
* @return the card played
*/
- public Card hit() {
- Card card = ui.playCard();
+ public Hitable hit() {
+ Hitable card = ui.playCard();
return card;
}
Modified: Java/trunk/src/prc/bubulina/cruce/client/TextUI.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/TextUI.java 2010-04-24 09:05:19 UTC (rev 128)
+++ Java/trunk/src/prc/bubulina/cruce/client/TextUI.java 2010-04-24 09:29:39 UTC (rev 129)
@@ -3,8 +3,10 @@
import java.io.IOException;
import java.util.List;
+import prc.bubulina.cruce.remote.Anunt;
import prc.bubulina.cruce.remote.Card;
import prc.bubulina.cruce.remote.Color;
+import prc.bubulina.cruce.remote.Hitable;
public class TextUI extends UI {
private List<Card> cards;
@@ -56,8 +58,8 @@
}
@Override
- public Card playCard() {
- int cardNo = 0;
+ public Hitable playCard() {
+ int cardNo = 0, anunt = 0;
System.out.println("Carti disponibile:");
showAvailableCards();
try {
@@ -65,9 +67,16 @@
System.out.println("Da-ti cartea jucata (1-" + cards.size() + "): ");
cardNo = System.in.read() - '0';
System.in.skip(System.in.available());
+ //System.out.println("Anunt? (20/40): ");
+ //anunt = System.in.read();
+ //TODO AICI TRE FACUT SA CITESTI CORECT DE LA TASTATURA
+ System.in.skip(System.in.available());
+
} catch (IOException e) {
e.printStackTrace();
}
+ if (anunt != 0)
+ return new Anunt(cards.get(cardNo - 1), anunt);
return cards.get(cardNo - 1);
}
Modified: Java/trunk/src/prc/bubulina/cruce/client/UI.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/UI.java 2010-04-24 09:05:19 UTC (rev 128)
+++ Java/trunk/src/prc/bubulina/cruce/client/UI.java 2010-04-24 09:29:39 UTC (rev 129)
@@ -4,6 +4,7 @@
import prc.bubulina.cruce.remote.Card;
import prc.bubulina.cruce.remote.Color;
+import prc.bubulina.cruce.remote.Hitable;
public abstract class UI {
@@ -53,7 +54,7 @@
*
* @return the card played
*/
- public abstract Card playCard();
+ public abstract Hitable playCard();
/**
* Informs the player about the tromph color.
Modified: Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java 2010-04-24 09:05:19 UTC (rev 128)
+++ Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java 2010-04-24 09:29:39 UTC (rev 129)
@@ -46,7 +46,7 @@
*
* @throws RemoteException
*/
- public Card hit() throws RemoteException;
+ public Hitable hit() throws RemoteException;
/**
* Informs the player about the tromf
Modified: Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java 2010-04-24 09:05:19 UTC (rev 128)
+++ Java/trunk/src/prc/bubulina/cruce/server/GameLogic.java 2010-04-24 09:29:39 UTC (rev 129)
@@ -51,8 +51,8 @@
Map<String, Integer> teamScore = new HashMap<String, Integer>();
for (Team t : teams) {
for (ServerSidePlayer p : t.getPlayers())
- scoreMap.put(p.getInfo(), t.computeScore());
- teamScore.put(t.getName(), t.computeScore());
+ scoreMap.put(p.getInfo(), t.getRoundScore());
+ teamScore.put(t.getName(), t.getRoundScore());
}
return new Score(scoreMap, teamScore);
Modified: Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-24 09:05:19 UTC (rev 128)
+++ Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-24 09:29:39 UTC (rev 129)
@@ -5,7 +5,9 @@
import java.util.List;
import java.util.Map;
+import prc.bubulina.cruce.remote.Anunt;
import prc.bubulina.cruce.remote.Card;
+import prc.bubulina.cruce.remote.Hitable;
public class RoundLogic {
@@ -44,6 +46,8 @@
startBid();
for (handNr = 0; handNr < 6; handNr++)
playHand();
+ for (Team t : teams)
+ t.computeScore();
}
private void sendCards() {
@@ -98,12 +102,23 @@
ServerSidePlayer p = playerOrder.get(i);
boolean ok = false;
while (ok == false) {
- Card card = server.hit(p);
- ok = acceptCard(p, card);
- if (ok == false)
- server.inform(p.getInfo(), "Ai dat gresit. Mai da o data");
- else
- server.informAll(p.getInfo() + " a dat " + card);
+ Hitable hitResult = server.hit(p);
+ if (hitResult instanceof Card) {
+ Card card = (Card) hitResult;
+ ok = acceptCard(p, card);
+ if (ok == false)
+ server.inform(p.getInfo(), "Ai dat gresit. Mai da o data");
+ else
+ server.informAll(p.getInfo() + " a dat " + card);
+ } else {
+ Card card = ((Anunt) hitResult).card;
+ int anunt = ((Anunt) hitResult).value;
+ ok = acceptCard(p, card, anunt);
+ if (ok == false)
+ server.inform(p.getInfo(), "Ai dat gresit. Mai da o data");
+ else
+ server.informAll(p.getInfo() + " a dat " + card + ", anuntand " + anunt);
+ }
}
}
int maxIndex = getMaxCard(cardsDown);
Modified: Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-24 09:05:19 UTC (rev 128)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-24 09:29:39 UTC (rev 129)
@@ -7,6 +7,7 @@
import prc.bubulina.cruce.remote.Card;
import prc.bubulina.cruce.remote.ClientInterface;
+import prc.bubulina.cruce.remote.Hitable;
import prc.bubulina.cruce.remote.Player;
import prc.bubulina.cruce.remote.Score;
import prc.bubulina.cruce.remote.ServerInterface;
@@ -91,9 +92,9 @@
return 0;
}
- public Card hit(ServerSidePlayer player) {
+ public Hitable hit(ServerSidePlayer player) {
ClientInterface client = playerMap.getClient(player.getInfo());
- Card card = null;
+ Hitable card = null;
try {
card = client.hit();
} catch (Exception e) {
Modified: Java/trunk/src/prc/bubulina/cruce/server/Team.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/Team.java 2010-04-24 09:05:19 UTC (rev 128)
+++ Java/trunk/src/prc/bubulina/cruce/server/Team.java 2010-04-24 09:29:39 UTC (rev 129)
@@ -12,6 +12,7 @@
private List<Card> cardsTaken;
private int overallScore;
private String teamName;
+ private int roundScore;
public Team(String teamName) {
this.teamName = teamName;
@@ -20,6 +21,7 @@
anunturi = 0;
goal = 0;
overallScore = 0;
+ roundScore = 0;
}
public void addPlayer(ServerSidePlayer player) {
@@ -57,6 +59,9 @@
}
overallScore += result;
+ roundScore = result;
+
+ resetRound();
return result;
}
@@ -64,6 +69,10 @@
public int getOverallScore() {
return overallScore;
}
+
+ public int getRoundScore() {
+ return roundScore;
+ }
public void resetRound() {
anunturi = 0;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|