Ejemplo n.º 1
0
 private void ApplyVegatables(INinja ninja)
 {
     foreach (var item in ninja.Vegetables)
     {
         item.VegetableEffect(ninja);
     }
 }
Ejemplo n.º 2
0
        private void AddVegetable(char possibleVegetable, INinja player)
        {
            switch (possibleVegetable)
            {
            case 'A':
                player.Vegetables.Add(new Asparagus());
                break;

            case 'B':
                player.Vegetables.Add(new Broccoli());
                break;

            case 'C':
                player.Vegetables.Add(new CherryBerry());;
                break;

            case 'M':
                player.Vegetables.Add(new Mushroom());
                break;

            case 'R':
                player.Vegetables.Add(new Royal());
                break;
            }
        }
Ejemplo n.º 3
0
 private void PrintWinner(INinja winner)
 {
     this.writer.Print(String.Format("Winner: {0}", winner.Name));
     this.writer.Print(String.Format("Power: {0}", winner.Power));
     this.writer.Print(String.Format("Stamina: {0}", winner.Stamina));
     Environment.Exit(0);
 }
Ejemplo n.º 4
0
 private void AttachEvents()
 {
     foreach (var ninja in this.Database.Ninjas)
     {
         INinja currentEventNinja = ninja;
         currentEventNinja.MeloLemonMelonEaten += this.ApplyMeloLemonMelon;
     }
 }
Ejemplo n.º 5
0
 public void AddNinjas(INinja ninja)
 {
     if (ninja == null)
     {
         throw new ArgumentNullException("ninja cannot be null");
     }
     this.ninjas.Add(ninja);
 }
Ejemplo n.º 6
0
 public override void VegetableEffect(INinja ninja)
 {
     ninja.Power += increasePower;
     if (ninja.Stamina - reduceStamina < 0)
     {
         ninja.Stamina = 0;
     }
     else
     {
         ninja.Stamina -= reduceStamina;
     }
 }
Ejemplo n.º 7
0
        private void ApplyMeloLemonMelon(INinja givenNinja, EventArgs args)
        {
            var enemies = this.Database.Ninjas.Where(ninja => !ninja.Equals(givenNinja));

            foreach (var enemy in enemies)
            {
                for (int i = 0; i < 5; i++)
                {
                    IVegetable mushroom = new Mushroom(new MatrixPosition(0, 0));
                    enemy.CollectVegetable(mushroom);
                }

                enemy.EatVegetable();
            }
        }
Ejemplo n.º 8
0
 public override void VegetableEffect(INinja ninja)
 {
     if (ninja.Power - powerReduce < 0)
     {
         ninja.Power = 0;
     }
     else
     {
         ninja.Power -= powerReduce;
     }
     if (ninja.Stamina - staminaReduce < 0)
     {
         ninja.Stamina = 0;
     }
     else
     {
         ninja.Stamina -= staminaReduce;
     }
 }
Ejemplo n.º 9
0
        private void CheckIfFoundOtherPlayer(INinja attacker)
        {
            INinja attackerNinja         = attacker;
            var    findingDefendingNinja = this.data.Ninjas.Where(x => x.Name != attackerNinja.Name);
            INinja defenderNinja         = findingDefendingNinja.First();

            if (attackerNinja.RowPositionField == defenderNinja.RowPositionField && attackerNinja.ColPositionFIeld == defenderNinja.ColPositionFIeld)
            {
                if (attackerNinja.Power == defenderNinja.Power)
                {
                    PrintWinner(attackerNinja);
                }
                else if (attackerNinja.Power > defenderNinja.Power)
                {
                    PrintWinner(attackerNinja);
                }
                else if (attackerNinja.Power < defenderNinja.Power)
                {
                    PrintWinner(defenderNinja);
                }
            }
        }
Ejemplo 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();
            }
        }
Ejemplo n.º 11
0
        private void MoveLeft(INinja player)
        {
            if (player.Stamina - 1 < 0)
            {
                player.Stamina = 0;
            }
            else
            {
                player.Stamina -= 1;
            }
            player.ColPositionFIeld -= 1;
            if (player.ColPositionFIeld < 0)
            {
                player.ColPositionFIeld = 0;
            }
            this.CheckIfFoundOtherPlayer(player);
            int  row = player.RowPositionField;
            int  col = player.ColPositionFIeld;
            char possibleVegetable = this.data.Fields.First().GameField[row][col];

            this.AddVegetable(possibleVegetable, player);
        }
