Example #1
0
    public void CreatePlant(Vector2Int c, PuzzleCell.PlantType t, PuzzleCell.PlantType[] p = null)
    {
        cells[c.x][c.y].plants = t;

        cells[c.x][c.y].showBroto = true;

        switch (t)
        {
        case PuzzleCell.PlantType.AV:
            cells[c.x][c.y].influenced = PuzzleCell.InfluenceType.AVOnly;
            break;

        case PuzzleCell.PlantType.P:
            cells[c.x][c.y].influenced  = PuzzleCell.InfluenceType.PSingle;
            cells[c.x][c.y].turnsToGrow = 3;
            break;

        case PuzzleCell.PlantType.S:
            cells[c.x][c.y].influenced  = PuzzleCell.InfluenceType.SSingle;
            cells[c.x][c.y].turnsToGrow = 5;
            break;

        case PuzzleCell.PlantType.C:
            cells[c.x][c.y] = new PuzzleCell(PuzzleCell.PlantType.C, PuzzleCell.InfluenceType.Double, p);
            break;
        }

        map.CallInstantiate(t, c.x, c.y);
    }
Example #2
0
    public void CallInstantiate(PuzzleCell.PlantType p, int i, int j, bool isObstacle = false)
    {
        Vector3 pos = g.GetCellCenterWorld(g.WorldToCell(mapHolder.position + new Vector3(i, -j, 0)));

        if (isObstacle)
        {
            GameObject obj = Instantiate(obstaclePrefab, pos, Quaternion.identity, mapHolder);
            obj.GetComponent <ObstacleController>().SetSprite(area.cells[i][j].obstacleSprite);
            return;
        }

        GameObject cellObj = null;

        switch (p)
        {
        case PuzzleCell.PlantType.AV:
            cellObj = Instantiate(avPrefab, pos, Quaternion.identity, mapHolder);
            break;

        case PuzzleCell.PlantType.P:
            cellObj = Instantiate(pPrefab, pos, Quaternion.identity, mapHolder);
            break;

        case PuzzleCell.PlantType.S:
            cellObj = Instantiate(sPrefab, pos, Quaternion.identity, mapHolder);
            break;

        case PuzzleCell.PlantType.C:
            cellObj = Instantiate(cPrefab, pos, Quaternion.identity, mapHolder);
            break;
        }

        if (area.cells[i][j].showBroto)
        {
            GameObject broto = Instantiate(brotoPrefab, cellObj.transform);
            broto.transform.localPosition = new Vector3(0, 0, -1);
        }
    }
