package edu.miamioh.cse283.htw;

import java.net.*;

/**
 * Client (player) for the Hunt the Wumpus game.
 *
 */
public class Client {

	/** Proxy object that connects the client to its current cave. */
	protected CaveProxy cave;

	/** Constructor. */
	public Client(CaveProxy cave) {
		this.cave = cave;
	}

	/** Returns true if the player is still alive. */
	public synchronized boolean isAlive() {
		return true;
	}

	/**
	 * Plays the game.
	 * 
	 * @param args
	 *            holds address and port number for the CaveSystemServer this
	 *            client will connect to.
	 */
	public void run() {
		try {
			// all clients initially experience a handoff:
			cave = cave.handoff();
			System.out.println(cave.getMessage());

			// now start the sense and respond loop:
			while (isAlive()) {
				System.out.println(cave.getSenses());

				// get an action from the player, and
				// send it to the cave server.
				cave.sendAction("move 1");

			}

		} catch (Exception ex) {
			// If an exception is thrown, we can't fix it here -- Crash.
			ex.printStackTrace();
			System.exit(1);
		}
	}

	/**
	 * Main method for clients.
	 * 
	 * @param args
	 *            contains the hostname and port number of the server that this
	 *            client should connect to.
	 */
	public static void main(String[] args) throws Exception {
		CaveProxy cave = new CaveProxy(new Socket(
				InetAddress.getByName(args[0]), Integer.parseInt(args[1])));
		Client c = new Client(cave);
		c.run();
	}
}

@@ -99,16 +99,187 @@
 s game.%0A
+ * %0A * The Client class takes the following command-line parameters:%0A * %0A * %3CHostname of CaveSystemServer%3E %3Cport number of CaveSystemServer%3E%0A * %0A * E.g., %22localhost 1234%22%0A
  *%0A */%0Ap
@@ -1508,55 +1508,126 @@
 %7B%0A%09%09
-CaveProxy cave
+InetAddress addr
  = 
+I
 ne
-w CaveProxy(new Socket(%0A%09%09%09%09
+tAddress.getByName(%22localhost%22);%0A%09%09int cavePortBase = 1234;%0A%0A%09%09if (args.length %3E 0) %7B%0A%09%09%09addr = 
 Inet
@@ -1652,17 +1652,35 @@
 args%5B0%5D)
-,
+;%0A%09%09%09cavePortBase =
  Integer
@@ -1697,16 +1697,85 @@
 args%5B1%5D)
+;%0A%09%09%7D%0A%0A%09%09CaveProxy cave = new CaveProxy(new Socket(addr, cavePortBase
 ));%0A%09%09Cl

add comments and default command-line arguments to client class