Changing default piece counts
authortimoph <timop.harkonen@gmail.com>
Sun, 24 Jan 2010 08:45:47 +0000 (08:45 +0000)
committertimoph <timop.harkonen@gmail.com>
Sun, 24 Jan 2010 08:45:47 +0000 (08:45 +0000)
git-svn-id: file:///svnroot/impuzzle/trunk@12 e6bec12f-0854-4cc4-ad26-6875f1509f77

src/defines.h
src/gameview.cpp
src/imageimporter.cpp
src/imageimporter.h
src/puzzleitem.cpp
src/puzzleitem.h
src/settings.cpp

index 5ab8bb1..d4dd36b 100644 (file)
 
 #define GAME_VERSION 0.3
 
-#define EASY_PIECE_COUNT 12
-#define HARD_PIECE_COUNT 20
+#define EASY_PIECE_COUNT 9
+#define EASY_HORIZONTAL_COUNT 3
+#define HARD_PIECE_COUNT 16
+#define HARD_HORIZONTAL_COUNT 4
 
 #define DEFAULT_IMAGE_TXT "Default image"
 #define RANDOM_IMAGE_TXT "Random image"
index 2f70c51..2089637 100644 (file)
@@ -83,11 +83,11 @@ void GameView::setPieces(const QList<PuzzleItem *> pieces)
     int horizontalCount = 0;
 
     // Find out board size
-    if(pieces_.count() == 12) {
-        horizontalCount = 4;
+    if(pieces_.count() == EASY_PIECE_COUNT) {
+        horizontalCount = EASY_HORIZONTAL_COUNT;
     }
-    else if(pieces_.count() == 20) {
-        horizontalCount = 5;
+    else if(pieces_.count() == HARD_PIECE_COUNT) {
+        horizontalCount = HARD_HORIZONTAL_COUNT;
     }
     else {
         qDebug() << "Invalid piece count @ GameView::setPieces";
@@ -109,11 +109,12 @@ void GameView::setPieces(const QList<PuzzleItem *> pieces)
             pieces_.at(pieceNumber)->setPos(point);
             pieces_.at(pieceNumber)->setCorrectPlace(point);
             pieces_.at(pieceNumber)->setCurrentPlace(point);
+            pieces_.at(pieceNumber)->setDrawNumber(true);
             pieceNumber++;
         }
     }
 
-    // Wait a second
+    // Wait
     QTimer::singleShot(750, this, SLOT(shufflePieces()));
 }
 
@@ -186,9 +187,10 @@ bool GameView::areAllPiecesOk() const
     pieces_.at(hiddenIndex_)->show();
     pieces_.at(hiddenIndex_)->moveMeTo(emptyPlace_);
 
-    // Set all pieces not movable
+    // Set all pieces not movable and hide numbers
     for(int i = 0; i < pieces_.count(); ++i) {
         pieces_.at(i)->setMovable(false);
+        pieces_.at(i)->setDrawNumber(false);
     }
 
     // Show dialog with move count
index ab341e9..e666335 100644 (file)
@@ -61,13 +61,14 @@ QList<PuzzleItem *> ImageImporter::newPieces(const QPixmap &pixmap, const int co
 
     int horizontalCount = 0;
 
-    if(count == 12) {
-        horizontalCount = 4;
+    if(count == EASY_PIECE_COUNT) {
+        horizontalCount = EASY_HORIZONTAL_COUNT;
     }
-    else if(count == 20) {
-        horizontalCount = 5;
+    else if(count == HARD_PIECE_COUNT) {
+        horizontalCount = HARD_HORIZONTAL_COUNT;
     }
     else {
+        qDebug() << QString("Bad piece count ( %1 ) @ ImageImporter::newPieces").arg(count);
         return list;
     }
 
index 9d56c62..440bce7 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <QObject>
 
+#include "defines.h"
+
 class QPixmap;
 class PuzzleItem;
 
@@ -30,7 +32,7 @@ class ImageImporter : public QObject
 
 public:
     static ImageImporter *instance();
-    QList<PuzzleItem *> newPieces(const QPixmap &pixmap, const int count = 12);
+    QList<PuzzleItem *> newPieces(const QPixmap &pixmap, const int count = EASY_PIECE_COUNT);
 
 private:
     ImageImporter(QObject *parent = 0);
index ccf0b33..de9d3dc 100644 (file)
@@ -33,6 +33,7 @@ PuzzleItem::PuzzleItem(QGraphicsItem *parent) :
     movable_ = true;
     moveAnimation_ = new QPropertyAnimation(this, "pos", this);
     pieceNumber_ = 0;
+    drawNumber_ = true;
 }
 
 QPointF PuzzleItem::correctPlace() const
@@ -118,25 +119,27 @@ void PuzzleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
 {
     QGraphicsPixmapItem::paint(painter, option, widget);
 
-    painter->save();
+    if(drawNumber_) {
+        painter->save();
 
-    QFont font = painter->font();
-    QFontMetrics metrics(font);
-    QRect numberRect(0, 0, metrics.height(), metrics.height());
+        QFont font = painter->font();
+        QFontMetrics metrics(font);
+        QRect numberRect(0, 0, metrics.height(), metrics.height());
 
-    painter->setPen(Qt::NoPen);
+        painter->setPen(Qt::NoPen);
 
-    painter->setBrush(QColor(255, 255, 255, 192));
-    painter->drawRect(numberRect);
+        painter->setBrush(QColor(255, 255, 255, 192));
+        painter->drawRect(numberRect);
 
-    painter->setPen(Qt::black);
+        painter->setPen(Qt::black);
 
-    QTextOption textOption;
-    textOption.setAlignment(Qt::AlignCenter);
+        QTextOption textOption;
+        textOption.setAlignment(Qt::AlignCenter);
 
-    painter->drawText(numberRect, QString::number(pieceNumber_), textOption);
+        painter->drawText(numberRect, QString::number(pieceNumber_), textOption);
 
-    painter->restore();
+        painter->restore();
+    }
 }
 
 int PuzzleItem::pieceNumber() const
@@ -148,3 +151,16 @@ void PuzzleItem::setPieceNumber(const int pieceNumber)
 {
     pieceNumber_ = pieceNumber;
 }
+
+void PuzzleItem::setDrawNumber(bool value)
+{
+    if(value != drawNumber_) {
+        drawNumber_ = value;
+        update();
+    }
+}
+
+bool PuzzleItem::drawNumber() const
+{
+    return drawNumber_;
+}
index af4aca3..3e8297e 100644 (file)
@@ -43,6 +43,8 @@ public:
     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
     void setPieceNumber(const int pieceNumber);
     int pieceNumber() const;
+    void setDrawNumber(bool value);
+    bool drawNumber() const;
 
 protected:
     void mousePressEvent(QGraphicsSceneMouseEvent *event);
@@ -55,5 +57,6 @@ private:
     QPropertyAnimation *moveAnimation_;
     static int moveCount_;
     int pieceNumber_;
+    bool drawNumber_;
 };
 #endif
index ecbd675..62801af 100644 (file)
@@ -1,11 +1,12 @@
 #include "settings.h"
+#include "defines.h"
 
 Settings *Settings::instance_ = 0;
 
 Settings::Settings(QObject *parent) :
         QObject(parent)
 {
-    pieceCount_ = 12;
+    pieceCount_ = EASY_PIECE_COUNT;
     image_ = 0;
 }