Esempio n. 1
0
    private GridSq GrabNeighbor(GridSq currentTile, Location location)
    {
        GridSq neighbor = null;

        int i = currentTile.x;
        int j = currentTile.y;

        if (location == Location.above)
        {
            if (GridSetup.gridObj.grid[i, j - 1] != null)
            {
                neighbor = GridSetup.gridObj.grid[i, j - 1];
            }
        }
        else if (location == Location.left)
        {
            if (GridSetup.gridObj.grid[i - 1, j] != null)
            {
                neighbor = GridSetup.gridObj.grid[i - 1, j];
            }
        }
        else if (location == Location.right)
        {
            if (GridSetup.gridObj.grid[i + 1, j] != null)
            {
                neighbor = GridSetup.gridObj.grid[i + 1, j];
            }
        }
        else if (location == Location.below)
        {
            if (GridSetup.gridObj.grid[i, j + 1] != null)
            {
                neighbor = GridSetup.gridObj.grid[i, j + 1];
            }
        }
        else if (location == Location.tlCorner)
        {
            if (GridSetup.gridObj.grid[i - 1, j - 1] != null)
            {
                neighbor = GridSetup.gridObj.grid[i - 1, j - 1];
            }
        }
        else if (location == Location.trCorner)
        {
            if (GridSetup.gridObj.grid[i + 1, j - 1] != null)
            {
                neighbor = GridSetup.gridObj.grid[i + 1, j - 1];
            }
        }
        else if (location == Location.blCorner)
        {
            if (GridSetup.gridObj.grid[i - 1, j + 1] != null)
            {
                neighbor = GridSetup.gridObj.grid[i - 1, j + 1];
            }
        }
        else if (location == Location.brCorner)
        {
            if (GridSetup.gridObj.grid[i + 1, j + 1] != null)
            {
                neighbor = GridSetup.gridObj.grid[i + 1, j + 1];
            }
        }
        else
        {
            throw new System.ArgumentException("The location specified does not exist.");
        }
        return(neighbor);
    }
Esempio n. 2
0
    private int AddValidNeighbors(GridSq tile)
    {
        int      amtAliveNei = 0;
        TileType tileType    = tile.TileType;

        if (tileType == TileType.normal)
        {
            if (GrabNeighbor(tile, Location.above).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.left).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.right).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.below).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.tlCorner).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.trCorner).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.blCorner).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.brCorner).state)
            {
                amtAliveNei++;
            }
        }
        else if (tileType == TileType.leftSide)
        {
            if (GrabNeighbor(tile, Location.above).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.right).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.below).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.trCorner).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.brCorner).state)
            {
                amtAliveNei++;
            }
        }
        else if (tileType == TileType.blCorner)
        {
            if (GrabNeighbor(tile, Location.above).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.right).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.trCorner).state)
            {
                amtAliveNei++;
            }
        }
        else if (tileType == TileType.tlCorner)
        {
            if (GrabNeighbor(tile, Location.right).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.below).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.brCorner).state)
            {
                amtAliveNei++;
            }
        }
        else if (tileType == TileType.topSide)
        {
            if (GrabNeighbor(tile, Location.left).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.right).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.below).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.brCorner).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.brCorner).state)
            {
                amtAliveNei++;
            }
        }
        else if (tileType == TileType.bottomSide)
        {
            if (GrabNeighbor(tile, Location.above).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.left).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.right).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.tlCorner).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.trCorner).state)
            {
                amtAliveNei++;
            }
        }
        else if (tileType == TileType.rightSide)
        {
            if (GrabNeighbor(tile, Location.above).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.left).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.below).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.tlCorner).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.blCorner).state)
            {
                amtAliveNei++;
            }
        }
        else if (tileType == TileType.trCorner)
        {
            if (GrabNeighbor(tile, Location.left).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.below).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.blCorner).state)
            {
                amtAliveNei++;
            }
        }
        else if (tileType == TileType.brCorner)
        {
            if (GrabNeighbor(tile, Location.above).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.left).state)
            {
                amtAliveNei++;
            }
            if (GrabNeighbor(tile, Location.tlCorner).state)
            {
                amtAliveNei++;
            }
        }
        return(amtAliveNei);
    }