Skip to content

Instantly share code, notes, and snippets.

@michelsalib
Created February 11, 2012 20:50
Show Gist options
  • Save michelsalib/1804150 to your computer and use it in GitHub Desktop.
Save michelsalib/1804150 to your computer and use it in GitHub Desktop.
Green Planet client basic example
package greenplanettestclient;
import greenplanetclient.*;
import java.io.IOException;
import java.util.ArrayList;
import javax.xml.bind.JAXBException;
/**
* @author michel
*/
public class GreenPlanetTestClient {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException, JAXBException, InterruptedException {
// create client
ClientInterface client = new OfflineClient("Michel"); // offline client
//ClientInterface client = new Client(3, "Michel"); // online client
try {
// wait for game to start
Game game = client.waitForStart();
// while game is running
while (game.getState() == GameStateEnum.RUNNING) {
// display some stufs
System.out.println("Play turn #" + game.getTurn().getNumber());
// compute order (AI job)
Order order = new Order(10, new ArrayList<String>());
// give order, wait for next turn
game = client.giveOrder(order);
}
} catch (ClientException ex) {
System.out.println(ex);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment