Esempio n. 1
0
    public void SetNumberTileInCubic(Vector3Int locationInCubicCoord, int number, Color color)
    {
        var offset = CubicCrabGrid.CubicToOffset(locationInCubicCoord);

        Debug.LogFormat("Number tile cubic {0} offset {1} amount {2}", locationInCubicCoord, offset, number);
        SetNumberTileInOffsetCoordinates(offset, number, color);
    }
Esempio n. 2
0
 /// <summary>
 /// Makes the new instance of CubicGrabGrid a copy of another supplied grid
 /// </summary>
 /// <param name="gridToCopy">This grid is copied</param>
 public CubicCrabGrid(CubicCrabGrid gridToCopy)
 {
     foreach (Vector3Int key in gridToCopy.Keys)
     {
         Add(key, gridToCopy[key]);
     }
 }
Esempio n. 3
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="location"></param>
    /// <returns>Whether the given tile contains a number tile</returns>
    internal bool HasNumberTile(Vector3Int locationInCubic)
    {
        Tile tile = (Tile)numberTilemap.GetTile(CubicCrabGrid.CubicToOffset(locationInCubic));

        if (tile != null && tile.sprite != null)
        {
            return(true);
        }
        return(false);
    }
Esempio n. 4
0
    // Start is called before the first frame update
    void Start()
    {
        DifficultyLevel difficulty = GameController.GetInstance().Difficulty;

        CubicCrabGrid startPopulation = GetSwarms(difficulty.PopulationConcentration, difficulty.NumberOfSwarms, difficulty.EmptySpaceBetweenCenters);

        crabPopulation = startPopulation;

        //A copy is made of the start population.
        originalCrabPopulation = new CubicCrabGrid(startPopulation);
    }
Esempio n. 5
0
    public Vector3Int GetRandomSwarmPlacementInCubic()
    {
        var locations = new List <Vector3Int>();

        foreach (var location in randomizerTilemap.cellBounds.allPositionsWithin)
        {
            Tile tile = (Tile)randomizerTilemap.GetTile(location);

            if (tile != null && tile.sprite != null)
            {
                locations.Add(location);
            }
        }
        int random = randomizer.Next(0, locations.Count);

        return(CubicCrabGrid.OffsetToCubic(locations[random]));
    }
Esempio n. 6
0
    public int GetCrab(Vector3Int locationInOffsetCoord)
    {
        Vector3Int locationInCubic = CubicCrabGrid.OffsetToCubic(locationInOffsetCoord);

        if (crabPopulation.TryGetValue(locationInCubic, out int crabAmount))
        {
            Debug.Log("Area " + locationInCubic + " contained " + crabAmount + " crab");

            if (crabAmount > 1)
            {
                crabPopulation[locationInCubic] = 1;
            }
            else if (crabAmount >= 1)
            {
                crabPopulation[locationInCubic] = 0;
            }

            return(crabAmount);
        }
        Debug.Log("Area " + locationInCubic + " contained no crab");
        return(0);
    }
Esempio n. 7
0
    CubicCrabGrid GetSwarms(int[] populationConcentration, int number, int emptySpaceAroundCenters)
    {
        var crabGrid = new CubicCrabGrid();

        for (int i = 1; i <= number; i++)
        {
            Vector3Int newSwarmPlace = gridTracker.GetRandomSwarmPlacementInCubic();

            bool acceptablePlacement = false;
            int  attemptNumber       = 0;

            while (!acceptablePlacement)
            {
                attemptNumber++;
                if (!crabGrid.IsAcceptableSwarmPlace(newSwarmPlace, emptySpaceAroundCenters) || !gridTracker.SwarmPlacementIsWithinPlayArea(newSwarmPlace))
                {
                    newSwarmPlace = gridTracker.GetRandomSwarmPlacementInCubic();

                    if (attemptNumber >= maximumAttempts)
                    {
                        Debug.LogWarningFormat("Attempted {0} times and couldn't find placement for swarm number {1}", attemptNumber, i);

                        acceptablePlacement = true;
                    }

                    continue;
                }
                else
                {
                    acceptablePlacement = true;
                }
            }

            crabGrid.AddSwarm(newSwarmPlace, populationConcentration);
        }
        return(crabGrid);
    }
Esempio n. 8
0
    public void PlaceOrRemovePot(Vector3 worldPos, bool playerHasPotsLeft, ThrowPotDelegate throwPotDelegate, AddPotDelegate addPotDelegate)
    {
        var  terrainCoordinate  = terrainGrid.WorldToCell(worldPos);
        bool terrainIsWaterTile = HasWaterTileInOffset(terrainCoordinate);

        Vector3Int markerCoordinate = markerGrid.WorldToCell(worldPos);
        var        markerTile       = (Tile)markerTilemap.GetTile(markerCoordinate);

        bool markerGridHasPlacedPotTile = TileHasSpriteWithName(markerTile, potSprite.name);

        bool       allowedToPlace  = terrainIsWaterTile && !markerGridHasPlacedPotTile;
        bool       allowedToRemove = terrainIsWaterTile && markerGridHasPlacedPotTile;
        Vector3Int location        = markerCoordinate;

        /**
         * Not all of the information gathered above is actually necessary if playerHasPotsLeft equals 'false'.
         * This function could be "optimized", but what's the point? The execution is lightning-fast anyway.
         * */
        if (allowedToPlace && playerHasPotsLeft)
        {
            Tile tile = ScriptableObject.CreateInstance <Tile>();
            tile.sprite = potSprite;
            markerTilemap.SetTile(location, tile);

            Debug.LogFormat("Placed pot at offset {0}, cubic {1}", location, CubicCrabGrid.OffsetToCubic(location));

            throwPotDelegate();
        }
        else if (allowedToRemove)
        {
            Tile tile = ScriptableObject.CreateInstance <Tile>();
            markerTilemap.SetTile(location, tile);

            addPotDelegate();
        }
    }
Esempio n. 9
0
    public bool SwarmPlacementIsWithinPlayArea(Vector3Int locationInCubic)
    {
        var tile = (Tile)randomizerTilemap.GetTile(CubicCrabGrid.CubicToOffset(locationInCubic));

        return(tile != null && tile.sprite != null);
    }
Esempio n. 10
0
 internal bool HasWaterTile(Vector3Int locationInCubic)
 {
     return(HasWaterTileInOffset(CubicCrabGrid.CubicToOffset(locationInCubic)));
 }