我需要获取一个具有一个布尔值的二维数组元素。它是唯一一个带有这个布尔值的。
public void getCurrentTile()
{
for (int x = 0; x < 75; x++)
{
for (int y = 0; y < 75; y++)
{
if (((Tile)grid[y, x]).lit)
{
current = (Tile)grid[y, x];
}
}
}
}
这是我当前的代码。它似乎无法正常工作。它仅在点亮一个瓷砖时返回电流。当另一个瓷砖被点亮时,它不会返回瓷砖。
瓷砖代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace SimMedieval
{
public class Tile
{
public int size;
public String path;
public Texture2D texture;
public bool lit = false;
public bool lightable;
MouseState mouseState;
public System.Drawing.Color color;
public int posX;
public int posY;
public Tile(int s, String texturepath, bool light)
{
size = s;
path = texturepath;
lightable = light;
}
public void load(Game game, Game1 game1, System.Drawing.Color colour)
{
color = colour;
texture = game.Content.Load<Texture2D>(path);
game1.tiles.Add(this);
}
public void render(SpriteBatch sprites,int x, int y, Camera cam, Tile[,] grid)
{
mouseState = Mouse.GetState();
float camPosX = (x * size) + cam.posX;
float camPosY = (y * size) + cam.posY;
if (-20 < camPosX && camPosX < 960 && -20 < camPosY && camPosY < 640)
{
if (new Microsoft.Xna.Framework.Rectangle(x, y, 1, 1).Contains((mouseState.X / size) - ((int)Math.Round(cam.posX) / size), (mouseState.Y / size) - ((int)Math.Round(cam.posY) / size)))
{
lit = true;
grid[y, x] = this;
sprites.Draw(texture, new Vector2((x * size) + cam.posX, (y * size) + cam.posY), Microsoft.Xna.Framework.Color.Coral);
}
else
{
lit = false;
grid[y, x] = this;
sprites.Draw(texture, new Vector2((x * size) + cam.posX, (y * size) + cam.posY), Microsoft.Xna.Framework.Color.White);
}
}
}
public void spawn(int x, int y, Tile[,] grid)
{
grid[y, x] = this;
posX = x;
posY = y;
}
}
}