From bfcc7a80c63d5988221ec59323508502b590e7b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Thu, 17 Jan 2013 17:21:33 +0100 Subject: [PATCH] Bag: the number of tiles cannot be negative --- game/bag.cpp | 8 ++++---- game/bag.h | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/game/bag.cpp b/game/bag.cpp index a54218d..035a453 100644 --- a/game/bag.cpp +++ b/game/bag.cpp @@ -43,7 +43,7 @@ Bag::Bag(const Dictionary &iDic) } -unsigned int Bag::count(const Tile &iTile) const +unsigned Bag::count(const Tile &iTile) const { map::const_iterator it = m_tilesMap.find(iTile); if (it != m_tilesMap.end()) @@ -52,7 +52,7 @@ unsigned int Bag::count(const Tile &iTile) const } -unsigned int Bag::getNbVowels() const +unsigned Bag::getNbVowels() const { int v = 0; @@ -66,7 +66,7 @@ unsigned int Bag::getNbVowels() const } -unsigned int Bag::getNbConsonants() const +unsigned Bag::getNbConsonants() const { int c = 0; @@ -118,7 +118,7 @@ Tile Bag::selectRandomConsonant() const } -Tile Bag::selectRandomTile(unsigned int total, +Tile Bag::selectRandomTile(unsigned total, bool onlyVowels, bool onlyConsonants) const { ASSERT(total > 0, "Not enough tiles (of the requested kind) in the bag"); diff --git a/game/bag.h b/game/bag.h index e2d1367..b8bd7aa 100644 --- a/game/bag.h +++ b/game/bag.h @@ -46,16 +46,16 @@ public: void replaceTile(const Tile &iTile); /// Count how many tiles identical to iTile are available in the bag - unsigned int count(const Tile &iTile) const; + unsigned count(const Tile &iTile) const; /** * Return how many tiles/vowels/consonants are available * Warning: b.getNbVowels() + b.getNbConsonants() != b.getNbTiles(), * because of the jokers and the 'Y'. */ - unsigned int getNbTiles() const { return m_nbTiles; } - unsigned int getNbVowels() const; - unsigned int getNbConsonants() const; + unsigned getNbTiles() const { return m_nbTiles; } + unsigned getNbVowels() const; + unsigned getNbConsonants() const; /** * Return a random available tile @@ -88,10 +88,10 @@ private: map m_tilesMap; /// Total number of tiles in the bag - int m_nbTiles; + unsigned m_nbTiles; /// Helper method, used by the various selectRandom*() methods - Tile selectRandomTile(unsigned int total, + Tile selectRandomTile(unsigned total, bool onlyVowels, bool onlyConsonants) const; };