typedef enum{
HTetrisPieceShapeNone,
HTetrisPieceShapeI,
HTetrisPieceShapeT,
HTetrisPieceShapeJ,
HTetrisPieceShapeL,
HTetrisPieceShapeO,
HTetrisPieceShapeZ,
HTetrisPieceShapeS
}HTetrisPieceShape;
typedef enum{
HTetrisPieceRotateZero,
HTetrisPieceRotate90,
HTetrisPieceRotate180,
HTetrisPieceRotate270
}HTetrisPieceRotate;
class HTetrisPiece
{
public:
HTetrisPiece(){setShape(HTetrisPieceShapeNone);}
void setRandomShape();
void setShape(HTetrisPieceShape shape);
HTetrisPieceShape shape() const { return pieceShape; }
int x(int index) const { return coords[index][0]; }
int y(int index) const { return coords[index][1]; }
int minX() const;
int maxX() const;
int minY() const;
int maxY() const;
void setRotate(HTetrisPieceRotate rotate);
HTetrisPiece pieceFromRotatedLeft() const;
HTetrisPiece pieceFromRotatedRight() const;
private:
void setX(int index, int x) { coords[index][0] = x; }
void setY(int index, int y) { coords[index][1] = y; }
HTetrisPieceShape pieceShape;
int coords[4][2];
};
#endif // HTetrisPIECE_H
/*
*Filename: HTetrispiece.cpp
*Author: Hale Chan <halechan@qq.com>
*Date: 2011-11-24
*/
#include "HTetrisPiece.h"
#include <QtCore>
static const int coordsTable[8][4][2] = {
热门文档