summaryrefslogtreecommitdiff
path: root/noncore/games/mindbreaker
authorzecke <zecke>2004-02-06 12:14:56 (UTC)
committer zecke <zecke>2004-02-06 12:14:56 (UTC)
commit0c74629e8f5c12a9b5a282b817f884fa10dee491 (patch) (side-by-side diff)
tree3294663b92023f8d24d68a01022e011a3c94002d /noncore/games/mindbreaker
parent46ce5afcfbe7be19f4d5ac0fed6886a0759f1a25 (diff)
downloadopie-0c74629e8f5c12a9b5a282b817f884fa10dee491.zip
opie-0c74629e8f5c12a9b5a282b817f884fa10dee491.tar.gz
opie-0c74629e8f5c12a9b5a282b817f884fa10dee491.tar.bz2
Merge from the 1.0.x release
Diffstat (limited to 'noncore/games/mindbreaker') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/mindbreaker/main.cpp10
-rw-r--r--noncore/games/mindbreaker/mindbreaker.cpp455
-rw-r--r--noncore/games/mindbreaker/mindbreaker.h27
-rw-r--r--noncore/games/mindbreaker/mindbreaker.pro5
-rw-r--r--noncore/games/mindbreaker/opie-mindbreaker.control2
5 files changed, 327 insertions, 172 deletions
diff --git a/noncore/games/mindbreaker/main.cpp b/noncore/games/mindbreaker/main.cpp
index 8ba0fde..2ca16e3 100644
--- a/noncore/games/mindbreaker/main.cpp
+++ b/noncore/games/mindbreaker/main.cpp
@@ -1,7 +1,7 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
@@ -20,14 +20,14 @@
#include "mindbreaker.h"
-#include <qpe/qpeapplication.h>
+#include <qtopia/qpeapplication.h>
int main( int argc, char **argv )
{
QPEApplication a( argc, argv );
- MindBreaker w(0, "new window");
- w.setCaption("Mind Breaker");
+ MindBreaker w;
+ w.setCaption(MindBreaker::tr("Mind Breaker"));
QPEApplication::setInputMethodHint( &w, QPEApplication::AlwaysOff );
a.showMainWidget(&w);
diff --git a/noncore/games/mindbreaker/mindbreaker.cpp b/noncore/games/mindbreaker/mindbreaker.cpp
index 7802e38..e1f43d0 100644
--- a/noncore/games/mindbreaker/mindbreaker.cpp
+++ b/noncore/games/mindbreaker/mindbreaker.cpp
@@ -1,7 +1,7 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
@@ -20,17 +20,19 @@
#include "mindbreaker.h"
-#include <qpe/resource.h>
-#include <qpe/config.h>
+#include <qtopia/resource.h>
+#include <qtopia/config.h>
+#include <qtopia/qpeapplication.h>
+#include <qtoolbar.h>
#include <qpainter.h>
#include <qpixmap.h>
-#include <qpe/qpetoolbar.h>
#include <qtoolbutton.h>
#include <qpushbutton.h>
#include <qmessagebox.h>
#include <qlabel.h>
-#include <qstyle.h>
+#include <qlayout.h>
+#include <qtimer.h>
#include <stdlib.h>
#include <sys/time.h>
@@ -38,6 +40,64 @@
static int pegRTTI = 3393393;
+static int adjusted_panel_height;
+static int adjusted_panel_width;
+
+static int adjusted_bin_margin;
+static int adjusted_peg_size;
+static int adjusted_answerpeg_size;
+
+static int adjusted_title_height;
+static int adjusted_title_width;
+
+static int adjusted_first_peg_x_diff;
+static int adjusted_first_peg_y_diff;
+static int adjusted_peg_spacing;
+
+static int adjusted_answerpegx;
+static int adjusted_answerpegy;
+static int adjusted_answerpeg_xdiff;
+static int adjusted_answerpeg_ydiff;
+
+static int adjusted_board_height;
+static int adjusted_board_width;
+
+static void setupBoardSize(int w, int h)
+{
+ adjusted_panel_width = w * 3/4;
+ adjusted_title_width = w * 3/4;
+
+ adjusted_title_height = h/10;
+ adjusted_panel_height = (h-adjusted_title_height)/9;
+
+ adjusted_bin_margin = w * 10/240;
+ adjusted_peg_size = adjusted_panel_height*3/4;
+ adjusted_answerpeg_size = QMIN(adjusted_panel_width*15/180,adjusted_panel_height*15/25);
+
+ // looks a bit dodgy on larger sizes
+ if ( adjusted_peg_size > 40 )
+ adjusted_peg_size = 40;
+
+ adjusted_first_peg_x_diff = w * 31/240-adjusted_peg_size/2;
+ adjusted_first_peg_y_diff = (adjusted_panel_height - adjusted_peg_size)/2;
+ adjusted_peg_spacing = w * 30/240;
+
+ // looks a bit dodgy on larger sizes (still does though, but not as much...)
+ if ( adjusted_answerpeg_size > 22 )
+ adjusted_answerpeg_size = 22;
+
+ adjusted_answerpegx = adjusted_panel_width * 159/180 - adjusted_answerpeg_size/2;
+ adjusted_answerpegy = adjusted_panel_height/3 - adjusted_answerpeg_size/2;
+ adjusted_answerpeg_xdiff = adjusted_panel_width * 10/180;
+ adjusted_answerpeg_ydiff = adjusted_panel_height * 9/25;
+
+ adjusted_board_height = adjusted_title_height + (adjusted_panel_height * 9);
+ adjusted_board_width = adjusted_panel_width + (adjusted_bin_margin * 2) + adjusted_peg_size;
+
+// qDebug("Adjusted width %d height %d", adjusted_board_width, adjusted_board_height);
+}
+
+
/* helper class, */
class Peg : public QCanvasRectangle
{
@@ -48,7 +108,7 @@ public:
bool hit( const QPoint &) const;
-/* a placed peg is one that has been set down on the board correctly and
+/* a placed peg is one that has been set down on the board correctly and
should not be moved, only copied */
bool placed() const;
void setPlaced(bool);
@@ -77,27 +137,27 @@ private:
int aniStep;
};
-
int Peg::eggLevel = 0;
QVector<QImage> Peg::normalPegs;
QVector<QImage> Peg::specialPegs;
void Peg::buildImages()
{
-
QImage pegs = Resource::loadImage("mindbreaker/pegs");
- int x = 0;
+ int x = 0;
int y = 0;
int i;
eggLevel = 0;
normalPegs.resize(10);
for (i = 0; i < 6; i++) {
- normalPegs.insert(i, new QImage(pegs.copy(x, y, peg_size, peg_size)));
+ normalPegs.insert(i, new QImage(pegs.copy(x, y, peg_size, peg_size).
+ smoothScale(adjusted_peg_size, adjusted_peg_size) ));
x += peg_size;
}
specialPegs.resize(5);
for (i = 0; i < 5; i++) {
- specialPegs.insert(i, new QImage(pegs.copy(x,y,peg_size, peg_size)));
+ specialPegs.insert(i, new QImage(pegs.copy(x,y,peg_size, peg_size).
+ smoothScale(adjusted_peg_size, adjusted_peg_size) ));
x += peg_size;
}
@@ -105,23 +165,29 @@ void Peg::buildImages()
/* copy from master image to functional images */
x = 0;
y = panel_height;
- normalPegs.insert(8,
- new QImage(image.copy(x, y, panel_width, panel_height)));
+ normalPegs.insert(8,
+ new QImage( image.copy(x, y, panel_width, panel_height).
+ smoothScale( adjusted_panel_width, adjusted_panel_height)
+ ));
y += panel_height;
y += title_height;
- normalPegs.insert(9,
- new QImage(image.copy(x, y, title_width, title_height)));
+ normalPegs.insert(9,
+ new QImage(image.copy(x, y, title_width, title_height).
+ smoothScale( adjusted_title_width, adjusted_title_height)
+ ));
y += title_height;
x = 6 * peg_size;
- normalPegs.insert(6,
- new QImage(image.copy(x, y, answerpeg_size, answerpeg_size)));
+ normalPegs.insert(6,
+ new QImage(image.copy(x, y, answerpeg_size, answerpeg_size).
+ smoothScale( adjusted_answerpeg_size, adjusted_answerpeg_size) ));
x += answerpeg_size;
- normalPegs.insert(7,
- new QImage(image.copy(x, y, answerpeg_size, answerpeg_size)));
+ normalPegs.insert(7,
+ new QImage(image.copy(x, y, answerpeg_size, answerpeg_size).
+ smoothScale( adjusted_answerpeg_size, adjusted_answerpeg_size) ));
}
-QImage Peg::imageForType(int t)
+QImage Peg::imageForType(int t)
{
if (eggLevel > t ) {
if( t < 5) {
@@ -133,7 +199,7 @@ QImage Peg::imageForType(int t)
return *normalPegs[t];
}
-Peg::Peg(QCanvas *canvas , int t, int g, int p)
+Peg::Peg(QCanvas *canvas , int t, int g, int p)
: QCanvasRectangle(canvas)
{
setSize(normalPegs[t]->width(), normalPegs[t]->height() );
@@ -157,9 +223,9 @@ void Peg::advance(int phase) {
void Peg::drawShape(QPainter &p )
{
if ((pegtype == 5) && eggLevel > 5) {
- p.drawImage(x(), y(), *normalPegs[aniStep]);
- } else
- p.drawImage(x(), y(), imageForType(pegtype));
+ p.drawImage(int(x()), int(y()), *normalPegs[aniStep]);
+ } else
+ p.drawImage(int(x()), int(y()), imageForType(pegtype));
}
bool Peg::hit( const QPoint &p ) const
@@ -187,39 +253,49 @@ inline int Peg::pegPos() const
return peg_pos;
}
-inline void Peg::setPegPos(int p)
+inline void Peg::setPegPos(int p)
{
peg_pos = p;
}
-inline void Peg::setPlaced(bool p)
+inline void Peg::setPlaced(bool p)
{
isplaced = p;
}
-inline int Peg::type() const
+inline int Peg::type() const
{
return pegtype;
}
-/* Load the main image, copy from it the pegs, the board, and the answer image
+/* Load the main image, copy from it the pegs, the board, and the answer image
* and use these to create the tray, answer and board
*/
MindBreaker::MindBreaker( QWidget *parent, const char *name, int wFlags )
-: QMainWindow(parent, name, wFlags),
- canvas(board_height, board_width)
+ : QMainWindow(parent, name, wFlags)
{
- MindBreakerBoard *m = new MindBreakerBoard(canvas, this);
- setCentralWidget(m);
-
+ setCaption( tr("Mind Breaker"));
+ QPEApplication::setInputMethodHint( this, QPEApplication::AlwaysOff );
+ setMinimumSize(160,210);
+
+ QWidget *w = new QWidget( this );
+ w->setBackgroundColor( black );
+ QHBoxLayout *hb = new QHBoxLayout( w );
+ hb->addStretch();
+ board = new MindBreakerBoard(w);
+ hb->addWidget( board, 100 );
+ hb->addStretch();
+
+ setCentralWidget(w);
+
setToolBarsMovable( FALSE );
QToolBar *tb = new QToolBar(this);
tb->setHorizontalStretchable( TRUE );
- QPixmap newicon = Resource::loadPixmap("new");
- new QToolButton(newicon, tr("New Game"), 0,
- m, SLOT(clear()), tb, "NewGame");
+ QIconSet newicon = Resource::loadIconSet("new");
+ new QToolButton(newicon, tr("New Game"), 0,
+ board, SLOT(clear()), tb, "NewGame");
score = new QToolButton(tb);
score->setText("");
@@ -227,12 +303,14 @@ MindBreaker::MindBreaker( QWidget *parent, const char *name, int wFlags )
score->setUsesTextLabel(TRUE);
tb->setStretchableWidget(score);
- connect(m, SIGNAL(scoreChanged(int, int)), this, SLOT(setScore(int, int)));
- connect(score, SIGNAL(clicked()), m, SLOT(resetScore()));
+ connect(board, SIGNAL(scoreChanged(int,int)), this, SLOT(setScore(int,int)));
+ connect(score, SIGNAL(clicked()), board, SLOT(resetScore()));
int a, b;
- m->getScore(&a, &b);
+ board->getScore(&a, &b);
setScore(a,b);
+
+ layout()->setResizeMode(QLayout::FreeResize);
}
void MindBreaker::setScore(int turns, int games)
@@ -241,54 +319,55 @@ void MindBreaker::setScore(int turns, int games)
double total_turns = turns;
double total_games = games;
- if(total_games > 0)
+ if(total_games > 0)
average = total_turns / total_games;
- else
+ else
average = 0.0;
score->setText(tr("win avg: %1 turns (%2 games)").arg(average).arg(games));
}
+void MindBreaker::resizeEvent( QResizeEvent *e )
+{
+ board->fixSize();
+ QMainWindow::resizeEvent( e );
+}
+
-MindBreakerBoard::MindBreakerBoard( QCanvas &canv, QWidget *parent,
+MindBreakerBoard::MindBreakerBoard( QWidget *parent,
const char *name, int wFlags )
- : QCanvasView(&canv, parent, name, wFlags)
+ : QCanvasView(0, parent, name, wFlags),
+ moving(0), game_over(FALSE), total_turns(0), total_games(0)
{
- int i, x, y;
+ setFrameStyle( NoFrame );
+ setupBoardSize(qApp->desktop()->width(),qApp->desktop()->height());
+ cnv.resize(100,100);
+ setCanvas(&cnv);
+ setBackgroundColor( black );
+
struct timeval tv;
current_go = 0;
gettimeofday(&tv, 0);
-
srand(tv.tv_usec);
canvas()->setAdvancePeriod(500);
+ current_highlight = 0;
- QImage image = Resource::loadImage("mindbreaker/mindbreaker");
-
- /* copy from master image to functional images */
- x = 0;
- y = 0;
- panelImage = image.copy(x,y, panel_width, panel_height);
- y += panel_height;
- y += panel_height;
-
- titleImage = image.copy(x, y, title_width, title_height);
-
- Peg::buildImages(); // must be done BEFORE any pegs are made
-
- current_highlight = new Peg(canvas(), 8);
- current_highlight->setPlaced(TRUE);
- current_highlight->setX(0);
- current_highlight->setY(board_height - ((current_go + 1) * panel_height));
- current_highlight->setZ(0);
- current_highlight->show();
+ widthTimer = new QTimer( this );
+ connect(widthTimer, SIGNAL(timeout()), this, SLOT(doFixSize()) );
+ setMaximumWidth( QMIN(qApp->desktop()->height(),qApp->desktop()->width()) );
+ //doFixSize(); // build images... needs to be done before reading config.
+ //readConfig(); // first read... to ensure initial labels and side look right.
+}
- /* set up the game */
+void MindBreakerBoard::readConfig()
+{
Config c("MindBreaker", Config::User);
c.setGroup("Board");
game_over = FALSE;
+ int i;
if (c.readNumEntry("Answer0") < 0) {
for (i = 0; i < 4; i++) {
answer[i] = rand() % 6;
@@ -309,7 +388,7 @@ MindBreakerBoard::MindBreakerBoard( QCanvas &canv, QWidget *parent,
checkScores();
c.setGroup("Board");
- for(i = 0; i < 4; i++)
+ for(i = 0; i < 4; i++)
answer[i] = c.readNumEntry(QString("Answer%1").arg(i));
/* read, and parse past guesses */
current_go = 0;
@@ -328,19 +407,15 @@ MindBreakerBoard::MindBreakerBoard( QCanvas &canv, QWidget *parent,
}
for(i = 0; i < 4; i++) {
current_guess[i] = c.readNumEntry(QString("CurrentGo%1").arg(i));
- if (current_guess[i] != 6)
+ if (current_guess[i] != 6)
placeGuessPeg(i, current_guess[i]);
}
}
-
- /* draw initial screen */
- drawBackground();
- canvas()->update();
}
MindBreakerBoard::~MindBreakerBoard()
{
- int i, j;
+ int i;
if (game_over) {
current_go = 0;
/* clear the answer, clear the guess */
@@ -349,19 +424,24 @@ MindBreakerBoard::~MindBreakerBoard()
current_guess[i] = 6;
}
}
-
+ writeConfig();
+}
+
+void MindBreakerBoard::writeConfig()
+{
Config c("MindBreaker", Config::User);
c.setGroup("Board");
c.clearGroup();
/* write the board */
+ int i,j;
for (i = 0; i < current_go; i++) {
for(j = 0; j < 4; j++)
- c.writeEntry(tr("Go%1p%2").arg(i).arg(j), past_guesses[4*i+j]);
+ c.writeEntry(QString("Go%1p%2").arg(i).arg(j), past_guesses[4*i+j]);
}
- for(j = 0; j < 4; j++)
- c.writeEntry(tr("CurrentGo%1").arg(j), current_guess[j]);
- for(j = 0; j < 4; j++)
- c.writeEntry(tr("Answer%1").arg(j), answer[j]);
+ for(j = 0; j < 4; j++)
+ c.writeEntry(QString("CurrentGo%1").arg(j), current_guess[j]);
+ for(j = 0; j < 4; j++)
+ c.writeEntry(QString("Answer%1").arg(j), answer[j]);
c.setGroup("Score");
/* write the score */
@@ -377,11 +457,75 @@ void MindBreakerBoard::getScore(int *a, int *b)
return;
}
+void MindBreakerBoard::fixSize()
+{
+ hide();
+ setMaximumWidth( parentWidget()->height() );
+ widthTimer->start( 20, TRUE );
+}
+
+void MindBreakerBoard::doFixSize()
+{
+ QSize s = size();
+ int fw = frameWidth();
+ s.setWidth(s.width() - fw);
+ s.setHeight(s.height() - fw);
+
+ /* min size is 200 x 260 */
+/*
+ if (s.width() < adjusted_board_width)
+ s.setWidth(adjusted_board_width);
+
+ if (s.height() < adjusted_board_height)
+ s.setHeight(adjusted_board_height);
+*/
+
+ if ( current_highlight ) // non-first resize
+ writeConfig();
+
+ setupBoardSize(s.width() - fw, s.height() - fw);
+ canvas()->resize(s.width() - fw, s.height() - fw);
+ Peg::buildImages(); // must be done BEFORE any pegs are made
+
+ QImage image = Resource::loadImage("mindbreaker/mindbreaker");
+
+ /* copy from master image to functional images */
+ int x = 0;
+ int y = 0;
+ panelImage = image.copy(x, y, panel_width, panel_height).
+ smoothScale( adjusted_panel_width, adjusted_panel_height);
+
+ y += panel_height;
+ y += panel_height;
+
+ titleImage = image.copy(x, y, title_width, title_height).
+ smoothScale( adjusted_title_width, adjusted_title_height);
+ show();
+
+ delete current_highlight;
+ current_highlight = new Peg(canvas(), 8);
+ current_highlight->setPlaced(TRUE);
+ current_highlight->setX(0);
+ current_highlight->setY(adjusted_board_height - ((current_go + 1) * adjusted_panel_height));
+ current_highlight->setZ(0);
+ current_highlight->show();
+
+ /* set up the game */
+ //readConfig();
+
+ /* draw initial screen */
+ //drawBackground();
+ //canvas()->update();
+ clear();
+
+ readConfig();
+}
+
void MindBreakerBoard::placeGuessPeg(int pos, int pegId)
{
- int x = first_peg_x_diff + (pos * peg_spacing);
- int y = board_height - ((current_go + 1) * panel_height)
- + first_peg_y_diff;
+ int x = adjusted_first_peg_x_diff + (pos * adjusted_peg_spacing);
+ int y = adjusted_board_height - ((current_go + 1) * adjusted_panel_height)
+ + adjusted_first_peg_y_diff;
Peg *peg = new Peg(canvas(), pegId, current_go, pos);
peg->setPegPos(pos);
@@ -405,18 +549,18 @@ void MindBreakerBoard::drawBackground()
QPen pen(QColor(85, 45, 27), 4);
painter.setPen(pen);
- x_gap = canvas()->width() - (panel_width + (2 * bin_margin));
+ x_gap = canvas()->width() - (adjusted_panel_width + (2 * adjusted_bin_margin));
//x_gap += peg_size >> 1;
- if (x_gap < 1)
+ if (x_gap < 1)
x_gap = 1;
- y_gap = board_height / 6;
- y_gap -= (2 * bin_margin);
+ y_gap = adjusted_board_height / 6;
+ y_gap -= (2 * adjusted_bin_margin);
//y_gap += peg_size >> 1;
- if (y_gap < 1)
+ if (y_gap < 1)
y_gap = 1;
- x = panel_width + bin_margin - (peg_size >> 1);
- y = bin_margin - (peg_size >> 1) + 2;
+ x = adjusted_panel_width + adjusted_bin_margin - (adjusted_peg_size >> 1);
+ y = adjusted_bin_margin - (adjusted_peg_size >> 1) + 2;
for (i = 0; i < 6; i++) {
for (j = 0; j < 10; j++) {
@@ -424,17 +568,17 @@ void MindBreakerBoard::drawBackground()
int ry = y + (rand() % y_gap);
painter.drawImage(rx,ry, Peg::imageForType(i));
}
- y += board_height / 6;
+ y += adjusted_board_height / 6;
}
/* now draw the surrounding boxes */
- x_gap = canvas()->width() - panel_width;
+ x_gap = canvas()->width() - adjusted_panel_width;
if (x_gap < 1) x_gap = 1;
- y_gap = board_height / 6;
- x = panel_width;
+ y_gap = adjusted_board_height / 6;
+ x = adjusted_panel_width;
y = 1;
for (i = 0; i < 6; i++) {
- painter.drawRect(x, y, x_gap, y_gap);
+ painter.drawRect(x, y, x_gap, y_gap);
y += y_gap;
}
@@ -442,11 +586,11 @@ void MindBreakerBoard::drawBackground()
y = 0;
painter.drawImage(x,y, titleImage);
- y = title_height;
+ y = adjusted_title_height;
/* now nine gues panels */
for (i = 0; i < 9; i ++) {
painter.drawImage(x, y, panelImage);
- y += panel_height;
+ y += adjusted_panel_height;
}
painter.flush();
@@ -469,7 +613,7 @@ void MindBreakerBoard::checkGuess()
if (answer[i] == current_guess[i]) {
num_black++;
copy_answer[i] = 6;
- copy_guess[i] = 7;
+ copy_guess[i] = 7;
}
}
@@ -486,9 +630,9 @@ void MindBreakerBoard::checkGuess()
}
}
- int x = answerpegx;
- int y = (board_height - ((current_go + 1) * panel_height)) + answerpegy;
-
+ int x = adjusted_answerpegx;
+ int y = (adjusted_board_height - ((current_go + 1) * adjusted_panel_height)) + adjusted_answerpegy;
+
if (num_black == 4)
game_over = TRUE;
@@ -500,12 +644,12 @@ void MindBreakerBoard::checkGuess()
p->setZ(1);
p->show();
num_black--;
-
- if (x == answerpegx)
- x = answerpegx + answerpeg_diff;
+
+ if (x == adjusted_answerpegx)
+ x = adjusted_answerpegx + adjusted_answerpeg_xdiff;
else {
- x = answerpegx;
- y += answerpeg_diff;
+ x = adjusted_answerpegx;
+ y += adjusted_answerpeg_ydiff;
}
}
while(num_white > 0){
@@ -516,12 +660,12 @@ void MindBreakerBoard::checkGuess()
p->setZ(1);
p->show();
num_white--;
-
- if (x == answerpegx)
- x = answerpegx + answerpeg_diff;
+
+ if (x == adjusted_answerpegx)
+ x = adjusted_answerpegx + adjusted_answerpeg_xdiff;
else {
- x = answerpegx;
- y += answerpeg_diff;
+ x = adjusted_answerpegx;
+ y += adjusted_answerpeg_ydiff;
}
}
/* move to next go */
@@ -535,7 +679,7 @@ void MindBreakerBoard::checkGuess()
total_games++;
if(!game_over)
total_turns += 10;
- else
+ else
total_turns += current_go;
emit scoreChanged(total_turns, total_games);
@@ -546,16 +690,16 @@ void MindBreakerBoard::checkGuess()
p->setY(0);
p->setZ(0);
p->show();
-
+
for (i = 0; i < 4; i++) {
p = new Peg(canvas(), answer[i], -1);
- p->setX(first_peg_x_diff + (i * peg_spacing));
- p->setY(5);
+ p->setX(adjusted_first_peg_x_diff + (i * adjusted_peg_spacing));
+ p->setY(adjusted_first_peg_y_diff);
p->setZ(3);
p->show();
}
} else {
- current_highlight->setY(board_height - ((current_go + 1) * panel_height));
+ current_highlight->setY(adjusted_board_height - ((current_go + 1) * adjusted_panel_height));
}
canvas()->update();
}
@@ -586,17 +730,17 @@ void MindBreakerBoard::clear()
delete *it;
}
- current_highlight->setY(board_height - ((current_go + 1) * panel_height));
+ current_highlight->setY(adjusted_board_height - ((current_go + 1) * adjusted_panel_height));
checkScores();
drawBackground();
canvas()->update();
}
-void MindBreakerBoard::resetScore()
+void MindBreakerBoard::resetScore()
{
/* are u sure */
- if (QMessageBox::information(this, tr( "Reset Statistics" ),
+ if (QMessageBox::information(this, tr( "Reset Statistics" ),
tr( "Reset the win ratio?" ),
tr( "OK" ), tr( "Cancel" ) ) == 0) {
total_turns = 0;
@@ -612,21 +756,28 @@ void MindBreakerBoard::resetScore()
void MindBreakerBoard::contentsMousePressEvent(QMouseEvent *e)
{
+ if (game_over) {
+ null_press = TRUE;
+ null_point = e->pos();
+ moving = 0;
+ return;
+ }
+
copy_press = FALSE;
null_press = FALSE;
/* ok, first work out if it is one of the bins that
got clicked */
- if (e->x() > panel_width) {
+ if (e->x() > adjusted_panel_width) {
/* its a bin, but which bin */
- if(e->y() > board_height)
+ int bin = (e->y() + 2) / (adjusted_board_height / 6);
+ if (bin > 5)
return; // missed everything
- int bin = (e->y() + 2) / (board_height / 6);
/* make new peg... set it moving */
moving_pos = e->pos();
moving = new Peg(canvas(), bin, current_go);
- moving->setX(e->x() - (peg_size >> 1));
- moving->setY(e->y() - (peg_size >> 1));
+ moving->setX(e->x() - (adjusted_peg_size >> 1));
+ moving->setY(e->y() - (adjusted_peg_size >> 1));
moving->setZ(5);
moving->show();
canvas()->update();
@@ -652,10 +803,10 @@ void MindBreakerBoard::contentsMousePressEvent(QMouseEvent *e)
copy_press = TRUE;
copy_peg = item;
}
- moving = new Peg(canvas(),
+ moving = new Peg(canvas(),
item->type(), current_go);
- moving->setX(e->x() - (peg_size >> 1));
- moving->setY(e->y() - (peg_size >> 1));
+ moving->setX(e->x() - (adjusted_peg_size >> 1));
+ moving->setY(e->y() - (adjusted_peg_size >> 1));
moving->setZ(5);
moving->show();
moving_pos = QPoint(e->x(), e->y());
@@ -681,7 +832,7 @@ void MindBreakerBoard::contentsMouseMoveEvent(QMouseEvent* e)
moving_pos = e->pos();
canvas()->update();
return;
- }
+ }
}
void MindBreakerBoard::contentsMouseReleaseEvent(QMouseEvent* e)
@@ -693,7 +844,7 @@ void MindBreakerBoard::contentsMouseReleaseEvent(QMouseEvent* e)
copy_press = FALSE;
QCanvasItemList l = canvas()->collisions(e->pos());
for (QCanvasItemList::Iterator it=l.begin(); it !=l.end(); ++it) {
- if (*it == copy_peg)
+ if (*it == copy_peg)
copy_press = TRUE;
}
if (copy_press) {
@@ -707,33 +858,33 @@ void MindBreakerBoard::contentsMouseReleaseEvent(QMouseEvent* e)
return;
}
}
-
+
/* first work out if in y */
- if (e->y() > (board_height - (current_go * panel_height))) {
+ if (e->y() > (adjusted_board_height - (current_go * adjusted_panel_height))) {
delete moving;
moving = 0;
canvas()->update();
return;
}
- if (e->y() < (board_height - ((current_go + 1) * panel_height))) {
+ if (e->y() < (adjusted_board_height - ((current_go + 1) * adjusted_panel_height))) {
delete moving;
moving = 0;
canvas()->update();
return;
}
/* ok, a valid go, but which peg */
- int x_bar = first_peg_x_diff - (peg_size >> 1);
- x_bar += peg_spacing;
+ int x_bar = adjusted_first_peg_x_diff - (adjusted_peg_size >> 1);
+ x_bar += adjusted_peg_spacing;
int pos = 0;
- if (e->x() > x_bar)
+ if (e->x() > x_bar)
pos = 1;
- x_bar += peg_spacing;
+ x_bar += adjusted_peg_spacing;
if (e->x() > x_bar)
pos = 2;
- x_bar += peg_spacing;
+ x_bar += adjusted_peg_spacing;
if (e->x() > x_bar)
pos = 3;
- x_bar += peg_spacing;
+ x_bar += adjusted_peg_spacing;
if (e->x() > x_bar) {
/* invalid x */
@@ -743,9 +894,9 @@ void MindBreakerBoard::contentsMouseReleaseEvent(QMouseEvent* e)
return;
}
- int x = first_peg_x_diff + (pos * peg_spacing);
- int y = board_height - ((current_go + 1) * panel_height)
- + first_peg_y_diff;
+ int x = adjusted_first_peg_x_diff + (pos * adjusted_peg_spacing);
+ int y = adjusted_board_height - ((current_go + 1) * adjusted_panel_height)
+ + adjusted_first_peg_y_diff;
moving->setPegPos(pos);
moving->setX(x);
moving->setY(y);
@@ -769,29 +920,17 @@ void MindBreakerBoard::contentsMouseReleaseEvent(QMouseEvent* e)
moving = 0;
null_point -= e->pos();
if(null_point.manhattanLength() < 6) {
- if (game_over)
+ if (game_over)
clear();
- else
+ else
checkGuess();
}
}
void MindBreakerBoard::resizeEvent(QResizeEvent *e)
{
- QSize s = e->size();
- int fw = style().defaultFrameWidth();
- s.setWidth(s.width() - fw);
- s.setHeight(s.height() - fw);
-
- /* min size is 200 x 260 */
- if (s.width() < board_width)
- s.setWidth(board_width);
-
- if (s.height() < board_height)
- s.setHeight(board_height);
-
- canvas()->resize(s.width() - fw, s.height() - fw);
- drawBackground();
+ QCanvasView::resizeEvent(e);
+ fixSize();
}
@@ -804,12 +943,12 @@ void MindBreakerBoard::checkScores()
Peg::eggLevel = 0;
double break_even = 5.0;
- if (g < 1.0)
+ if (g < 1.0)
return;
double avg = turns / games;
g--;
while (break_even >= 0.0) {
- if (avg >= (break_even + g))
+ if (avg >= (break_even + g))
return;
// score a peg.
break_even -= 1.0;
diff --git a/noncore/games/mindbreaker/mindbreaker.h b/noncore/games/mindbreaker/mindbreaker.h
index fca649a..3132e80 100644
--- a/noncore/games/mindbreaker/mindbreaker.h
+++ b/noncore/games/mindbreaker/mindbreaker.h
@@ -1,7 +1,7 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
@@ -51,15 +51,20 @@ static const int board_width = (panel_width + (bin_margin * 2) + peg_size);
class Peg;
class QToolButton;
+class QTimer;
class MindBreakerBoard : public QCanvasView // QWidget
{
Q_OBJECT
public:
- MindBreakerBoard(QCanvas &c, QWidget *parent=0, const char *name=0, int wFlags=0 );
+ MindBreakerBoard(QWidget *parent=0, const char *name=0, int wFlags=0 );
~MindBreakerBoard();
void getScore(int *, int *);
+
+ void resizeEvent(QResizeEvent*);
+ void fixSize();
+
signals:
void scoreChanged(int, int);
@@ -67,13 +72,20 @@ public slots:
void clear();
void resetScore();
+private slots:
+ void doFixSize();
+
protected:
void contentsMousePressEvent(QMouseEvent *);
void contentsMouseMoveEvent(QMouseEvent *);
void contentsMouseReleaseEvent(QMouseEvent *);
- void resizeEvent(QResizeEvent *);
private:
+ QCanvas cnv;
+
+ void readConfig();
+ void writeConfig();
+
void drawBackground();
void checkGuess();
void checkScores();
@@ -100,6 +112,8 @@ private:
int total_turns;
int total_games;
+
+ QTimer *widthTimer;
};
class MindBreaker : public QMainWindow // QWidget
@@ -107,10 +121,13 @@ class MindBreaker : public QMainWindow // QWidget
Q_OBJECT
public:
MindBreaker(QWidget *parent=0, const char *name=0, int wFlags=0 );
-
+ static QString appName() { return QString::fromLatin1("mindbreaker"); }
public slots:
void setScore(int, int);
+protected:
+ void resizeEvent( QResizeEvent * );
+
private:
QCanvas canvas;
MindBreakerBoard *board;
diff --git a/noncore/games/mindbreaker/mindbreaker.pro b/noncore/games/mindbreaker/mindbreaker.pro
index 4ca3b84..0a37fa7 100644
--- a/noncore/games/mindbreaker/mindbreaker.pro
+++ b/noncore/games/mindbreaker/mindbreaker.pro
@@ -1,6 +1,4 @@
-TEMPLATE = app
-CONFIG += qt warn_on release
-DESTDIR = $(OPIEDIR)/bin
+CONFIG += qt warn_on release quick-app
HEADERS = mindbreaker.h
SOURCES = main.cpp \
mindbreaker.cpp
@@ -9,4 +7,5 @@ INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe
+
include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/games/mindbreaker/opie-mindbreaker.control b/noncore/games/mindbreaker/opie-mindbreaker.control
index 7b5ead6..5b342da 100644
--- a/noncore/games/mindbreaker/opie-mindbreaker.control
+++ b/noncore/games/mindbreaker/opie-mindbreaker.control
@@ -1,5 +1,5 @@
Package: opie-mindbreaker
-Files: bin/mindbreaker apps/Games/mindbreaker.desktop pics/mindbreaker
+Files: plugins/application/libmindbreaker.so* bin/mindbreaker apps/Games/mindbreaker.desktop pics/mindbreaker
Priority: optional
Section: opie/games
Maintainer: Martin Imobersteg <imm@gmx.ch>