Example #3
0
    public void ApplyGrowth(Vector2Int pos, PuzzleCell.PlantType p)
    {
        //Adubo verde
        if (p == PuzzleCell.PlantType.AV)
        {
            if (CheckNotBoundries(new Vector2Int(pos.x + 1, pos.y)))
            {
                if (cells[pos.x + 1][pos.y].isObstacle)
                {
                    return;
                }

                if (cells[pos.x + 1][pos.y].plants == PuzzleCell.PlantType.C)
                {
                    if (cells[pos.x + 1][pos.y].plantsToGrow.Contains(PuzzleCell.PlantType.AV) &&
                        !cells[pos.x + 1][pos.y].progressToWin.Contains(PuzzleCell.PlantType.AV))
                    {
                        Debug.Log("AV added");
                        cells[pos.x + 1][pos.y].progressToWin.Add(PuzzleCell.PlantType.AV);
                    }
                }
                else if (cells[pos.x + 1][pos.y].plants != PuzzleCell.PlantType.None &&
                         cells[pos.x + 1][pos.y].plants != PuzzleCell.PlantType.C)
                {
                    cells[pos.x + 1][pos.y].plants     = PuzzleCell.PlantType.AV;
                    cells[pos.x + 1][pos.y].influenced = PuzzleCell.InfluenceType.AVOnly;
                }
                else if (cells[pos.x + 1][pos.y].influenced == PuzzleCell.InfluenceType.None)
                {
                    cells[pos.x + 1][pos.y].influenced = PuzzleCell.InfluenceType.AVOnly;
                    if (!(cells[pos.x + 1][pos.y].plants == PuzzleCell.PlantType.AV))
                    {
                        cells[pos.x + 1][pos.y].plants = PuzzleCell.PlantType.AV;
                    }
                }
            }
        }

        //Primária
        if (p == PuzzleCell.PlantType.P)
        {
            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    if (CheckNotBoundries(new Vector2Int(pos.x + i, pos.y + j)))
                    {
                        if (cells[pos.x + i][pos.y + j].isObstacle)
                        {
                            continue;
                        }

                        if (cells[pos.x + i][pos.y + j].plants == PuzzleCell.PlantType.C)
                        {
                            if (cells[pos.x + i][pos.y + j].plantsToGrow.Contains(PuzzleCell.PlantType.P) &&
                                !cells[pos.x + i][pos.y + j].progressToWin.Contains(PuzzleCell.PlantType.P))
                            {
                                cells[pos.x + i][pos.y + j].progressToWin.Add(PuzzleCell.PlantType.P);
                                Debug.Log("P added");
                            }
                        }
                        else if (cells[pos.x + i][pos.y + j].influenced == PuzzleCell.InfluenceType.None)
                        {
                            cells[pos.x + i][pos.y + j].influenced = PuzzleCell.InfluenceType.PSingle;
                        }
                    }
                }
            }
        }

        //Secundária
        if (p == PuzzleCell.PlantType.S)
        {
            int startX  = 0;
            int startY  = 0;
            int stopOnX = gridSize - 1;
            int stopOnY = gridSize - 1;

            for (int i = 0; i < pos.x; i++)
            {
                if (cells[i][pos.y].isObstacle)
                {
                    startX = Mathf.Clamp(i - 1, 0, gridSize - 1);
                }
            }

            for (int i = 0; i < pos.y; i++)
            {
                if (cells[pos.x][i].isObstacle)
                {
                    startY = Mathf.Clamp(i - 1, 0, gridSize - 1);
                }
            }

            for (int i = pos.x; i < gridSize; i++)
            {
                if (cells[i][pos.y].isObstacle)
                {
                    stopOnX = Mathf.Clamp(i - 1, pos.x + 1, gridSize - 1);
                    break;
                }
            }

            for (int i = pos.y; i < gridSize; i++)
            {
                if (cells[pos.x][i].isObstacle)
                {
                    stopOnY = Mathf.Clamp(i - 1, pos.y + 1, gridSize - 1);
                    break;
                }
            }

            /*for (int i = 0; i < gridSize; i++) {
             *  if (cells[i][w].isObstacle && i == pos.x) {
             *      if (pos.x > i) {
             *          startX = i;
             *      }
             *      else {
             *          if (!triggerX) {
             *              stopOnX = i;
             *              triggerX = true;
             *          }
             *      }
             *  }
             *
             *  for (int j = 0; j < gridSize; j++) {
             *      if (i == pos.x || j == pos.y) {
             *          if (CheckNotBoundries(new Vector2Int(i, j))) {
             *              if (cells[i][j].isObstacle) {
             *                  if (pos.y > j) {
             *                      startY = j;
             *                  }
             *                  else {
             *                      if (!triggerY) {
             *                          stopOnY = j;
             *                          triggerY = true;
             *                      }
             *                  }
             *              }
             *          }
             *      }
             *  }
             *  w++;
             * }*/

            Debug.Log("Start:" + startX + ", " + startY);
            Debug.Log("Stop:" + stopOnX + ", " + stopOnY);

            for (int i = startX; i <= stopOnX; i++)
            {
                for (int j = startY; j <= stopOnY; j++)
                {
                    Debug.Log("Iterating on S");
                    if (i == pos.x || j == pos.y)
                    {
                        Debug.Log("Is same line or column");
                        if (CheckNotBoundries(new Vector2Int(i, j)))
                        {
                            Debug.Log("S is on boundries");
                            if (cells[i][j].plants == PuzzleCell.PlantType.C)
                            {
                                Debug.Log("Is C type");
                                //Teste
                                Debug.Log(i + ", " + j);

                                foreach (PuzzleCell.PlantType planta in cells[i][j].plantsToGrow)
                                {
                                    switch (planta)
                                    {
                                    case PuzzleCell.PlantType.AV:
                                        Debug.Log("AV here");
                                        break;

                                    case PuzzleCell.PlantType.P:
                                        Debug.Log("P here");
                                        break;

                                    case PuzzleCell.PlantType.S:
                                        Debug.Log("S here");
                                        break;

                                    case PuzzleCell.PlantType.C:
                                        Debug.Log("C here");
                                        break;
                                    }
                                }

                                foreach (PuzzleCell.PlantType planta in cells[i][j].progressToWin)
                                {
                                    switch (planta)
                                    {
                                    case PuzzleCell.PlantType.AV:
                                        Debug.Log("AV here 2");
                                        break;

                                    case PuzzleCell.PlantType.P:
                                        Debug.Log("P here 2");
                                        break;

                                    case PuzzleCell.PlantType.S:
                                        Debug.Log("S here 2");
                                        break;

                                    case PuzzleCell.PlantType.C:
                                        Debug.Log("C here 2");
                                        break;
                                    }
                                }
                                //fim do teste
                                if (cells[i][j].plantsToGrow.Contains(PuzzleCell.PlantType.S) &&
                                    !cells[i][j].progressToWin.Contains(PuzzleCell.PlantType.S))
                                {
                                    cells[i][j].progressToWin.Add(PuzzleCell.PlantType.S);
                                    Debug.Log("S added");
                                }
                            }
                            else if (cells[i][j].influenced == PuzzleCell.InfluenceType.None)
                            {
                                cells[i][j].influenced = PuzzleCell.InfluenceType.SSingle;
                            }
                        }
                    }
                }
            }
        }

        //Climax
        if (p == PuzzleCell.PlantType.C)
        {
            for (int i = -2; i <= 2; i++)
            {
                for (int j = -2; j <= 2; j++)
                {
                    if (CheckNotBoundries(new Vector2Int(pos.x + i, pos.y + j)))
                    {
                        cells[pos.x + i][pos.y + j].influenced = PuzzleCell.InfluenceType.Double;
                    }
                }
            }
        }
    }