Beispiel #1
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();
        }
Beispiel #2
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();
        }
Beispiel #3
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);
        }
        /// <summary>
        /// This method creates a new baby pig, when conditions are right.
        /// There is an even chance of producing either a GirlPig or a BoyPig.
        ///
        /// They will not produce a baby if one or the other is (1) too tired,
        /// (2) not in the mood for love, (3) they are brother-and-sister, or
        /// (4) they are parent-and-child.
        /// </summary>
        public bool TryToMakeBaby(BoyPig boyFriend)
        {
            if (IsTired() || !IsInTheMoodForLove() || IsSibling(boyFriend) || IsParent(boyFriend) || boyFriend.IsParent(this))
            {
                return(false);
            }

            Position position = Cell.Position;

            if (Util.random.NextDouble() >= 0.5)
            {
                new BoyPig(this.PigWorld, position, this, boyFriend);
            }
            else
            {
                new GirlPig(this.PigWorld, position, this, boyFriend);
            }

            UseEnergy(STOMACH_EMPTY_LEVEL);
            IncreaseTiredness(5);
            Shriek();
            return(true);
        }
Beispiel #5
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)
 {
 }
Beispiel #6
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.
        }