diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/tile.cpp | 31 | ||||
-rw-r--r-- | common/tile.h | 16 |
2 files changed, 46 insertions, 1 deletions
diff --git a/common/tile.cpp b/common/tile.cpp index 29e0c84..5a05548 100644 --- a/common/tile.cpp +++ b/common/tile.cpp @@ -6,10 +6,27 @@ Tile::Tile() { } -Tile::Tile(Tile::Type t, bool re, bool ro) : type(t), red(re), rotated(ro){ +Tile::Tile(Tile::Type t, bool re, bool ro) : type(t), red(re), rotated(ro) { } +Tile::Tile(Set s, int num, bool re, bool ro) : red(re), rotated(ro) { + switch(s) { + case Man: + type = Type(Man_1 + num - 1); + break; + case Pin: + type = Type(Pin_1 + num - 1); + break; + case Sou: + type = Type(Sou_1 + num - 1); + break; + default: + // Invalid. + break; + } +} + int Tile::get_num() const { if(type >= Man_1 && type <= Sou_9) { return (type - Man_1) % 9 + 1; @@ -18,6 +35,18 @@ int Tile::get_num() const { } } +Tile::Set Tile::get_set() const { + if(type >= Man_1 && type <= Man_9) { + return Man; + } else if(type >= Pin_1 && type <= Pin_9) { + return Pin; + } else if(type >= Sou_1 && type <= Sou_9) { + return Sou; + } else { + return Honor; + } +} + bool Tile::operator==(const Tile& other) const { return type == other.type; } diff --git a/common/tile.h b/common/tile.h index 84552aa..90e25dc 100644 --- a/common/tile.h +++ b/common/tile.h @@ -51,18 +51,34 @@ class Tile { Hatsu }; + enum Set { + Honor, + Man, + Pin, + Sou + }; + Type type; bool red; bool rotated; + //! Default constructor. Tile(); + + //! Construct tile by type. Tile(Type t, bool re = false, bool ro = false); + //! Construct tile by set and number. + Tile(Set s, int num, bool re = false, bool ro = false); + virtual ~Tile(){}; //! Get the numeric value of the tile (if one of the man/pin/sou-sets). int get_num() const; + //! Get the set type of the tile (if one of the man/pin/sou-sets). + Set get_set() const; + //! Compare two tiles. Equal if type matches; flags are not compared. bool operator==(const Tile& other) const; |