public void StartSession(PlayerInfo opponent) { bool isExit = false; while (!isExit) { ClientCommand command = ReceiveCommand(); switch (command.Type) { case CommandType.MOVE: Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine($"Move on {command.MoveCoord} from {command.Nickname}"); opponent.SendMoveCommand(command.MoveCoord); break; case CommandType.WIN: Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"{command.Nickname} win!"); opponent.SendLoseCommand(command.Nickname); break; case CommandType.DRAW: Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine($"Draw!"); opponent.SendDrawCommand(); break; case CommandType.CLOSE: Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine($"Close command from {command.Nickname}"); isExit = true; break; case CommandType.EXIT: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Exit command from {command.Nickname}"); opponent.SendCloseCommand(); isExit = true; break; } } }
// метод обробки команд від клієнта та взаємодії з опонентом public void StartSession(PlayerInfo opponent) { bool isExit = false; while (!isExit) { // отримання команди від клієнта ClientCommand command = ReceiveCommand(); // обробка команди switch (command.Type) { // команда ходу case CommandType.MOVE: Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine($"Move on {command.MoveCoord} from {command.Nickname}"); // повідомлення опонента про виконаний хід opponent.SendMoveCommand(command.MoveCoord); break; // команда закриття сесії на сервері case CommandType.CLOSE: Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine($"Close command from {command.Nickname}"); // встановлення змінної для закриття цикла обробки подій поточного гравця isExit = true; break; // команда завершення гри case CommandType.EXIT: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Exit command from {command.Nickname}"); // повідомлення опонента про закриття сесії opponent.SendCloseCommand(); // встановлення змінної для закриття цикла обробки подій поточного гравця isExit = true; break; } } }