Пример #1
0
    public void ValidateGenerationDescriptionSuccess()
    {
        var gameDescription = new Boss()
        {
        };
        var recipe = new Recipe()
        {
            Ingredients = new List <RequiredIngredientDesc>()
            {
                new RequiredIngredientDesc()
                {
                    Amount = 1,
                    Color  = ColorType.Blue,
                    Type   = IngredientsType.Crystal
                }
            }
        };

        var possibleItems = new GenerationDescription()
        {
            Ingredients = new List <GenerationItem>()
            {
                new GenerationItem()
                {
                    Amount = 1,
                    Color  = ColorType.Blue,
                    Type   = IngredientsType.Crystal
                }
            }
        };

        Assert.IsTrue(Helper.Validate(recipe, possibleItems));
    }
    public void ReplaceGenerationDescription(GenerationDescription newValue)
    {
        var index     = GameComponentsLookup.GenerationDescription;
        var component = CreateComponent <GenerationDescriptionComponent>(index);

        component.value = newValue;
        ReplaceComponent(index, component);
    }
Пример #3
0
    public void CreateIngredientsViewTest()
    {
        var contexts = new Contexts();
        var game     = contexts.game;

        game.SetGameField(10, 10);

        var factory = new GameObject().AddComponent <IngredientViewFactory>();

        factory.Inject(contexts);

        factory.Descs = new IngredientViewFactory.IngredientDesc[]
        {
            new IngredientViewFactory.IngredientDesc()
            {
                Type = IngredientsType.Ingot,
                View = new GameObject()
            },
            new IngredientViewFactory.IngredientDesc()
            {
                Type = IngredientsType.Plant,
                View = new GameObject()
            }
        };

        var systems = new Systems().Add(new GenerateItemsSystem(contexts))
                      .Add(new CreateIngredientViewSystem(contexts));

        systems.Initialize();

        Assert.IsTrue(game.hasGameField);

        var generationDescription = new GenerationDescription();

        generationDescription.Ingredients = new List <GenerationItem>()
        {
            new GenerationItem()
            {
                Amount = 5,
                Type   = IngredientsType.Ingot
            },
            new GenerationItem()
            {
                Amount = 3,
                Type   = IngredientsType.Plant
            }
        };

        game.gameFieldEntity.ReplaceGenerationDescription(generationDescription);
        game.gameFieldEntity.isNeedRegenerate = true;

        systems.Execute();

        var ingredientsEntities = game.GetGroup(GameMatcher.AllOf(GameMatcher.Ingredient, GameMatcher.GameObject));

        Assert.AreEqual(8, ingredientsEntities.count);
    }
Пример #4
0
 public static bool Validate(Recipe recipe, GenerationDescription generationDescription)
 {
     foreach (var ingredient in recipe.Ingredients)
     {
         var totalSum = generationDescription.Ingredients.Where(x => x.Color == ingredient.Color && x.Type == ingredient.Type).Sum(x => x.Amount);
         if (totalSum < ingredient.Amount)
         {
             Debug.LogWarningFormat("Problem with {0}. You need: {1} but have only: {2}", ingredient, ingredient.Amount, totalSum);
             return(false);
         }
     }
     return(true);
 }
Пример #5
0
    public void BasicGeneration()
    {
        var contexts = new Contexts();
        var game     = contexts.game;

        game.SetGameField(10, 10);

        var systems = new GenerateItemsSystem(contexts);

        Assert.IsTrue(game.hasGameField);

        var generationDescription = new GenerationDescription();

        generationDescription.Ingredients = new List <GenerationItem>()
        {
            new GenerationItem()
            {
                Amount = 5,
                Type   = IngredientsType.Ingot
            },
            new GenerationItem()
            {
                Amount = 3,
                Type   = IngredientsType.Plant
            }
        };

        game.gameFieldEntity.ReplaceGenerationDescription(generationDescription);
        game.gameFieldEntity.isNeedRegenerate = true;

        systems.Execute();

        var ingredientsEntities = game.GetGroup(GameMatcher.Ingredient);

        Assert.AreEqual(8, ingredientsEntities.count);
    }