/// <summary> /// This method is used everytime we want to clear all the path. Pops out every cell (cleaning it out) /// of the stack until only left the first cell. /// </summary> public void ClearAllPath() { while (cellStack.Count > 1) { cellStack.Peek().DeactivateCell(); cellStack.Pop(); _cellsFilled--; } cellStack.Peek().DeactivateDirectionLine(); currentCellCoordinates = cellStack.Peek().GetCoordinates(); }
/// <summary> /// This method is used everytime a cell has received the instruction of being "painted". /// Makes the respective action depending on the cell status. /// </summary> /// <param name="cellToPush">The cell that has to be painted private void AddCellToPath(Cell cellToPush) { cellToPush.SetActive(); cellToPush.SetDirection(_lastActivatedCell); if (cellToPush.GetDirection() == Cell.DIRS.LEFT || cellToPush.GetDirection() == Cell.DIRS.DOWN) { cellToPush.SetDirectionLine(cellToPush.GetDirection()); } else { _lastActivatedCell.SetDirectionLine(cellToPush.GetDirection()); } cellStack.Push(cellToPush); currentCellCoordinates = cellToPush.GetCoordinates(); _cellsFilled++; }
/// <summary> /// This method is used for creating a cell in concrete coordinates. /// The created cell can be of Type "Empty" or "First", or "Regular". Depending /// on its type we generate a cell with different parameters. /// </summary> /// <param name="empty">Cell is empty /// <param name="first">Cell is the first /// <param name="coords">Coordinates the cell will have private void GenerateCell(bool empty, bool first, Cell.Coordinates coords) { grid[coords.x, coords.y] = Instantiate(prefab); grid[coords.x, coords.y].GetComponent <Cell>().FillCell(); grid[coords.x, coords.y].GetComponent <Cell>().DeactivateHint(); grid[coords.x, coords.y].transform.SetParent(this.transform); if (!empty) { grid[coords.x, coords.y].GetComponent <Cell>().SetCoordinates(coords.x, coords.y); grid[coords.x, coords.y].GetComponent <Cell>().SetNoneDirection(); if (first) { grid[coords.x, coords.y].GetComponent <Cell>().SetActive(); firstCellCoordinates = coords; currentCellCoordinates = coords; } } else { grid[coords.x, coords.y].GetComponent <Cell>().SetCoordinates(-1, -1); grid[coords.x, coords.y].GetComponent <Cell>().SetInactive(); } grid[coords.x, coords.y].GetComponent <Cell>().SetPosition(iniPosX + (separation * coords.y), iniPosY - (separation * coords.x)); }
/// <summary> /// This method is used everytime a cell has received the instruction of being "erased". /// Makes the respective action depending on the cell direction. /// </summary> /// <param name="cellToClear">The cell that has to be erased private void ClearPath(Cell cellToClear) { while (cellStack.Count > 1 && cellToClear != cellStack.Peek()) { _lastActivatedCell = cellStack.Peek(); cellStack.Peek().DeactivateCell(); switch (cellStack.Peek().GetDirection()) { //In case the direction of the cell that is gonna be erased: /* * LEFT: Deactivate any direction of any cell. */ case Cell.DIRS.LEFT: cellStack.Peek().DeactivateDirectionLine(); if (cellToClear.GetDirection() == Cell.DIRS.NONE) { cellToClear.DeactivateDirectionLine(); } if (cellToClear.GetDirection() == Cell.DIRS.DOWN) { cellToClear.ActivateVertical(); } if (cellToClear.GetDirection() == Cell.DIRS.UP) { cellToClear.DeactivateVertical(); } break; /* * RIGHT: Deactivate any direction of any cell and deactive direction of itself depending of its own direction */ case Cell.DIRS.RIGHT: cellStack.Peek().DeactivateDirectionLine(); if (cellToClear.GetDirection() == Cell.DIRS.DOWN) { cellToClear.ActivateVertical(); cellToClear.DeactivateHorizontal(); } else { cellToClear.DeactivateHorizontal(); } if (cellToClear.GetDirection() == Cell.DIRS.NONE) { cellToClear.DeactivateDirectionLine(); } break; /* * UP: Deactivate vertical direction of itself and activate its horizontal direction depending of previous cell's direction */ case Cell.DIRS.UP: cellToClear.DeactivateVertical(); if (cellToClear.GetDirection() == Cell.DIRS.LEFT) { cellToClear.ActivateHorizontal(); } if (cellToClear.GetDirection() == Cell.DIRS.NONE) { cellToClear.DeactivateDirectionLine(); } break; /* * DOWN: Deactivate any direction of any cell and activate or deactivate its own directions depending of previous cell's direction */ case Cell.DIRS.DOWN: cellStack.Peek().DeactivateDirectionLine(); if (cellToClear.GetDirection() == Cell.DIRS.LEFT) { cellToClear.ActivateHorizontal(); cellToClear.DeactivateVertical(); } else { cellToClear.DeactivateHorizontal(); cellToClear.DeactivateVertical(); } if (cellToClear.GetDirection() == Cell.DIRS.DOWN || cellToClear.GetDirection() == Cell.DIRS.UP) { cellToClear.ActivateVertical(); } if (cellToClear.GetDirection() == Cell.DIRS.NONE) { cellToClear.DeactivateDirectionLine(); } break; /* * NONE: Deactivate everything */ case Cell.DIRS.NONE: cellToClear.DeactivateDirectionLine(); break; } cellStack.Pop(); _cellsFilled--; currentCellCoordinates = cellToClear.GetCoordinates(); } }