2005-02-05 12:14:56 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Copyright (C) 2005 Eliot
|
|
|
|
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
|
|
|
|
*
|
|
|
|
* 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
|
2005-10-23 16:53:42 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-02-05 12:14:56 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _TILE_H_
|
|
|
|
#define _TILE_H_
|
|
|
|
|
|
|
|
#include <list>
|
2006-01-22 13:23:52 +01:00
|
|
|
#include <vector>
|
2005-02-05 12:14:56 +01:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
/*************************
|
|
|
|
* A Tile is the internal representation
|
|
|
|
* used within the game library to
|
|
|
|
* handle letters
|
|
|
|
*************************/
|
|
|
|
|
|
|
|
class Tile
|
|
|
|
{
|
|
|
|
public:
|
2005-04-09 16:56:03 +02:00
|
|
|
|
|
|
|
// a lowercase character always a joker
|
|
|
|
// - this permits to detect joker in already played games
|
|
|
|
// - we need to pay attention when inserting character taken
|
|
|
|
// from user input
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
Tile(wchar_t c = 0);
|
2005-02-05 12:14:56 +01:00
|
|
|
virtual ~Tile() {}
|
|
|
|
|
2005-02-17 21:01:59 +01:00
|
|
|
bool isEmpty() const { return m_dummy; }
|
2005-02-05 12:14:56 +01:00
|
|
|
bool isJoker() const { return m_joker; }
|
|
|
|
bool isVowel() const;
|
|
|
|
bool isConsonant() const;
|
2005-04-09 16:56:03 +02:00
|
|
|
unsigned int maxNumber() const;
|
|
|
|
unsigned int getPoints() const;
|
2006-01-22 13:23:52 +01:00
|
|
|
wchar_t toChar() const;
|
|
|
|
unsigned int toCode() const;
|
2005-11-04 21:00:05 +01:00
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
static const Tile &dummy() { return m_TheDummy; }
|
|
|
|
static const Tile &Joker() { return m_TheJoker; }
|
|
|
|
static const list<Tile>& getAllTiles();
|
2006-01-22 13:23:52 +01:00
|
|
|
static const Tile &GetTileFromCode(unsigned int iCode);
|
2005-02-05 12:14:56 +01:00
|
|
|
|
|
|
|
bool operator <(const Tile &iOther) const;
|
|
|
|
bool operator ==(const Tile &iOther) const;
|
|
|
|
bool operator !=(const Tile &iOther) const;
|
|
|
|
|
|
|
|
private:
|
2006-01-22 13:23:52 +01:00
|
|
|
wchar_t m_char;
|
2005-02-05 12:14:56 +01:00
|
|
|
bool m_joker;
|
|
|
|
bool m_dummy;
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
/**
|
|
|
|
* Internal code, used in the dictionary to represent the letter.
|
|
|
|
* It is mainly used by the Cross class.
|
|
|
|
*/
|
|
|
|
int m_code;
|
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
// Special tiles are declared static
|
|
|
|
static const Tile m_TheJoker;
|
|
|
|
static const Tile m_TheDummy;
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
/// List of available tiles
|
2005-02-05 12:14:56 +01:00
|
|
|
static list<Tile> m_tilesList;
|
2006-01-22 13:23:52 +01:00
|
|
|
/// Vector of tiles indexed by their code, for fast look-up
|
|
|
|
static vector<Tile> m_tilesVect;
|
|
|
|
/// True when m_tilesVect is correctly initialized
|
|
|
|
static bool m_vectInitialized;
|
2005-02-05 12:14:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2006-01-01 20:49:35 +01:00
|
|
|
|
|
|
|
/// Local Variables:
|
|
|
|
/// mode: c++
|
|
|
|
/// mode: hs-minor
|
|
|
|
/// c-basic-offset: 4
|
|
|
|
/// indent-tabs-mode: nil
|
|
|
|
/// End:
|