Esempio n. 1
0
    private void LightGenerate(Room room, int[,] collideGrid)
    {
        for (int y = 0; y < room.Height; y++)
        {
            for (int x = 0; x < room.Width; x++)
            {
                if (collideGrid[y, x] != 3)
                {
                    continue;
                }

                int[,] neighbours = GridMath.GetNeighbours(collideGrid, new Vector2Int(x, y), 0);

                // if empty below
                if (neighbours[2, 1] == 0)
                {
                    if (Roll.Chance(5))
                    {
                        Vector3 worldLocation = new Vector3(x - Mathf.FloorToInt(room.Width / 2) + 0.5f, y - Mathf.FloorToInt(room.Height / 2) + 0.5f, 0f);

                        GameObject torch = Instantiate(_torchPrefab, worldLocation, Quaternion.identity);
                        torch.transform.parent = room.LightContainer;
                    }
                }
            }
        }
    }
Esempio n. 2
0
        public void TurnDegrees(int pDegrees)
        {
            int degrees = (int)IntPoint.DirectionToIntPoint(direction).Degrees();

            degrees  -= pDegrees;
            direction = GridMath.DegreesToDirection((int)degrees);
        }
Esempio n. 3
0
 public void MoveUp()
 {
     if (GridMath.GetRowForIndex(selectedCell) > 0)
     {
         SetSelectedIndex(selectedCell - 9);
     }
 }
Esempio n. 4
0
 public void MoveLeft()
 {
     if (GridMath.GetColumnForIndex(selectedCell) > 0)
     {
         SetSelectedIndex(selectedCell - 1);
     }
 }
Esempio n. 5
0
        public bool ApplyRule(ref Board board)
        {
            bool ruleSucceeded = false;

            for (int squareNumber = 0; squareNumber < 9; squareNumber++)
            {
                CellData cellData = board.GetCellDataForSquare(squareNumber);

                foreach (int unsolvedValue in cellData.GetUnsolvedValues())
                {
                    List <int> cellIndicesWithUnsolvedValue = cellData.GetCellIndicesWithValue(unsolvedValue);
                    if (InSameRow(cellIndicesWithUnsolvedValue))
                    {
                        CellData allCellsInRow    = board.GetCellDataForRow(GridMath.GetRowForIndex(cellIndicesWithUnsolvedValue.First()));
                        bool     removalSucceeded = RemoveUnsolvedValueFromCellsNotInSquare(ref board, unsolvedValue, squareNumber, allCellsInRow);
                        ruleSucceeded |= removalSucceeded;
                    }
                    else if (InSameColumn(cellIndicesWithUnsolvedValue))
                    {
                        CellData allCellsInColumn = board.GetCellDataForColumn(GridMath.GetColumnForIndex(cellIndicesWithUnsolvedValue.First()));
                        bool     removalSucceeded = RemoveUnsolvedValueFromCellsNotInSquare(ref board, unsolvedValue, squareNumber, allCellsInColumn);
                        ruleSucceeded |= removalSucceeded;
                    }
                }
            }

            return(ruleSucceeded);
        }
Esempio n. 6
0
    private void ExpandNodeChance(int expandThreshold = 33)
    {
        int[,] _newMapGrid = _mapGrid;

        for (int y = 0; y < mapSize; y++)
        {
            for (int x = 0; x < mapSize; x++)
            {
                if (_mapGrid[y, x] != 0)
                {
                    continue;
                }

                int[,] neighbours = GridMath.GetNeighbours(_mapGrid, new Vector2Int(x, y));
                if (!GridMath.NeighboursContainsX(neighbours, 1))
                {
                    continue;
                }


                if (Roll(33))
                {
                    _newMapGrid[y, x] = 1;
                }
            }
        }

        _mapGrid = _newMapGrid;
    }
Esempio n. 7
0
 public void DegreesToDirection()
 {
     Assert.AreEqual(Direction.UP, GridMath.DegreesToDirection(0));
     Assert.AreEqual(Direction.RIGHT, GridMath.DegreesToDirection(90));
     Assert.AreEqual(Direction.DOWN, GridMath.DegreesToDirection(180));
     Assert.AreEqual(Direction.LEFT, GridMath.DegreesToDirection(270));
 }
