1 /*********************************************************************** 2 * 3 * Copyright (C) 2007-2008 Graeme Gott <graeme@gottcode.org> 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 ***********************************************************************/ 19 20 #ifndef PIECE_H 21 #define PIECE_H 22 23 struct Cell 24 { 25 Cell(int x1 = -1, int y1 = -1) xCell26 : x(x1), 27 y(y1) 28 { 29 } 30 31 int x; 32 int y; 33 }; 34 35 class Board; 36 37 class Piece 38 { 39 public: 40 Piece(int type, Board* board); 41 isValid()42 bool isValid() const 43 { 44 return m_valid; 45 } 46 moveLeft()47 bool moveLeft() 48 { 49 return move(-1, 0); 50 } 51 moveRight()52 bool moveRight() 53 { 54 return move(1, 0); 55 } 56 moveDown()57 bool moveDown() 58 { 59 return move(0, 1); 60 } 61 62 bool rotate(); 63 void drop(); 64 cells()65 const Cell* cells() const 66 { 67 return m_cells; 68 } 69 type()70 int type() const 71 { 72 return m_type; 73 } 74 75 static void cells(Cell* cells, int type); 76 77 private: 78 bool move(int x, int y); 79 bool updatePosition(const Cell* cells); 80 81 int m_type; 82 Cell m_cells[4]; 83 Cell m_pivot; 84 bool m_valid; 85 Board* m_board; 86 }; 87 88 #endif // PIECE_H 89