Exemplo n.º 1
0
 private static Game CreateGame([NotNull] string gameFolder, JsonStage[] stages)
 {
     return new Game(Path.GetFileName(gameFolder),
         stages
             .Select(s => new GameStage(s.Name, s.TimeToSolve, s.CardsInGroup, s.CardsRows))
             .ToArray());
 }
Exemplo n.º 2
0
        private static Result ValidateStages(JsonStage[] stages, int numberOfImages)
        {
            if ((stages?.Length ?? 0) == 0)
                return new Failure("No stages");

            Contract.Assume(stages != null);

            for (int i = 0; i < stages.Length; i++)
            {
                var stage = stages[i];
                if (string.IsNullOrWhiteSpace(stage.Name))
                    return new Failure($"Stage #{i + 1}. Name can't be null or empty");
                if (stage.TimeToSolve < 0)
                    return new Failure($"Stage #{i + 1}. Time to solve the stage must be non-negative");
                if (stage.CardsInGroup < 2)
                    return new Failure($"Stage #{i + 1}. Number of cards in group should be greater that 1");
                if ((stage.CardsRows?.Length ?? 0) == 0)
                    return new Failure($"Stage #{i + 1}. Cards in rows array must be specified");
                Contract.Assume(stage.CardsRows != null);
                if ((stage.CardsRows.Sum() % stage.CardsInGroup) != 0)
                    return new Failure($"Stage #{i + 1}. Total number of cards in all rows should be divisible by size of group");
                if ((stage.CardsRows.Sum() / stage.CardsInGroup) > numberOfImages)
                    return new Failure($"Stage #{i + 1}. {stage.CardsRows.Sum() / stage.CardsInGroup} images required for this stage but only {numberOfImages} available");
            }

            return new Success();
        }