Time for action - manipulating the game board

  1. Add public methods to the GameBoard class to interact with GamePiece:
    public void RotatePiece(int x, int y, bool clockwise)
    {
    boardSquares[x, y].RotatePiece(clockwise);
    }
    public Rectangle GetSourceRect(int x, int y)
    {
    return boardSquares[x, y].GetSourceRect();
    }
    public string GetSquare(int x, int y)
    {
    return boardSquares[x, y].PieceType;
    }
    public void SetSquare(int x, int y, string pieceName)
    {
    boardSquares[x, y].SetPiece(pieceName);
    }
    public bool HasConnector(int x, int y, string direction)
    {
    return boardSquares[x, y].HasConnector(direction);
    }
    public void RandomPiece(int x, int y)
    {
    boardSquares[x, y].SetPiece(GamePiece.PieceTypes[rand.Next(0,
    GamePiece.MaxPlayablePieceIndex+1)]);
    }
    
    

What just happened?

RotatePiece(), GetSourceRect(), GetSquare(), SetSquare(), and HasConnector() methods simply locate the appropriate GamePiece within the boardSquares array and pass on the function request to the piece.

The RandomPiece() method uses the rand object to get a random value from the PieceTypes array and assign it to a GamePiece. It is important to remember that with the Random.Next() method overload used here, the second parameter is non-inclusive. In order to generate a random number from 0 through 5, the second parameter needs to be 6.

Filling in the gaps

Whenever the player completes a scoring chain, the pieces in that chain are removed from the board. Any pieces above them fall down into the vacated spots and new pieces are generated.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.196.182