Esempio n. 1
0
 public Vegetable(IMatrixPosition position, char charValue, int powerBonus, int staminaBonus, int timeToGrow)
     : base(position, charValue)
 {
     this.PowerBonus   = powerBonus;
     this.StaminaBonus = staminaBonus;
     this.TimeToGrow   = timeToGrow;
 }
Esempio n. 2
0
        private IMatrixPosition GetNewPosition(IMatrixPosition oldPosition, char direction)
        {
            switch (direction)
            {
            case 'U':
                if (!this.ValidateCoordinates(oldPosition.PositionX - 1, oldPosition.PositionY))
                {
                    break;
                }
                return(new MatrixPosition(oldPosition.PositionX - 1, oldPosition.PositionY));

            case 'R':
                if (!this.ValidateCoordinates(oldPosition.PositionX, oldPosition.PositionY + 1))
                {
                    break;
                }
                return(new MatrixPosition(oldPosition.PositionX, oldPosition.PositionY + 1));

            case 'D':
                if (!this.ValidateCoordinates(oldPosition.PositionX + 1, oldPosition.PositionY))
                {
                    break;
                }
                return(new MatrixPosition(oldPosition.PositionX + 1, oldPosition.PositionY));

            case 'L':
                if (!this.ValidateCoordinates(oldPosition.PositionX, oldPosition.PositionY - 1))
                {
                    break;
                }
                return(new MatrixPosition(oldPosition.PositionX, oldPosition.PositionY - 1));
            }

            return(null);
        }
 protected Vegetable(IMatrixPosition position, char charValue, int powerBonus, int staminaBonus, int timeToGrow)
     : base(position, charValue)
 {
     this.PowerBonus = powerBonus;
     this.StaminaBonus = staminaBonus;
     this.TimeToGrow = timeToGrow;
 }
Esempio n. 4
0
        public void ProcessInput(string inputLine)
        {
            foreach (var direction in inputLine)
            {
                IMatrixPosition newPosition = this.GetNewPosition(this.currentNinja.Position, direction);

                if (newPosition == null)
                {
                    this.currentNinja.Move(newPosition);
                }
                else
                {
                    this.ProcessMove(newPosition);
                }

                if (this.winnerNinja != null)
                {
                    return;
                }

                if (this.currentNinja.Stamina == 0)
                {
                    this.currentNinja.EatVegetable();
                    this.SwitchPlayer();
                }

                this.GrowVegetable();
            }
        }
 public Ninja(IMatrixPosition position, string name)
     : base(position, name[0])
 {
     this.Name = name;
     this.Power = 1;
     this.Stamina = 1;
     this.collectedVegetables = new List<IVegetable>();
 }
Esempio n. 6
0
 public Ninja(IMatrixPosition position, string name)
     : base(position, name[0])
 {
     this.Name                = name;
     this.Power               = 1;
     this.Stamina             = 1;
     this.collectedVegetables = new List <IVegetable>();
 }
        public void Move(IMatrixPosition newPosition)
        {
            if (newPosition == null)
            {
                this.Stamina--;
                return;
            }

            this.Position = newPosition;
            this.Stamina--;
        }
        private void ProcessMove(IMatrixPosition newPosition)
        {
            IMatrixPosition oldNinjaPosition = this.currentNinja.Position;
            this.currentNinja.Move(newPosition);

            if (
                this.Database.Vegetables.Any(
                    veg =>
                    veg.Position.Equals(newPosition)))
            {
                IVegetable currentVegetable =
                    this.Database.Vegetables.First(
                        veg =>
                    veg.Position.Equals(newPosition));

                this.Database.RemoveVegetable(currentVegetable);
                this.currentNinja.CollectVegetable(currentVegetable);
                
                IBlankSpace newBlankSpace = new BlankSpace(
                    this.currentNinja.Position,
                    currentVegetable.TimeToGrow,
                    (VegetableType)Enum.Parse(typeof(VegetableType), currentVegetable.GetType().Name));

                this.Database.AddGrowingVegetable(newBlankSpace);

                IBlankSpace oldFieldPositionElement = new BlankSpace(oldNinjaPosition, -1, VegetableType.Blank);

                if (
                    this.Database.GrowingVegetables.Any(
                        growingVegetable =>
                        growingVegetable.Position.Equals(oldNinjaPosition)))
                {
                    oldFieldPositionElement =
                        this.Database.GrowingVegetables.First(
                            growingVegetable =>
                            growingVegetable.Position.Equals(oldNinjaPosition));
                }

                this.Database.SetGameFieldObject(oldNinjaPosition, oldFieldPositionElement);
                this.Database.SetGameFieldObject(this.currentNinja.Position, this.currentNinja);
                return;
            }

            INinja otherNinja = this.Database.GetOtherPlayer(this.currentNinja.Name);

            if (this.currentNinja.Position.Equals(otherNinja.Position))
            {
                this.Fight();
            }
        }
