当前位置: 首页>>代码示例>>C#>>正文


C# Room.hasNeighbor方法代码示例

本文整理汇总了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");
 }
开发者ID:imperialsoup,项目名称:HuntTheWumpus,代码行数:16,代码来源:TestRoom.cs

示例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;
    }
开发者ID:imperialsoup,项目名称:HuntTheWumpus_3D,代码行数:36,代码来源:Arrow.cs


注:本文中的Room.hasNeighbor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。