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);
}
errMsgvariable 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:56break) when the tile that intsects the mouse position was found... – bummzack Oct 5 '12 at 18:04if else. It's a logical error with the code. – Byte56 Oct 5 '12 at 18:40