Ejemplo n.º 12
0
        private void ExecuteCommand(char input, INinja player)
        {
            switch (input)
            {
            case 'U':
                this.MoveUp(player);
                break;

            case 'D':
                this.MoveDown(player);
                break;

            case 'L':
                this.MoveLeft(player);
                break;

            case 'R':
                this.MoveRight(player);
                break;

            default:
                throw new ArgumentException("Unknown Command");
            }
        }
 public override void VegetableEffect(INinja ninja)
 {
     ninja.Stamina += increseStamina;
 }
Ejemplo n.º 14
0
 private void SwitchPlayer()
 {
     this.currentNinja = this.Database.GetOtherPlayer(this.currentNinja.Name);
 }
Ejemplo n.º 15
0
        public void SeedField(IList <string> inputMatrix, string firstNinjaName, string secondNinjaName)
        {
            for (int i = 0; i < inputMatrix.Count; i++)
            {
                List <IGameObject> currentRow = new List <IGameObject>();

                string currentInputRow = inputMatrix[i];

                for (int j = 0; j < currentInputRow.Length; j++)
                {
                    char currentElement = currentInputRow[j];

                    IVegetable      newVegetable   = null;
                    IBlankSpace     newBlanckSpace = null;
                    INinja          newNinja       = null;
                    IMatrixPosition position       = new MatrixPosition(i, j);

                    switch (currentElement)
                    {
                    case 'A':
                        newVegetable = new Asparagus(position);
                        break;

                    case 'B':
                        newVegetable = new Broccoli(position);
                        break;

                    case 'C':
                        newVegetable = new CherryBerry(position);
                        break;

                    case 'M':
                        newVegetable = new Mushroom(position);
                        break;

                    case 'R':
                        newVegetable = new Royal(position);
                        break;

                    case '*':
                        newVegetable = new MeloLemonMelon(position);
                        break;

                    case '-':
                        newBlanckSpace = new BlankSpace(position, -1, VegetableType.Blank);
                        break;
                    }

                    if (currentElement.Equals(firstNinjaName[0]))
                    {
                        newNinja = new Ninja(position, firstNinjaName);
                    }

                    if (currentElement.Equals(secondNinjaName[0]))
                    {
                        newNinja = new Ninja(position, secondNinjaName);
                    }

                    if (newVegetable != null)
                    {
                        this.AddVegetable(newVegetable);
                        currentRow.Add(newVegetable);
                    }

                    if (newNinja != null)
                    {
                        this.AddNinja(newNinja);
                        currentRow.Add(newNinja);
                    }

                    if (newBlanckSpace != null)
                    {
                        currentRow.Add(newBlanckSpace);
                    }
                }

                this.gameField.Add(currentRow);
            }
        }
 public GameController(IDatabase database)
 {
     this.database = database;
     this.winnerNinja = null;
 }
 private void SwitchPlayer()
 {
     this.currentNinja = this.Database.GetOtherPlayer(this.currentNinja.Name);
 }
Ejemplo n.º 18
0
 public override void VegetableEffect(INinja ninja)
 {
     ninja.Power   += increasePower;
     ninja.Stamina += increaseStamina;
 }
 public void InitialiseGameData(string firstNinjaName)
 {
     this.currentNinja = this.Database.Ninjas.First(ninja => ninja.Name.Equals(firstNinjaName));
     this.AttachEvents();
 }
Ejemplo n.º 20
0
 public GameController(IDatabase database)
 {
     this.database    = database;
     this.winnerNinja = null;
 }
