package edu.miamioh.cse283.htw;

import java.io.*;
import java.net.*;

public class Client {
	// networking code
	//
	// connecting
	// handoff
	// send actions to server
	// receive messages from server

	protected Socket server;

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		Client c = new Client();
		c.run(InetAddress.getByName(args[0]), Integer.parseInt(args[1]));
	}

	/**
	 * plays the game
	 * 
	 * @param server
	 *            IP address for a {@link CaveSystemServer}
	 * 
	 * @param port
	 *            Port # for a {@link CaveSystemServer}
	 * @throws IOException
	 */
	public void run(InetAddress serverAddress, int port) throws IOException {
		server = new Socket(serverAddress, port);
		SocketCommunicator serverComm = new SocketCommunicator(server);

		InetAddress caveAddr = InetAddress.getByName(serverComm.receive());
		int cavePort = Integer.parseInt(serverComm.receive());

		Socket cave = new Socket(caveAddr, cavePort);
		SocketCommunicator caveComm = new SocketCommunicator(cave);

		System.out.println(caveComm.receive());
	}

	/**
	 * connects to a given server
	 * 
	 * @param address
	 *            the address of the {@link Server}
	 * @param port
	 *            the port number of the {@link Server}
	 */
	public void connect(InetAddress address, int port) {

	}

	/**
	 * transfers this client to a new {@link Server}
	 * 
	 * @param address
	 *            the address of the {@link Server}
	 * @param port
	 *            the port number of the {@link Server}
	 */
	public void handoff(InetAddress address, int port) {

	}
}

@@ -1081,16 +1081,785 @@
 (cave);%0D
+%0A%09%09%0D%0A%09%09String line = %22%22;%0D%0A%09%09%0D%0A%09%09while ((line = caveComm.receive()) != null) %7B%0D%0A%09%09%09if (line.startsWith(%22MSG%22)) %7B%0D%0A%09%09%09%09line = caveComm.receive();%0D%0A%09%09%09%09System.out.println(line);%0D%0A%09%09%09%7D else if (line.startsWith(%22SENSE%22)) %7B%0D%0A%09%09%09%09line = caveComm.receive();%0D%0A%09%09%09%09System.out.println(line);%0D%0A%09%09%09%7D else if (line.startsWith(%22CHOICES%22)) %7B%0D%0A%09%09%09%09System.out.print(%22You can go to the following rooms: %22);%0D%0A%09%09%09%09while (!(line = caveComm.receive()).equals(%22END_CHOICES%22)) %7B%0D%0A%09%09%09%09%09if (line.startsWith(%22CHOICE%22)) %7B%0D%0A%09%09%09%09%09%09line = caveComm.receive();%0D%0A%09%09%09%09%09%09System.out.print(line + %22 %22);%0D%0A%09%09%09%09%09%7D%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%09System.out.println();%0D%0A%09%09%09%7D else if (line.startsWith(%22ROOM%22)) %7B%0D%0A%09%09%09%09line = caveComm.receive();%0D%0A%09%09%09%09System.out.println(%22You are in room %22 + line);%0D%0A%09%09%09%7D%0D%0A%09%09%09System.out.println();%0D%0A%09%09%7D%0D
 %0A%0D%0A%09%09Sys

use new protocol on the client