Beispiel #1
0
        /// <summary>
        /// Listen for the incoming message from the server
        /// </summary>
        static void ListenServer()
        {
            byte[] bytes;
            while (sender.Connected)
            {
                try
                {
                    bytes = new byte[500];
                    int bytesRec = sender.Receive(bytes);

                    string msg = Encoding.ASCII.GetString(bytes, 0, bytesRec);
                    switch (msg)
                    {
                    //i the server ask to start the game
                    case "StartGame":

                        Console.WriteLine("Game begin in 5 seconds");
                        Thread.Sleep(5000);
                        Console.Clear();
                        newGame.LaunchGame();
                        break;

                    case "You Win":
                        Console.Clear();
                        Console.WriteLine(msg);
                        break;

                    //when the server send "1" a block of one square should be displayed in the game
                    case "1":
                        //when he send "2" a block of four square
                        break;

                    case "2":

                        break;

                    //add a penalty
                    case "Penalty":
                        newGame.Penalty += 1;
                        break;
                    }
                }
                catch (SocketException ex)
                {
                    Console.Clear();
                    Console.WriteLine("The server has disconnected!");
                    Console.ReadLine();
                    Environment.Exit(1);
                }
            }
        }