Skip to content

Commit

Permalink
LBlock returns blocks at row
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew long committed Apr 11, 2012
1 parent bf69074 commit 2b78aae
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
3 changes: 1 addition & 2 deletions BlockFactory.cpp
Expand Up @@ -15,8 +15,7 @@ BlockFactory::BlockFactory()

Block * BlockFactory::nextShape(QPointF point)
{
return new LineBlock(point);
int random = rand() % 7;
int random = rand() % 2;//7;

switch (random)
{
Expand Down
66 changes: 66 additions & 0 deletions LBlock.cpp
Expand Up @@ -79,6 +79,72 @@ int LBlock::numberBlocksAtRow(int row)
}
}

QList<Block *> LBlock::getBlocksAtRow(int row)
{
QList<Block *> rowOfBlocks;

if (angle == 0)
{
if (row == 0)
{
rowOfBlocks << new Block(QPointF(x(), y() + BLOCK_SIZE / 2), FILL_COLOR);
rowOfBlocks << new Block(QPointF(x() + BLOCK_SIZE / 2, y() + BLOCK_SIZE / 2), FILL_COLOR);
rowOfBlocks << new Block(QPointF(x() + ((BLOCK_SIZE / 2) * 2), y() + BLOCK_SIZE / 2), FILL_COLOR);
}
else
{
rowOfBlocks << new Block(QPointF(x() + ((BLOCK_SIZE / 2) * 2), y()), FILL_COLOR);
}
}
else if (angle == 90)
{
if (row == 0)
{
rowOfBlocks << new Block(QPointF(x(), y() + ((BLOCK_SIZE / 2) * 2)), FILL_COLOR);
rowOfBlocks << new Block(QPointF(x() + (BLOCK_SIZE / 2), y() + ((BLOCK_SIZE / 2) * 2)), FILL_COLOR);
}
else if (row == 1)
{
rowOfBlocks << new Block(QPointF(x(), y() + (BLOCK_SIZE / 2)), FILL_COLOR);
}
else
{
rowOfBlocks << new Block(QPointF(x(), y()), FILL_COLOR);
}
}
else if (angle == 180)
{
if (row == 0)
{
rowOfBlocks << new Block(QPointF(x(), y() + BLOCK_SIZE / 2), FILL_COLOR);
}
else
{
rowOfBlocks << new Block(QPointF(x(), y()), FILL_COLOR);
rowOfBlocks << new Block(QPointF(x() + BLOCK_SIZE / 2, y()), FILL_COLOR);
rowOfBlocks << new Block(QPointF(x() + ((BLOCK_SIZE / 2) * 2), y()), FILL_COLOR);
}
}
else
{
if (row == 0)
{
rowOfBlocks << new Block(QPointF(x() + BLOCK_SIZE / 2, y() + ((BLOCK_SIZE / 2) * 2)), FILL_COLOR);
}
else if (row == 1)
{
rowOfBlocks << new Block(QPointF(x() + BLOCK_SIZE / 2, y() + BLOCK_SIZE / 2), FILL_COLOR);
}
else
{
rowOfBlocks << new Block(QPointF(x(), y()), FILL_COLOR);
rowOfBlocks << new Block(QPointF(x() + BLOCK_SIZE / 2, y()), FILL_COLOR);
}
}

return rowOfBlocks;
}

QRectF LBlock::boundingRect() const
{
if (angle == 90 || angle == 270)
Expand Down
1 change: 1 addition & 0 deletions LBlock.h
Expand Up @@ -12,6 +12,7 @@ class LBlock : public Block
QPainterPath shape() const;
int numberRowsOfBlocks();
int numberBlocksAtRow(int row);
QList<Block *> getBlocksAtRow(int row);
private:
static const int BLOCK_WIDTH = (BLOCK_SIZE*3);
static const int BLOCK_HEIGHT = (BLOCK_SIZE * 2);
Expand Down

0 comments on commit 2b78aae

Please sign in to comment.