Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am developing chess like game and i wanted to show error message if user try to place any player inside the box which is not empty. For example in certain place if there is empty then the object(2d object) is placed else it should show error message. However in my program it is showing message everytime i.e when i place object on empty place then also it is showing error message. Please see the below code:

    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

        for (int i = 0; i < 25; i++)
        {
            MouseState mouseState;
            mouseDiBack = false;
            mouseState = Mouse.GetState();

            if (new Rectangle(mouseState.X, mouseState.Y, 1, 1).Intersects(rect_arr[i]))
            {
                background_color_arr[i] = Color.Red;                   

            }
            else
            {
                background_color_arr[i] = Color.White;

            }

            if (new Rectangle(mouseState.X, mouseState.Y, 1, 1).Intersects(rect_arr[i]) && (mouseState.LeftButton == ButtonState.Pressed))
            {                   

                if (boxes[i] != "goat" && boxes[i] != "tiger")
                {
                    place = i;
                    if (turn == "goat")
                    {
                        boxes[i] = "goat";
                        turn = "tiger";
                    }
                    else
                    {
                        boxes[i] = "tiger";
                        turn = "goat";
                    }
                }
                else {
                    errMsg = "This " + i + " block is not empty to place " + turn + ". Please select empty block!!";
                }

            }               
        }



        base.Update(gameTime);
    }
share|improve this question
2  
This site is not the place for such localized questions. See the FAQ about what types of questions to ask here. You may want to consider clearing your errMsg variable on success. Step through your code with the debugger and you'll find that you're setting the error message every time. – Byte56 Oct 5 '12 at 17:56
@Byte56 I have debugged many times and i have placed 2 different situations on if else conditions eventhough its not working properly so i have asked here. – user1090751 Oct 5 '12 at 18:00
1  
@user1090751 I'm pretty sure you didn't debug, otherwise you would have noticed that you need to exit your for loop (using break) when the tile that intsects the mouse position was found... – bummzack Oct 5 '12 at 18:04
1  
@ChewyGumball Regardless of the issue here, it's too localized for the site. This is a specific problem with the OPs code. What the problem is doesn't actually matter. It's certainly not C# having a bug in their implementation of if else. It's a logical error with the code. – Byte56 Oct 5 '12 at 18:40
1  
So, based on that question, I say this is a "here's what I'm trying to do but not getting the expected result" question. Since I can't find any actual logical flaws aside from the non obvious one I stated above, and we don't have the whole program to put this function into context, I don't think we can judge this user's programming abilities well enough to discard this question as a fundamental misunderstanding/not knowing how to code. It would seem you disagree, and the votes on this question show that. Perhaps a rename/edit is needed, to make this question/answer useful to others. – Chewy Gumball Oct 5 '12 at 19:08
show 10 more comments

closed as too localized by Byte56, bummzack, Tetrad Oct 5 '12 at 20:34

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

Browse other questions tagged or ask your own question.