本文整理汇总了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)
{
//.........这里部分代码省略.........
示例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");
}
}