1
0
mirror of git://projects.qi-hardware.com/openwrt-packages.git synced 2024-06-28 23:34:31 +03:00

Tile: count moves

This commit is contained in:
kyak 2011-01-16 00:15:43 +03:00
parent 0f9e96c3bf
commit cccd60c34a
4 changed files with 34 additions and 4 deletions

View File

@ -7,6 +7,7 @@
#endif #endif
bool isRunning = 0; bool isRunning = 0;
int Moves = 0;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {

View File

@ -159,6 +159,10 @@ void Tile::swapButtons(QPushButton *button, QPushButton *button_neighbour) {
button->setText("16"); button->setText("16");
button_neighbour->show(); button_neighbour->show();
button_neighbour->setFocus(); button_neighbour->setFocus();
if (isRunning) {
Moves++;
updateMoves();
}
if (isRunning && isSolved()) { if (isRunning && isSolved()) {
isRunning = 0; isRunning = 0;
switch (QMessageBox::information(this, switch (QMessageBox::information(this,
@ -176,6 +180,9 @@ void Tile::swapButtons(QPushButton *button, QPushButton *button_neighbour) {
void Tile::Reset() void Tile::Reset()
{ {
isRunning = 0;
Moves=0;
updateMoves();
for (int i = 1; i < 16; i++) { for (int i = 1; i < 16; i++) {
QPushButton *button = idtoButton(i); QPushButton *button = idtoButton(i);
QString str; QString str;
@ -381,3 +388,9 @@ bool Tile::isSolved()
} }
return 1; return 1;
} }
void Tile::updateMoves()
{
QString mooves;
ui->moves->setText("Moves:\n"+mooves.setNum(Moves));
}

View File

@ -9,6 +9,7 @@
#include <QKeyEvent> #include <QKeyEvent>
extern bool isRunning; extern bool isRunning;
extern int Moves;
namespace Ui { namespace Ui {
class Tile; class Tile;
@ -35,6 +36,7 @@ public slots:
void keyUp(QPushButton *button); void keyUp(QPushButton *button);
void keyDown(QPushButton *button); void keyDown(QPushButton *button);
bool isSolved(); bool isSolved();
void updateMoves();
protected: protected:
void changeEvent(QEvent *e); void changeEvent(QEvent *e);

View File

@ -334,7 +334,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>255</x> <x>255</x>
<y>20</y> <y>10</y>
<width>60</width> <width>60</width>
<height>20</height> <height>20</height>
</rect> </rect>
@ -350,7 +350,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>255</x> <x>255</x>
<y>80</y> <y>50</y>
<width>60</width> <width>60</width>
<height>20</height> <height>20</height>
</rect> </rect>
@ -366,7 +366,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>255</x> <x>255</x>
<y>200</y> <y>130</y>
<width>60</width> <width>60</width>
<height>20</height> <height>20</height>
</rect> </rect>
@ -382,7 +382,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>255</x> <x>255</x>
<y>140</y> <y>90</y>
<width>60</width> <width>60</width>
<height>20</height> <height>20</height>
</rect> </rect>
@ -407,6 +407,20 @@
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
</widget> </widget>
<widget class="QLabel" name="moves">
<property name="geometry">
<rect>
<x>255</x>
<y>200</y>
<width>60</width>
<height>40</height>
</rect>
</property>
<property name="text">
<string>Moves:
0</string>
</property>
</widget>
</widget> </widget>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>