Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Game namespace ---------------------------------------------------------------------
- class Tetris
- {
- public:
- // A tetromino --------------------------------------------------------------------
- class Block
- {
- public:
- // A piece of a tetromino -----------------------------------------------------
- struct Piece
- {
- // Simply the position
- Byte2 Position;
- };
- // A rotation state -----------------------------------------------------------
- struct State
- {
- // State building object forward declaration
- class Builder;
- // Four pieces to make a block
- Piece Piece[4];
- // Helper to build up a state I guess
- Builder& Build();
- };
- // Rotation state builder object ----------------------------------------------
- class State::Builder
- {
- public:
- // The state we're building
- State& Handle;
- // A counter
- Byte Slot;
- public:
- // Default constructor
- Builder(State& state) : Handle(state), Slot(0) {};
- // Destructor
- ~Builder() = default;
- // Build operator!
- Builder& operator () (Byte x, Byte y)
- {
- // Add the position to the state
- Handle.Piece[Slot].Position.x = x;
- Handle.Piece[Slot].Position.y = y;
- // Ready to next slot!
- Slot++;
- return *this;
- }
- };
- public:
- // Four rotation states and their pieces makes a tetromino
- State State[4];
- Byte Rotation;
- private:
- // Eurgh
- Byte Padding[3];
- public:
- // Default constructor
- Block() : State(), Rotation() {};
- // Destructor
- ~Block() = default;
- // No methods for now
- };
- static Void CreateBlock()
- {
- // An L tetromino
- Block tetromino;
- // -- //
- tetromino.State[0].Build()(0, 1)(1, 1)(2, 1)(3, 1);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement