cruce-commit Mailing List for Cruce (Page 3)
Status: Beta
Brought to you by:
caiusb
You can subscribe to this list here.
| 2010 |
Jan
|
Feb
|
Mar
(68) |
Apr
(51) |
May
(31) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|---|
|
From: <ca...@us...> - 2010-04-12 18:09:21
|
Revision: 116
http://cruce.svn.sourceforge.net/cruce/?rev=116&view=rev
Author: caiusb
Date: 2010-04-12 18:09:15 +0000 (Mon, 12 Apr 2010)
Log Message:
-----------
Clean-up
Removed Paths:
-------------
Java/trunk/security.policy
Java/trunk/src/prc/bubulina/cruce/tests/
Deleted: Java/trunk/security.policy
===================================================================
--- Java/trunk/security.policy 2010-04-12 16:54:21 UTC (rev 115)
+++ Java/trunk/security.policy 2010-04-12 18:09:15 UTC (rev 116)
@@ -1,36 +0,0 @@
-// This file was generated by the RMI Plugin for Eclipse.
-
-///////////////////////////////////////////////////////////////
-// This is a sample policy file that grants the application all permissions.
-// A policy file is needed by the RMISecurityManager and your application might
-// not work after installing the RMISecurityManager unless you provide a
-// security policy file at launch.
-//
-// You can configure the security policy of a launched application using either
-// the RMI Launcher or by manually setting the java.security.policy property.
-//
-// SECURITY NOTE: This security policy is good for development. For deployment
-// you may need a stricter security policy.
-//
-// For more information see:
-// http://java.sun.com/docs/books/tutorial/rmi/running.html
-// http://java.sun.com/j2se/1.5.0/docs/guide/security/PolicyFiles.html
-//
-
-grant {
- permission java.security.AllPermission;
-
- // Other options:
- // permission java.net.SocketPermission "127.0.0.1:1024-", "accept, connect, listen, resolve";
- // permission java.net.SocketPermission "localhost:1024-", "accept, connect, listen, resolve";
-
- // From http://java.sun.com/docs/books/tutorial/rmi/running.html
- // Copyright 1995-2005 Sun Microsystems, Inc. Reprinted with permission
-
- // permission java.net.SocketPermission "*:1024-65535", "connect,accept";
- // permission java.net.SocketPermission "*:80", "connect";
-
- // permission java.net.SocketPermission "*:1024-65535", "connect,accept";
- // permission java.io.FilePermission "c:\\home\\ann\\public_html\\classes\\-", "read";
- // permission java.io.FilePermission "c:\\home\\jones\\public_html\\classes\\-", "read";
-};
\ 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:54:43
|
Revision: 115
http://cruce.svn.sourceforge.net/cruce/?rev=115&view=rev
Author: horiaradu
Date: 2010-04-12 16:54:21 +0000 (Mon, 12 Apr 2010)
Log Message:
-----------
Modified Paths:
--------------
Java/trunk/.classpath
Java/trunk/.project
Added Paths:
-----------
Java/trunk/.settings/
Java/trunk/.settings/net.genady.rmi.prefs
Java/trunk/.settings/org.eclipse.jdt.core.prefs
Java/trunk/security.policy
Modified: Java/trunk/.classpath
===================================================================
--- Java/trunk/.classpath 2010-04-12 16:52:40 UTC (rev 114)
+++ Java/trunk/.classpath 2010-04-12 16:54:21 UTC (rev 115)
@@ -1,8 +1,8 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" output="testBin" path="test"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" output="testBin" path="test"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_18"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Modified: Java/trunk/.project
===================================================================
--- Java/trunk/.project 2010-04-12 16:52:40 UTC (rev 114)
+++ Java/trunk/.project 2010-04-12 16:54:21 UTC (rev 115)
@@ -1,17 +1,23 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>Cruce</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Cruce</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>net.genady.rmi.RMIBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>net.genady.rmi.RMINature</nature>
+ </natures>
+</projectDescription>
Added: Java/trunk/.settings/net.genady.rmi.prefs
===================================================================
--- Java/trunk/.settings/net.genady.rmi.prefs (rev 0)
+++ Java/trunk/.settings/net.genady.rmi.prefs 2010-04-12 16:54:21 UTC (rev 115)
@@ -0,0 +1,7 @@
+#Mon Apr 12 12:57:06 EEST 2010
+eclipse.preferences.version=1
+flags.advancedHierarchy=false
+flags.debug=true
+flags.internalCompiler=true
+flags.keepSrc=true
+flags.stubsVersion=2
Added: Java/trunk/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- Java/trunk/.settings/org.eclipse.jdt.core.prefs (rev 0)
+++ Java/trunk/.settings/org.eclipse.jdt.core.prefs 2010-04-12 16:54:21 UTC (rev 115)
@@ -0,0 +1,12 @@
+#Mon Apr 12 12:58:15 EEST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
Added: Java/trunk/security.policy
===================================================================
--- Java/trunk/security.policy (rev 0)
+++ Java/trunk/security.policy 2010-04-12 16:54:21 UTC (rev 115)
@@ -0,0 +1,36 @@
+// This file was generated by the RMI Plugin for Eclipse.
+
+///////////////////////////////////////////////////////////////
+// This is a sample policy file that grants the application all permissions.
+// A policy file is needed by the RMISecurityManager and your application might
+// not work after installing the RMISecurityManager unless you provide a
+// security policy file at launch.
+//
+// You can configure the security policy of a launched application using either
+// the RMI Launcher or by manually setting the java.security.policy property.
+//
+// SECURITY NOTE: This security policy is good for development. For deployment
+// you may need a stricter security policy.
+//
+// For more information see:
+// http://java.sun.com/docs/books/tutorial/rmi/running.html
+// http://java.sun.com/j2se/1.5.0/docs/guide/security/PolicyFiles.html
+//
+
+grant {
+ permission java.security.AllPermission;
+
+ // Other options:
+ // permission java.net.SocketPermission "127.0.0.1:1024-", "accept, connect, listen, resolve";
+ // permission java.net.SocketPermission "localhost:1024-", "accept, connect, listen, resolve";
+
+ // From http://java.sun.com/docs/books/tutorial/rmi/running.html
+ // Copyright 1995-2005 Sun Microsystems, Inc. Reprinted with permission
+
+ // permission java.net.SocketPermission "*:1024-65535", "connect,accept";
+ // permission java.net.SocketPermission "*:80", "connect";
+
+ // permission java.net.SocketPermission "*:1024-65535", "connect,accept";
+ // permission java.io.FilePermission "c:\\home\\ann\\public_html\\classes\\-", "read";
+ // permission java.io.FilePermission "c:\\home\\jones\\public_html\\classes\\-", "read";
+};
\ 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:52:54
|
Revision: 114
http://cruce.svn.sourceforge.net/cruce/?rev=114&view=rev
Author: horiaradu
Date: 2010-04-12 16:52:40 +0000 (Mon, 12 Apr 2010)
Log Message:
-----------
Removed Paths:
-------------
Java/trunk/src/prc/bubulina/cruce/tests/server/
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:29:42
|
Revision: 113
http://cruce.svn.sourceforge.net/cruce/?rev=113&view=rev
Author: horiaradu
Date: 2010-04-12 16:29:25 +0000 (Mon, 12 Apr 2010)
Log Message:
-----------
Added Paths:
-----------
Java/trunk/test/prc/bubulina/cruce/tests/
Java/trunk/test/prc/bubulina/cruce/tests/server/
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-12 09:12:19
|
Revision: 111
http://cruce.svn.sourceforge.net/cruce/?rev=111&view=rev
Author: caiusb
Date: 2010-04-12 09:12:08 +0000 (Mon, 12 Apr 2010)
Log Message:
-----------
TextUI este gata implementat.
Added Paths:
-----------
Java/trunk/src/prc/bubulina/cruce/client/TextUI.java
Added: Java/trunk/src/prc/bubulina/cruce/client/TextUI.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/TextUI.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/client/TextUI.java 2010-04-12 09:12:08 UTC (rev 111)
@@ -0,0 +1,81 @@
+package prc.bubulina.cruce.client;
+
+import java.io.IOException;
+import java.util.List;
+
+import prc.bubulina.cruce.remote.Card;
+import prc.bubulina.cruce.remote.Color;
+
+public class TextUI extends UI {
+
+ @Override
+ public void announceWinner(String name) {
+ System.out.println("The winner is " + name);
+ }
+
+ @Override
+ public int bid() {
+ int bidAmount = 0;
+ System.out.println("Cat licitati?");
+ try {
+ bidAmount = System.in.read();
+ } catch (IOException e) {
+ System.out.println("Error reading input");
+ }
+ return bidAmount;
+ }
+
+ @Override
+ public boolean joinGame() {
+ return askBinaryQuestion("Join Game?");
+ }
+
+ private boolean askBinaryQuestion(String question) {
+ char answer = 'n';
+ System.out.println(question);
+ try {
+ answer = (char) System.in.read();
+ } catch (IOException e) {
+ System.out.println("Error reading input");
+ }
+ if (answer == 'y' || answer == 'Y')
+ return true;
+ return false;
+ }
+
+ @Override
+ public void putCard(Card card) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void sendMessage(String message) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean setCards(List<Card> cards, boolean force) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void setTromf(Color color) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Card showCard() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean startGame() {
+ return askBinaryQuestion("Start Game?");
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ca...@us...> - 2010-04-11 21:52:55
|
Revision: 110
http://cruce.svn.sourceforge.net/cruce/?rev=110&view=rev
Author: caiusb
Date: 2010-04-11 21:52:49 +0000 (Sun, 11 Apr 2010)
Log Message:
-----------
Am adaugat urmatoarele functionalitati la client:
- Start Game
- Join Game
- Bid
- Send Cards
Am facut si teste care verifica aceste metode.
Stiu ca clasa Game pare un pic cam redundanta deoarece nu face mare lucru in afara de a adauga un nivel de indirectare intre client si UI. Dar scopul ei ar fi sa verifice anumite chestii (de exemplu cand se da o carte, s-ar putea verifica daca (,) cartea este corecta (sa nu se faca -3 sau alte bucurii)).
UI nu exista momentan, decat sub forma unei clase abstracte. DummyUI este folosit pentru testing purposes. Ideea din spate este de a face, momentan, un UI textual urmand sa vina si ceva grafic :D. Dar momentan m-am concentrat pe functionalitate.
Daca aveti un timp, va rog uitati-va putin peste chestia si trimite-ti comentarii.
O seara faina,
Caius
Modified Paths:
--------------
Java/trunk/.classpath
Added 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/UI.java
Java/trunk/test/
Java/trunk/test/prc/
Java/trunk/test/prc/bubulina/
Java/trunk/test/prc/bubulina/cruce/
Java/trunk/test/prc/bubulina/cruce/client/
Java/trunk/test/prc/bubulina/cruce/client/DummyUI.java
Java/trunk/test/prc/bubulina/cruce/client/GameTest.java
Modified: Java/trunk/.classpath
===================================================================
--- Java/trunk/.classpath 2010-04-09 09:33:41 UTC (rev 109)
+++ Java/trunk/.classpath 2010-04-11 21:52:49 UTC (rev 110)
@@ -1,7 +1,8 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" output="testBin" path="test"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: Java/trunk/src/prc/bubulina/cruce/client/Client.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/Client.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/client/Client.java 2010-04-11 21:52:49 UTC (rev 110)
@@ -0,0 +1,96 @@
+package prc.bubulina.cruce.client;
+
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
+import java.util.List;
+
+import prc.bubulina.cruce.remote.Card;
+import prc.bubulina.cruce.remote.ClientInterface;
+import prc.bubulina.cruce.remote.Color;
+import prc.bubulina.cruce.remote.Player;
+import prc.bubulina.cruce.remote.Score;
+import prc.bubulina.cruce.remote.ServerInterface;
+
+public class Client extends UnicastRemoteObject implements ClientInterface {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -8368188426444139259L;
+
+ private Game game;
+ private ServerInterface server;
+ private Player player;
+
+ /**
+ *
+ * @param game
+ * the <code>Game</code> object for this game
+ * @param gameServerAddress
+ * the address of the used game server
+ * @param gameServerName
+ * the name of the used game server
+ * @throws RemoteException
+ */
+ public Client(Game game, String gameServerAddress, String gameServerName)
+ throws RemoteException {
+ super();
+ String url = "rmi://" + gameServerAddress + "/" + gameServerName;
+
+ this.game = game;
+
+ //TODO instantiate server
+ //server = (ServerInterface) Naming.lookup(url);
+ // TODO this looks weird
+ if (game.joinGame())
+ player = server.joinGame(game.getPlayerName(), this);
+ if (game.startGame())
+ server.startGame(player);
+ }
+
+ @Override
+ public int bid() throws RemoteException {
+ return game.bid();
+ }
+
+ @Override
+ public void endGame(Score score) throws RemoteException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void forceReceive(List<Card> cards) throws RemoteException {
+ game.setCards(cards, true);
+ }
+
+ @Override
+ public void hit() throws RemoteException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void inform(String information) throws RemoteException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean receiveCards(List<Card> cards) throws RemoteException {
+ return game.setCards(cards, false);
+ }
+
+ @Override
+ public void receiveRoundScore(Score score) throws RemoteException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setTromf(Color tromf) throws RemoteException {
+ game.setTromf(tromf);
+ }
+
+}
Added: Java/trunk/src/prc/bubulina/cruce/client/Game.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/Game.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/client/Game.java 2010-04-11 21:52:49 UTC (rev 110)
@@ -0,0 +1,89 @@
+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.ServerInterface;
+
+public class Game {
+ private int bidAmount;
+ private List<Card> cardsInHand;
+ private List<Card> cardsTaken;
+ private Color tromf;
+ private UI ui;
+ private String name;
+
+ /**
+ * Constructor
+ *
+ * @param name
+ * the name of the player
+ * @param ui
+ * the UI used
+ */
+ public Game(String name, UI ui) {
+ this.name = name;
+ this.ui = ui;
+ cardsTaken = new ArrayList<Card>();
+ }
+
+ public boolean joinGame() {
+ return ui.joinGame();
+ }
+
+ public boolean startGame() {
+ return ui.startGame();
+ }
+
+ /**
+ * Gets the amount bided by the player
+ *
+ * @return the amount bided
+ */
+ public int bid() {
+ bidAmount = ui.bid();
+ return bidAmount;
+ }
+
+ /**
+ * Anounces the tromph color
+ *
+ * @param color
+ * the color
+ */
+ public void setTromf(Color color) {
+ tromf = color;
+ ui.setTromf(tromf);
+ }
+
+ /**
+ * Gives the player it's cards
+ *
+ * @param cards
+ * the cards
+ * @param force
+ * true if the user has no choice and has to accept them
+ * @return true if the player accepts them, false otherwise
+ */
+ public boolean setCards(List<Card> cards, boolean force) {
+ boolean accept = ui.setCards(cards, force);
+ if (force || accept) {
+ cardsInHand = cards;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Returns the players name
+ *
+ * @return the players name
+ */
+ public String getPlayerName() {
+ return name;
+ }
+}
Added: Java/trunk/src/prc/bubulina/cruce/client/UI.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/client/UI.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/client/UI.java 2010-04-11 21:52:49 UTC (rev 110)
@@ -0,0 +1,79 @@
+package prc.bubulina.cruce.client;
+
+import java.util.List;
+
+import prc.bubulina.cruce.remote.Card;
+import prc.bubulina.cruce.remote.Color;
+
+public abstract class UI {
+
+ /**
+ * Ask the user if he wants to start a game
+ *
+ * @return the answer of the user
+ */
+ public abstract boolean startGame();
+
+ /**
+ * Ask the user if he wants to join the game
+ *
+ * @return the answer of the user
+ */
+ public abstract boolean joinGame();
+
+ /**
+ * Sends the cards the user has received from the server. If
+ * <code>force</code> is false, he can refuse them
+ *
+ * @param cards
+ * the cards
+ * @param force
+ * <code>true</code> if he cannot refuse them
+ * @return true if the user accepts the cards, false otherwise
+ */
+ public abstract boolean setCards(List<Card> cards, boolean force);
+
+ /**
+ * Gets the amount bided by the user
+ *
+ * @return the amount bided by the user
+ */
+ public abstract int bid();
+
+ /**
+ * Informs the player of a card that has been played
+ *
+ * @param card
+ * the card played
+ */
+ public abstract void putCard(Card card);
+
+ /**
+ * Informs the player about the tromph color.
+ *
+ * @param color
+ * the color
+ */
+ public abstract void setTromf(Color color);
+
+ /**
+ * Gets the card played by this player in this round
+ *
+ * @return the card played
+ */
+ public abstract Card showCard();
+
+ /**
+ * Announces the winner of the bid, hand or game
+ *
+ * @param name
+ * the name of the winner
+ */
+ public abstract void announceWinner(String name);
+
+ /**
+ * Sends a message to the user
+ * @param message
+ */
+ public abstract void sendMessage(String message);
+}
Added: Java/trunk/test/prc/bubulina/cruce/client/DummyUI.java
===================================================================
--- Java/trunk/test/prc/bubulina/cruce/client/DummyUI.java (rev 0)
+++ Java/trunk/test/prc/bubulina/cruce/client/DummyUI.java 2010-04-11 21:52:49 UTC (rev 110)
@@ -0,0 +1,65 @@
+package prc.bubulina.cruce.client;
+
+import java.util.List;
+
+import prc.bubulina.cruce.remote.Card;
+import prc.bubulina.cruce.remote.Color;
+
+public class DummyUI extends UI {
+ public Color tromf;
+ public boolean reject;
+ public boolean join;
+ public boolean start;
+
+ @Override
+ public void announceWinner(String name) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public int bid() {
+ return 1;
+ }
+
+ @Override
+ public boolean joinGame() {
+ return join;
+ }
+
+ @Override
+ public void putCard(Card card) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void sendMessage(String message) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean setCards(List<Card> cards, boolean force) {
+ if (!force && reject)
+ return false;
+ return true;
+ }
+
+ @Override
+ public void setTromf(Color color) {
+ this.tromf = color;
+ }
+
+ @Override
+ public Card showCard() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean startGame() {
+ return start;
+ }
+
+}
Added: Java/trunk/test/prc/bubulina/cruce/client/GameTest.java
===================================================================
--- Java/trunk/test/prc/bubulina/cruce/client/GameTest.java (rev 0)
+++ Java/trunk/test/prc/bubulina/cruce/client/GameTest.java 2010-04-11 21:52:49 UTC (rev 110)
@@ -0,0 +1,83 @@
+package prc.bubulina.cruce.client;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import prc.bubulina.cruce.remote.Card;
+import prc.bubulina.cruce.remote.Color;
+
+public class GameTest {
+ private DummyUI ui;
+ private Game game;
+ private Client client;
+
+ @Before
+ public void setUp() throws Exception {
+ ui = new DummyUI();
+ game = new Game("Test Player",ui);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ ui = null;
+ game = null;
+ }
+
+ @Test
+ public void testJoinGame() {
+ ui.join = false;
+ assertFalse(game.joinGame());
+ ui.join = true;
+ assertTrue(game.joinGame());
+ }
+
+ @Test
+ public void testStartGame() {
+ ui.start = false;
+ assertFalse(game.startGame());
+ ui.start = true;
+ assertTrue(game.startGame());
+ }
+
+ @Test
+ public void testBid() {
+ assertEquals(game.bid(),1);
+ }
+
+ @Test
+ public void testSetTromf() {
+ game.setTromf(Color.DUBA);
+ assertEquals(ui.tromf,Color.DUBA);
+ }
+
+ @Test
+ public void testSetCards() {
+ List<Card> card = new ArrayList<Card>();
+ card.add(new Card(0,Color.DUBA));
+ assertFalse(testRejectCards(card));
+ assertTrue(testRejectForce(card));
+ assertTrue(notRejectCards(card));
+ }
+
+ private boolean testRejectCards(List<Card> cards) {
+ ui.reject = true;
+ return game.setCards(cards, false);
+ }
+
+ private boolean testRejectForce(List<Card> cards) {
+ ui.reject = true;
+ return game.setCards(cards, true);
+ }
+
+ private boolean notRejectCards(List<Card> cards) {
+ ui.reject = false;
+ return game.setCards(cards, false);
+ }
+
+}
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: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: <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-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.
|
|
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-07 18:20:31
|
Revision: 105
http://cruce.svn.sourceforge.net/cruce/?rev=105&view=rev
Author: alinposho
Date: 2010-04-07 18:20:12 +0000 (Wed, 07 Apr 2010)
Log Message:
-----------
Clasa Team este implementata si testata complet.
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/tests/server/TeamTest.java
Modified: Java/trunk/src/prc/bubulina/cruce/tests/server/TeamTest.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/tests/server/TeamTest.java 2010-04-07 18:09:17 UTC (rev 104)
+++ Java/trunk/src/prc/bubulina/cruce/tests/server/TeamTest.java 2010-04-07 18:20:12 UTC (rev 105)
@@ -1,10 +1,9 @@
package prc.bubulina.cruce.tests.server;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-import java.util.ArrayList;
-import java.util.List;
-
import org.junit.Before;
import org.junit.Test;
@@ -14,15 +13,13 @@
public class TeamTest
{
- private Team team;
- private List<Card> cardsTaken;
+ private Team team;
private int goal;
@Before
public void setUp() throws Exception
{
- team = new Team();
- cardsTaken = new ArrayList<Card>();
+ team = new Team();
}
@Test
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-07 17:32:01
|
Revision: 103
http://cruce.svn.sourceforge.net/cruce/?rev=103&view=rev
Author: alinposho
Date: 2010-04-07 17:31:52 +0000 (Wed, 07 Apr 2010)
Log Message:
-----------
Am adaugat teste pentru metoda "setupPlayer(Strin name)" din clasa StartGameLogic.
Modified Paths:
--------------
Java/trunk/.classpath
Java/trunk/src/prc/bubulina/cruce/server/PlayerFactory.java
Java/trunk/src/prc/bubulina/cruce/server/StartGameLogic.java
Java/trunk/src/prc/bubulina/cruce/server/Team.java
Added Paths:
-----------
Java/trunk/src/prc/bubulina/cruce/tests/
Java/trunk/src/prc/bubulina/cruce/tests/server/
Java/trunk/src/prc/bubulina/cruce/tests/server/StartGameLogicTest.java
Modified: Java/trunk/.classpath
===================================================================
--- Java/trunk/.classpath 2010-04-07 16:38:07 UTC (rev 102)
+++ Java/trunk/.classpath 2010-04-07 17:31:52 UTC (rev 103)
@@ -1,6 +1,7 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Modified: Java/trunk/src/prc/bubulina/cruce/server/PlayerFactory.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/PlayerFactory.java 2010-04-07 16:38:07 UTC (rev 102)
+++ Java/trunk/src/prc/bubulina/cruce/server/PlayerFactory.java 2010-04-07 17:31:52 UTC (rev 103)
@@ -3,8 +3,10 @@
import prc.bubulina.cruce.remote.Player;
public class PlayerFactory {
- private static int val = 0;
- public static Player getPlayer(String name) {
+
+ private int val = 0;
+
+ public Player getPlayer(String name) {
return new Player(name, val++);
}
}
\ 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-07 16:38:07 UTC (rev 102)
+++ Java/trunk/src/prc/bubulina/cruce/server/StartGameLogic.java 2010-04-07 17:31:52 UTC (rev 103)
@@ -1,6 +1,5 @@
package prc.bubulina.cruce.server;
-import java.util.LinkedList;
import java.util.List;
import prc.bubulina.cruce.remote.Player;
@@ -10,23 +9,27 @@
private int joinedPlayers;
private int readyPlayers;
private List<Team> teams;
+ private PlayerFactory factory;
- public StartGameLogic() {
+ public StartGameLogic(List<Team> teams) {
+
joinedPlayers = 0;
readyPlayers = 0;
- teams = new LinkedList<Team>();
- teams.add(new Team());
- teams.add(new Team());
+ factory = new PlayerFactory();
+
+ this.teams = teams;
}
public ServerSidePlayer setupPlayer(String name) {
if (joinedPlayers < 4) {
- Player player = PlayerFactory.getPlayer(name);
+ Player player = factory.getPlayer(name);
ServerSidePlayer ssplayer = new ServerSidePlayer(player);
joinedPlayers++;
- int teamIndex = player.getID() % 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;
@@ -46,4 +49,5 @@
public boolean gameReady() {
return readyPlayers == 4;
}
+
}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/server/Team.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/Team.java 2010-04-07 16:38:07 UTC (rev 102)
+++ Java/trunk/src/prc/bubulina/cruce/server/Team.java 2010-04-07 17:31:52 UTC (rev 103)
@@ -31,22 +31,31 @@
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;
+ {
+ 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/StartGameLogicTest.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/tests/server/StartGameLogicTest.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/tests/server/StartGameLogicTest.java 2010-04-07 17:31:52 UTC (rev 103)
@@ -0,0 +1,136 @@
+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.Player;
+import prc.bubulina.cruce.server.ServerSidePlayer;
+import prc.bubulina.cruce.server.StartGameLogic;
+import prc.bubulina.cruce.server.Team;
+
+public class StartGameLogicTest
+{
+
+ private StartGameLogic startGameLogic;
+ private List<Team> teams;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ teams = new ArrayList<Team>();
+ teams.add(new Team());
+ teams.add(new Team());
+ startGameLogic = new StartGameLogic(teams);
+ }
+
+ @Test
+ public void testSetupPlayer_OnePlayer_BestCaseScenario()
+ {
+ String playerName = "Player1";
+ teams.clear();
+ teams.add(new Team());
+
+ //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());
+ }
+
+ @Test
+ 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);
+ 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++)
+ {
+ ServerSidePlayer actual = startGameLogic.setupPlayer(playerName[i]);
+ 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())
+ {
+ assertNotSame(playerName[4], player.getInfo().getName());
+ }
+ }
+ }
+
+ @Test
+ public void testSetupPlayer_TwoPlayersWithTheSameName()
+ {
+ String[] playerName = {"Player1", "Player1"};
+
+ assertEquals(playerName[0], playerName[1]);
+
+ //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);
+ 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++)
+ {
+ ServerSidePlayer actual = startGameLogic.setupPlayer(playerName[i]);
+ 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 testPlayerReady()
+ {
+ fail("Not yet implemented");
+ }
+
+}
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 15:39:54
|
Revision: 101
http://cruce.svn.sourceforge.net/cruce/?rev=101&view=rev
Author: alinposho
Date: 2010-04-07 15:39:48 +0000 (Wed, 07 Apr 2010)
Log Message:
-----------
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
Modified: Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-07 15:14:54 UTC (rev 100)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-07 15:39:48 UTC (rev 101)
@@ -11,6 +11,7 @@
import prc.bubulina.cruce.remote.ServerInterface;
public class ServerImplementation implements ServerInterface {
+
private static ServerImplementation instance;
private ServerImplementation() {}
@@ -24,11 +25,11 @@
private List<Team> teams = new LinkedList<Team>();
private List<ClientInterface> clients = new LinkedList<ClientInterface>();
private StartGameLogic startGameLogic;
- private GameLogic gameLogic;
+ private GameLogic gameLogic;
-
public synchronized boolean sendCards(List<Card> cards, ServerSidePlayer player) {
ClientInterface client = PlayerMap.getInstance().getClient(player.getInfo());
+
try {
if (client.receiveCards(cards) == false) {
int sum = 0;
@@ -59,7 +60,9 @@
// TODO Auto-generated method stub
return null;
}
+
public synchronized Player joinGame(String name, ClientInterface client) throws RemoteException {
+
ServerSidePlayer ssplayer = startGameLogic.setupPlayer(name, client);
if (ssplayer != null)
return ssplayer.getInfo();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-04-07 15:15:00
|
Revision: 100
http://cruce.svn.sourceforge.net/cruce/?rev=100&view=rev
Author: alinposho
Date: 2010-04-07 15:14:54 +0000 (Wed, 07 Apr 2010)
Log Message:
-----------
Am modificat diagrama de secventa: GameLogicSequenceDiagram.
Modified Paths:
--------------
Java/trunk/Documentation/GameLogicSequenceDiagram.jpg
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
Modified: Java/trunk/Documentation/GameLogicSequenceDiagram.jpg
===================================================================
(Binary files differ)
Modified: Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java 2010-04-07 14:12:12 UTC (rev 99)
+++ Java/trunk/src/prc/bubulina/cruce/server/PlayerMap.java 2010-04-07 15:14:54 UTC (rev 100)
@@ -11,31 +11,38 @@
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();
}
Modified: Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-07 14:12:12 UTC (rev 99)
+++ Java/trunk/src/prc/bubulina/cruce/server/RoundLogic.java 2010-04-07 15:14:54 UTC (rev 100)
@@ -9,6 +9,7 @@
public class RoundLogic {
private List<Team> teams;
private Map<Integer, ServerSidePlayer> playerOrder;
+
public RoundLogic(List<Team> teams) {
this.teams = teams;
int i = 0;
@@ -16,15 +17,18 @@
for (ServerSidePlayer p : t.getPlayers())
playerOrder.put(i++, p);
}
- private Team getTeam(ServerSidePlayer player) {
+
+ public 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++) {
@@ -32,9 +36,12 @@
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);
}
Modified: Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-07 14:12:12 UTC (rev 99)
+++ Java/trunk/src/prc/bubulina/cruce/server/ServerImplementation.java 2010-04-07 15:14:54 UTC (rev 100)
@@ -12,17 +12,22 @@
public class ServerImplementation implements ServerInterface {
private static ServerImplementation instance;
+
private ServerImplementation() {}
- public static ServerImplementation getInstance() {
+
+ public synchronized 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) {
+
+
+ public synchronized boolean sendCards(List<Card> cards, ServerSidePlayer player) {
ClientInterface client = PlayerMap.getInstance().getClient(player.getInfo());
try {
if (client.receiveCards(cards) == false) {
@@ -39,28 +44,33 @@
}
return true;
}
- public boolean acceptCard(Player sender, Card card) throws RemoteException {
+
+ public synchronized 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 {
+
+ public synchronized boolean acceptCard(Player sender, Card card, int anunt) throws RemoteException {
// TODO Auto-generated method stub
return false;
}
- public Score getOverallScore() throws RemoteException {
+
+ public synchronized Score getOverallScore() throws RemoteException {
// TODO Auto-generated method stub
return null;
}
- public Player joinGame(String name, ClientInterface client) throws RemoteException {
+ public synchronized 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 {
+
+ public synchronized void registerForNotifications(ClientInterface callback) throws RemoteException {
clients.add(callback);
}
- public void startGame(Player sender) throws RemoteException {
+
+ public synchronized void startGame(Player sender) throws RemoteException {
startGameLogic.playerReady();
if (startGameLogic.gameReady()) {
for (ClientInterface client : clients)
@@ -68,4 +78,5 @@
gameLogic.startGame(teams);
}
}
+
}
\ 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: <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: <ali...@us...> - 2010-04-07 12:39:29
|
Revision: 97
http://cruce.svn.sourceforge.net/cruce/?rev=97&view=rev
Author: alinposho
Date: 2010-04-07 12:39:23 +0000 (Wed, 07 Apr 2010)
Log Message:
-----------
Diagrame de secventa.
Added Paths:
-----------
Java/trunk/Documentation/FirstHandSequenceDiagram.jpg
Java/trunk/Documentation/GameLogicSequenceDiagram.jpg
Java/trunk/Documentation/SendCardsSequenceDiagram.jpg
Added: Java/trunk/Documentation/FirstHandSequenceDiagram.jpg
===================================================================
(Binary files differ)
Property changes on: Java/trunk/Documentation/FirstHandSequenceDiagram.jpg
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: Java/trunk/Documentation/GameLogicSequenceDiagram.jpg
===================================================================
(Binary files differ)
Property changes on: Java/trunk/Documentation/GameLogicSequenceDiagram.jpg
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: Java/trunk/Documentation/SendCardsSequenceDiagram.jpg
===================================================================
(Binary files differ)
Property changes on: Java/trunk/Documentation/SendCardsSequenceDiagram.jpg
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-04-07 09:37:03
|
Revision: 96
http://cruce.svn.sourceforge.net/cruce/?rev=96&view=rev
Author: alinposho
Date: 2010-04-07 09:36:57 +0000 (Wed, 07 Apr 2010)
Log Message:
-----------
Am adaugat in documentatie cateva diagrame de clase si de secventa.
Added Paths:
-----------
Java/trunk/Documentation/JoinGameSequenceDiagram.jpg
Java/trunk/Documentation/Overview of remote.jpg
Java/trunk/Documentation/ServerOverview.jpg
Java/trunk/Documentation/StartGameSequenceDiagram.jpg
Added: Java/trunk/Documentation/JoinGameSequenceDiagram.jpg
===================================================================
(Binary files differ)
Property changes on: Java/trunk/Documentation/JoinGameSequenceDiagram.jpg
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: Java/trunk/Documentation/Overview of remote.jpg
===================================================================
(Binary files differ)
Property changes on: Java/trunk/Documentation/Overview of remote.jpg
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: Java/trunk/Documentation/ServerOverview.jpg
===================================================================
(Binary files differ)
Property changes on: Java/trunk/Documentation/ServerOverview.jpg
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: Java/trunk/Documentation/StartGameSequenceDiagram.jpg
===================================================================
(Binary files differ)
Property changes on: Java/trunk/Documentation/StartGameSequenceDiagram.jpg
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-04-07 09:30:24
|
Revision: 95
http://cruce.svn.sourceforge.net/cruce/?rev=95&view=rev
Author: alinposho
Date: 2010-04-07 09:30:18 +0000 (Wed, 07 Apr 2010)
Log Message:
-----------
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java
Modified: Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java 2010-04-06 08:57:03 UTC (rev 94)
+++ Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java 2010-04-07 09:30:18 UTC (rev 95)
@@ -62,6 +62,6 @@
* @param score
* @throws RemoteException
*/
- public void endaGame(Score score) throws RemoteException;
+ public void endGame(Score score) throws RemoteException;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-04-06 08:57:10
|
Revision: 94
http://cruce.svn.sourceforge.net/cruce/?rev=94&view=rev
Author: alinposho
Date: 2010-04-06 08:57:03 +0000 (Tue, 06 Apr 2010)
Log Message:
-----------
Am adaugat implementarea clasei Card.
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/remote/Card.java
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Card.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-01 20:59:15 UTC (rev 93)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-06 08:57:03 UTC (rev 94)
@@ -2,5 +2,33 @@
public class Card
{
+ private int value;
+ private Color color;
+ private static Color tromf;
+ public Card(int value, Color color)
+ {
+ this.color = color;
+ this.value = value;
+ }
+
+ public int getValue()
+ {
+ return value;
+ }
+
+ public Color getColor()
+ {
+ return color;
+ }
+
+ public static void setTromf(Color tromf)
+ {
+ Card.tromf = tromf;
+ }
+
+ public boolean isTromf()
+ {
+ return color.equals(tromf);
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-04-01 20:59:29
|
Revision: 93
http://cruce.svn.sourceforge.net/cruce/?rev=93&view=rev
Author: alinposho
Date: 2010-04-01 20:59:15 +0000 (Thu, 01 Apr 2010)
Log Message:
-----------
am facut si o diagrama UML pentru ierarhia de clase a server-ului. Imaginea am adaugat-o intr-un folder "Documentatie". In acelasi folder
eu propun sa punem si CRC de la intalnirea de azi dimineata.
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java
Added Paths:
-----------
Java/trunk/Documentation/
Java/trunk/Documentation/ServerClass_Diagram.jpg
Added: Java/trunk/Documentation/ServerClass_Diagram.jpg
===================================================================
(Binary files differ)
Property changes on: Java/trunk/Documentation/ServerClass_Diagram.jpg
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java 2010-04-01 20:20:26 UTC (rev 92)
+++ Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java 2010-04-01 20:59:15 UTC (rev 93)
@@ -17,7 +17,7 @@
* 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 cient rejects the
+ * @return True in case the client accepts the cars. False in case the client rejects the
* cards
* @throws RemoteException
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-04-01 20:20:32
|
Revision: 92
http://cruce.svn.sourceforge.net/cruce/?rev=92&view=rev
Author: alinposho
Date: 2010-04-01 20:20:26 +0000 (Thu, 01 Apr 2010)
Log Message:
-----------
Am scris codul pentru interfetele la distanta. In plus am adaugat si clasele necesare atat in server cat si in client.
Added 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: Java/trunk/src/prc/bubulina/cruce/remote/Card.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Card.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-01 20:20:26 UTC (rev 92)
@@ -0,0 +1,6 @@
+package prc.bubulina.cruce.remote;
+
+public class Card
+{
+
+}
Added: Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/remote/ClientInterface.java 2010-04-01 20:20:26 UTC (rev 92)
@@ -0,0 +1,67 @@
+package prc.bubulina.cruce.remote;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+
+public interface ClientInterface extends Remote
+{
+ /**
+ * 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 cient 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
+ * @throws RemoteException
+ */
+ public void forceReceive(ArrayList<Card> cards) throws RemoteException;
+
+ /**
+ * 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
+ * @throws RemoteException
+ */
+ public void hit() throws RemoteException;
+
+ /**
+ * Informs the player about the tromf
+ * @param 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
+ * @param score
+ * @throws RemoteException
+ */
+ public void endaGame(Score score) throws RemoteException;
+
+}
Added: Java/trunk/src/prc/bubulina/cruce/remote/Color.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Color.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Color.java 2010-04-01 20:20:26 UTC (rev 92)
@@ -0,0 +1,9 @@
+package prc.bubulina.cruce.remote;
+
+public enum Color
+{
+ ROSU,
+ DUBA,
+ VERDE,
+ GHINDA
+}
Added: Java/trunk/src/prc/bubulina/cruce/remote/Player.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Player.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Player.java 2010-04-01 20:20:26 UTC (rev 92)
@@ -0,0 +1,25 @@
+package prc.bubulina.cruce.remote;
+
+public class Player
+{
+ private String name;
+ private int id;
+
+ public Player(String name, int ID)
+ {
+ this.name = name;
+ this.id = ID;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public int getID()
+ {
+ return id;
+ }
+
+
+}
Added: Java/trunk/src/prc/bubulina/cruce/remote/Score.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Score.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Score.java 2010-04-01 20:20:26 UTC (rev 92)
@@ -0,0 +1,28 @@
+package prc.bubulina.cruce.remote;
+
+import java.util.Map;
+
+/**
+ * This class will be a container for a name value pair "player-score"
+ * @author alinposho
+ *
+ */
+public class Score
+{
+ private 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)
+ {
+ return score.get(player);
+ }
+}
Added: Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/remote/ServerInterface.java 2010-04-01 20:20:26 UTC (rev 92)
@@ -0,0 +1,49 @@
+package prc.bubulina.cruce.remote;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+public interface ServerInterface extends Remote
+{
+
+ public Player joinGame(String name) 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
+ * @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
+ * @throws RemoteException
+ */
+ public boolean acceptCard(Player sender, Card card, int anunt) throws RemoteException;
+
+ /**
+ *
+ * @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
+ * @throws RemoteException
+ */
+ public void registerForNotifications(ClientInterface callback) throws RemoteException;
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|