1 つの bool true を持つ 2D 配列の要素を取得する必要があります。このブール値を持つ唯一のものです。
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];
}
}
}
}
これが私の現在のコードです。正しく動作しないようです。1 つのタイルが点灯している場合にのみ電流を返します。別のタイルが点灯している場合、タイルは返されません。
タイルのコード:
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;
}
}
}