Trying piece data with vectors of vectors of booleans.
This commit is contained in:
parent
59cab98b20
commit
ac95bac62e
4
Makefile
4
Makefile
@ -1,6 +1,6 @@
|
||||
build/apad: main.cpp Pieces.cpp
|
||||
build/apad: main.cpp Pieces.cpp Pieces.h
|
||||
mkdir -p build
|
||||
clang++ -g -O0 -std=c++17 -o $@ $^ -lncurses
|
||||
clang++ -g -O0 -std=c++17 -o $@ main.cpp Pieces.cpp -lncurses
|
||||
|
||||
clean:
|
||||
rm build/apad
|
||||
|
83
Pieces.cpp
83
Pieces.cpp
@ -330,3 +330,86 @@ void DrawPiece(const Piece &piece, int y, int x, Rotation rotation)
|
||||
}
|
||||
}
|
||||
|
||||
PieceData RotatePieceData(const PieceData &data, Rotation rotation)
|
||||
{
|
||||
PieceData rtn;
|
||||
switch(rotation)
|
||||
{
|
||||
default:
|
||||
case Rotation::ROTATION_NONE:
|
||||
return data;
|
||||
break;
|
||||
case Rotation::ROTATION_90:
|
||||
// TODO(dev):
|
||||
// TODO(dev): x's become y's
|
||||
// TODO(dev): y's become max x - x's
|
||||
// TODO(dev):
|
||||
break;
|
||||
case Rotation::ROTATION_180:
|
||||
for(size_t row = 0; row < data.size(); ++row)
|
||||
{
|
||||
size_t opposite_row = data.size() - row - 1;
|
||||
for(size_t col = 0; col < data[row].size(); ++col)
|
||||
{
|
||||
size_t opposite_col = data[opposite_col].size() - col - 1;
|
||||
rtn[opposite_row][opposite_col] = data[row][col];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Rotation::ROTATION_270:
|
||||
// TODO(dev):
|
||||
// TODO(dev): I mean we could just rotate 90 & then 180,
|
||||
// TODO(dev): but that seems like the cheap way out.
|
||||
// TODO(dev):
|
||||
break;
|
||||
};
|
||||
rtn.resize(PD_PieceWidth(data));
|
||||
for(auto row : data)
|
||||
{
|
||||
for(auto col : row)
|
||||
{
|
||||
}
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
unsigned PD_PieceHeight(const PieceData &data)
|
||||
{
|
||||
return data.size();
|
||||
}
|
||||
unsigned PD_PieceWidth(const PieceData &data)
|
||||
{
|
||||
size_t rtn = 0;
|
||||
for(auto row : data)
|
||||
rtn = std::max(rtn, row.size());
|
||||
return rtn;
|
||||
}
|
||||
|
||||
unsigned PD_PieceHeight(const Piece &piece, Rotation rotation)
|
||||
{
|
||||
switch(rotation)
|
||||
{
|
||||
default:
|
||||
case Rotation::ROTATION_NONE:
|
||||
case Rotation::ROTATION_180:
|
||||
return pieces.at(piece).size();
|
||||
break;
|
||||
case Rotation::ROTATION_90:
|
||||
case Rotation::ROTATION_270:
|
||||
return PD_PieceHeight(RotatePieceData(pieces.at(piece), Rotation::ROTATION_90));
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
unsigned PD_PieceWidth(const Piece &piece, Rotation rotation)
|
||||
{
|
||||
size_t rtn = 0;
|
||||
for(auto row : pieces.at(piece))
|
||||
rtn = std::max(rtn, row.size());
|
||||
return rtn;
|
||||
}
|
||||
|
||||
void PD_DrawPiece(const Piece &piece, int y, int x, Rotation rotation)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
81
Pieces.h
81
Pieces.h
@ -2,6 +2,8 @@
|
||||
#define APAD_PIECES_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
enum Rotation {
|
||||
ROTATION_NONE,
|
||||
@ -69,6 +71,75 @@ typedef uint8_t Piece; // only need literally 8, not 8 bits, but hey.
|
||||
* [][][]
|
||||
*/
|
||||
|
||||
typedef std::vector<std::vector<bool>> PieceData;
|
||||
const std::unordered_map<Piece, PieceData> pieces =
|
||||
{
|
||||
{
|
||||
PIECE_ONE,
|
||||
{
|
||||
{ true, true, true, },
|
||||
{ true, true, true, },
|
||||
}
|
||||
},
|
||||
{
|
||||
PIECE_TWO,
|
||||
{
|
||||
{ true, false, },
|
||||
{ true, true, },
|
||||
{ true, false, },
|
||||
{ true, false, },
|
||||
}
|
||||
},
|
||||
{
|
||||
PIECE_THREE,
|
||||
{
|
||||
{ false, true, },
|
||||
{ false, true, },
|
||||
{ false, true, },
|
||||
{ true, true, },
|
||||
}
|
||||
},
|
||||
{
|
||||
PIECE_FOUR,
|
||||
{
|
||||
{ true, true, },
|
||||
{ true, false, },
|
||||
{ true, true, },
|
||||
}
|
||||
},
|
||||
{
|
||||
PIECE_FIVE,
|
||||
{
|
||||
{ true, true, false, },
|
||||
{ false, true, false, },
|
||||
{ false, true, true, },
|
||||
}
|
||||
},
|
||||
{
|
||||
PIECE_SIX,
|
||||
{
|
||||
{ true, true, false, false, },
|
||||
{ false, true, true, true, },
|
||||
}
|
||||
},
|
||||
{
|
||||
PIECE_SEVEN,
|
||||
{
|
||||
{ true, true, },
|
||||
{ true, true, },
|
||||
{ true, false, },
|
||||
}
|
||||
},
|
||||
{
|
||||
PIECE_EIGHT,
|
||||
{
|
||||
{ false, false, true, },
|
||||
{ false, false, true, },
|
||||
{ true, true, true, },
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
unsigned PieceHeight(const Piece &piece,
|
||||
Rotation rotation = Rotation::ROTATION_NONE);
|
||||
unsigned PieceWidth(const Piece &piece,
|
||||
@ -76,4 +147,14 @@ unsigned PieceWidth(const Piece &piece,
|
||||
void DrawPiece(const Piece &piece, int y, int x,
|
||||
Rotation rotation = Rotation::ROTATION_NONE);
|
||||
|
||||
PieceData RotatePieceData(const PieceData &data, Rotation rotation);
|
||||
unsigned PD_PieceHeight(const PieceData &data);
|
||||
unsigned PD_PieceHeight(const Piece &piece,
|
||||
Rotation rotation = Rotation::ROTATION_NONE);
|
||||
unsigned PD_PieceWidth(const PieceData &data);
|
||||
unsigned PD_PieceWidth(const Piece &piece,
|
||||
Rotation rotation = Rotation::ROTATION_NONE);
|
||||
void PD_DrawPiece(const Piece &piece, int y, int x,
|
||||
Rotation rotation = Rotation::ROTATION_NONE);
|
||||
|
||||
#endif
|
||||
|
8
main.cpp
8
main.cpp
@ -39,7 +39,7 @@ int main(int argc, char *argv[])
|
||||
try {
|
||||
Piece piece = 0b111 & std::atoi(argv[input]);
|
||||
DrawPiece(piece, y, 1);
|
||||
y += PieceHeight(piece) + 1;
|
||||
y += PD_PieceHeight(piece) + 1;
|
||||
} catch(const std::exception &e) {
|
||||
mvaddstr(y, 1, "std::atoi error");
|
||||
y += 2;
|
||||
@ -118,16 +118,16 @@ void DemoPieces()
|
||||
{
|
||||
Piece piece = static_cast<Piece>(i);
|
||||
DrawPiece(piece, y, x, rotation);
|
||||
x += PieceWidth(piece, rotation) * 2 + 2;
|
||||
x += PD_PieceWidth(piece, rotation) * 2 + 2;
|
||||
}
|
||||
// Always same height apart, sharing first piece with same-width row:
|
||||
x = 2;
|
||||
y = 10 + PieceHeight(0, rotation) + 1;
|
||||
y = 10 + PD_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;
|
||||
y += PD_PieceHeight(piece, rotation) + 1;
|
||||
}
|
||||
|
||||
getch();
|
||||
|
Loading…
Reference in New Issue
Block a user