Ejemplo n.º 21
0
        public void Run()
        {
            //Reading Players
            for (int i = 0; i < 2; i++)
            {
                string input  = this.reader.ReadLine();
                INinja player = this.ninjaFactory.CreateNinja(input);
                this.data.AddNinjas(player);
            }

            //Reading Field
            string[] fieldRowCol = this.reader.ReadLine().Split();
            int      fieldRow    = int.Parse(fieldRowCol[0]);
            int      fieldCol    = int.Parse(fieldRowCol[1]);
            IField   field       = this.fieldFactory.CreateField(fieldRow, fieldCol);

            this.data.AddFIeld(field);

            //FindingPostionsInField
            this.FindingPostionInField();

            //Reading Moves
            while (true)
            {
                char[] input = this.reader.ReadLine().ToCharArray();
                for (int i = 0; i < input.Length; i++)
                {
                    if (this.data.Ninjas.First().Stamina == 0)
                    {
                        this.data.Ninjas.First().Stamina = 1;
                    }
                    if (this.data.Ninjas.First().Stamina > 0)
                    {
done:
                        if (i == input.Length)
                        {
                            break;
                        }
                        this.ExecuteCommand(input[i], this.data.Ninjas.First());
                        if (this.data.Ninjas.First().Stamina > 0)
                        {
                            i++;
                            goto done;
                        }
                        this.ApplyVegatables(this.data.Ninjas.First());
                        this.data.Ninjas.First().Vegetables.Clear();
                        i++;
                    }

                    if (this.data.Ninjas.Last().Stamina == 0)
                    {
                        this.data.Ninjas.Last().Stamina = 1;
                    }
                    if (this.data.Ninjas.Last().Stamina > 0)
                    {
done2:
                        if (i == input.Length)
                        {
                            break;
                        }
                        this.ExecuteCommand(input[i], this.data.Ninjas.Last());
                        if (this.data.Ninjas.Last().Stamina > 0)
                        {
                            i++;
                            goto done2;
                        }

                        this.ApplyVegatables(this.data.Ninjas.Last());
                        this.data.Ninjas.Last().Vegetables.Clear();
                    }
                }
            }
        }
Ejemplo n.º 22
0
 public abstract void VegetableEffect(INinja ninja);
Ejemplo n.º 23
0
 public NinjaController()
 {
     _ninjaService = new SimpleNinja();
 }
Ejemplo n.º 24
0
 public RestState(INinja ninja)
 {
     this.ninja = ninja;
 }
Ejemplo n.º 25
0
 public void AttackTarget(INinja ninja)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 26
0
 private void Fight()
 {
     this.winnerNinja = this.currentNinja.Power >= this.Database.GetOtherPlayer(this.currentNinja.Name).Power
         ? this.currentNinja
         : this.Database.GetOtherPlayer(this.currentNinja.Name);
 }
Ejemplo n.º 27
0
 public void SetNinja(INinja ninja)
 {
     _linkedNinja = ninja;
 }
Ejemplo n.º 28
0
 public StandbyState(INinja ninja)
 {
     this.ninja = ninja;
     ninja.ActionQueue.ExecuteActions();
 }
 private void Fight()
 {
     this.winnerNinja = this.currentNinja.Power >= this.Database.GetOtherPlayer(this.currentNinja.Name).Power
                ? this.currentNinja
                : this.Database.GetOtherPlayer(this.currentNinja.Name);
 }
Ejemplo n.º 30
0
 public void AddNinja(INinja ninja)
 {
     this.ninjas.Add(ninja);
 }
        private void ApplyMeloLemonMelon(INinja givenNinja, EventArgs args)
        {
            var enemies = this.Database.Ninjas.Where(ninja => !ninja.Equals(givenNinja));
            foreach (var enemy in enemies)
            {
                for (int i = 0; i < 5; i++)
                {
                    IVegetable mushroom = new Mushroom(new MatrixPosition(0, 0));
                    enemy.CollectVegetable(mushroom);
                }

                enemy.EatVegetables();
            }
        }
Ejemplo n.º 32
0
 public void InitialiseGameData(string firstNinjaName)
 {
     this.currentNinja = this.Database.Ninjas.First(ninja => ninja.Name.Equals(firstNinjaName));
     this.AttachEvents();
 }
Ejemplo n.º 33
0
 public void AttackTarget(INinja ninja)
 {
     ninja.DefendAttack(Weapon);
 }
 public void AddNinja(INinja ninja)
 {
     this.ninjas.Add(ninja);
 }