Skip to content

Commit

Permalink
interface to server, gameInitiator
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Lankenau committed May 12, 2011
1 parent 22182c6 commit 2a9f5c3
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Galaxy/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" 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="lib" path="/home/mlankenau/projects/Galaxy/lib/json_simple-1.1.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry combineaccessrules="false" kind="src" path="/libs"/>
<classpathentry kind="output" path="bin"/>
</classpath>
63 changes: 63 additions & 0 deletions Galaxy/src/org/galaxy/GameInitiator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.galaxy;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class GameInitiator {
Remote remote = null;

public static final String BASE_SERVER_URL = "http://sharp-fog-360.heroku.com";

String baseUrl = BASE_SERVER_URL;


protected static String httpGet(String address) throws Exception {
URL url = new URL(address);
URLConnection yc = url.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine;

StringBuffer resultBuffer = new StringBuffer();
while ((inputLine = in.readLine()) != null)
resultBuffer.append(inputLine+ "\n");
in.close();

return resultBuffer.toString();
}


protected static void enlist(String url, int port, String name) throws Exception {
String cmdUrl = url + "/enlist/" + InetAddress.getLocalHost().getHostAddress() + "?name="+name + "&port="+port;
httpGet(cmdUrl);

}

protected static String getPlayers(String url) throws Exception {
//URL urlConnection = new URL(url + "/players");
//String result = readStream((InputStream)urlConnection.openStream());

return httpGet(url + "/players");
}



public GameInitiator(String name) {

}


public void startMultiplayer() {
//getPlayers(baseUrl);
}



}
3 changes: 2 additions & 1 deletion Galaxy/src/org/galaxy/Remote.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public class Remote {
public boolean isFirst() {
return first;
}



public Remote(Game game, String host, int port, Party party) {
this.game = game;
try {
Expand Down
21 changes: 21 additions & 0 deletions Galaxy/test/org/galaxy/GameInitiatorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.galaxy;

import org.junit.Test;

public class GameInitiatorTest extends GameInitiator{
String LOCAL_TEST_SERVER = "http://localhost:8090";

public GameInitiatorTest() {
super("tralala");
}

@Test
public void testServer() throws Exception {
enlist(LOCAL_TEST_SERVER, 1001, "marcus");
enlist(LOCAL_TEST_SERVER, 1002, "sebastian");

String players = getPlayers(LOCAL_TEST_SERVER);
System.out.println("players: " + players);

}
}
1 change: 0 additions & 1 deletion SwingClient/src/org/galaxy/swing/GalaxyScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public GalaxyScreen() {

game = GameFactory.getLevel(1);


addMouseListener(this);
addMouseMotionListener(this);

Expand Down
8 changes: 8 additions & 0 deletions libs/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +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 exported="true" kind="lib" path="httpclient-4.1.1.jar"/>
<classpathentry exported="true" kind="lib" path="json_simple-1.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions libs/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>libs</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>
12 changes: 12 additions & 0 deletions libs/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#Thu May 12 16:16:25 CEST 2011
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
Binary file added libs/httpclient-4.1.1.jar
Binary file not shown.
Binary file added libs/json_simple-1.1.jar
Binary file not shown.

0 comments on commit 2a9f5c3

Please sign in to comment.