--- /dev/null
+intro01
+intro02
--- /dev/null
+5
+7
+2
+12 0 0
+14 4 6
+6
+1 9
+2 9
+3 9
+4 9
+5 9
+6 9
+60
--- /dev/null
+Build a pipe from the start <img src="IMGDIR/5_180.png" width="30" height="30"><br>to the end <img src="IMGDIR/6_0.png" width="30" height="30">.
\ No newline at end of file
--- /dev/null
+5
+7
+4
+12 4 2
+14 4 5
+3 1 1
+7 2 3
+6
+1 9
+2 9
+3 9
+4 9
+5 9
+6 9
+80
--- /dev/null
+You must use all pre-placed pipes.<br> For pieces with two pipes, <img src="IMGDIR/3_0.png" width="30" height="30"> and <img src="IMGDIR/4_0.png" width="30" height="30">,<br>both pipes must be used.
--- /dev/null
+To maximize your profit,<br>build as long and complicated pipe as you can!
\ No newline at end of file
+++ /dev/null
-5
-7
-2
-12 0 0
-14 4 6
-6
-1 9
-2 9
-3 9
-4 9
-5 9
-6 9
-60
+++ /dev/null
-Build a pipe from the start <img src="IMGDIR/5_180.png" width="30" height="30"><br>to the end <img src="IMGDIR/6_0.png" width="30" height="30">.
\ No newline at end of file
+++ /dev/null
-5
-7
-4
-12 4 2
-14 4 5
-3 1 1
-7 2 3
-6
-1 9
-2 9
-3 9
-4 9
-5 9
-6 9
-80
+++ /dev/null
-You must use all pre-placed pipes.<br> For pieces with two pipes, <img src="IMGDIR/3_0.png" width="30" height="30"> and <img src="IMGDIR/4_0.png" width="30" height="30">,<br>both pipes must be used.
+++ /dev/null
-To maximize your profit,<br>build as long and complicated pipe as you can!
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>LevelCollections</class>
+ <widget class="QWidget" name="LevelCollections">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>430</height>
+ </rect>
+ </property>
+ <property name="font">
+ <font>
+ <family>Sans Serif</family>
+ <pointsize>20</pointsize>
+ </font>
+ </property>
+ <property name="autoFillBackground">
+ <bool>false</bool>
+ </property>
+ <property name="styleSheet">
+ <string>QWidget
+{
+ background-color: #15445d;
+ color: #9fb2bc;
+}</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QLabel" name="startTitle">
+ <property name="font">
+ <font>
+ <family>Sans Serif</family>
+ <pointsize>20</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+ <property name="margin">
+ <number>10</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QListWidget" name="levelList">
+ <property name="font">
+ <font>
+ <family>Sans Serif</family>
+ <pointsize>20</pointsize>
+ </font>
+ </property>
+ <property name="editTriggers">
+ <set>QAbstractItemView::NoEditTriggers</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="startButton">
+ <property name="font">
+ <font>
+ <family>Sans Serif</family>
+ <pointsize>20</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>Start</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="quitButton">
+ <property name="font">
+ <font>
+ <family>Sans Serif</family>
+ <pointsize>20</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>Quit</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
#include "game.h"
#include <QTableWidget>
-#include <QDebug>
+#include <QListWidget>
#include <QLabel>
#include <QFile>
#include <QPushButton>
-#include <QFrame>
#include <QApplication>
+#include <QDebug>
QString pieceToIconId(const Piece* piece, bool flow1 = false, bool flow2 = false)
void GameField::initGame(int rows_, int cols_, int count, PrePlacedPiece* prePlaced)
{
fieldUi->clear();
- // FIXME: Does the table widget call the destructors of its items...
rows = rows_;
cols = cols_;
QLabel* label = (QLabel*)fieldUi->indexWidget(mIndex);
label->setPixmap(QPixmap(iconId));
- // The pixmap won't show nicely if we're just sleeping...
- QApplication::processEvents();
}
QHash<QPair<PieceType, int>, const Piece*> AvailablePieces::pieceCache;
flowPreplaced += 1;
}
-LevelSwitcher::LevelSwitcher(GameController* gameController, QLabel* levelLabel,
- QFrame* startFrame, QLabel* startTitle, QLabel* startLabel, QPushButton* startButton,
- QLabel* scoreLabel,
-
- QStringList levels)
- : gameController(gameController), levelLabel(levelLabel),
- startFrame(startFrame), startTitle(startTitle), startLabel(startLabel), startButton(startButton),
- scoreLabel(scoreLabel),
- levels(levels), level(0), totalScore(0)
+LevelSwitcher::LevelSwitcher(GameController* gameController,
+ QWidget* levelWidget, QListWidget* levelList,
+ QPushButton* levelStartButton,
+ QWidget* startWidget, QLabel* startTitle,
+ QLabel* startLabel, QPushButton* startButton,
+ QLabel* levelLabel, QLabel* scoreLabel,
+ QStringList levelCollections)
+ : gameController(gameController),
+ levelWidget(levelWidget), levelList(levelList), levelStartButton(levelStartButton),
+ startWidget(startWidget), startTitle(startTitle), startLabel(startLabel), startButton(startButton),
+ levelLabel(levelLabel), scoreLabel(scoreLabel),
+ levelCollections(levelCollections), level(0), totalScore(0)
{
+ connect(levelStartButton, SIGNAL(clicked()), this, SLOT(onLevelCollectionChosen()));
+
connect(startButton, SIGNAL(clicked()), this, SLOT(onStartClicked()));
connect(gameController, SIGNAL(levelPassed(int)), this, SLOT(onLevelPassed(int)));
connect(gameController, SIGNAL(levelFailed()), this, SLOT(onLevelFailed()));
startTitle->setText("Starting a new game.");
scoreLabel->setText("0");
+ chooseLevelCollection();
+}
+
+void LevelSwitcher::chooseLevelCollection()
+{
+ levelList->clear();
+ foreach (const QString& collection, levelCollections) {
+ QListWidgetItem *newItem = new QListWidgetItem();
+ newItem->setText(collection);
+ levelList->addItem(newItem); // transfers ownership
+ }
+ levelWidget->show();
+}
+
+void LevelSwitcher::onLevelCollectionChosen()
+{
+ levelWidget->hide();
+ QString collection = levelList->currentItem()->text();
+ QFile file(QString(LEVDIR) + "/" + collection + ".dat");
+ if (!file.exists())
+ qFatal("Error reading game file: doesn't exist");
+ file.open(QIODevice::ReadOnly);
+ QTextStream levelData(&file);
+ levels.clear();
+
+ while (!levelData.atEnd())
+ levels << levelData.readLine();
+
+ level = 0;
+ totalScore = 0;
initiateLevel();
}
void LevelSwitcher::onStartClicked()
{
- startFrame->hide();
+ startWidget->hide();
levelLabel->setText(QString::number(level+1));
gameController->startLevel(QString(LEVDIR) + "/" + levels[level] + ".dat");
}
void LevelSwitcher::initiateLevel()
{
+ if (level >= levels.size()) {
+ qWarning() << "Level index too large";
+ return;
+ }
+
QFile file(QString(LEVDIR) + "/" + levels[level] + ".leg");
if (!file.exists())
qFatal("Error reading game file: doesn't exist");
QString introText = gameData.readLine();
introText.replace("IMGDIR", IMGDIR);
startLabel->setText(introText);
- startFrame->show();
+ startWidget->show();
}
void LevelSwitcher::onLevelPassed(int score)
startLabel->setText("Start a new game?");
// TODO: go to the level set selection screen
level = 0;
- startFrame->show();
+ startWidget->show();
}
}
}
// Todo next:
-// desktop stuff
-// icon for app manager
-// install all graphics
// better graphics
// save & load
// level collections: introduction + basic
// more levels
// make fixed pipes look different than non-fixed ones
+// color theme
+// transparency
// --------------
// re-placing pieces
// graphical hints on what to do next
class QLabel;
class QWidget;
class QPushButton;
-class QFrame;
+class QListWidget;
enum PieceType
{
{
Q_OBJECT
public:
- LevelSwitcher(GameController* gameController, QLabel* levelLabel,
- QFrame* startFrame, QLabel* startTitle, QLabel* startLabel, QPushButton* startButton,
- QLabel* scoreLabel,
+ LevelSwitcher(GameController* gameController,
+ QWidget* levelWidget, QListWidget* levelList, QPushButton* levelStartButton,
+ QWidget* startWidget, QLabel* startTitle, QLabel* startLabel, QPushButton* startButton,
+ QLabel* levelLabel, QLabel* scoreLabel,
QStringList levels);
- void initiateLevel();
private slots:
+ void onLevelCollectionChosen();
void onStartClicked();
void onLevelPassed(int score);
void onLevelFailed();
private:
+ void initiateLevel();
+ void chooseLevelCollection();
+
GameController* gameController; // Not owned
- QLabel* levelLabel; // Not owned
- QFrame* startFrame; // Not owned
+ QWidget* levelWidget; // Not owned
+ QListWidget* levelList; // Not owned
+ QPushButton* levelStartButton; // Not owned
+ QWidget* startWidget; // Not owned
QLabel* startTitle; // Not owned
QLabel* startLabel; // Not owned
QPushButton* startButton; // Not owned
+ QLabel* levelLabel; // Not owned
QLabel* scoreLabel; // Not owned
+ QStringList levelCollections;
QStringList levels;
int level;
int totalScore;
#include "ui_main.h"
+#include "ui_startlevel.h"
+#include "ui_collections.h"
#include "game.h"
#include <QDebug>
int main(int argc, char** argv)
{
- QApplication app(argc, argv);
+ QApplication app(argc, argv);
- qDebug() << "Reading levels from" << LEVDIR;
- qDebug() << "Reading images from" << IMGDIR;
+ qDebug() << "Reading levels from" << LEVDIR;
+ qDebug() << "Reading images from" << IMGDIR;
- QWidget mainWindow;
-
- Ui::Main ui;
- ui.setupUi(&mainWindow);
- QObject::connect(ui.quitButton, SIGNAL(clicked()), &app, SLOT(quit()));
+ QWidget mainWindow;
+ Ui::Main ui;
+ ui.setupUi(&mainWindow);
- GameField field(ui.gameTable);
- AvailablePieces pieces(ui.pieceTable);
- QStringList levels;
- levels << "level01" << "level02";
- GameController controller(&pieces, &field, ui.timeLabel, ui.doneButton);
- LevelSwitcher switcher(&controller, ui.levelLabel, ui.startFrame, ui.startTitle, ui.startLabel, ui.startButton, ui.scoreLabel, levels);
+ Ui::StartLevel startUi;
+ startUi.setupUi(ui.startWidget);
+ QObject::connect(startUi.quitButton, SIGNAL(clicked()), &app, SLOT(quit()));
- mainWindow.show();
+ Ui::LevelCollections levelUi;
+ levelUi.setupUi(ui.collectionWidget);
+ QObject::connect(levelUi.quitButton, SIGNAL(clicked()), &app, SLOT(quit()));
+ GameField field(ui.gameTable);
+ AvailablePieces pieces(ui.pieceTable);
+ QStringList levelCollections;
+ levelCollections << "intro" << "basic"; // TODO: read from fs
+ GameController controller(&pieces, &field, ui.timeLabel, ui.doneButton);
+ LevelSwitcher switcher(&controller,
+ ui.collectionWidget, levelUi.levelList, levelUi.startButton,
+ ui.startWidget, startUi.startTitle,
+ startUi.startLabel, startUi.startButton,
+ ui.levelLabel, ui.scoreLabel, levelCollections);
+ mainWindow.show();
- return app.exec();
+ return app.exec();
}
<property name="windowTitle">
<string>Evil Plumber</string>
</property>
+ <property name="styleSheet">
+ <string>QWidget
+{
+ background-color: #15445d;
+ color: #9fb2bc;
+}</string>
+ </property>
<widget class="QTableWidget" name="gameTable">
<property name="geometry">
<rect>
<string/>
</property>
</widget>
- <widget class="QFrame" name="startFrame">
- <property name="geometry">
- <rect>
- <x>100</x>
- <y>90</y>
- <width>581</width>
- <height>251</height>
- </rect>
- </property>
- <property name="font">
- <font>
- <family>Sans Serif</family>
- </font>
- </property>
- <property name="autoFillBackground">
- <bool>true</bool>
- </property>
- <property name="frameShape">
- <enum>QFrame::Box</enum>
- </property>
- <property name="frameShadow">
- <enum>QFrame::Raised</enum>
- </property>
- <property name="lineWidth">
- <number>3</number>
- </property>
- <property name="midLineWidth">
- <number>0</number>
- </property>
- <widget class="QWidget" name="layoutWidget">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>581</width>
- <height>251</height>
- </rect>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QLabel" name="startTitle">
- <property name="font">
- <font>
- <family>Sans Serif</family>
- </font>
- </property>
- <property name="text">
- <string/>
- </property>
- <property name="textFormat">
- <enum>Qt::RichText</enum>
- </property>
- <property name="margin">
- <number>10</number>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="startLabel">
- <property name="font">
- <font>
- <family>Sans Serif</family>
- </font>
- </property>
- <property name="text">
- <string/>
- </property>
- <property name="textFormat">
- <enum>Qt::RichText</enum>
- </property>
- <property name="margin">
- <number>10</number>
- </property>
- </widget>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="startButton">
- <property name="font">
- <font>
- <family>Sans Serif</family>
- <pointsize>20</pointsize>
- </font>
- </property>
- <property name="text">
- <string>Start</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer_3">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="quitButton">
- <property name="text">
- <string>Quit</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer_2">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </item>
- <item>
- <spacer name="verticalSpacer_2">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </widget>
- </widget>
<widget class="QLabel" name="levelLabel">
<property name="geometry">
<rect>
<string/>
</property>
</widget>
+ <widget class="QWidget" name="startWidget" native="true">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>430</height>
+ </rect>
+ </property>
+ <property name="styleSheet">
+ <string/>
+ </property>
+ </widget>
+ <widget class="QWidget" name="collectionWidget" native="true">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>10</y>
+ <width>800</width>
+ <height>430</height>
+ </rect>
+ </property>
+ <property name="styleSheet">
+ <string/>
+ </property>
+ </widget>
</widget>
<resources/>
<connections/>
# Input
HEADERS += game.h
-FORMS += main.ui
+FORMS += main.ui collections.ui startlevel.ui
SOURCES += game.cpp main.cpp
include("../common.pri")
target.path =$$BINDIR
levels.path = $$DATADIR/$${TARGET}
-levels.files = ../data/level01.dat ../data/level01.leg ../data/level02.dat ../data/level02.leg
+levels.files = ../data/*.dat ../data/*.leg
images.path = $$DATADIR/$${TARGET}
images.files = ../img/*.png
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>StartLevel</class>
+ <widget class="QWidget" name="StartLevel">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>430</height>
+ </rect>
+ </property>
+ <property name="font">
+ <font>
+ <family>Sans Serif</family>
+ <pointsize>20</pointsize>
+ </font>
+ </property>
+ <property name="autoFillBackground">
+ <bool>false</bool>
+ </property>
+ <property name="styleSheet">
+ <string>QWidget
+{
+ background-color: #15445d;
+ color: #9fb2bc;
+}</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QLabel" name="startTitle">
+ <property name="font">
+ <font>
+ <family>Sans Serif</family>
+ <pointsize>20</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+ <property name="margin">
+ <number>10</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="startLabel">
+ <property name="font">
+ <font>
+ <family>Sans Serif</family>
+ <pointsize>20</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+ <property name="margin">
+ <number>10</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="startButton">
+ <property name="font">
+ <font>
+ <family>Sans Serif</family>
+ <pointsize>20</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>Start</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="quitButton">
+ <property name="font">
+ <font>
+ <family>Sans Serif</family>
+ <pointsize>20</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>Quit</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>