public MainMenuState()
        {
            const int buffer      = 50;
            const int buttonWidth = 300;
            int       leftx       = (GameEnvironment.Screen.X - (buttonWidth * 2 + buffer)) / 2;
            int       rightx      = leftx + buttonWidth + buffer;

            SpriteFont defaultFont   = GameEnvironment.AssetManager.GetFont("Arial12");
            SpriteFont textfieldFont = GameEnvironment.AssetManager.GetFont("Arial26");

            singlePlayerButton        = new Button("button", "Singleplayer", textfieldFont, Color.Black);
            singlePlayerButton.Action = () =>
            {
                GameSetupState gss = GameEnvironment.GameStateManager.GetGameState("gameSetupState") as GameSetupState;
                gss.InitializeGameMode(GameSetupState.GameMode.Singleplayer);
                GameEnvironment.GameStateManager.SwitchTo("gameSetupState");
            };
            singlePlayerButton.Position = new Vector2(leftx, 300);
            Add(singlePlayerButton);

            multiPlayerButton          = new Button("button", "Multiplayer", textfieldFont, Color.Black);
            multiPlayerButton.Position = new Vector2(rightx, 300);
            multiPlayerButton.Action   = () =>
            {
                GameEnvironment.GameStateManager.SwitchTo("multiplayerMenu");
            };
            Add(multiPlayerButton);

            helpButton        = new Button("button", "Help", textfieldFont, Color.Black);
            helpButton.Action = () =>
            {
                GameEnvironment.GameStateManager.SwitchTo("helpMenu");
            };
            helpButton.Position = new Vector2(leftx, 375);
            Add(helpButton);

            optionsButton        = new Button("button", "Options", textfieldFont, Color.Black);
            optionsButton.Action = () =>
            {
                GameEnvironment.GameStateManager.SwitchTo("optionsMenu");
            };
            optionsButton.Position = new Vector2(rightx, 375);
            Add(optionsButton);

            creditsButton        = new Button("button", "Credits", textfieldFont, Color.Black);
            creditsButton.Action = () =>
            {
                GameEnvironment.GameStateManager.SwitchTo("creditsMenu");
            };
            creditsButton.Position = new Vector2(leftx, 450);
            Add(creditsButton);

            quitButton        = new Button("button", "Quit", textfieldFont, Color.Black);
            quitButton.Action = () =>
            {
                Treehugger.ExitGame();
            };
            quitButton.Position = new Vector2(rightx, 450);
            Add(quitButton);
        }
            public LANTab()
            {
                Point      screen  = GameEnvironment.Screen;
                SpriteFont arial26 = GameEnvironment.AssetManager.GetFont("Arial26");

                //Create a text field for the ip address
                ipAddress          = new TextField(arial26, Color.Black);
                ipAddress.Position = new Vector2((screen.X - ipAddress.Width) / 2, 50);
                ipAddress.Editable = true;
                Add(ipAddress);
                TextGameObject ipAddressLabel = new TextGameObject("Arial26");

                ipAddressLabel.Text     = "IP address: ";
                ipAddressLabel.Position = new Vector2(ipAddress.Position.X - ipAddressLabel.Size.X - 10, ipAddress.Position.Y);
                ipAddressLabel.Color    = Color.Black;
                Add(ipAddressLabel);

                //Create a text field for the user name
                userName          = new TextField(arial26, Color.Black);
                userName.Position = new Vector2((screen.X - userName.Width) / 2, 125);
                userName.Editable = true;
                Add(userName);
                TextGameObject userNameLabel = new TextGameObject("Arial26");

                userNameLabel.Text     = "Username: "******"button", "Connect", arial26, Color.Black);
                connectButton.Action = () =>
                {
                    GameEnvironment.GameSettingsManager.SetValue("user_name", userName.Text);
                    GameEnvironment.GameSettingsManager.SetValue("server_ip_address", ipAddress.Text);
                    GameSetupState gss = GameEnvironment.GameStateManager.GetGameState("gameSetupState") as GameSetupState;
                    gss.InitializeGameMode(GameSetupState.GameMode.MultiplayerClient);
                    GameEnvironment.GameStateManager.SwitchTo("gameSetupState");
                };
                //Create a button to start hosting.
                hostButton        = new Button("button", "Host a Game", arial26, Color.Black);
                hostButton.Action = () =>
                {
                    GameEnvironment.GameSettingsManager.SetValue("user_name", userName.Text);
                    GameSetupState gss = GameEnvironment.GameStateManager.GetGameState("gameSetupState") as GameSetupState;
                    gss.InitializeGameMode(GameSetupState.GameMode.MultiplayerHost);
                    GameEnvironment.GameStateManager.SwitchTo("gameSetupState");
                };

                int x = (screen.X - hostButton.Width - connectButton.Width - 25) / 2;

                hostButton.Position = new Vector2(x + connectButton.Width + 25, 200);
                Add(hostButton);

                connectButton.Position = new Vector2(x, 200);
                Add(connectButton);
            }
