Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WindowWidth = 60;


            Connection.FirstConnect();
            //connect to server
            Socket clientSocket = Connection.cliSocket;

            while (true)
            {
                //default state
                FirstUI();

                string command = GetCommand();
                //login state
                if (command.Equals("LOGIN"))
                {
                    //try login
                    LogIn(clientSocket);

                    bool loginResult = LogInAccept(clientSocket);

                    if (loginResult)
                    {
                        string lobbyCommand = String.Empty;


                        HeartBeatThread hb = new HeartBeatThread();
                        // hb.StartListen();
                        //login success
                        do
                        {
                            //lobby state
                            LobbyUI();

                            lobbyCommand = GetCommand();

                            switch (lobbyCommand)
                            {
                            case "LIST":
                                GetList();

                                break;

                            case "JOIN":

                                Console.Write("Select Room Number :");
                                int roomNum = Convert.ToInt32(Console.ReadLine());

                                JoinRoom(clientSocket, roomNum);

                                break;

                            case "CREATE":

                                int roomNumber = CreateRoom(clientSocket);

                                if (roomNumber == -1)
                                {
                                    Console.WriteLine("Can not create new room");
                                }
                                else
                                {
                                    Console.WriteLine("Create Room " + roomNumber);
                                    JoinRoom(clientSocket, roomNumber);
                                }

                                break;

                            case "LOGOUT":
                                LogOut(clientSocket);
                                //logout success

                                Console.WriteLine("Logout");
                                break;

                            default:
                                Console.WriteLine("Invalid Command : " + lobbyCommand);
                                break;
                            }
                        } while (!lobbyCommand.Equals("LOGOUT"));
                    }
                    else
                    {
                        continue;
                    }
                }//login state
                else if (command.Equals("EXIT"))
                {
                    clientSocket.Close();
                    Environment.Exit(0);
                }//exit
                else
                {
                    Console.WriteLine("Invalid Command");
                } //Login State End
            }     //Application End
        }         //main ends