/// <summary>
        /// Called when a connection error occurs during the game. Disconnects all clients from the server.
        /// </summary>
        public static void Error()
        {
            State_Menu.Singleton.targetState = State_Menu.Singleton;
            Console.WriteLine("ERROR, Targetstate is Menu");
            Pong.targetState          = State_Menu.Singleton;
            State_Menu.Singleton.info = "A client has logged out or a connection error \nocurred, you have been disconnected.";

            PongConnection.CloseConnection();
        }
Example #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            prevKeyState = currKeyState;
            currKeyState = Keyboard.GetState();

            if (PongConnection.PlayerID != -1 && PongConnection.running)
            {
                if (currKeyState != prevKeyState)
                {
                    Keys[] pressedKeys = currKeyState.GetPressedKeys();

                    if (pressedKeys.Length > 0)
                    {
                        PongConnection.SyncPlayerPositions(pressedKeys[0].ToString());
                    }
                }
            }

            if (currKeyState.IsKeyDown(Keys.Escape))
            {
                if (currKeyState != prevKeyState)
                {
                    if (!PongConnection.running)
                    {
                        Exit();
                    }
                    else
                    {
                        PongConnection.CloseConnection();
                    }
                }
            }

            currentState = targetState;
            currentState.Update(gameTime);

            base.Update(gameTime);
        }