-rw-r--r-- | noncore/games/mindbreaker/mindbreaker.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/noncore/games/mindbreaker/mindbreaker.cpp b/noncore/games/mindbreaker/mindbreaker.cpp index b0e4d88..1a1d05d 100644 --- a/noncore/games/mindbreaker/mindbreaker.cpp +++ b/noncore/games/mindbreaker/mindbreaker.cpp @@ -88,216 +88,216 @@ void Peg::buildImages() QImage pegs = Resource::loadImage("mindbreaker/pegs"); 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))); 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))); x += peg_size; } QImage image = Resource::loadImage("mindbreaker/mindbreaker"); /* 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))); y += panel_height; y += title_height; normalPegs.insert(9, new QImage(image.copy(x, y, title_width, title_height))); y += title_height; x = 6 * peg_size; normalPegs.insert(6, new QImage(image.copy(x, y, answerpeg_size, answerpeg_size))); x += answerpeg_size; normalPegs.insert(7, new QImage(image.copy(x, y, answerpeg_size, answerpeg_size))); } QImage Peg::imageForType(int t) { if (eggLevel > t ) { if( t < 5) { return *specialPegs[t]; } else { return *normalPegs[rand() % 6]; } } return *normalPegs[t]; } -Peg::Peg(QCanvas *canvas , int t, int g = -1, int p = -1) +Peg::Peg(QCanvas *canvas , int t, int g, int p) : QCanvasRectangle(canvas) { setSize(normalPegs[t]->width(), normalPegs[t]->height() ); pegtype = t; isplaced = FALSE; peg_pos = p; peg_go = g; aniStep = rand() % 6; setAnimated(TRUE); } void Peg::advance(int phase) { if (phase == 0) aniStep = (++aniStep) % 6; else { hide(); show(); } } void Peg::drawShape(QPainter &p ) { if ((pegtype == 5) && eggLevel > 5) { p.drawImage(x(), y(), *normalPegs[aniStep]); } else p.drawImage(x(), y(), imageForType(pegtype)); } bool Peg::hit( const QPoint &p ) const { int ix = p.x() - int(x()); int iy = p.y() - int(y()); if (!normalPegs[pegtype]->valid(ix, iy)) return FALSE; QRgb pixel = normalPegs[pegtype]->pixel(ix, iy); return (qAlpha(pixel ) != 0); } inline bool Peg::placed() const { return isplaced; } inline int Peg::pegGo() const { return peg_go; } inline int Peg::pegPos() const { return peg_pos; } inline void Peg::setPegPos(int p) { peg_pos = p; } inline void Peg::setPlaced(bool p) { isplaced = p; } inline int Peg::type() const { return pegtype; } /* 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=0, const char *name=0, int wFlags=0 ) +MindBreaker::MindBreaker( QWidget *parent, const char *name, int wFlags ) : QMainWindow(parent, name, wFlags), canvas(board_height, board_width) { MindBreakerBoard *m = new MindBreakerBoard(canvas, this); setCentralWidget(m); setToolBarsMovable( FALSE ); QPEToolBar *tb = new QPEToolBar(this); tb->setHorizontalStretchable( TRUE ); QPixmap newicon = Resource::loadPixmap("new"); new QToolButton(newicon, tr("New Game"), 0, m, SLOT(clear()), tb, "NewGame"); score = new QToolButton(tb); score->setText(""); score->setMaximumHeight(20); score->setUsesTextLabel(TRUE); tb->setStretchableWidget(score); connect(m, SIGNAL(scoreChanged(int, int)), this, SLOT(setScore(int, int))); connect(score, SIGNAL(clicked()), m, SLOT(resetScore())); int a, b; m->getScore(&a, &b); setScore(a,b); } void MindBreaker::setScore(int turns, int games) { double average; double total_turns = turns; double total_games = games; if(total_games > 0) average = total_turns / total_games; else average = 0.0; score->setText(tr("win avg: %1 turns (%2 games)").arg(average).arg(games)); } -MindBreakerBoard::MindBreakerBoard( QCanvas &c, QWidget *parent=0, - const char *name=0, int wFlags=0 ) - : QCanvasView(&c, parent, name, wFlags) +MindBreakerBoard::MindBreakerBoard( QCanvas &canv, QWidget *parent, + const char *name, int wFlags ) + : QCanvasView(&canv, parent, name, wFlags) { int i, x, y; struct timeval tv; current_go = 0; gettimeofday(&tv, 0); srand(tv.tv_usec); canvas()->setAdvancePeriod(500); 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(); /* set up the game */ Config c("MindBreaker", Config::User); c.setGroup("Board"); game_over = FALSE; if (c.readNumEntry("Answer0") < 0) { for (i = 0; i < 4; i++) { answer[i] = rand() % 6; current_guess[i] = 6; } total_turns = 0; total_games = 0; } else { int j; c.setGroup("Score"); total_turns = c.readNumEntry("Turns"); total_games = c.readNumEntry("Games"); |