/// <summary> /// runs a client and interact with user commands and server connection /// </summary> /// <param name="args">arguments from the user</param> static void Main(string[] args) { // get the connection info from the app.config file int port = int.Parse(ConfigurationManager.AppSettings["port"].ToString()); string ip = ConfigurationManager.AppSettings["server"].ToString(); IPAddress ipAdress = IPAddress.Parse(ip); IPEndPoint ep = new IPEndPoint(ipAdress, port); // create the message transfering class and the controller MessageTransmiter mr = new MessageTransmiter(ep); ClientController clientController = new ClientController(mr); // repeat until status from the command is exit //do //{ try { // get command from user Console.Write("Please enter a command: \n"); string command = Console.ReadLine(); // apply command with the controller //status = clientController.ExecuteCommand(command); } catch (Exception e) { // connection error Console.WriteLine(e); //break; } //} while (status != Status.Exit); }
/// <summary> /// constructor /// </summary> /// <param name="messageReceiver">responsible for message transferring to the server</param> public ClientController(MessageTransmiter messageReceiver) { mr = messageReceiver; SinglePlayCommand singlePC = new SinglePlayCommand(mr); // set the commands dictionary commands = new Dictionary <string, ICommand>(); commands.Add("generate", singlePC); commands.Add("solve", singlePC); commands.Add("list", singlePC); commands.Add("start", new StartMultiPlayCommand(mr)); commands.Add("join", new StartMultiPlayCommand(mr)); commands.Add("play", new MultiPlayCommand(mr)); commands.Add("close", new CloseGameCommand(mr)); commands.Add("finish", new FinishCommand(mr)); }
/// <summary> /// constructor /// </summary> /// <param name="mr">is the messageTransmiter </param> public MultiPlayCommand(MessageTransmiter mr) { messageRec = mr; }
/// <summary> /// constructor /// </summary> /// <param name="mr">is the messageTransmiter </param> public SinglePlayCommand(MessageTransmiter mr) { messageRec = mr; }
/// <summary> /// constructor /// </summary> /// <param name="mr">is the messageTransmiter </param> public CloseGameCommand(MessageTransmiter mr) { messageRec = mr; }