private Vector2[,] ConvertCoordinatesAccordingDifficultyLevel(Vector2[,] originalCoordinates, DifficultyLevel targetCoordinatesDifficultyLevel)
        {
            DifficultyLevel originalCoordinatesDifficaltyLevel = DetermineDifficultyLevelForCoordinates(originalCoordinates.GetUpperBound(0));

            if (targetCoordinatesDifficultyLevel < originalCoordinatesDifficaltyLevel)
            {
                throw new Exception($"[SquareTilePositionGenerator.ConvertCoordinatesAccordingDifficultyLevel] attempt to convert from greater difficulty to less. {targetCoordinatesDifficultyLevel} < {originalCoordinatesDifficaltyLevel}");
            }

            switch (targetCoordinatesDifficultyLevel)
            {
            // ширина поля 1 тайл
            case DifficultyLevel.High:
            {
                var x = originalCoordinates.GetUpperBound(0);
                var y = originalCoordinates.GetUpperBound(1);
                return(new Vector2[1, 1] {
                        { originalCoordinates[x, y] }
                    });
            }

            // ширина поля 2х2 тайла
            case DifficultyLevel.Middle:
            {
                Vector2[,] result = new Vector2[2, 2];

                int[] coordinatesIndexes = { 1, 2 };

                for (int y = 0; y < coordinatesIndexes.Length; y++)
                {
                    for (int x = 0; x < coordinatesIndexes.Length; x++)
                    {
                        result[x, y] = originalCoordinates[coordinatesIndexes[x], coordinatesIndexes[y]];
                    }
                }
                return(result);
            }

            //ширина поля 3х3 тайла
            case DifficultyLevel.Low:
                return(originalCoordinates);

            default:
                throw new Exception($"[SquareTilePositionGenerator.ConvertCoordinatesAccordingDifficultyLevel] unhandled difficulty level: {targetCoordinatesDifficultyLevel}");
            }
        }
        public IReadOnlyCollection <Vector2> GeneratePositoins()
        {
            FaceDirections extremeFace = (FaceDirections)UnityEngine.Random.Range(0, 2);

            Vector2[,] generatedTilePositions = tilePositionGenerator.GenerateTilePositoins(extremeFace, extremeCellPositions);
            extremeCellPositions = tilePositionGenerator.GenerateExtremeCellPositions(generatedTilePositions);

            List <Vector2> result = new List <Vector2>();

            for (int y = 0; y <= generatedTilePositions.GetUpperBound(1); y++)
            {
                for (int x = 0; x <= generatedTilePositions.GetUpperBound(0); x++)
                {
                    result.Add(generatedTilePositions[x, y]);
                }
            }

            return(result.AsReadOnly());
        }
Beispiel #3
0
        /// <summary>
        /// Writes a 2D array of vector2 structs to the output.
        /// </summary>
        /// <param name="name">Name of the value</param>
        /// <param name="value">2D array of vector2</param>
        public void Write(string name, Vector2[,] value)
        {
            if (value == null)
            {
                _output.Write(NULL_OBJECT);
                return;
            }
            else
            {
                _output.Write(A_OK);
            }
            int row = value.GetUpperBound(0);
            int col = value.GetUpperBound(1);

            _output.Write(row);
            _output.Write(col);
            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    this.Write(null, value[i, j]);
                }
            }
        }