title: Tetris: Layout of Classes
body: <p>I've written a working tetris clone but it has a pretty messy layout. Could I please get feedback on how to restructure my classes to make my coding better. I focuses on making my code as generic as possible, trying to make it more an engine for games only using blocks.</p>
  
  <p>Each block is created seperately in the game.
  My game has 2 BlockLists (linked lists): StaticBlocks and Tetroid.
  StaticBlocks is obviously the list of all non-moving blocks, and tetroid are the 4 blocks of the current tetroid.</p>
  
  <ol>
  <li><p>In main a World is created.</p></li>
  <li><p>First a new tetroid (4 blocks in a list Tetroid) is created by (NewTetroid)</p></li>
  <li><p>Collision is detected by the (***Collide) functions, by comparing each of Tetroid with all of the StaticBlocks using the (If*****) functions.</p></li>
  <li><p>When the tetroid stops (hits the bottom/blocks), it is copied (CopyTetroid) to the StaticBlocks and Tetroid is made empty, then tests are made for complete lines, blocks are destroyed/dropped etc by searching StaticBlocks with (SearchY).</p></li>
  <li><p>A new tetroid is created.</p></li>
  </ol>
  
  <p>(TranslateTetroid) and (RotateTetroid) perform operations on each block in the Tetroid list one by one ( <strong>I think this is bad practise</strong>).</p>
  
  <p>(DrawBlockList) just goes through a list, running the Draw() function for each block.</p>
  
  <p>Rotation is controlled by setting rotation axis relative to the first block in Tetroid when (NewTetroid) is called. My rotation function (Rotate) for each block rotates it around the axis, using an input +-1 for left/right rotation. RotationModes and States are for blocks that rotate in 2 or 4 different ways, defining what state they are currently in, and whether they should be rotated left or right. <strong>I am not happy with how these are defined in "World", but I don't know where to put them, whilst still keeping my (Rotate) function generic for each block</strong>.</p>
  
  <p>My classes are as follows</p>
  
  <pre><code>class World
  {
      public:
      /* Constructor/Destructor */
      World();
      ~World();
  
      /* Blocks Operations */
      void AppendBlock(int, int, BlockList&amp;);
      void RemoveBlock(Block*, BlockList&amp;);;
  
      /* Tetroid Operations */
      void NewTetroid(int, int, int, BlockList&amp;);
      void TranslateTetroid(int, int, BlockList&amp;);
      void RotateTetroid(int, BlockList&amp;);
      void CopyTetroid(BlockList&amp;, BlockList&amp;);
  
      /* Draw */
      void DrawBlockList(BlockList&amp;);
      void DrawWalls();
  
      /* Collisions */
      bool TranslateCollide(int, int, BlockList&amp;, BlockList&amp;);
      bool RotateCollide(int, BlockList&amp;, BlockList&amp;);
      bool OverlapCollide(BlockList&amp;, BlockList&amp;); // For end of game
  
      /* Game Mechanics */
      bool CompleteLine(BlockList&amp;); // Test all line
      bool CompleteLine(int, BlockList&amp;); // Test specific line
      void ColourLine(int, BlockList&amp;);
      void DestroyLine(int, BlockList&amp;);
      void DropLine(int, BlockList&amp;); // Drops all blocks above line
  
      int rotationAxisX;
      int rotationAxisY;
      int rotationState; // Which rotation it is currently in
      int rotationModes; // How many diff rotations possible
  
      private:
      int wallX1;
      int wallX2;
      int wallY1;
      int wallY2;
  };
  
  class BlockList
  {
      public:
      BlockList();
      ~BlockList();
  
      Block* GetFirst();
      Block* GetLast();
  
      /* List Operations */
      void Append(int, int);
      int  Remove(Block*);
      int  SearchY(int);
  
      private:
      Block *first;
      Block *last;
  };
  
  class Block
  {
      public:
      Block(int, int);
      ~Block();
  
      int GetX();
      int GetY();
  
      void SetColour(int, int, int);
  
      void Translate(int, int);
      void Rotate(int, int, int);
  
      /* Return values simulating the operation (for collision purposes) */
      int IfTranslateX(int);
      int IfTranslateY(int);
      int IfRotateX(int, int, int);
      int IfRotateY(int, int, int);
  
      void Draw();
  
      Block *next;
  
      private:
      int pX; // position x
      int pY; // position y
      int colourR;
      int colourG;
      int colourB;
  };
  </code></pre>
  
  <p>Sorry if this is a bit unclear or long winded, I'm just looking for some help restructuring.</p>