Esempio n. 8
0
 public void MoveDown()
 {
     if (GridMath.GetRowForIndex(selectedCell) < 8)
     {
         SetSelectedIndex(selectedCell + 9);
     }
 }
Esempio n. 9
0
 public void MoveRight()
 {
     if (GridMath.GetColumnForIndex(selectedCell) < 8)
     {
         SetSelectedIndex(selectedCell + 1);
     }
 }
Esempio n. 10
0
        public void ConvertFromFloatToIntRoundsDownWhenLessThanFive()
        {
            var expected      = 0;
            var startingFloat = 0.4999f;

            int actual = GridMath.ConvertFromFloatToInt(startingFloat);

            Assert.Equal(expected, actual);
        }
Esempio n. 11
0
        private void TalkToSignetPerson(Person signetNpc)
        {
            int dist = GridMath.GetDistancePos(Traveler.Position, signetNpc.Position);

            if (dist < 3)
            {
                HasSignet = true;
            }
        }
Esempio n. 12
0
        public void ClampTurnsPositiveNumberToOne()
        {
            float number = 1;
            var   want   = 1f;

            float got = GridMath.Clamp(number, 0, 1);

            Assert.Equal(want, got);
        }
Esempio n. 13
0
        public void ClampTurnsNegativeNumberToZero()
        {
            float number = -1;
            var   want   = 0f;

            float got = GridMath.Clamp(number, 0, 1);

            Assert.Equal(want, got);
        }
Esempio n. 14
0
        public void ConvertFromFloatToIntRoundsDownWhenLessThanFiveNegative()
        {
            int   expected      = -0;
            float startingFloat = -0.4999f;

            int actual = GridMath.ConvertFromFloatToInt(startingFloat);

            Assert.Equal(expected, actual);
        }
Esempio n. 15
0
        public void ConvertFromFloatToIntCanRoundAndConvertNegativeCorrectly()
        {
            int   expected      = -1;
            float startingFloat = -0.51f;

            int actual = GridMath.ConvertFromFloatToInt(startingFloat);

            Assert.Equal(expected, actual);
        }
Esempio n. 16
0
        public void CalculateIndex()
        {
            int column = 4;
            int row    = 4;

            int index = GridMath.CalculateIndexFromColumnRow(column, 3, 2);

            Assert.AreEqual(11, index);
        }
Esempio n. 17
0
        public void ConvertFromFloatToIntCanRoundAndConvertCorrectly()
        {
            var expected      = 1;
            var startingFloat = 0.51f;

            int actual = GridMath.ConvertFromFloatToInt(startingFloat);

            Assert.Equal(expected, actual);
        }
Esempio n. 18
0
 void CreateCells(int columnCount, int rowCount)
 {
     allCells = new CellCollection(Enumerable.Range(0, columnCount * rowCount).Select(delegate(int index)
     {
         int column, row;
         GridMath.CalculateColumnRow(index, columnCount, out column, out row);
         return(new Cell.Cell(column, row));
     }));
 }
Esempio n. 19
0
        public bool PathIsFound(Node currentGridNode, Node targetGridNode)
        {
            if (currentGridNode == targetGridNode)
                return true;

            if (GridMath.GetDistance(currentGridNode, targetGridNode) <= DistanceTolerance)
                return true;

            return false;
        }
Esempio n. 20
0
        public void TestIndicesInSquare(int square, int[] expectedIndices)
        {
            List <int> actualIndicesInSquare = GridMath.GetIndicesInSquare(square);

            actualIndicesInSquare.Should().NotBeEmpty()
            .And.HaveCount(GridMath.CellsInSquare);

            foreach (int expectedIndex in expectedIndices)
            {
                actualIndicesInSquare.Should().Contain(expectedIndex);
            }
        }
Esempio n. 21
0
        public void TestIndicesInColumn(int column, int[] expectedIndices)
        {
            List <int> actualIndicesInColumn = GridMath.GetIndicesInColumn(column);

            actualIndicesInColumn.Should().NotBeEmpty()
            .And.HaveCount(GridMath.CellsInColumn);

            foreach (int expectedIndex in expectedIndices)
            {
                actualIndicesInColumn.Should().Contain(expectedIndex);
            }
        }
