1 /* 2 Bastet - tetris clone with embedded bastard block chooser 3 (c) 2005-2009 Federico Poloni <f.polonithirtyseven@sns.it> minus 37 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 #ifndef BLOCK_POSITION_HPP 20 #define BLOCK_POSITION_HPP 21 22 #include "Block.hpp" 23 24 namespace Bastet{ 25 26 /** Block position = position (x,y) + orientation -- this is the object that gets evaluated by the block chooser 27 */ 28 class Well; 29 30 enum Movement {RotateCW,RotateCCW,Left,Right,Down}; 31 32 class BlockPosition{ 33 private: 34 Dot _pos; 35 Orientation _orientation; 36 public: BlockPosition(Dot d=(Dot){3,-2},Orientation o=Orientation ())37 BlockPosition(Dot d=(Dot){3,-2}, Orientation o=Orientation()):_pos(d),_orientation(o){}; operator ==(const BlockPosition & p) const38 bool operator==(const BlockPosition &p) const{ 39 return _pos==p._pos && _orientation==p._orientation; 40 } 41 ///returns an y such that the block lies completely in [y,y+3] GetBaseY() const42 int GetBaseY() const{return _pos.y;} 43 void Move(Movement m); 44 bool MoveIfPossible(Movement m, BlockType b, const Well *w); 45 46 void Drop(BlockType bt, const Well *w); 47 48 const DotMatrix GetDots(BlockType b) const; 49 bool IsValid(BlockType bt, const Well *w) const; 50 bool IsOutOfScreen(BlockType bt) const; 51 hash_value(const BlockPosition & p)52 friend size_t hash_value(const BlockPosition &p){ 53 return hash_value(p._pos)*4+int(p._orientation); 54 } 55 56 }; 57 58 } 59 60 #endif //BLOCK_POSITION_HPP 61