Пример #1
0
    public BoardState GetBoardState()
    {
        BoardState state = new BoardState(rows - 2, columns - 2, elementsParent.childCount, hintsParent.childCount);
        int        i     = 0;

        //Iterate the cells of the current board
        foreach (BoardCell cell in board)
        {
            Vector2Int pos = cell.GetPosition();
            //If it's a valid position and not a hole
            if (cell == null || pos.x == 0 || pos.y == 0 || pos.x == columns - 1 || pos.y == rows - 1)
            {
                continue;
            }
            state.SetBoardCell(cell);
            //Process the object in the cell if there's any
            if (i < elementsParent.childCount && cell.GetState() == BoardCell.BoardCellState.OCUPPIED)
            {
                state.SetBoardObject(i++, cell);
            }
        }

        //Get hints of the current board
        i = 0;
        foreach (Transform hintT in hintsParent.transform)
        {
            BoardHint hint = hintT.GetComponent <BoardHint>();
            if (hint != null)
            {
                state.SetBoardHint(i++, hint);
            }
        }

        return(state);
    }
Пример #2
0
    public void SetBoardHint(int i, BoardHint hint)
    {
        BoardHintState hintState = new BoardHintState();

        hintState.id          = hint.GetHintID();
        hintState.x           = hint.GetPosition().x;
        hintState.y           = hint.GetPosition().y;
        hintState.amount      = hint.GetAmount();
        hintState.orientation = (int)hint.GetDirection();
        boardHints[i]         = hintState;
    }
Пример #3
0
    public void AddBoardHint(BoardHintState hintState)
    {
        if (!IsInBoardBounds(hintState.x, hintState.y))
        {
            return;
        }

        BoardHint hint = Instantiate(hintsPrefab, hintsParent);

        hint.SetDirection((BoardObject.Direction)hintState.orientation);
        hint.SetAmount(hintState.amount);
        hint.SetPosition(hintState.x, hintState.y);
        hint.SetHintID(hintState.id);

        board[hintState.x, hintState.y].SetHint(hint);
    }
Пример #4
0
    public void AddBoardHint(Vector2Int pos, int amount, int id)
    {
        if (!IsInBoardBounds(pos))
        {
            return;
        }

        BoardHint hint = Instantiate(hintsPrefab, hintsParent);

        hint.SetDirection((BoardObject.Direction) 0);
        hint.SetAmount(amount);
        hint.SetPosition(pos.x, pos.y);
        hint.SetHintID(id);
        hint.gameObject.SetActive(true);

        board[pos.x, pos.y].SetHint(hint);
    }
Пример #5
0
 public void SetHint(BoardHint hint)
 {
     hints.Add(hint);
 }