示例#1
0
        // 招集附近的流浪夥伴一起蓋新家.
        private void FindNewHome()
        {
            if (this.Hometown != null)
            {
                return;
            }

            Point3D position = this.position.Copy();

            position.MoveFor(this.vector, 1);

            Grid targetGrid = World.GetAt(position);

            if (targetGrid == null || targetGrid.Obj != null)
            {
                return;
            }


            Point2D positOnPlain         = new Point2D(position, Dimention.Z);
            int     stoneCount           = 0;
            int     wallCount            = 0;
            int     animalCount          = 0;
            bool    sameColorOfAllAnimal = true;

            Iterator iter = new Iterator(positOnPlain, 2);

            do
            {
                Point2D point = iter.Iter;
                Grid    grid  = World.GetAt(point.Binded);

                if (grid == null || grid.Obj == null)
                {
                    continue;
                }

                else if (grid.Obj is Stone)
                {
                    ++stoneCount;
                }

                else if (grid.Obj is Wall)
                {
                    ++wallCount;
                }

                else if (grid.Obj is Animal && grid.Obj != this)
                {
                    Animal animal = (Animal)grid.Obj;

                    if (animal.Color.Equals(this.Color))
                    {
                        if (animal.Hometown == null)
                        {
                            ++animalCount;
                        }
                    }
                    else
                    {
                        sameColorOfAllAnimal = false;
                        break;
                    }
                }

                else if (grid.Obj is Creater)
                {
                    Creater creater = (Creater)grid.Obj;
                    this.ChangeHomeTown(creater);
                    return;
                }
            } while (iter.MoveToNext());

            if (sameColorOfAllAnimal && animalCount > 1)
            {
                Creater newHome = new Creater(position, this.Color);
                targetGrid.InsertObj(newHome);
                this.Hometown = newHome;
                GlobalAsset.creaters.Add(newHome);
            }
        }
示例#2
0
 public void ShowHintAt(Maze.Point2D position)
 {
     ShowHintAt(Maze.VectorConvert.Convert(position));
 }
示例#3
0
        // 偵測周圍 7*7 內有什麼.
        // 並選擇採取什麼模式.
        private void Survey()
        {
            Iterator iter   = new Iterator(this.posit, surveyExtra);
            Animal   animal = null;

            do
            {
                Point2D point = iter.Iter;
                Grid    grid  = World.GetAt(point.Binded);

                if (grid == null || grid.Obj == null)
                {
                    continue;
                }

                if (grid.Obj is Food && this.hungry.BarRate < 0.5f)
                {
                    FeedOn((Food)grid.Obj);
                    return;
                }

                if (grid.Obj is Animal)
                {
                    if (((Animal)(grid.Obj)).Color.Equals(this.Color))
                    {
                        animal = (Animal)grid.Obj;
                    }

                    else if (ep.BarRate > 0.3f)
                    {
                        Battle((Animal)grid.Obj);
                        return;
                    }
                }

                if (grid.Obj is Creater)
                {
                    Creater creater = (Creater)grid.Obj;
                    if (this.Hometown == null && creater.Color.Equals(this.Color))
                    {
                        this.ChangeHomeTown((Creater)grid.Obj);
                    }
                }
            } while (iter.MoveToNext());


            if (friend != null)
            {
                Follow();
            }
            else if (Hometown != null)
            {
                Patrol(Hometown);

                if (Hometown.IsDead)
                {
                    Hometown = null;
                }
            }
            else
            {
                Wander();
            }
        }