Esempio n. 9
0
        private void GrowVegetable()
        {
            foreach (var growingVegetable in this.Database.GrowingVegetables)
            {
                if (!this.Database.Ninjas.Any(ninja =>
                                              ninja.Position.Equals(growingVegetable.Position)))
                {
                    growingVegetable.Grow();
                }

                if (growingVegetable.GrowthTime == 0)
                {
                    IVegetable      newVegetable = null;
                    IMatrixPosition position     = growingVegetable.Position;

                    switch (growingVegetable.VegetableHolder)
                    {
                    case VegetableType.Asparagus:
                        newVegetable = new Asparagus(position);
                        break;

                    case VegetableType.Broccoli:
                        newVegetable = new Broccoli(position);
                        break;

                    case VegetableType.CherryBerry:
                        newVegetable = new CherryBerry(position);
                        break;

                    case VegetableType.Mushroom:
                        newVegetable = new Mushroom(position);
                        break;

                    case VegetableType.Royal:
                        newVegetable = new Royal(position);
                        break;
                    }

                    this.Database.AddVegetable(newVegetable);
                    this.Database.SetGameFieldObject(growingVegetable.Position, newVegetable);
                }
            }
        }
Esempio n. 10
0
        private void ProcessMove(IMatrixPosition newPosition)
        {
            IMatrixPosition oldNinjaPosition = this.currentNinja.Position;

            this.currentNinja.Move(newPosition);

            if (this.Database.Vegetables.Any(veg => veg.Position.Equals(newPosition)))
            {
                IVegetable currentVegetable = this.Database.Vegetables.First(veg => veg.Position.Equals(newPosition));

                this.Database.RemoveVegetable(currentVegetable);
                this.currentNinja.CollectVegetable(currentVegetable);

                IBlankSpace newBlankSpace = new BlankSpace(this.currentNinja.Position,
                                                           currentVegetable.TimeToGrow,
                                                           (VegetableType)Enum.Parse(typeof(VegetableType), currentVegetable.GetType().Name));

                this.Database.AddGrowingVegetable(newBlankSpace);

                IBlankSpace oldFieldPositionElement = new BlankSpace(oldNinjaPosition, -1, VegetableType.Blank);

                if (this.Database.GrowingVegetables.Any(growingVegetable => growingVegetable.Position.Equals(oldNinjaPosition)))
                {
                    oldFieldPositionElement = this.Database.GrowingVegetables.First(growingVegetable =>
                                                                                    growingVegetable.Position.Equals(oldNinjaPosition));
                }

                this.Database.SetGameFieldObject(oldNinjaPosition, oldFieldPositionElement);
                this.Database.SetGameFieldObject(this.currentNinja.Position, this.currentNinja);
                return;
            }

            INinja otherNinja = this.Database.GetOtherPlayer(this.currentNinja.Name);

            if (this.currentNinja.Position.Equals(otherNinja.Position))
            {
                this.Fight();
            }
        }
 public Mushroom(IMatrixPosition position)
     : base(position, DefaultMushroomCharValue, DefaultMushroomPowerBonus, DefaultMushroomStaminaBonus, DefaultMushroomTimeToGrow)
 {
 }
Esempio n. 12
0
 public Asparagus(IMatrixPosition position)
     : base(position, DefaultAsparagusCharValue, DefaultAsparagusPowerBonus, DefaultAsparagusStaminaBonus, DefaultAsparagusTimeToGrow)
 {
 }
 public MeloLemonMelon(IMatrixPosition position)
     : base(position, DefaultMeloLemonMelonCharValue, DefaultMeloLemonMelonPowerBonus, DefaultMeloLemonMelonStaminaBonus, DefaultMeloLemonMelonTimeToGrow)
 {
 }
