eliot/game/rack.h

63 lines
1.9 KiB
C
Raw Normal View History

/*****************************************************************************
* Eliot
* Copyright (C) 2002-2012 Antoine Fraboulet & Olivier Teulière
* Authors: Antoine Fraboulet <antoine.fraboulet @@ free.fr>
* Olivier Teulière <ipkiss @@ gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
2004-04-08 11:43:06 +02:00
#ifndef RACK_H_
#define RACK_H_
2004-04-08 11:43:06 +02:00
#include <vector>
2005-12-26 22:08:08 +01:00
#include <string>
2004-04-08 11:43:06 +02:00
#include "tile.h"
2012-02-18 22:26:52 +01:00
#include "logging.h"
using namespace std;
2004-04-08 11:43:06 +02:00
2005-03-27 19:30:48 +02:00
/**
* A rack is a set of tiles, no more.
* Tiles have to be in the bag for the rack to be valid.
2005-03-27 19:30:48 +02:00
*/
class Rack
{
2012-02-18 22:26:52 +01:00
DEFINE_LOGGER();
public:
Rack();
2004-04-08 11:43:06 +02:00
unsigned int getNbTiles() const { return m_ntiles; }
bool isEmpty() const { return getNbTiles() == 0; }
2004-04-08 11:43:06 +02:00
unsigned int in(const Tile &t) const { return m_tiles[t.toCode()]; }
void add(const Tile &t) { m_tiles[t.toCode()]++; m_ntiles++; }
void remove(const Tile &t);
void clear();
void getTiles(vector<Tile> &oTiles) const;
2004-04-08 11:43:06 +02:00
wstring toString() const;
2005-12-26 22:08:08 +01:00
private:
/// Vector indexed by tile codes, containing the number of tiles
vector<unsigned int> m_tiles;
unsigned int m_ntiles;
};
2004-04-08 11:43:06 +02:00
#endif
2006-01-01 20:47:03 +01:00