Esempio n. 1
0
        public void IncrementIterationWithoutEatingIfSquareContainsAnimal(ref Square mySquare, int tempOtherSquarePositionX, int tempOtherSquarePositionY)
        {
            MaleElephant   myMaleElephant   = new MaleElephant();
            FemaleElephant myFemaleElephant = new FemaleElephant();
            MaleLion       myMaleLion       = new MaleLion();
            FemaleLion     myFemaleLion     = new FemaleLion();
            MaleDeer       myMaleDeer       = new MaleDeer();
            FemaleDeer     myFemaleDeer     = new FemaleDeer();

            if (mySquare.GetType() == myMaleElephant.GetType() ||
                mySquare.GetType() == myFemaleElephant.GetType() ||
                mySquare.GetType() == myMaleLion.GetType() ||
                mySquare.GetType() == myFemaleLion.GetType() ||
                mySquare.GetType() == myMaleDeer.GetType() ||
                mySquare.GetType() == myFemaleDeer.GetType())
            {
                Animal animal = (Animal)mySquare;
                animal.IterationsWithoutEating++;
                if (animal.IterationsWithoutEating <= animal.StarvationPeriod)
                {
                    mySquare = animal;
                }
                else
                {
                    mySquare                    = new Square();
                    mySquare.PositionX          = tempOtherSquarePositionX;
                    mySquare.PositionY          = tempOtherSquarePositionY;
                    mySquare.IsEmpty            = true;
                    mySquare.hasIterationPassed = true;
                }
            }
        }
Esempio n. 2
0
        public bool MoveSquare(ref Square originalSquare, ref Square otherSquare, ref int retry, ref int hasTriedCounter)
        {
            Type originalSquareType = originalSquare.GetType();
            Type otherSquareType    = otherSquare.GetType();
            Type maleElephantType   = myMaleElephant.GetType();
            Type femaleElephantType = myFemaleElephant.GetType();
            Type maleLionType       = myMaleLion.GetType();
            Type femaleLionType     = myFemaleLion.GetType();
            Type maleDeerType       = myMaleDeer.GetType();
            Type femaleDeerType     = myFemaleDeer.GetType();
            Type rockType           = myRock.GetType();
            Type treeType           = myTree.GetType();
            Type plantType          = myPlant.GetType();
            Type emptySqaureType    = myEmptySquare.GetType();

            if (originalSquareType == rockType ||
                originalSquareType == treeType ||
                originalSquareType == plantType)
            {
                return(false);
            }

            if ((originalSquareType == maleElephantType ||
                 originalSquareType == femaleElephantType ||
                 originalSquareType == maleLionType ||
                 originalSquareType == femaleLionType ||
                 originalSquareType == maleDeerType ||
                 originalSquareType == femaleDeerType) &&
                (otherSquareType == emptySqaureType))
            {
                return(true);
            }

            if ((originalSquareType == maleElephantType ||
                 originalSquareType == femaleElephantType ||
                 originalSquareType == maleLionType ||
                 originalSquareType == femaleLionType ||
                 originalSquareType == maleDeerType ||
                 originalSquareType == femaleLionType) &&
                (otherSquareType == rockType))
            {
                retry--;
                if (otherSquare.hasTried == false)
                {
                    hasTriedCounter += 1;
                }
                otherSquare.hasTried = true;
                return(false);
            }

            if ((originalSquareType == maleElephantType ||
                 originalSquareType == femaleElephantType) &&
                (otherSquareType == treeType))
            {
                callEatMethodOnAnimal(ref originalSquare);
                return(true);
            }

            if ((originalSquareType == maleLionType ||
                 originalSquareType == femaleLionType ||
                 originalSquareType == maleDeerType ||
                 originalSquareType == femaleLionType) &&
                (otherSquareType == treeType))
            {
                retry--;
                if (otherSquare.hasTried == false)
                {
                    hasTriedCounter += 1;
                }
                otherSquare.hasTried = true;
                return(false);
            }

            if ((originalSquareType == maleElephantType ||
                 originalSquareType == femaleElephantType ||
                 originalSquareType == maleLionType ||
                 originalSquareType == femaleLionType) &&
                (otherSquareType == treeType))
            {
                return(true);
            }

            if ((originalSquareType == maleDeerType ||
                 originalSquareType == femaleDeerType) &&
                (otherSquareType == plantType))
            {
                callEatMethodOnAnimal(ref originalSquare);
                return(true);
            }

            if ((originalSquareType == maleElephantType ||
                 originalSquareType == femaleElephantType ||
                 originalSquareType == maleLionType ||
                 originalSquareType == femaleLionType ||
                 originalSquareType == maleDeerType ||
                 originalSquareType == femaleLionType) &&
                (otherSquareType == maleElephantType ||
                 otherSquareType == femaleElephantType))
            {
                retry--;
                if (otherSquare.hasTried == false)
                {
                    hasTriedCounter += 1;
                }
                otherSquare.hasTried = true;
                return(false);
            }

            if ((originalSquareType == maleElephantType ||
                 originalSquareType == femaleElephantType) &&
                (otherSquareType == maleLionType ||
                 otherSquareType == femaleLionType))
            {
                return(true);
            }

            if ((originalSquareType == maleLionType ||
                 originalSquareType == femaleLionType ||
                 originalSquareType == maleDeerType ||
                 originalSquareType == femaleLionType) &&
                (otherSquareType == maleLionType ||
                 otherSquareType == femaleLionType))
            {
                retry--;
                if (otherSquare.hasTried == false)
                {
                    hasTriedCounter += 1;
                }
                otherSquare.hasTried = true;
                return(false);
            }

            if ((originalSquareType == maleElephantType ||
                 originalSquareType == femaleElephantType) &&
                (otherSquareType == maleDeerType ||
                 otherSquareType == femaleDeerType))
            {
                return(true);
            }

            if ((originalSquareType == maleLionType ||
                 originalSquareType == femaleLionType) &&
                (otherSquareType == maleDeerType ||
                 otherSquareType == femaleDeerType))
            {
                callEatMethodOnAnimal(ref originalSquare);
                return(true);
            }

            if ((originalSquareType == maleLionType ||
                 originalSquareType == femaleLionType) &&
                (otherSquareType == maleDeerType ||
                 otherSquareType == femaleDeerType))
            {
                retry--;
                if (otherSquare.hasTried == false)
                {
                    hasTriedCounter += 1;
                }
                otherSquare.hasTried = true;
                return(false);
            }

            return(false);
        }