Width & Height take rotations into account.

This commit is contained in:
David Vereb 2023-04-02 12:41:16 -04:00
parent 10c06d8103
commit 75a8f365ce
3 changed files with 132 additions and 11 deletions

View File

@ -3,34 +3,127 @@
#include <curses.h>
#include <stdlib.h> // exit()
unsigned PieceHeight(const Piece &piece)
unsigned PieceHeight(const Piece &piece, Rotation rotation)
{
switch(piece)
{
case PIECE_ONE:
switch(rotation)
{
default:
case ROTATION_NONE:
case ROTATION_180:
return 2;
case ROTATION_90:
case ROTATION_270:
return 3;
};
break;
case PIECE_TWO:
return 4;
break;
case PIECE_THREE:
switch(rotation)
{
default:
case ROTATION_NONE:
case ROTATION_180:
return 4;
case ROTATION_90:
case ROTATION_270:
return 2;
};
break;
case PIECE_FOUR:
case PIECE_SEVEN:
switch(rotation)
{
default:
case ROTATION_NONE:
case ROTATION_180:
return 3;
case ROTATION_90:
case ROTATION_270:
return 2;
};
break;
case PIECE_FIVE:
case PIECE_EIGHT:
return 3;
break;
case PIECE_SIX:
switch(rotation)
{
default:
case ROTATION_NONE:
case ROTATION_180:
return 2;
case ROTATION_90:
case ROTATION_270:
return 4;
};
break;
case PIECE_SEVEN:
}
std::exit(-1);
}
unsigned PieceWidth(const Piece &piece, Rotation rotation)
{
switch(piece)
{
case PIECE_ONE:
switch(rotation)
{
default:
case ROTATION_NONE:
case ROTATION_180:
return 3;
case ROTATION_90:
case ROTATION_270:
return 2;
};
break;
case PIECE_TWO:
case PIECE_THREE:
switch(rotation)
{
default:
case ROTATION_NONE:
case ROTATION_180:
return 2;
case ROTATION_90:
case ROTATION_270:
return 4;
};
break;
case PIECE_FOUR:
case PIECE_SEVEN:
switch(rotation)
{
default:
case ROTATION_NONE:
case ROTATION_180:
return 2;
case ROTATION_90:
case ROTATION_270:
return 3;
};
break;
case PIECE_FIVE:
case PIECE_EIGHT:
return 3;
break;
case PIECE_SIX:
switch(rotation)
{
default:
case ROTATION_NONE:
case ROTATION_180:
return 4;
case ROTATION_90:
case ROTATION_270:
return 2;
};
break;
}
std::exit(-1);

View File

@ -69,7 +69,10 @@ typedef uint8_t Piece; // only need literally 8, not 8 bits, but hey.
* [][][]
*/
unsigned PieceHeight(const Piece &piece);
unsigned PieceHeight(const Piece &piece,
Rotation rotation = Rotation::ROTATION_NONE);
unsigned PieceWidth(const Piece &piece,
Rotation rotation = Rotation::ROTATION_NONE);
void DrawPiece(const Piece &piece, int y, int x,
Rotation rotation = Rotation::ROTATION_NONE);

View File

@ -96,13 +96,38 @@ void DemoPieces()
for(auto rotation : rotations)
{
clear();
int x = 1;
int x, y;
// Always same distance apart:
x = 10;
y = 2;
for(auto i = 0; i < 8; ++i)
{
Piece piece = static_cast<Piece>(i);
DrawPiece(piece, 2, x, rotation);
DrawPiece(piece, y, x, rotation);
x += 12;
}
// Always same width apart:
x = 2;
y = 10;
for(auto i = 0; i < 8; ++i)
{
Piece piece = static_cast<Piece>(i);
DrawPiece(piece, y, x, rotation);
x += PieceWidth(piece, rotation) * 2 + 2;
}
// Always same height apart, sharing first piece with same-width row:
x = 2;
y = 10 + PieceHeight(0, rotation) + 1;
for(auto i = 1; i < 8; ++i) // skip first
{
Piece piece = static_cast<Piece>(i);
DrawPiece(piece, y, x, rotation);
y += PieceHeight(piece, rotation) + 1;
}
getch();
}
move(8, 2);