2010-06-16 12:53:56 +00:00
|
|
|
/***************************************************************************
|
2011-12-21 11:49:33 +00:00
|
|
|
* Copyright (C) 2008 by Oliver Groß *
|
|
|
|
* z.o.gross@gmx.de *
|
2010-06-16 12:53:56 +00:00
|
|
|
* *
|
|
|
|
* 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., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
|
|
|
#ifndef LIBQCROSS_CMONOPICTURE_H
|
|
|
|
#define LIBQCROSS_CMONOPICTURE_H
|
|
|
|
|
2012-04-23 16:04:51 +00:00
|
|
|
#include <QObject>
|
2010-06-16 12:53:56 +00:00
|
|
|
#include <QSize>
|
|
|
|
#include <QVector>
|
|
|
|
#include <QString>
|
2012-04-23 16:04:51 +00:00
|
|
|
#include <QBasicTimer>
|
2010-06-16 12:53:56 +00:00
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
#include "nonogramproblem.h"
|
|
|
|
#include "nonogrammarker.h"
|
|
|
|
|
2010-06-16 12:53:56 +00:00
|
|
|
class QImage;
|
|
|
|
|
2011-12-21 11:49:33 +00:00
|
|
|
namespace libqnono {
|
2012-04-23 16:04:51 +00:00
|
|
|
class CNonogram : public QObject {
|
|
|
|
Q_OBJECT
|
2010-06-16 12:53:56 +00:00
|
|
|
public:
|
|
|
|
typedef QVector<quint16> NumbersVector;
|
|
|
|
|
2012-04-23 16:04:51 +00:00
|
|
|
explicit CNonogram(QObject *parent = 0);
|
|
|
|
|
|
|
|
void start(const NonogramProblem & problem);
|
2010-06-16 12:53:56 +00:00
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
const NonogramProblem & problem() const { return m_problem; }
|
|
|
|
QString name() const { return m_problem.name(); }
|
|
|
|
quint16 timeout() const { return m_problem.timeout(); }
|
|
|
|
const NonogramImage & solution() const { return m_problem.solution(); }
|
|
|
|
const NonogramNumbers & numbers() const { return m_problem.numbers(); }
|
2010-06-16 12:53:56 +00:00
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
const NonogramMarker & marker() const { return m_marker; }
|
2010-06-16 12:53:56 +00:00
|
|
|
|
2012-04-23 16:04:51 +00:00
|
|
|
bool valid() const { return (!size().isEmpty()) && (0 != m_problem.solution().blackPixels()); }
|
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
QSize size() const { return m_problem.size(); }
|
|
|
|
int width() const { return size().width(); }
|
|
|
|
int height() const { return size().height(); }
|
2010-06-16 12:53:56 +00:00
|
|
|
|
2012-04-23 16:04:51 +00:00
|
|
|
int time() const { return m_time; }
|
|
|
|
|
|
|
|
bool isPaused() const { return m_paused; }
|
|
|
|
bool isFinished() const { return m_finished; }
|
|
|
|
|
|
|
|
bool saveGame(QString fileName);
|
|
|
|
bool loadGame(QString fileName);
|
2010-06-16 12:53:56 +00:00
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
bool readFromStream(QDataStream & stream);
|
|
|
|
void writeToStream(QDataStream& stream) const;
|
2010-06-16 12:53:56 +00:00
|
|
|
|
2012-04-23 16:04:51 +00:00
|
|
|
public slots:
|
|
|
|
void setMark(int x, int y, NonogramMarker::Mark mark);
|
|
|
|
void restart();
|
|
|
|
void pause();
|
|
|
|
void resume();
|
|
|
|
void solve();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void loaded(); /* new problem/loaded savegame */
|
|
|
|
|
|
|
|
void won(int score); /* score is the current time */
|
|
|
|
void timeup();
|
|
|
|
|
|
|
|
void wrongMark(int x, int y, int penaltyTime);
|
|
|
|
void changedMark(int x, int y);
|
|
|
|
|
|
|
|
void restarted();
|
|
|
|
void paused(int time);
|
|
|
|
void resumed(int time);
|
|
|
|
void tick(int time);
|
|
|
|
|
2010-06-16 12:53:56 +00:00
|
|
|
protected:
|
2012-04-23 16:04:51 +00:00
|
|
|
virtual void timerEvent(QTimerEvent * event);
|
|
|
|
|
|
|
|
void internRestart(bool newGame);
|
|
|
|
|
|
|
|
QBasicTimer m_timer;
|
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
NonogramProblem m_problem;
|
|
|
|
NonogramMarker m_marker;
|
2012-04-23 16:04:51 +00:00
|
|
|
int m_markedPixels;
|
|
|
|
|
|
|
|
int m_time; /* timeout() == 0: used time, timeout() > 0: remaining time */
|
|
|
|
int m_errorCount;
|
|
|
|
bool m_preventErrors; /* (timeout() > 0) for now - must be false if timeout() == 0 */
|
|
|
|
bool m_finished, m_paused;
|
2010-06-16 12:53:56 +00:00
|
|
|
};
|
2011-12-21 11:49:33 +00:00
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
QDataStream & operator<<(QDataStream & stream, const CNonogram & nonogram);
|
2011-12-21 11:49:33 +00:00
|
|
|
QDataStream & operator>>(QDataStream & stream, CNonogram & nonogram);
|
2010-06-16 12:53:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|