1
0
mirror of git://projects.qi-hardware.com/openwrt-packages.git synced 2024-06-26 02:44:33 +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
bool isRunning = 0;
int Moves = 0;
int main(int argc, char *argv[])
{

View File

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

View File

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

View File

@ -334,7 +334,7 @@
<property name="geometry">
<rect>
<x>255</x>
<y>20</y>
<y>10</y>
<width>60</width>
<height>20</height>
</rect>
@ -350,7 +350,7 @@
<property name="geometry">
<rect>
<x>255</x>
<y>80</y>
<y>50</y>
<width>60</width>
<height>20</height>
</rect>
@ -366,7 +366,7 @@
<property name="geometry">
<rect>
<x>255</x>
<y>200</y>
<y>130</y>
<width>60</width>
<height>20</height>
</rect>
@ -382,7 +382,7 @@
<property name="geometry">
<rect>
<x>255</x>
<y>140</y>
<y>90</y>
<width>60</width>
<height>20</height>
</rect>
@ -407,6 +407,20 @@
<enum>Qt::Vertical</enum>
</property>
</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>
<layoutdefault spacing="6" margin="11"/>