//methods public void RiseEvent(Command command) { switch (command.CurrentCommand) { case "Move": MoveEvent(command.Data); break; case "Exit": ExitEvent(); break; case "StartGame": StartGameEvent(); break; case "YourStep": YourStepEvent(command.Data); break; case "OpponentStep": OpponentStepEvent(command.Data); break; case "Win": WinEvent(); break; case "Lose": LoseEvent(); break; case "Continue": ContinueEvent(); break; } }
public void Exit() { Command command = new Command(Command.Commands.Exit, ""); string message = protocol.ToMessage(command); messanger.SendMessage(clientThread.Client.Socket, message); clientThread.Stop(); }
//methods public bool Login(IPEndPoint ipEndPoint, string name) { clientThread.Client.Connect(ipEndPoint); clientThread.Client.Name = name; Command command = new Command(Command.Commands.Connect, clientThread.Client.Name); string message = protocol.ToMessage(command); messanger.SendMessage(clientThread.Client.Socket, message); message = messanger.ReadMessage(clientThread.Client.Socket); command = protocol.ToCommand(message); return command.CurrentCommand == Command.Commands.Confirm.ToString(); }
//method public void RiseEvent(Command command) { switch (command.CurrentCommand) { case "GetPlayers": GetPlayersEvent(command.Data); break; case "Invite": InviteEvent(command.Data); break; case "Confirm": ConfirmEvent(); break; case "Reject": RejectEvent(); break; case "StartGame": StartGameEvent(command.Data); break; } }
public string ToMessage(Command command) { return jsonParser.CommandToJson(command); }
public void SendInvite(string name) { Command command = new Command(Command.Commands.Invite, name); string message = protocol.ToMessage(command); messanger.SendMessage(clientThread.Client.Socket, message); }
//methods public string CommandToJson(Command command) { return JsonConvert.SerializeObject(command); }
internal void Move(int position) { Command command = new Command(Command.Commands.Move, position.ToString()); string message = protocol.ToMessage(command); gameThread.Client.SendMessage(message); }