Beispiel #1
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)
        {
            // Allows the game to exit
            // if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            //   this.Exit();

            // TODO: Add your update logic here
            if (gameState == GameState.SplashScreen)
            {
                timer += 1;
                if (timer >= timeToStayOnScreen)
                {

                    gameState = GameState.Menu;
                    //                  MyGameForm.FormBorderStyle = FormBorderStyle.FixedSingle;
                    IsMouseVisible = true;

                }
            }
            if (gameState == GameState.Menu)
            {
                mouseState = Mouse.GetState();
                CheckMousePosition(mouseState.X, mouseState.Y);
                if (previousMouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed
                    && mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released)
                {
                    MouseClicked(mouseState.X, mouseState.Y);
                }
                previousMouseState = mouseState;
            }
            if (gameState == GameState.getInfo)
            {
                mouseState = Mouse.GetState();
                CheckMousePosition(mouseState.X, mouseState.Y);
                TimetobBlink++;
                if (TimetobBlink > 25)
                {
                    TimetobBlink = 0;
                    blink = !blink;
                }
                if (previousMouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed
                    && mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released)
                {
                    MouseClicked(mouseState.X, mouseState.Y);

                }
                previousMouseState = mouseState;
                keybrdState = Keyboard.GetState();
                if ((TryConvertKeyboardInput(keybrdState, oldkeybrdState, out input)) == true)
                {
                    if (textBoxSelected == TextboxSelected.name)
                    {
                        if (input == 8)
                        {
                            //Debug.WriteLine("\nbackspace for name");
                            if (txtName.Length > 0)
                            {
                                txtName = txtName.Remove(txtName.Length - 1);
                                CursortxtNameButtonPosition.X -= moveForwardCursor;
                            }
                        }
                        else if (input == (char)Microsoft.Xna.Framework.Input.Keys.Tab)
                        {
                            textBoxSelected = TextboxSelected.age;
                        }
                        else
                        {
                            if (txtName.Length < 30)
                            {

                                txtName += input;
                                CursortxtNameButtonPosition.X += moveForwardCursor;
                            }
                        }

                    }
                    else if (textBoxSelected == TextboxSelected.age)
                    {
                        if ((Microsoft.Xna.Framework.Input.Keys)input == Microsoft.Xna.Framework.Input.Keys.Back)
                        {
                            if (txtAge.Length > 0)
                            {

                                txtAge = txtAge.Remove(txtAge.Length - 1);

                                CursortxtAgeButtonPosition.X -= moveForwardCursor;

                            }
                        }
                        else if (input == (char)Microsoft.Xna.Framework.Input.Keys.Tab)
                        {
                            textBoxSelected = TextboxSelected.qualification;
                        }
                        else
                        {
                            if (txtAge.Length < 4)
                            {
                                if (input >= '0' && input <= '9')
                                {
                                    txtAge += input;
                                    CursortxtAgeButtonPosition.X += moveForwardCursor;
                                }
                            }
                        }
                    }
                    else if (textBoxSelected == TextboxSelected.qualification)
                    {
                        if (input == 8)
                        {
                            if (txtQualification.Length > 0)
                            {

                                txtQualification = txtQualification.Remove(txtQualification.Length - 1);
                                CursortxtQualificationButtonPosition.X -= moveForwardCursor;
                            }
                        }
                        else if (input == (char)Microsoft.Xna.Framework.Input.Keys.Tab)
                        {
                            textBoxSelected = TextboxSelected.name;
                        }
                        else
                        {
                            if (txtQualification.Length < 30)
                            {
                                txtQualification += input;

                                CursortxtQualificationButtonPosition.X += moveForwardCursor;

                            }
                        }
                    }
                    Debug.WriteLine("state : " + textBoxSelected + "     intput : " + input + "    name : " + txtName + "     age : " + txtAge + "     qualification : " + txtQualification);
                }

                oldkeybrdState = keybrdState;
            }

            base.Update(gameTime);
        }
