示例#1
0
    private int CountAliveNeighborsOf(BoardCellIndex index)
    {
        var neighborsTypes = new BoardCellType[]
        {
            GetCellType(new BoardCellIndex(index.X - 1, index.Y - 1)),
            GetCellType(new BoardCellIndex(index.X - 1, index.Y)),
            GetCellType(new BoardCellIndex(index.X - 1, index.Y + 1)),
            GetCellType(new BoardCellIndex(index.X, index.Y + 1)),
            GetCellType(new BoardCellIndex(index.X, index.Y - 1)),
            GetCellType(new BoardCellIndex(index.X + 1, index.Y - 1)),
            GetCellType(new BoardCellIndex(index.X + 1, index.Y)),
            GetCellType(new BoardCellIndex(index.X + 1, index.Y + 1))
        };

        var aliveCount = 0;

        foreach (var nType in neighborsTypes)
        {
            if (nType == BoardCellType.Alive)
            {
                ++aliveCount;
            }
        }

        return(aliveCount);
    }
示例#2
0
 private void ChangeCellType(BoardCellIndex index, BoardCellType newCellType)
 {
     if (IsValidCellIndex(index))
     {
         var cellIndex1d = ToIndex1D(index);
         var cell        = cells[cellIndex1d];
         ChangeCellType(cell, cellIndex1d, newCellType);
     }
 }
示例#3
0
 private Vector2[] GetNewUVs(BoardCellType newCellType, BoardCellIndex cellIndex)
 {
     if (IsBorder(cellIndex))
     {
         return(BoardCellUVsFactory.GetTransparentUVs());
     }
     else
     {
         return(BoardCellUVsFactory.GetUVsFor(newCellType));
     }
 }
示例#4
0
        private void SetPointArray(Coordinate[] coordinates, BoardCellType boardCellType)
        {
            if (coordinates == null)
            {
                return;
            }

            foreach (var point in coordinates)
            {
                SetBoardPositionType(point, boardCellType);
            }
        }
示例#5
0
    private void ChangeCellType(BoardCell cell, int cellIndex1d, BoardCellType newCellType)
    {
        var newUVs       = GetNewUVs(newCellType, cell.Index);
        var firstUvIndex = cellIndex1d * 4;

        for (var i = 0; i < 4; ++i)
        {
            meshUVsBuffer[firstUvIndex + i] = newUVs[i];
        }

        cell.Type = newCellType;
    }
示例#6
0
        private bool TryGetWinPositionsOnDirections(BoardCellType value, MapPosition position, MapNavigator direction, MapNavigator oppositeDirection, out IEnumerable <MapPosition> winPositions)
        {
            IList <MapPosition> potentialWinPositions = new List <MapPosition>();

            potentialWinPositions.Add(position);

            GetMatchingPositionsOnDirection(value, position, direction, potentialWinPositions);
            GetMatchingPositionsOnDirection(value, position, oppositeDirection, potentialWinPositions);

            if (potentialWinPositions.Count >= this.WinSequenceSize)
            {
                winPositions = potentialWinPositions;
                return(true);
            }

            winPositions = null;
            return(false);
        }
示例#7
0
        private void GetMatchingPositionsOnDirection(BoardCellType cellType, MapPosition position, MapNavigator directionNavigator, IList <MapPosition> matchingPositions)
        {
            MapPosition currentPosition = position;

            do
            {
                currentPosition = directionNavigator.Next(currentPosition);
                if (!this.GameBoard.IsPositionOnMap(currentPosition))
                {
                    break;
                }

                if (this.GameBoard[currentPosition].CellType != cellType)
                {
                    break;
                }

                matchingPositions.Add(currentPosition);
            } while (true);
        }
示例#8
0
 private void SetBoardPositionType(Coordinate coordinate, BoardCellType cellType)
 {
     grid[coordinate[0], coordinate[1]] = cellType;
 }
示例#9
0
 public BoardCellStruct(BoardCellId cellId, BoardCellType cellType)
 {
     CellId   = cellId;
     CellType = cellType;
     Figure   = null;
 }
示例#10
0
 public BoardCellStruct(BoardCellId cellId, BoardCellType cellType, FigureStructure figure)
 {
     CellId   = cellId;
     CellType = cellType;
     Figure   = figure;
 }
示例#11
0
    private void ChangeCellType(BoardCell cell, BoardCellType newCellType)
    {
        var cellIndex1d = ToIndex1D(cell.Index);

        ChangeCellType(cell, cellIndex1d, newCellType);
    }
示例#12
0
 public bool TryGetWinPositions(BoardCellType cellType, MapPosition position, out IEnumerable <MapPosition> winPositions) =>
 TryGetWinPositionsOnDirections(cellType, position, MapNavigator.N, MapNavigator.S, out winPositions) ||
 TryGetWinPositionsOnDirections(cellType, position, MapNavigator.NE, MapNavigator.SW, out winPositions) ||
 TryGetWinPositionsOnDirections(cellType, position, MapNavigator.E, MapNavigator.W, out winPositions) ||
 TryGetWinPositionsOnDirections(cellType, position, MapNavigator.SE, MapNavigator.NW, out winPositions);
示例#13
0
 public static Vector2[] GetUVsFor(BoardCellType type)
 {
     return(tileTypeToUVs[type]);
 }