public Vegetable(IMatrixPosition position, char charValue, int powerBonus, int staminaBonus, int timeToGrow) : base(position, charValue) { this.PowerBonus = powerBonus; this.StaminaBonus = staminaBonus; this.TimeToGrow = timeToGrow; }
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; }
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>(); }
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(); } }
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); } } }
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) { }
public Asparagus(IMatrixPosition position) : base(position, DefaultAsparagusCharValue, DefaultAsparagusPowerBonus, DefaultAsparagusStaminaBonus, DefaultAsparagusTimeToGrow) { }
public MeloLemonMelon(IMatrixPosition position) : base(position, DefaultMeloLemonMelonCharValue, DefaultMeloLemonMelonPowerBonus, DefaultMeloLemonMelonStaminaBonus, DefaultMeloLemonMelonTimeToGrow) { }
public CherryBerry(IMatrixPosition position) : base(position, DefaultCherryBerryCharValue, DefaultCherryBerryPowerBonus, DefaultCherryBerryStaminaBonus, DefaultCherryBerryTimeToGrow) { }
public Broccoli(IMatrixPosition position) : base(position, DefaultBroccoliCharValue, DefaultBroccoliPowerBonus, DefaultBroccoliStaminaBonus, DefaultBroccoliTimeToGrow) { }
public Royal(IMatrixPosition position) : base(position, DefaultRoyalCharValue, DefaultRoyalPowerBonus, DefaultRoyalStaminaBonus, DefaultRoyalTimeToGrow) { }
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; }
protected GameObject(IMatrixPosition position, char charValue) { this.Position = position; this.CharValue = charValue; }
public void SetGameFieldObject(IMatrixPosition position, IGameObject gameObject) { this.gameField[position.PositionX][position.PositionY] = gameObject; }