本文整理汇总了C#中Room.hasNeighbor方法的典型用法代码示例。如果您正苦于以下问题:C# Room.hasNeighbor方法的具体用法?C# Room.hasNeighbor怎么用?C# Room.hasNeighbor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Room
的用法示例。
在下文中一共展示了Room.hasNeighbor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: testNeighbors
public void testNeighbors(Room rm1, Room rm2)
{
Debug.Write("testNeighbors :");
if (rm1.hasNeighbor(rm2) && rm2.hasNeighbor(rm1))
{
Debug.Write("Room " + rm1.id + " and Room " + rm2.id + " are neighbors");
}
else
{
if(!(rm1.hasNeighbor(rm2)))
Debug.Write("Room " + rm1.id + " is not connected to Room " + rm2.id + ".");
if(!(rm2.hasNeighbor(rm1)))
Debug.Write("Room " + rm2.id + " is not connected to Room " + rm1.id + ".");
}
Debug.Write("\n");
}
示例2: fly
public void fly(List<Room> path, Room current, Wumpus target)
{
//Random rand = new Random();
location = current;
location.addOccupant(this);
int flightLength = 0;
//TODO: this is ugly, clean up later
foreach (Room room in path){ //check current length of flight
if (flightLength < maxFlight){
if (location.hasOccupant(target)){
target.die();
//Console.WriteLine("Aha! You got the Wumpus!");
return;
}
//check if rooms are connected
if (location.hasNeighbor(room)){
move(room);
}
else{
//Console.WriteLine("Room " + (location.id + 1) + " is not neighbors with Room " +
// (room.id + 1) + "! Picking another room...");
int i = Random.Range(0, location.neighbors.Count - 1);
move(location.neighbors[i]);
}
if (location == current){
//Console.WriteLine("Ouch! The arrow got you!");
break;
}
flightLength++;
}
}
//Console.WriteLine("Missed!");
target.wake(); //wake the wumpus if you miss
used = true;
}