コード例 #1
0
        private void GrowVegetables()
        {
            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);
                }
            }
        }
コード例 #2
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 newBlankSpace = 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 '-':
                            newBlankSpace = 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 (newBlankSpace != null)
                    {
                        currentRow.Add(newBlankSpace);
                    }
                }

                this.gameField.Add(currentRow);
            }
        }