Пример #1
0
        public override void Update(GameTime gameTime)
        {
            MouseState currentMouseState = Mouse.GetState();
            Rectangle  MouseRect         = new Rectangle(currentMouseState.X, currentMouseState.Y, 1, 1);

            changeScreen = PossibleScreen.game;

            serverIP = GameGlobals.UpdateString(serverIP, 15);

            foreach (GraphObject _graphObject in graphList)
            {
                var temp = new Rectangle((int)_graphObject.Position.X, (int)_graphObject.Position.Y, _graphObject.Texture.Width, _graphObject.Texture.Height);
                if ((MouseRect.Intersects(temp)) && (_graphObject.IsButton))
                {
                    _graphObject.Color = Color.Brown;
                }
                else
                {
                    _graphObject.Color = Color.White;
                }

                if ((currentMouseState.LeftButton == ButtonState.Pressed) && MouseRect.Intersects(temp) && (_graphObject.IsButton) && (_graphObject.Color == Color.Brown))
                {
                    if (_graphObject.Name.Equals("BACK"))
                    {
                        MediaPlayer.Stop();
                        changeScreen = PossibleScreen.main;
                        Hide();
                    }
                    if (_graphObject.Name.Equals("SERVER"))
                    {
                        MediaPlayer.Stop();
                        GameGlobals.Initialize();
                        GameGlobals.StartServer();
                        GameGlobals.Player = new Player(GameGlobals.NICKNAMES[0], Player.PlayerColor.Red);
                        GameGlobals.Player.Connect(GameGlobals.LocalIPAddress(), GameGlobals.PORT);
                        changeScreen = PossibleScreen.lobby;
                        Hide();
                    }
                    if (_graphObject.Name.Equals("JOIN"))
                    {
                        if (GameGlobals.isIP(serverIP))
                        {
                            MediaPlayer.Stop();
                            GameGlobals.Initialize();
                            GameGlobals.Player = new Player(GameGlobals.NICKNAMES[1], Player.PlayerColor.Blue);
                            GameGlobals.Player.Connect(serverIP, GameGlobals.PORT);
                            changeScreen = PossibleScreen.lobby;
                            Hide();
                        }
                    }
                }
            }
        }