Esempio n. 22
0
        public void TestIndicesInRow(int row, int[] expectedIndices)
        {
            List <int> actualIndicesInRow = GridMath.GetIndicesInRow(row);

            actualIndicesInRow.Should().NotBeEmpty()
            .And.HaveCount(GridMath.CellsInRow);

            foreach (int expectedIndex in expectedIndices)
            {
                actualIndicesInRow.Should().Contain(expectedIndex);
            }
        }
Esempio n. 23
0
        public void TestRelatedCellIndices(int index, int[] expectedRelatedIndices)
        {
            List <int> actualRelatedIndices = GridMath.GetRelatedCellIndices(index);

            actualRelatedIndices.Should().NotBeEmpty()
            .And.HaveCount(EXPECTED_NUMBER_OF_RELATED_INDICES);

            foreach (int expectedIndex in expectedRelatedIndices)
            {
                actualRelatedIndices.Should().Contain(expectedIndex);
            }
        }
Esempio n. 24
0
    private Tile SelectPadTile(Vector2Int loc, int[,] padGrid)
    {
        int[,] neighbours = GridMath.GetNeighbours(padGrid, loc);
        string gridType = GridMath.Comparison(neighbours, GridMath.PadComparisonGrids, 1);

        if (gridType != null)
        {
            return(_padTiles[gridType]);
        }

        return(_wallTiles["wall"]);
    }
Esempio n. 25
0
    private Tile SelectWallTile(Vector2Int loc, int[,] collideGrid)
    {
        int[,] neighbours = GridMath.GetNeighbours(collideGrid, loc);
        string gridType = GridMath.Comparison(neighbours, GridMath.WallComparisonGrids);

        if (gridType != null)
        {
            return(_wallTiles[gridType]);
        }

        return(_wallTiles["wall"]);
    }
        public IGrid Create()
        {
            SquareGrid grid = new SquareGrid(gridConfig);

            int cellCount = gridConfig.RowCount * gridConfig.ColumnCount;

            for (int i = 0; i < cellCount; i++)
            {
                int row, column;
                GridMath.CalculateColumnRow(i, gridConfig.ColumnCount, out column, out row);
                grid.GetCell(column, row).Content = randomContentProvider.Get();
            }

            return(grid);
        }
Esempio n. 27
0
    private void RemoveSurroundedNodes()
    {
        for (int y = 0; y < mapSize; y++)
        {
            for (int x = 0; x < mapSize; x++)
            {
                int[,] neighbours = GridMath.GetNeighbours(_mapGrid, new Vector2Int(x, y), 1);

                if (GridMath.CheckSurroundedFully(neighbours, 1))
                {
                    _mapGrid[y, x] = 0;
                }
            }
        }
    }
Esempio n. 28
0
        public void CheckAllPossibleValues()
        {
            var actual = GridMath.AllPossibleValues();

            actual.Count.Should().Be(9);
            actual.Should().Contain(1);
            actual.Should().Contain(2);
            actual.Should().Contain(3);
            actual.Should().Contain(4);
            actual.Should().Contain(5);
            actual.Should().Contain(6);
            actual.Should().Contain(7);
            actual.Should().Contain(8);
            actual.Should().Contain(9);
        }
Esempio n. 29
0
    private void RemoveUnreachableNodes()
    {
        for (int y = 0; y < mapSize; y++)
        {
            for (int x = 0; x < mapSize; x++)
            {
                int[,] neighbours = GridMath.GetNeighbours(_mapGrid, new Vector2Int(x, y), 0);

                if (GridMath.CheckSurroundedCardinal(neighbours, 0))
                {
                    _mapGrid[y, x] = 0;
                }
            }
        }
    }
Esempio n. 30
0
        private bool RemoveUnsolvedValueFromCellsNotInSquare(ref Board board, int unsolvedValue, int squareNumber, CellData cells)
        {
            bool success = false;

            foreach (int cellIndex in cells.Keys)
            {
                if (GridMath.GetSquareForIndex(cellIndex) != squareNumber)
                {
                    bool removalSucceeded = board.RemoveValueFromCell(cellIndex, unsolvedValue);
                    success |= removalSucceeded;
                }
            }

            return(success);
        }