mirror of
git://projects.qi-hardware.com/openwrt-packages.git
synced 2024-11-22 07:08:05 +02:00
Tile: count moves
This commit is contained in:
parent
0f9e96c3bf
commit
cccd60c34a
@ -7,6 +7,7 @@
|
||||
#endif
|
||||
|
||||
bool isRunning = 0;
|
||||
int Moves = 0;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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"/>
|
||||
|
Loading…
Reference in New Issue
Block a user