Ejemplo n.º 1
0
        public static LoginData Login()
        {
            LoginData data = new LoginData();

            string name = "";
            do
            {
                Handler.Clear();
                Handler.WriteLine("Login: "******"Please enter your name: ");
                name = Handler.ReadString();
            } while (!Validator.HasMinLength(name, 3));

            data.Name = name;
            Handler.Write("Enter a password for your character:");
            data.Password = Handler.ReadString();
            return data;
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                ConnectToServer();
                LoginData data = Login();
                SendLoginRequest(data.Name, data.Password);
                Handler.Clear();
                while (true)
                {
                    RecieveResponse();
                    while (_responseQueue.Count != 0)
                    {
                        ServerResponse response = _responseQueue.Dequeue();
                        switch (response)
                        {
                        case ServerResponse.YourTurn:
                            Handler.ClearLine(0, gameBoard.GetLength(1) + _players.Count);
                            Handler.Write("Your turn. Press Arrow keys to move or press (c) to chat", 0, gameBoard.GetLength(1) + _players.Count);
                            bool ok = false;
                            while (!ok)
                            {
                                ok = SendMoveRequest();
                            }
                            Handler.ClearLine(0, gameBoard.GetLength(1) + _players.Count);
                            Handler.Write("Waiting for other players to move", 0, gameBoard.GetLength(1) + _players.Count);
                            break;

                        case ServerResponse.Sendstate:
                            Display();
                            break;

                        case ServerResponse.NewPlayer:
                            Display();
                            break;

                        case ServerResponse.UpdatePlayer:
                            Display();
                            break;

                        case ServerResponse.RemovePlayer:
                            Display();
                            break;

                        case ServerResponse.Message:
                            ClearChattMessages();
                            PrintChattMessages();
                            break;

                        case ServerResponse.LoginDenied:
                            Handler.Clear();
                            Handler.WriteLine("Wrong password!");
                            Handler.ReadKey();
                            data = Login();
                            SendLoginRequest(data.Name, data.Password);
                            break;

                        case ServerResponse.MoveDenied:
                            Handler.ClearLine(0, gameBoard.GetLength(1) + _players.Count);
                            Handler.Write("Your turn", 0, gameBoard.GetLength(1) + _players.Count);
                            ok = false;
                            while (!ok)
                            {
                                ok = SendMoveRequest();
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
                Console.ReadLine();
            }
            finally
            {
                _socket?.Close();
            }
            Console.WriteLine("Client shut down.");
            Console.ReadLine();
        }