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


C# Creature.move方法代码示例

本文整理汇总了C#中Creature.move方法的典型用法代码示例。如果您正苦于以下问题:C# Creature.move方法的具体用法?C# Creature.move怎么用?C# Creature.move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Creature的用法示例。


在下文中一共展示了Creature.move方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetTo

        /// <summary>
        /// Move towards a target location
        /// </summary>
        /// <param name="c">Creature to move</param>
        /// <param name="x">X or location</param>
        /// <param name="y">Y of location</param>
        /// <param name="EatInPassing">False for no. if you are on your way to attack say no to foods</param>
        /// <returns></returns>
        public static bool GetTo(Creature c, int x, int y, bool EatInPassing)
        {
            try
            {
                int Safeguard = 35;
                int Stuck = 0;
                if (EatInPassing)
                {
                    EatInPassingFn(c);
                }
                while (c.MovementLeft > 0 && Safeguard > 0)
                {
                    Safeguard--;
                    Random rand = new Random();
                    switch (rand.Next(0, 2))
                    {
                        case 0:
                            if (c.X > x)
                            {
                                if (LegalMove(c.X - 1, c.Y))
                                {
                                    c.move(c.X - 1, c.Y);
                                }
                                else
                                {
                                    Stuck++;
                                }
                            }
                            else if (c.X < x)
                            {
                                if (LegalMove(c.X + 1, c.Y))
                                {
                                    c.move(c.X + 1, c.Y);
                                }
                                else
                                {
                                    Stuck++;
                                }
                            }
                            break;
                        case 1:
                            if (c.Y > y)
                            {
                                if (LegalMove(c.X, c.Y - 1))
                                {
                                    c.move(c.X, c.Y - 1);
                                }
                                else
                                {
                                    Stuck++;
                                }
                            }
                            else if (c.Y < y)
                            {
                                if (LegalMove(c.X, c.Y + 1))
                                {
                                    c.move(c.X, c.Y + 1);
                                }
                                else
                                {
                                    Stuck++;
                                }
                            }
                            break;
                    }
                    if (EatInPassing)
                    {
                        EatInPassingFn(c);
                    }
                    if (((Math.Abs(c.X - x) == 1 && c.Y == y) || (c.X == x && Math.Abs(c.Y - y) == 1)))
                    {
                        return true;
                    }
                    if (Stuck > 4)
                    {
                        Stuck = 0;
                        UnstuckMe(c);
                    }
                }

                if (c.MovementLeft > 0)
                {
                    UnstuckMe(c);
                }
                if (c.X == x && c.Y == y)
                {
                    return true;
                }
                return false;
            }
            catch (Exception ex)
            {
//.........这里部分代码省略.........
开发者ID:austingantner,项目名称:MegaMinerAI10-Galapagos,代码行数:101,代码来源:Movement.cs

示例2: UnstuckMe

 //private static void AttackInPassingFn(Creature c)
 //{
 //    try
 //    {
 //        if (c.CanEat > 0)
 //        {
 //            if (-1 != BaseAI.getCreatureAtLocation(c.X + 1, c.Y))
 //            {
 //                c.eat(c.X + 1, c.Y);
 //            }
 //            else if (-1 != BaseAI.getCreatureAtLocation(c.X - 1, c.Y))
 //            {
 //                c.eat(c.X - 1, c.Y);
 //            }
 //            else if (-1 != BaseAI.getCreatureAtLocation(c.X, c.Y + 1))
 //            {
 //                c.eat(c.X, c.Y + 1);
 //            }
 //            else if (-1 != BaseAI.getCreatureAtLocation(c.X, c.Y - 1))
 //            {
 //                c.eat(c.X, c.Y - 1);
 //            }
 //        }
 //    }
 //    catch
 //    {
 //    }
 //}
 private static void UnstuckMe(Creature c)
 {
     try
     {
         EatInPassingFn(c);
         if (c.MovementLeft > 0)
         {
             Random rand = new Random();
             switch (rand.Next(0, 4))
             {
                 case 0:
                     if (LegalMove(c.X - 1, c.Y))
                         c.move(c.X - 1, c.Y);
                     break;
                 case 1:
                     if (LegalMove(c.X + 1, c.Y))
                         c.move(c.X + 1, c.Y);
                     break;
                 case 2:
                     if (LegalMove(c.X, c.Y - 1))
                         c.move(c.X, c.Y - 1);
                     break;
                 case 3:
                     if (LegalMove(c.X, c.Y + 1))
                         c.move(c.X, c.Y + 1);
                     break;
                 default:
                     break;
             }
         }
     }
     catch
     {
         Console.WriteLine("error in unstuckme");
     }
 }
开发者ID:austingantner,项目名称:MegaMinerAI10-Galapagos,代码行数:64,代码来源:Movement.cs


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