我有这个类,它包含一个查看对象的方法:
internal class Game
{
private IEnumerable<Tuple<int, int>> PositionsInReach(int row, int column, int distance)
{
var visited = new bool[park.GetLength(0),park.GetLength(1)];
visited[row, column] = true;
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(row,column));
while (queue.Count!=0)
{
var aux = queue.Dequeue();
yield return aux;
foreach (var adjacentPosition in AdjacentPositions(aux.Item1,aux.Item2))
{
if (!visited[adjacentPosition.Item1, adjacentPosition.Item2]
&& Distance(row,column,aux.Item1,aux.Item2) <= distance)
{
queue.Enqueue(adjacentPosition);
visited[adjacentPosition.Item1, adjacentPosition.Item2] = true;
}
}
}
}
private IEnumerable<Tuple<int, int>> AdjacentPositions(int row, int col)
{
if(row+1 < park.GetLength(0)) yield return new Tuple<int,int>(row + 1, col);
if(row-1 >=0 ) yield return new Tuple<int,int>(row - 1, col);
if(col+1 < park.GetLength(1)) yield return new Tuple<int,int>(row , col + 1);
if(col - 1 >= 0) yield return new Tuple<int, int>(row , col - 1);
}
private static int Distance(int x1, int y1, int x2, int y2)
{
return Math.Abs(x2 - x1) + Math.Abs(y2 - y1);
}
private IEnumerable<Tuple<int, int>> PositionsInReach2(int row, int column, int distance) //actionrange
{
var visited = new bool[park.GetLength(0), park.GetLength(1)];
visited[row, column] = true;
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(row, column));
while (queue.Count != 0)
{
var aux = queue.Dequeue();
yield return aux;
foreach (var adjacentPosition in AdjacentPositions(aux.Item1, aux.Item2))
{
if (!visited[adjacentPosition.Item1, adjacentPosition.Item2]
&& Distance(row, column, aux.Item1, aux.Item2) <= distance && park[adjacentPosition.Item1,adjacentPosition.Item2]==null)
{
queue.Enqueue(adjacentPosition);
visited[adjacentPosition.Item1, adjacentPosition.Item2] = true;
}
}
}
}
}
所以我需要在其他名为 Behaviour 的类中使用这些方法:
public class EatingBehaviour
{
public static bool ToEat1(Dinosaur dino, int x, int y, LivingThing[,] park)
{
if (dino.Weight < dino.MiddleWeight /*&& Dinosaur in action range, I need use the methods of the class Game here*/)
{
return true;
}
return false;
}
}
我怎样才能做到这一点???