/// <summary>
    /// The Launcher is a temporary solution to test the server/client implementation.
    /// </summary>
    /// <param name="args"></param>
    static void Main(string[] args)
    {
        ClientProgram myFirstClient = new ClientProgram();

        // Thread serverThread = new Thread(new ThreadStart(() => MasterServer.StartServer()));
        // serverThread.Start();

        MasterServer.StartServer();

        System.Threading.Thread.Sleep(500);

        myFirstClient.ConnectToServer();
        myFirstClient.CreateNewGame("level1");
        myFirstClient.CreateNewPlayerForSession("Snoop Dog", MDC.CharacterClass.Knight);

        // myFirstClient.DisconnectFromServer();

        System.Threading.Thread.Sleep(500);

        ClientProgram mySecondClient = new ClientProgram();

        mySecondClient.ConnectToServer();
        mySecondClient.ConnectToGame(myFirstClient.GameSession_ID);
        mySecondClient.CreateNewPlayerForSession("Tux", MDC.CharacterClass.Archer);

        while (true)
        {
            if (mySecondClient.Update != null)
            {
                Console.WriteLine(mySecondClient.Update.PlayerList[0].PlayerName);
            }
            else
            {
                System.Threading.Thread.Sleep(1500);
            }
        }


        // try
        // {
        //     mySecondClient.ConnectToGame("4711");
        // }
        // catch (System.Exception)
        // {

        //     throw;
        // }

        // //############################################
        // ClientProgram elChappo01 = new ClientProgram();
        // elChappo01.ConnectToServer();
        // elChappo01.CreateNewGame();
        // System.Threading.Thread.Sleep(500);
        // ClientProgram elChappo02 = new ClientProgram();
        // elChappo02.ConnectToServer();
        // //############################################

        ClientProgram myThirdClient = new ClientProgram();

        myThirdClient.ConnectToServer();

        // elChappo02.ConnectToGame(elChappo01.GameSession_ID);
        myThirdClient.ConnectToGame(myFirstClient.GameSession_ID);

        ClientProgram myFourthClient = new ClientProgram();

        myFourthClient.ConnectToServer();
        myFourthClient.ConnectToGame(myFirstClient.GameSession_ID);


        // ClientProgram myFifthClient = new ClientProgram();
        // myFifthClient.ConnectToServer();
        // myFifthClient.ConnectToGame(myFirstClient.GameSession_ID);

        /*
         *
         * myFirstClient.CreateNewPlayerForSession("Snoop Dog", MDC.CharacterClass.MeleeFighter);
         * mySecondClient.CreateNewPlayerForSession("Tux", MDC.CharacterClass.RangeFighter);
         * myThirdClient.CreateNewPlayerForSession("Franz", MDC.CharacterClass.MeleeFighter);
         * myFourthClient.CreateNewPlayerForSession("Pepe", MDC.CharacterClass.MeleeFighter);
         *
         * myFirstClient.StartCreatedGame();
         *
         * myFirstClient.MovePlayer(1, 0);
         * myFirstClient.MovePlayer(2, 0);
         * myFirstClient.MovePlayer(2, 1);
         * // myFirstClient.EndTurn();
         * myFirstClient.MovePlayer(2, 2);
         * myFirstClient.MovePlayer(3, 2);
         *
         * System.Threading.Thread.Sleep(2000);
         * mySecondClient.MovePlayer(18, 2);
         *
         */
        // System.Threading.Thread.Sleep(5000);
        // myFirstClient.DisconnectFromServer();
        while (true)
        {
        }
        // ClientProgram myFifthClient = new ClientProgram();
        // myFifthClient.ConnectToServer();
        // myFifthClient.ConnectToGame(myFirstClient.GameSession_ID);
    }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("[1] Server\n[2] Simulate Client\n[3] Demo Mode");
            string input = Console.ReadLine();

            switch (input)
            {
            case "1":
                MasterServer.StartServer();
                break;

            case "2":
                Console.WriteLine("Please insert SessionID");
                string        s_ID       = Console.ReadLine();
                ClientProgram gameClient = new ClientProgram();
                gameClient.ConnectToServer();
                System.Threading.Thread.Sleep(500);
                gameClient.ConnectToGame(s_ID);
                System.Threading.Thread.Sleep(500);
                gameClient.CreateNewPlayerForSession("TestClient", GameLogic.MDC.CharacterClass.Knight);
                break;

            case "3":
                // MasterServer.StartServer();
                // System.Threading.Thread.Sleep(500);
                Console.WriteLine("How many clients?");
                int clientCount = int.Parse(Console.ReadLine());

                var clients = new ClientProgram[clientCount];
                for (int i = 0; i < clientCount; i++)
                {
                    clients[i] = new ClientProgram();
                }

                Console.WriteLine("Please enter session id");
                string sessionID = Console.ReadLine();

                foreach (var client in clients)
                {
                    client.ConnectToServer();
                    client.ConnectToGame(sessionID);
                    client.CreateNewPlayerForSession((int)(new Random().Next() * 100) + "", GameLogic.MDC.CharacterClass.Knight);
                }

                System.Threading.Thread.Sleep(3500);

                while (true)
                {
                    foreach (var client in clients)
                    {
                        if (client.CurrentStatus == ClientProgram.Status.Busy)
                        {
                            client.EndTurn();
                        }
                    }

                    System.Threading.Thread.Sleep(1000);
                }

            default:
                Console.WriteLine("Input not recognized");
                break;
            }

            while (true)
            {
            }
        }