[Cruce-commit] SF.net SVN: cruce:[107] Java/trunk/src/prc/bubulina/cruce
Status: Beta
Brought to you by:
caiusb
|
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 (IllegalArgumentException e) {
+ card = new Card(0, Color.ROSU);
}
- catch (IllegalArgumentException e)
- {
- card = new Card(0, Color.ROSU);
- }
-
+
takenCardsValue += card.getValue();
team.addCard(card);
}
-
- //Precondition check
+
+ // Precondition check
assertTrue(takenCardsValue < 66);
-
- //actual test
+
+ // actual test
assertEquals(-goal, team.computeScore());
assertEquals(-goal, team.getOverallScore());
}
-
+
@Test
- public void testComputeScore_Anunturi_CardsTaken_WithGoalFulfilled()
- {
- //set up
+ 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++)
- {
+
+ // adding some cards to the team
+ for (int i = 0; i < 66; i++) {
Card card;
- try
- {
- card = new Card(i * 2 % 12, Color.ROSU);
+ try {
+ card = new Card(i * 2 % 12, Color.ROSU);
+ } catch (IllegalArgumentException e) {
+ card = new Card(0, 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
+
+ // 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);
@@ -110,37 +96,33 @@
takenCardsValue += 20;
team.addAnunt(40);
takenCardsValue += 40;
-
- //Precondition check
+
+ // Precondition check
assertTrue(takenCardsValue >= 33 * 6);
-
- //actual test
+
+ // 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
- {
+ 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)
- {
+ } 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
+
+ // 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
+
+ // Notice how we can add more that one 40 and 3 20's
team = new Team();
team.addAnunt(40);
team.addAnunt(20);
@@ -148,7 +130,7 @@
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.
|