00001 #ifndef PIECE_H_
00002 #define PIECE_H_
00003
00004 class Piece
00005 {
00006 public:
00007 int down, left, up, right;
00008 int index, rotation;
00009
00010 Piece()
00011 {
00012 down = 0;
00013 left = 0;
00014 up = 0;
00015 right = 0;
00016 index = -1;
00017 rotation = 0;
00018 }
00019
00020 Piece(int _down, int _left, int _up, int _right, int _index, int _rotation) :
00021 down(_down), left(_left), up(_up), right(_right), index(_index), rotation(_rotation)
00022 {
00023 }
00024
00025 void rotate()
00026 {
00027 int first_down = down;
00028
00029 down = right;
00030 right = up;
00031 up = left;
00032
00033 left = first_down;
00034
00035 rotation++;
00036 if (rotation == 4)
00037 rotation = 0;
00038 }
00039 };
00040
00041 ostream& operator<<(ostream &os, const Piece &obj)
00042 {
00043 os << "(" << obj.down << "," << obj.left << "," << obj.up << "," << obj.right << ")";
00044 return os;
00045 }
00046
00047 ostream& operator<<(ostream &os, const Matrix<Piece> &obj)
00048 {
00049 cout << "game" << endl;
00050 for (int i = 0; i < obj.getRows(); i++)
00051 for (int count = 0; count < 3; count++)
00052 {
00053 if (count != 1)
00054 cout << " ";
00055 for (int j = 0; j < obj.getCols(); j++)
00056 {
00057 if (count == 0)
00058 cout << obj(i, j).up << " ";
00059 else if (count == 1)
00060 cout << obj(i, j).left << " " << obj(i, j).right << " ";
00061 else
00062 cout << obj(i, j).down << " ";
00063 }
00064
00065 cout << endl;
00066 }
00067
00068 return os;
00069 }
00070
00071 #endif