Пример #1
0
        /// <summary>
        /// When conditions are right, the BoyPig listens for a grunting GirlPig.
        /// When one is heard, the BoyPig tries to reach that GirlPig,
        /// which will only succeed when she is in an adjacent cell.
        ///
        /// If the BoyPig reaches a GirlPig, then they try to produce a baby pig.
        ///
        /// But if no GirlPig can be reached, then the BoyPig tries to move in the direction of the sound.
        /// (If there is no sound, then the BoyPig can move in any direction.)
        ///
        /// Overrides the LookForPig method in the base class, Pig.
        /// </summary>
        protected override void LookForPig()
        {
            // Do not modify, delete, or move the debugAnimalAction line below,
            // or the Debug Info will not show correctly in the GUI, and that could be confusing.
            debugAnimalAction = "LookForPig";

            Direction direction = Listen();  // When no GirlPigs are grunting, this will be null.

            if (direction == null)
            {
                WanderAround();
            }
            else
            {
                LifeForm lifeForm = Reach(direction);  // Will be null when that direction's cell has no LifeForm occupant.

                if (lifeForm is GirlPig)
                {
                    GirlPig girl = (GirlPig)lifeForm;
                    if (!IsTired() && IsInTheMoodForLove())
                    {
                        girl.TryToMakeBaby(this);
                        UseEnergy(STOMACH_EMPTY_LEVEL);
                        IncreaseTiredness(5);
                    }
                }
                else
                {
                    Move(direction);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Constructs a new Pig at, or near, the specified position.
        /// If the desired position is already occupied by another LifeForm,
        /// then the pig will be placed in a nearby Cell.
        /// If no nearby Cells are free, then the pig will not be added to the pigWorld.
        ///
        /// This constructor is protected since only Pig subclasses should be
        /// able to create a pig.
        /// </summary>
        /// <param name="pigWorld"> the pigWorld that this pig is entering </param>
        /// <param name="position"> the preferred position for the new pig </param>
        /// <param name="color"> the pig's colour (blue or pink) </param>
        /// <param name="mother"> the pig's mother (may be null)</param>
        /// <param name="father"> the pig's father (may be null)</param>
        protected Pig(PigWorld pigWorld, Position position, Color color, GirlPig mother, BoyPig father)
        {
            this.color  = color; // Must be set before AddToWorld is called.
            this.mother = mother;
            this.father = father;

            AddToWorld(pigWorld, position);  // Must be called before any sounds are played.
        }
Пример #3
0
        /// <summary>
        /// Set-up the second demo, by adding various objects (and walls) to PigWorld.
        /// </summary>
        public void SetupDemo2()
        {
            BoyPig  boyPig  = new BoyPig(PigWorld, new Position(0, 0));
            GirlPig girlPig = new GirlPig(PigWorld, new Position(2, 0));

            Tree tree1 = new Tree(PigWorld, new Position(0, 4));
            Tree tree2 = new Tree(PigWorld, new Position(7, 5));

            Wolf wolf = new Wolf(PigWorld, new Position(8, 8));

            PigFood pigFood1 = new PigFood(PigWorld, new Position(0, 5));
            PigFood pigFood2 = new PigFood(PigWorld, new Position(3, 3));
            PigFood pigFood3 = new PigFood(PigWorld, new Position(6, 0));

            CreateDemoWalls();
        }
Пример #4
0
        /// <summary>
        /// Set-up the first demo, by adding various objects (and walls) to PigWorld.
        /// </summary>
        public void SetupDemo1()
        {
            BoyPig  boyPig  = new BoyPig(PigWorld, new Position(5, 2));
            GirlPig girlPig = new GirlPig(PigWorld, new Position(7, 7));

            PigFood pigFood1  = new PigFood(PigWorld, new Position(1, 1));
            PigFood pigFood2  = new PigFood(PigWorld, new Position(1, 5));
            PigFood pigFood3  = new PigFood(PigWorld, new Position(2, 2));
            PigFood pigFood4  = new PigFood(PigWorld, new Position(2, 5));
            PigFood pigFood5  = new PigFood(PigWorld, new Position(3, 3));
            PigFood pigFood6  = new PigFood(PigWorld, new Position(3, 4));
            PigFood pigFood7  = new PigFood(PigWorld, new Position(3, 5));
            PigFood pigFood8  = new PigFood(PigWorld, new Position(4, 4));
            PigFood pigFood9  = new PigFood(PigWorld, new Position(4, 5));
            PigFood pigFood10 = new PigFood(PigWorld, new Position(5, 4));
            PigFood pigFood11 = new PigFood(PigWorld, new Position(5, 5));

            CreateDemoWalls();
        }
Пример #5
0
        /// <summary>
        /// Set-up the third demo, by adding various objects (and walls) to PigWorld.
        /// </summary>
        public void SetupDemo3()
        {
            BoyPig  boyPig  = new BoyPig(PigWorld, new Position(4, 3));
            GirlPig girlPig = new GirlPig(PigWorld, new Position(4, 5));

            Tree tree1 = new Tree(PigWorld, new Position(0, 4));
            Tree tree2 = new Tree(PigWorld, new Position(4, 4));
            Tree tree3 = new Tree(PigWorld, new Position(8, 4));

            Wolf wolf = new Wolf(PigWorld, new Position(0, 0));

            PigFood pigFood1 = new PigFood(PigWorld, new Position(8, 0));
            PigFood pigFood2 = new PigFood(PigWorld, new Position(8, 1));
            PigFood pigFood3 = new PigFood(PigWorld, new Position(7, 0));
            PigFood pigFood4 = new PigFood(PigWorld, new Position(1, 8));
            PigFood pigFood5 = new PigFood(PigWorld, new Position(0, 8));
            PigFood pigFood6 = new PigFood(PigWorld, new Position(0, 7));

            PigWorld.FillVerticalGap(2, 5);
            PigWorld.FillVerticalGap(3, 1);
            PigWorld.FillVerticalGap(3, 6);
            PigWorld.FillVerticalGap(4, 1);
            PigWorld.FillVerticalGap(4, 6);
            PigWorld.FillVerticalGap(5, 1);
            PigWorld.FillVerticalGap(5, 6);
            PigWorld.FillVerticalGap(6, 2);

            PigWorld.FillHorizontalGap(1, 3);
            PigWorld.FillHorizontalGap(1, 4);
            PigWorld.FillHorizontalGap(1, 5);
            PigWorld.FillHorizontalGap(3, 1);
            PigWorld.FillHorizontalGap(3, 7);
            PigWorld.FillHorizontalGap(4, 0);
            PigWorld.FillHorizontalGap(4, 8);
            PigWorld.FillHorizontalGap(6, 3);
            PigWorld.FillHorizontalGap(6, 4);
            PigWorld.FillHorizontalGap(6, 5);
        }
Пример #6
0
 /// <summary>
 /// Constructs a new BoyPig at, or near, the specified position.
 /// If the desired position is already occupied by another LifeForm,
 /// then the pig will be placed in a nearby Cell.
 /// If no nearby Cells are free, then the pig will not be added to the pigWorld.
 /// </summary>
 /// <param name="pigWorld"> the pigWorld that this pig is entering </param>
 /// <param name="position"> the preferred position for the new pig </param>
 /// <param name="color"> the pig's colour (blue or pink) </param>
 /// <param name="mother"> the pig's mother (may be null)</param>
 /// <param name="father"> the pig's father (may be null)</param>
 public BoyPig(PigWorld pigWorld, Position position, GirlPig mother, BoyPig father)
     : base(pigWorld, position, BOY_COLOR, mother, father)
 {
 }