1 /*********************************************************************** 2 * 3 * Copyright (C) 2009, 2013, 2014 Graeme Gott <graeme@gottcode.org> 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 20 #ifndef WORD_H 21 #define WORD_H 22 23 #include <QChar> 24 #include <QList> 25 #include <QPoint> 26 #include <QString> 27 class QGraphicsItem; 28 class Board; 29 class Random; 30 class WordList; 31 32 #include <random> 33 34 class Word { 35 public: 36 Word(const QString& word, const QPoint& position, Qt::Orientation orientation, std::mt19937& random); 37 at(int i)38 QChar at(int i) const { 39 return m_solutions.at(0).at(i); 40 } 41 42 void click(); 43 void check(); 44 QGraphicsItem* hint(); 45 isCorrect()46 bool isCorrect() const { 47 return m_correct; 48 } 49 orientation()50 Qt::Orientation orientation() const { 51 return m_orientation; 52 } 53 positions()54 QList<QPoint> positions() const { 55 return m_positions; 56 } 57 solutions()58 QList<QString> solutions() const { 59 return m_solutions; 60 } 61 62 void moveBy(const QPoint& delta); 63 64 void fromString(const QString& shuffled); 65 QString toString() const; 66 setBoard(Board * board)67 void setBoard(Board* board) { 68 m_board = board; 69 } 70 71 void setHighlight(bool highlight); 72 void shuffle(const WordList* words); 73 74 private: 75 Board* m_board; 76 bool m_correct; 77 QList<QPoint> m_positions; 78 QList<QString> m_solutions; 79 Qt::Orientation m_orientation; 80 std::mt19937& m_random; 81 }; 82 83 #endif 84