示例#3
0
        public GameOverState()
        {
            const int buffer        = 50;
            const int buttonWidth   = 300;
            int       leftx         = (GameEnvironment.Screen.X - (buttonWidth * 2 + buffer)) / 2;
            int       rightx        = leftx + buttonWidth + buffer;
            int       centerx       = (GameEnvironment.Screen.X - buttonWidth) / 2;
            int       buttonOffSett = 75;

            SpriteFont defaultFont   = GameEnvironment.AssetManager.GetFont("Arial12");
            SpriteFont textfieldFont = GameEnvironment.AssetManager.GetFont("Arial26");

            TextGameObject gameOverMessage = new TextGameObject("Arial26");

            gameOverMessage.Text     = "GameOver";
            gameOverMessage.Color    = Color.Red;
            gameOverMessage.Position = new Vector2(centerx, 200);
            Add(gameOverMessage);

            mainMenuButton        = new Button("button", "MainMenu", textfieldFont, Color.Black);
            mainMenuButton.Action = () =>
            {
                GameEnvironment.GameStateManager.SwitchTo("mainMenuState");
                GameEnvironment.AssetManager.PlayMusic("Sounds/Welcome Screen");
            };
            mainMenuButton.Position = new Vector2(centerx, 300);
            Add(mainMenuButton);

            restartButton        = new Button("button", "Restart", textfieldFont, Color.Black);
            restartButton.Action = () =>
            {
                GameSetupState gss = GameEnvironment.GameStateManager.GetGameState("gameSetupState") as GameSetupState;
                gss.InitializeGameMode(gameMode);
                GameEnvironment.GameStateManager.SwitchTo("gameSetupState");
            };
            restartButton.Position = new Vector2(centerx, mainMenuButton.Position.Y + buttonOffSett);
            Add(restartButton);

            quitButton        = new Button("button", "Quit", textfieldFont, Color.Black);
            quitButton.Action = () =>
            {
                Treehugger.ExitGame();
            };
            quitButton.Position = new Vector2(centerx, restartButton.Position.Y + buttonOffSett);
            Add(quitButton);
        }
示例#4
0
        public PlayingMenu() : base(350, 500, true, false)
        {
            SpriteFont sf = GameEnvironment.AssetManager.GetFont("Arial26");

            backButton          = new Button("button", "Main Menu", sf, Color.Black);
            backButton.Position = new Vector2(25, 25);
            backButton.Action   = () =>
            {
                GameEnvironment.GameStateManager.SwitchTo("mainMenuState");
                GameEnvironment.AssetManager.PlayMusic("Sounds/Welcome Screen");
            };
            Add(backButton);

            Vector2 buttonDistance = new Vector2(0, backButton.Sprite.Height + 15);

            restartButton          = new Button("button", "Restart", sf, Color.Black);
            restartButton.Position = backButton.Position + buttonDistance;
            restartButton.Action   = () =>
            {
                GameSetupState gss = GameEnvironment.GameStateManager.GetGameState("gameSetupState") as GameSetupState;
                PlayingState   ps  = GameEnvironment.GameStateManager.GetGameState("playingState") as PlayingState;
                ps.Reset();
                gss.InitializeGameMode(ps.CurrentGameMode);
                GameEnvironment.GameStateManager.SwitchTo("gameSetupState");
            };
            Add(restartButton);

            optionsButton          = new Button("button", "Options", sf, Color.Black);
            optionsButton.Action   = () => { };
            optionsButton.Position = restartButton.Position + buttonDistance;
            Add(optionsButton);

            quitButton          = new Button("button", "Quit", sf, Color.Black);
            quitButton.Position = optionsButton.Position + buttonDistance;
            quitButton.Action   = () =>
            {
                Treehugger.ExitGame();
            };
            Add(quitButton);
        }