Esempio n. 14
0
 public CherryBerry(IMatrixPosition position)
     : base(position, DefaultCherryBerryCharValue, DefaultCherryBerryPowerBonus, DefaultCherryBerryStaminaBonus, DefaultCherryBerryTimeToGrow)
 {
 }
Esempio n. 15
0
 public Broccoli(IMatrixPosition position)
     : base(position, DefaultBroccoliCharValue, DefaultBroccoliPowerBonus, DefaultBroccoliStaminaBonus, DefaultBroccoliTimeToGrow)
 {
 }
Esempio n. 16
0
 public Royal(IMatrixPosition position)
     : base(position, DefaultRoyalCharValue, DefaultRoyalPowerBonus, DefaultRoyalStaminaBonus, DefaultRoyalTimeToGrow)
 {
 }
 public Broccoli(IMatrixPosition position)
     : base(position, DefaultBroccoliCharValue, DefaultBroccoliPowerBonus, DefaultBroccoliStaminaBonus, DefaultBroccoliTimeToGrow)
 {
 }
Esempio n. 18
0
 public Mushroom(IMatrixPosition position)
     : base(position, DefaultMushroomCharValue, DefaultMushroomPowerBonus, DefaultMushroomStaminaBonus, DefaultMushroomTimeToGrow)
 {
 }
Esempio n. 19
0
 public BlankSpace(IMatrixPosition position, int growthTime, VegetableType vegetableType)
     : base(position, DefaultBlankSpaceCharValue)
 {
     this.GrowthTime      = growthTime;
     this.VegetableHolder = vegetableType;
 }
        private IMatrixPosition GetNewPosition(IMatrixPosition oldPosition, char direction)
        {
            switch (direction)
            {
                case 'U':
                    if (!this.ValidateCoordinate(oldPosition.PositionX - 1, oldPosition.PositionY))
                    {
                        break;
                    }

                    return new MatrixPosition(oldPosition.PositionX - 1, oldPosition.PositionY);
                case 'R':
                    if (!this.ValidateCoordinate(oldPosition.PositionX, oldPosition.PositionY + 1))
                    {
                        break;
                    }

                    return new MatrixPosition(oldPosition.PositionX, oldPosition.PositionY + 1);
                case 'D':
                    if (!this.ValidateCoordinate(oldPosition.PositionX + 1, oldPosition.PositionY))
                    {
                        break;
                    }

                    return new MatrixPosition(oldPosition.PositionX + 1, oldPosition.PositionY);
                case 'L':
                    if (!this.ValidateCoordinate(oldPosition.PositionX, oldPosition.PositionY - 1))
                    {
                        break;
                    }

                    return new MatrixPosition(oldPosition.PositionX, oldPosition.PositionY - 1);
            }

            return null;
        }
 public bool Equals(IMatrixPosition other)
 {
     return this.PositionX == other.PositionX && this.PositionY == other.PositionY;
 }
Esempio n. 22
0
 protected GameObject(IMatrixPosition position, char charValue)
 {
     this.Position  = position;
     this.CharValue = charValue;
 }
 public CherryBerry(IMatrixPosition position)
     : base(position, DefaultCherryBerryCharValue, DefaultCherryBerryPowerBonus, DefaultCherryBerryStaminaBonus, DefaultCherryBerryTimeToGrow)
 {
 }
 public Royal(IMatrixPosition position)
     : base(position, DefaultRoyalCharValue, DefaultRoyalPowerBonus, DefaultRoyalStaminaBonus, DefaultRoyalTimeToGrow)
 {
 }
Esempio n. 25
0
 public void SetGameFieldObject(IMatrixPosition position, IGameObject gameObject)
 {
     this.gameField[position.PositionX][position.PositionY] = gameObject;
 }
 public Asparagus(IMatrixPosition position)
     : base(position, DefaultAsparagusCharValue, DefaultAsparagusPowerBonus, DefaultAsparagusStaminaBonus, DefaultAsparagusTimeToGrow)
 {
 }
Esempio n. 27
0
 public MeloLemonMelon(IMatrixPosition position)
     : base(position, DefaultMeloLemonMelonCharValue, DefaultMeloLemonMelonPowerBonus, DefaultMeloLemonMelonStaminaBonus, DefaultMeloLemonMelonTimeToGrow)
 {
 }
 public void SetGameFieldObject(IMatrixPosition position, IGameObject gameObject)
 {
     this.gameField[position.PositionX][position.PositionY] = gameObject;
 }