Ejemplo n.º 1
0
 public void ChangeHomeTown(Creater creater)
 {
     if (creater.GetColor().Equals(this.Color))
     {
         this.Hometown   = creater;
         this.patrolDist = creater.Range;
     }
 }
Ejemplo n.º 2
0
        public Animal(Point3D position, Creater hometown) : base(position)
        {
            posit  = new Point2D(this.position, Dimention.Z);
            vector = Vector3D.Xp;

            hp     = new EnergyBar(200);
            ep     = new EnergyBar(100);
            hungry = new EnergyBar(200);
            Power  = 20;
            Armor  = 0;

            Color = hometown.GetColor();
            ChangeHomeTown(hometown);
        }
Ejemplo n.º 3
0
        // 創造一個 Mark 在 List.
        private void CreateMarkFor(Creater creater)
        {
            // 已存在:不執行.
            foreach (var e in objsForLittleMap)
            {
                if (e.creater == creater)
                {
                    return;
                }
            }

            // 不存在:加入.
            objsForLittleMap.Add(new Mark(creater));
        }
Ejemplo n.º 4
0
        // 吸收生成器.
        // false : 自己比對方弱,吸收失敗.
        private bool EatCreater(Creater creater)
        {
            if (this.Level < creater.Level)
            {
                return(false);
            }
            else if (this.Level == creater.Level && this.energy.Value < creater.energy.Value)
            {
                return(false);
            }

            energy.Add(creater.energy.Value);
            creater.energy.Set(0);
            creater.Destroy();
            return(true);
        }
Ejemplo n.º 5
0
        // 若為自己的村民,增加能量.
        // 若為敵人,減少能量.
        // 將同顏色的生物拉為自己村民.
        // 吸收比自己弱的生成器.
        // 消除石頭.
        private void UpdateByObj(MazeObject obj)
        {
            if (obj == null || obj == this)
            {
                return;
            }

            if (obj is Animal)
            {
                Animal animal = (Animal)obj;
                if (animal.Hometown == this)
                {
                    energy.Add(1);
                    ++animalsCount;
                }
                else if (!animal.Color.Equals(this.Color))
                {
                    energy.Add(-1);
                }
                else
                {
                    animal.ChangeHomeTown(this);
                }
            }
            else if (obj is Creater)
            {
                Creater creater = (Creater)obj;
                if (creater.Color.Equals(this.Color))
                {
                    EatCreater(creater);
                }
                else
                {
                    energy.Add(-creater.Level);
                }
            }
            else if (obj is Stone)
            {
                obj.Destroy();
            }
        }
Ejemplo n.º 6
0
        // 在家附近巡邏.不會離太遠.
        private void Patrol(Creater home)
        {
            Point2D  temp   = this.posit.Copy();
            Vector2D target = RandomVector(10);

            for (int i = 0; i < 4; ++i)
            {
                temp.MoveFor(target, 1);
                if (temp.DistanceTo(home.position) > patrolDist)
                {
                    temp.MoveFor(target, -1);
                    target = VectorConvert.Rotate(target);
                }
                else
                {
                    moveCommamd = Convert(target);
                    return;
                }
            }

            skillCommand = SkillCommand.None;
            patrolDist   = this.posit.DistanceTo(home.position);
        }
Ejemplo n.º 7
0
    // Use this for initialization.
    void Start()
    {
        // [遊戲素材設定]
        GlobalAsset.controller = this;

        // 物件造型.
        Maze.Animal.SetShape(new Maze.Shape(animalShapes));
        Maze.Stone.SetSprite(stoneSprite);
        Maze.Creater.SetSprite(createrSprite);
        Maze.Food.SetSprite(foodSprite);
        Maze.Wall.SetSprite(wallSprite);

        // 技能音效.
        Maze.SkillManager.attack        = punchAudio;
        Maze.SkillManager.specialAttack = otherSkillAudio;
        Maze.SkillManager.build         = buildAudio;

        // 技能造型.
        GlobalAsset.gridSprites = gridSprites;
        GlobalAsset.attack      = attack;
        GlobalAsset.straight    = straight;
        GlobalAsset.horizon     = horizon;
        GlobalAsset.create      = create;

        // 小地圖標示.
        GlobalAsset.playerMark  = playerMark;
        GlobalAsset.createrMark = createrMark;

        // UI提示框.
        GlobalAsset.positionHint = positionHint;
        GlobalAsset.hintBox      = hintBox;
        GlobalAsset.talkBox      = talkBox;


        // [遊戲地圖設定]
        // 放幾個gridSprite就生成幾層世界.
        gameMap  = new Maze.Map3D(GlobalAsset.mapSize, GlobalAsset.mapSize, gridSprites.Length);
        sceneMap = new Maze.Map2D(gameMap);
        Maze.MazeObject.SetMaze(gameMap);

        // [劇情]
        storyManager = new Story.StoryManager();


        // 在每個平面執行動作.
        for (int layer = 0; layer < Maze.MazeObject.World.Layers; ++layer)
        {
            // 創造6個不同顏色的村莊.
            for (int i = 0; i < 6; ++i)
            {
                Maze.Point3D position = gameMap.GetRandomPointOn(layer);
                Maze.Creater creater  = new Maze.Creater(position, GlobalAsset.colors[i]);

                if (gameMap.GetAt(position).InsertObj(creater))
                {
                    GlobalAsset.creaters.Add(creater);
                    creater.FullEnergy();
                    // 在每個村莊生成3隻村民.
                    creater.createAnimals(3);
                }

                else // 這個位置已經有東西了.
                {
                    --i;
                }
            }
        }

        // clock 歸零.
        timer = 0;
    }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
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();
            }
        }
Ejemplo n.º 10
0
 public Mark(Creater creater)
 {
     this.creater = creater;
     Update();
 }