private void PreparePlayer(PlayerConnection playerConnection) { var task = new Task(() => { playerConnection.Send("Bem vindo ao jogo, digite seu nome:"); var playerName = playerConnection.Receive(); Console.WriteLine("Nome jogador: {0}", playerName); if (players.Count == Arena.MAX_PLAYERS_IN_THE_GAME) { playerConnection.Send("The game is already full"); playerConnection.Dispose(); } else { var player = new PlayerProcessor(playerName, arena, playerConnection); player.OnStop = () => players.Remove(player); player.OnStart = () => StartPlayers(); players.Add(player); } }); task.Start(); task.ContinueWith(t => Console.WriteLine("The player was prepared!")); }
private string ReceiveAndProcessClientMessage() { string command; string response; command = connection.Receive(); try { ProcessCommand(command); response = GetNextCommand(); } catch (ArgumentException) { Console.WriteLine("invalid-command of player"); response = "invalid-command"; } connection.Send(response); return(command); }