Beispiel #2
0
        void MouseClicked(int x, int y)
        {
            //creates a rectangle of 10x10 around the place where the mouse was clicked

            Rectangle mouseClickRect = new Rectangle(x, y, 30, 20);

            //check the startmenu
            if (GameState.getInfo == gameState)
            {
                Rectangle backButtonRect = new Rectangle((int)backButtonPosition.X, (int)backButtonPosition.Y, 100, 20);
                Rectangle saveButtonRect = new Rectangle((int)saveButtonPosition.X, (int)saveButtonPosition.Y, 100, 20);
                //rectangles for textboxes
                Rectangle txtNameRect = new Rectangle((int)txtNameButtonPosition.X, (int)txtNameButtonPosition.Y, 400, 50);
                Rectangle txtAgeRect = new Rectangle((int)txtAgeButtonPosition.X, (int)txtAgeButtonPosition.Y, 400, 50);
                Rectangle txtQualificationRect = new Rectangle((int)txtQualificationButtonPosition.X, (int)txtQualificationButtonPosition.Y, 400, 50);
                Rectangle maleRadioButtonRect = new Rectangle((int)maleTexturePosition.X, (int)maleTexturePosition.Y, 50, 20);
                Rectangle femaleRadioButtonRect = new Rectangle((int)femaleTexturePosition.X, (int)femaleTexturePosition.Y, 50, 20);

                if (mouseClickRect.Intersects(backButtonRect))
                {
                    gameState = GameState.Menu;
                }
                else if (mouseClickRect.Intersects(saveButtonRect))
                {
                    bool res = WriteToFile();

                    if (res)
                    {
                        CursortxtNameButtonPosition = new Vector2(txtNameButtonPosition.X + 5, txtNameButtonPosition.Y);
                        CursortxtQualificationButtonPosition = new Vector2(txtQualificationButtonPosition.X + 5, txtQualificationButtonPosition.Y);
                        CursortxtAgeButtonPosition = new Vector2(txtAgeButtonPosition.X + 5, txtAgeButtonPosition.Y);
                        textBoxSelected = TextboxSelected.name;

                        gameState = GameState.SplashScreen;
                    }
                }
                else if (mouseClickRect.Intersects(txtNameRect))
                {
                    textBoxSelected = TextboxSelected.name;
                }
                else if (mouseClickRect.Intersects(txtAgeRect))
                {
                    textBoxSelected = TextboxSelected.age;
                }
                else if (mouseClickRect.Intersects(txtQualificationRect))
                {
                    textBoxSelected = TextboxSelected.qualification;
                }
                else if (mouseClickRect.Intersects(maleRadioButtonRect))
                {
                    genderForGetInfo = Gender.male;
                }
                else if (mouseClickRect.Intersects(femaleRadioButtonRect))
                {
                    genderForGetInfo = Gender.female;
                }

            }
            if (gameState == GameState.Menu)
            {

                Rectangle startButtonRect = new Rectangle((int)startButtonPosition.X,

                                            (int)startButtonPosition.Y, 120, 25);
                Rectangle infoButtonRect = new Rectangle((int)infoButtonPosition.X,

                                             (int)infoButtonPosition.Y, 200, 25);

                Rectangle exitButtonRect = new Rectangle((int)exitButtonPosition.X,

                                             (int)exitButtonPosition.Y, 120, 25);

                if (mouseClickRect.Intersects(startButtonRect)) //player clicked start button
                {

                    //gameState = GameState.Loading;
                    throw new Exception();
                    gameState = GameState.Game;
                    IsMouseVisible = false;

                }
                else if (mouseClickRect.Intersects(infoButtonRect))
                {
                    gameState = GameState.getInfo;

                }
                else if (mouseClickRect.Intersects(exitButtonRect)) //player clicked exit button
                {

                    Exit();

                }

            }
        }
Beispiel #3
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            font = Content.Load<SpriteFont>("myFont");
            fontForGetInfoLabels = Content.Load<SpriteFont>("myFontForGetInfoLabels");

            gameState = new GameState();
            gameState = GameState.SplashScreen;

            textBoxSelected = new TextboxSelected();
            textBoxSelected = TextboxSelected.name;
            xDimensionPositionForMainMenuItems = (GraphicsDevice.Viewport.Width / 4);

            startButtonPosition = new Vector2(xDimensionPositionForMainMenuItems, GraphicsDevice.Viewport.Height / 2 - 100);
            infoButtonPosition = new Vector2(xDimensionPositionForMainMenuItems, GraphicsDevice.Viewport.Height / 2);
            exitButtonPosition = new Vector2(xDimensionPositionForMainMenuItems, GraphicsDevice.Viewport.Height / 2 + 100);

            backButtonPosition = new Vector2(xDimensionPositionForMainMenuItems + 150, GraphicsDevice.Viewport.Height - 110);
            saveButtonPosition = new Vector2(xDimensionPositionForMainMenuItems, GraphicsDevice.Viewport.Height - 110);

            lblNameButtonPosition = new Vector2(50, 130);
            lblAgeButtonPosition = new Vector2(lblNameButtonPosition.X, lblNameButtonPosition.Y + 70);
            lblQualificationButtonPosition = new Vector2(lblNameButtonPosition.X, lblAgeButtonPosition.Y + 70);

            txtNameButtonPosition = new Vector2((lblNameButtonPosition.X) + 300, lblNameButtonPosition.Y);
            txtQualificationButtonPosition = new Vector2((lblQualificationButtonPosition.X) + 300, lblQualificationButtonPosition.Y);
            txtAgeButtonPosition = new Vector2((lblAgeButtonPosition.X) + 300, lblAgeButtonPosition.Y);

            maleTexturePosition = new Vector2(txtQualificationButtonPosition.X, txtQualificationButtonPosition.Y + 70);
            femaleTexturePosition = new Vector2(txtQualificationButtonPosition.X + 150, txtQualificationButtonPosition.Y + 70);

            CursortxtNameButtonPosition = new Vector2(txtNameButtonPosition.X + 5, txtNameButtonPosition.Y);
            CursortxtQualificationButtonPosition = new Vector2(txtQualificationButtonPosition.X + 5, txtQualificationButtonPosition.Y);
            CursortxtAgeButtonPosition = new Vector2(txtAgeButtonPosition.X + 5, txtAgeButtonPosition.Y);

            PositionForBackgroundImage = new Vector2(0, 0);

            txtName = txtAge = txtQualification = "";
            base.Initialize();
        }