diff --git a/CMakeLists.txt b/CMakeLists.txt index 3550c3d..cbe8e8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,40 +1,40 @@ cmake_minimum_required (VERSION 3.0) project (kdegames) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) find_package(KDE1 REQUIRED) add_definitions(-DHAVE_CONFIG_H) include_directories(common) include(CMakePackageConfigHelpers) include(KDE1Macros) include(KDE1InstallDirs) if (CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-write-strings") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -std=c++98") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") endif() #add_subdirectory(bsd-port) add_subdirectory(kabalone) add_subdirectory(kasteroids) # need kdesupport-1.1.2 for that (QwSpriteField.h) add_subdirectory(kblackbox) #add_subdirectory(kenolaba) # Apparently this is the old name for kabalone add_subdirectory(kmahjongg) add_subdirectory(kmines) add_subdirectory(konquest) add_subdirectory(kpat) #add_subdirectory(kpoker) #add_subdirectory(kreversi) #add_subdirectory(ksame) add_subdirectory(kshisen) #add_subdirectory(ksirtet) -#add_subdirectory(ksnake) +add_subdirectory(ksnake) add_subdirectory(po) diff --git a/ksnake/CMakeLists.txt b/ksnake/CMakeLists.txt new file mode 100644 index 0000000..3527328 --- /dev/null +++ b/ksnake/CMakeLists.txt @@ -0,0 +1,59 @@ +add_subdirectory(doc) + +include_directories ( + ${QT_INCLUDE_DIR} + ${KDE1_INCLUDE_DIR} +) + +set(Ksnake_SRCS + game.cpp trys.cpp rattler.cpp board.cpp + level.cpp ball.cpp snake.cpp + basket.cpp startroom.cpp lcdrange.cpp + score.cpp pixServer.cpp progress.cpp levels.cpp + view.cpp keys.cpp +) + +set(Ksnake_MOC + basket.moc + game.moc + keys.moc + lcdrange.moc + progress.moc + rattler.moc + score.moc + snake.moc + startroom.moc + trys.moc + view.moc + ) + +QT1_WRAP_MOC(MOC_FILES ${Ksnake_MOC}) + +add_executable(ksnake ${Ksnake_SRCS} ${MOC_FILES} ${QwSpriteField_SOURCES}) +target_link_libraries(ksnake + ${QT_LIBRARIES} + ${X11_LIBRARIES} + ${KDE1_KDECORE} + ${KDE1_KDEUI} + ${KDE1_MEDIATOOL} + QwSpriteField +) + +install(TARGETS ksnake RUNTIME DESTINATION ${KDE1_BINDIR}) +install(FILES ksnake.kdelnk DESTINATION ${KDE1_APPSDIR}/Games) +install_icon(ksnake.xpm) + +file(GLOB BACKGROUNDS data/backgrounds/*.xpm) +install(FILES ${BACKGROUNDS} + DESTINATION "${KDE1_DATADIR}/ksnake/backgrounds") + +file(GLOB PIXMAPS data/pixmaps/*.xpm) +install(FILES ${PIXMAPS} + DESTINATION "${KDE1_DATADIR}/ksnake/pics") + +install(FILES data/highScores + DESTINATION "${KDE1_DATADIR}/ksnake/") + +file(GLOB LEVELS data/levels/room*) +install(FILES ${LEVELS} + DESTINATION "${KDE1_DATADIR}/ksnake/levels") diff --git a/ksnake/basket.cpp b/ksnake/basket.cpp index 3678b0b..6741f25 100644 --- a/ksnake/basket.cpp +++ b/ksnake/basket.cpp @@ -1,93 +1,95 @@ #include #include #include #include #include "basket.h" #include "board.h" #include "pixServer.h" #include "qtimer.h" Kaffee::Kaffee(int pos) { p = pos; t = Red; int r = random() % 40000; QTimer::singleShot( r, this, SLOT(golden()) ); dirty = TRUE; } void Kaffee::golden() { dirty = TRUE; t = (t == Red ? Golden : Red); int r = random() % 40000; QTimer::singleShot( r, this, SLOT(golden()) ); } Basket::Basket(Board *b, PixServer *p) { board = b; pixServer = p; list = new QList; list->setAutoDelete( TRUE ); } void Basket::clear() { if( !list->isEmpty()) list->clear(); } void Basket::newApples() { int x; int i = 0; while(i < 10) { x = random() % board->size(); if ((unsigned)x < board->size() && board->isEmpty(x) && x > BoardWidth+4) { Kaffee *g = new Kaffee(x); board->set(x, Apple); list->append(g); i++; } } } void Basket::repaint(bool dirty ) { Kaffee *g; for ( g = list->first(); g != 0; g = list->next()) { if (dirty) { pixServer->draw(g->position(), ApplePix, (int)g->type()); if (g->dirty) g->dirty = FALSE; } else if (g->dirty) { pixServer->draw(g->position(), ApplePix, (int)g->type()); g->dirty = FALSE; } } } Fruits Basket::eaten(int i) { Kaffee *g; Fruits f = Red; for (g = list->first(); g != 0; g = list->next() ) { if (g->position() == i) { f = g->type(); list->remove(g); break; } } if (list->isEmpty()) emit openGate(); return f; } + +#include "basket.moc" diff --git a/ksnake/doc/CMakeLists.txt b/ksnake/doc/CMakeLists.txt new file mode 100644 index 0000000..bad0cf3 --- /dev/null +++ b/ksnake/doc/CMakeLists.txt @@ -0,0 +1,3 @@ +install(FILES + index-1.html index-2.html index-3.html index-4.html index.html logotp3.gif + DESTINATION ${KDE1_HTMLDIR}/en/ksnake ) diff --git a/ksnake/game.cpp b/ksnake/game.cpp index 1df6df2..f6ee0ca 100644 --- a/ksnake/game.cpp +++ b/ksnake/game.cpp @@ -1,326 +1,328 @@ /* note: the code to lookup and insert the pixmaps into the Options menu was copied and adapted from KReversi. thanks. */ #include #include #include #include #include #include #include #include #include #include #include "rattler.h" #include "score.h" #include "game.h" #include "startroom.h" #include "levels.h" #include "trys.h" #include "lcdrange.h" #include "progress.h" #include "view.h" #include "keys.h" #include "version.h" Game::Game() : KTopLevelWidget() { setCaption( kapp->getCaption() ); setIcon(klocale->translate("Snake Race")); conf = kapp->getConfig(); if(conf == NULL) { printf(klocale->translate("KConfig error ??\n")); kapp->quit(); } levels = new Levels(); score = new Score; menu(); checkMenuItems(); View *view = new View(this); rattler = view->rattler; rattler->setFocus(); connect(rattler, SIGNAL(setPoints(int)), view->lcd, SLOT(display(int))); connect(rattler, SIGNAL(setTrys(int)), view->trys, SLOT(set(int))); connect(rattler, SIGNAL(rewind()), view->pg, SLOT(rewind())); connect(rattler, SIGNAL(advance()), view->pg, SLOT(advance())); connect(view->pg, SIGNAL(restart()), rattler, SLOT(restartTimer())); connect(rattler, SIGNAL(togglePaused()), this, SLOT(togglePaused())); connect(rattler, SIGNAL(setScore(int)), score, SLOT(setScore(int))); menubar->show(); setMenu(menubar); view->show(); setView(view); } void Game::menu() { game = new QPopupMenu(); CHECK_PTR( game ); game->insertItem( klocale->translate("New"), this, SLOT(newGame()),Key_F2); pauseID = game->insertItem( klocale->translate("Pause"), this , SLOT(pauseGame()), Key_F3); game->insertItem( klocale->translate("High Scores..."), this, SLOT(showHighScores())); game->insertSeparator(); game->insertItem( klocale->translate("&Quit"), this, SLOT(quitGame()), CTRL+Key_Q ); game->setCheckable( TRUE ); balls = new QPopupMenu; CHECK_PTR( balls ); ballsID[0] = balls->insertItem( klocale->translate("0")); ballsID[1] = balls->insertItem( klocale->translate("1")); ballsID[2] = balls->insertItem( klocale->translate("2")); ballsID[3] = balls->insertItem( klocale->translate("3")); balls->setCheckable( TRUE ); connect(balls, SIGNAL(activated(int)), this, SLOT ( ballsChecked(int) )); snakes = new QPopupMenu; CHECK_PTR( snakes ); snakesID[0] = snakes->insertItem( klocale->translate("0")); snakesID[1] = snakes->insertItem( klocale->translate("1")); snakesID[2] = snakes->insertItem( klocale->translate("2")); snakesID[3] = snakes->insertItem( klocale->translate("3")); snakes->setCheckable( TRUE ); connect(snakes, SIGNAL(activated(int)), this, SLOT ( snakesChecked(int) )); pix = new QPopupMenu; lookupBackgroundPixmaps(); pixID.resize(backgroundPixmaps.count()); if(backgroundPixmaps.count() == 0) pix->insertItem(klocale->translate("none")); else for(unsigned i = 0; i < backgroundPixmaps.count(); i++) { // since the filename may contain underscore, they // are replaced with spaces in the menu entry QString s(backgroundPixmaps.at(i)->baseName()); s = s.replace(QRegExp("_"), " "); pixID[i] = pix->insertItem((const char *)s); } pix->setCheckable( TRUE ); connect(pix, SIGNAL(activated(int)), this, SLOT ( pixChecked(int) )); options = new QPopupMenu(); CHECK_PTR( options ); skillID[0] = options->insertItem( klocale->translate("Beginner")); skillID[1] = options->insertItem( klocale->translate("Intermediate")); skillID[2] = options->insertItem( klocale->translate("Advanced")); skillID[3] = options->insertItem( klocale->translate("Expert")); options->insertSeparator(); options->insertItem(klocale->translate("Balls"), balls); options->insertItem(klocale->translate("Computer Snakes"), snakes); options->insertSeparator(); options->insertItem(klocale->translate("Select background color..."), this, SLOT(backgroundColor())); options->insertItem(klocale->translate("Select background pixmap"), pix); options->insertSeparator(); options->insertItem(klocale->translate("Change keys..."),this, SLOT(confKeys())); options->insertSeparator(); options->insertItem(klocale->translate("Starting Room..."), this, SLOT(startingRoom())); options->setCheckable( TRUE ); connect(options, SIGNAL(activated(int)), this, SLOT ( skillChecked(int) )); QPopupMenu *help = kapp->getHelpMenu(true, QString(klocale->translate("Snake Race")) + " " + KSNAKE_VERSION + klocale->translate("\n\nby Michel Filippi" " (mfilippi@sade.rhein-main.de)")); menubar = new KMenuBar( this ); CHECK_PTR( menubar ); menubar->insertItem( klocale->translate("&Game"), game ); menubar->insertItem( klocale->translate("&Options"), options ); menubar->insertSeparator(); menubar->insertItem( klocale->translate("&Help"), help); } void Game::ballsChecked(int id) { for ( int x = 0; x < 4; x++) if (ballsID[x] != id) balls->setItemChecked( ballsID[x], FALSE ); else { balls->setItemChecked( ballsID[x], TRUE ); conf->writeEntry("Balls", x); rattler->setBalls(x); } } void Game::snakesChecked(int id) { for ( int x = 0; x < 4; x++) if (snakesID[x] != id) snakes->setItemChecked( snakesID[x], FALSE ); else { snakes->setItemChecked( snakesID[x], TRUE ); conf->writeEntry("ComputerSnakes", x); rattler->setCompuSnakes(x); } } void Game::skillChecked(int id) { if (options->indexOf(id) > 3) return; for ( int x = 0; x < 4; x++) if (skillID[x] != id) options->setItemChecked( skillID[x], FALSE ); else { options->setItemChecked( skillID[x], TRUE ); conf->writeEntry("Skill", x); rattler->setSkill(x); } } void Game::pixChecked(int id) { for ( unsigned int x = 0; x < backgroundPixmaps.count(); x++) pix->setItemChecked( pixID[x] , pixID[x] == id ); conf->writeEntry("Background", 2); conf->writeEntry("BackgroundPixmap", backgroundPixmaps.at(id)->filePath()); rattler->reloadRoomPixmap(); } void Game::checkMenuItems() { balls->setItemChecked( ballsID[conf->readNumEntry("Balls", 1)], TRUE ); snakes->setItemChecked( snakesID[conf->readNumEntry("ComputerSnakes", 1)], TRUE ); options->setItemChecked( skillID[conf->readNumEntry("Skill", 1)], TRUE ); QString path = conf->readEntry("BackgroundPixmap"); for ( unsigned int x = 0; x < backgroundPixmaps.count(); x++) { if (path == backgroundPixmaps.at(x)->filePath()) { pix->setItemChecked( x , TRUE ); break; } } } void Game::quitGame() { kapp->quit(); } void Game::showHighScores() { score->display(-1); // Magic number because bug in moc doesn't let us // default 2 parameters. } void Game::newGame() { rattler->restart(); } void Game::pauseGame() { rattler->pause(); } void Game::togglePaused() { static bool checked = FALSE; checked = !checked; game->setItemChecked( pauseID, checked ); } void Game::startingRoom() { int r = 0; StartRoom *sr = new StartRoom(conf->readNumEntry("StartingRoom", 1), &r); sr->exec(); delete sr; if (r != 0) { conf->writeEntry("StartingRoom", r); rattler->setRoom(r); } } void Game::confKeys() { Keys *keys = new Keys(); if (keys->exec() == QDialog::Accepted) rattler->initKeys(); delete keys; } //taken from KReversi void Game::backgroundColor() { QString s; QColor c; if(KColorDialog::getColor(c)) { conf->writeEntry("Background", 1); s.sprintf("%d %d %d", c.red(), c.green(), c.blue()); conf->writeEntry("BackgroundColor", (const char *)s); rattler->reloadRoomPixmap(); } } void Game::lookupBackgroundPixmaps() { QString pixDir; pixDir.setStr(KApplication::kde_datadir().copy()); pixDir.append("/ksnake/backgrounds"); QDir dir(pixDir, "*.xpm"); if(!dir.exists()) return; const QFileInfoList *fl = dir.entryInfoList(); // sanity check, maybe the directory is unreadable if(fl == NULL) return; QFileInfoListIterator it( *fl ); QFileInfo *fi; while((fi = it.current())) { backgroundPixmaps.append(new QFileInfo(*fi)); ++it; } } /************************** main ******************************/ int main( int argc, char **argv ) { KApplication a( argc, argv, "ksnake" ); Game g; a.setMainWidget( &g ); g.show(); return a.exec(); } + +#include "game.moc" diff --git a/ksnake/keys.cpp b/ksnake/keys.cpp index 43144c3..7251685 100644 --- a/ksnake/keys.cpp +++ b/ksnake/keys.cpp @@ -1,192 +1,194 @@ #include #include #include #include #include #include #include #include #include "keys.h" Keys::Keys( QWidget *parent, const char *name) : QDialog( parent, name, TRUE ) { QPushButton *okButton = new QPushButton(this); okButton->setText(klocale->translate("OK")); okButton->setFixedSize(okButton->size()); connect( okButton, SIGNAL(clicked()),this, SLOT(ok()) ); okButton->move(20,210); QPushButton *defaultButton = new QPushButton(this); defaultButton->setText(klocale->translate("Defaults")); defaultButton->setFixedSize(defaultButton->size()); connect( defaultButton, SIGNAL(clicked()),this, SLOT(defaults()) ); defaultButton->move(140,210); QPushButton *cancelButton = new QPushButton(this); cancelButton->setText(klocale->translate("Cancel")); cancelButton->setFixedSize(cancelButton->size()); connect( cancelButton, SIGNAL(clicked()),this, SLOT(reject()) ); cancelButton->move(260,210); QFrame *separator = new QFrame(this); separator->setFrameStyle( QFrame::HLine | QFrame::Sunken ); separator->setGeometry( 20, 190, 340, 4 ); for ( int x = 0; x < 4; x++) { QLabel *l = new QLabel(this); l->setAlignment(AlignCenter); labels[x] = l; } labels[0]->setGeometry(120, 20, 140, 20 ); labels[1]->setGeometry(120,160, 140, 20 ); labels[2]->setGeometry( 20, 92, 100, 20 ); labels[3]->setGeometry(265, 92, 100, 20 ); QString pixDir(KApplication::kde_datadir().copy()); pixDir.append("/ksnake/pics/"); QPushButton *up = new QPushButton(this); up->setPixmap( QPixmap((const char *)(pixDir + "up.xpm"))); up->adjustSize(); up->setFixedSize(up->size() ); connect( up, SIGNAL(clicked()),this, SLOT(butUp()) ); up->move(180, 50); QPushButton *down = new QPushButton(this); down->setPixmap( QPixmap((const char *)(pixDir + "down.xpm"))); down->adjustSize(); down->setFixedSize(down->size() ); connect( down, SIGNAL(clicked()),this, SLOT(butDown()) ); down->move(180, 130); QPushButton *left = new QPushButton(this); left->setPixmap( QPixmap((const char *)(pixDir + "left.xpm"))); left->adjustSize(); left->setFixedSize(left->size() ); connect( left, SIGNAL(clicked()),this, SLOT(butLeft()) ); left->move(140, 90); QPushButton *right = new QPushButton(this); right->setPixmap( QPixmap((const char *)(pixDir + "right.xpm"))); right->adjustSize(); right->setFixedSize(right->size() ); connect( right, SIGNAL(clicked()),this, SLOT(butRight()) ); right->move(220, 90); setCaption(klocale->translate("Change Direction Keys")); setFixedSize(380, 260); lab = 0; init(); } void Keys::keyPressEvent( QKeyEvent *e ) { uint kCode = e->key() & ~(SHIFT | CTRL | ALT); QString string = keyToString(kCode); if (lab != 0) { if ( string.isNull() ) lab->setText(klocale->translate("Undefined key")); else lab->setText(string); } else if ( lab == 0 && e->key() == Key_Escape) reject(); } void Keys::butUp() { getKey(0); } void Keys::butDown() { getKey(1); } void Keys::butLeft() { getKey(2); } void Keys::butRight() { getKey(3); } void Keys::getKey(int i) { if ( lab != 0) focusOut(lab); focusIn(labels[i]); } void Keys::focusOut(QLabel *l) { l->setFrameStyle( QFrame::NoFrame ); l->setBackgroundColor(backgroundColor()); l->repaint(); } void Keys::focusIn(QLabel *l) { lab = l; lab->setFrameStyle( QFrame::Panel | QFrame::Sunken ); lab->setBackgroundColor(white); lab->repaint(); } void Keys::defaults() { if ( lab != 0) focusOut(lab); lab = 0; labels[0]->setText(i18n("Up")); labels[1]->setText(i18n("Down")); labels[2]->setText(i18n("Left")); labels[3]->setText(i18n("Right")); } void Keys::init() { KConfig *conf = kapp->getConfig(); if(conf != NULL) { QString up("Up"); up = conf->readEntry("upKey", (const char*) up); labels[0]->setText(up); QString down("Down"); down = conf->readEntry("downKey", (const char*) down); labels[1]->setText(down); QString left("Left"); left = conf->readEntry("leftKey", (const char*) left); labels[2]->setText(left); QString right("Right"); right = conf->readEntry("rightKey", (const char*) right); labels[3]->setText(right); } } void Keys::ok() { KConfig *conf = kapp->getConfig(); if(conf != NULL) { conf->writeEntry("upKey", (const char*) labels[0]->text() ); conf->writeEntry("downKey", (const char*) labels[1]->text() ); conf->writeEntry("leftKey", (const char*) labels[2]->text() ); conf->writeEntry("rightKey",(const char*) labels[3]->text() ); } accept(); } + +#include "keys.moc" diff --git a/ksnake/lcdrange.cpp b/ksnake/lcdrange.cpp index 0e3bda1..9f2cdfa 100644 --- a/ksnake/lcdrange.cpp +++ b/ksnake/lcdrange.cpp @@ -1,80 +1,82 @@ /**************************************************************** ** ** Implementation of LCDRange class, Qt tutorial 14 ** ****************************************************************/ #include "lcdrange.h" #include #include #include #include LCDRange::LCDRange( QWidget *parent, const char *name ) : QWidget( parent, name ) { init(); } LCDRange::LCDRange( const char *s, QWidget *parent, const char *name ) : QWidget( parent, name ) { init(); setText( s ); } void LCDRange::init() { lcd = new QLCDNumber( 2, this, "lcd" ); lcd->move( 0, 0 ); sBar = new QScrollBar( 0, 99, // range 1, 10, // line/page steps 0, // inital value QScrollBar::Horizontal, // orientation this, "scrollbar" ); label = new QLabel( this, "label" ); label->setAlignment( AlignCenter ); connect( sBar, SIGNAL(valueChanged(int)), lcd, SLOT(display(int)) ); connect( sBar, SIGNAL(valueChanged(int)), SIGNAL(valueChanged(int)) ); } int LCDRange::value() const { return sBar->value(); } const char *LCDRange::text() const { return label->text(); } void LCDRange::setValue( int value ) { sBar->setValue( value ); } void LCDRange::setRange( int minVal, int maxVal ) { if ( minVal < 0 || maxVal > 99 || minVal > maxVal ) { warning( klocale->translate("LCDRange::setRange(%d,%d)\n" "\tRange must be 0..99\n" "\tand minVal must not be greater than maxVal"), minVal, maxVal ); return; } sBar->setRange( minVal, maxVal ); } void LCDRange::setText( const char *s ) { label->setText( s ); } void LCDRange::resizeEvent( QResizeEvent * ) { lcd->resize( width(), height() - 41 - 5 ); sBar->setGeometry( 0, lcd->height() + 5, width(), 16 ); label->setGeometry( 0, lcd->height() + 21, width(), 20 ); } + +#include "lcdrange.moc" diff --git a/ksnake/progress.cpp b/ksnake/progress.cpp index 3759a00..22549cb 100644 --- a/ksnake/progress.cpp +++ b/ksnake/progress.cpp @@ -1,28 +1,30 @@ #include "progress.h" Progress::Progress(QWidget *parent, const char *name) : KProgress(0, 300, 300, KProgress::Horizontal, parent, name) { setBackgroundColor("lightgray"); setBarColor("green1"); setTextEnabled(FALSE); } void Progress::advance() { if (value() == 0) { emit restart(); return; } else if (value() == 80) setBarColor("red1"); KProgress::advance(-1); } void Progress::rewind() { setBarColor("green1"); KProgress::setValue(300); } + +#include "progress.moc" diff --git a/ksnake/rattler.cpp b/ksnake/rattler.cpp index c0487c9..8c00cdc 100644 --- a/ksnake/rattler.cpp +++ b/ksnake/rattler.cpp @@ -1,605 +1,607 @@ #include #include #include #include #include #include #include #include #include #include #include #include "rattler.h" #include "board.h" #include "level.h" #include "basket.h" #include "ball.h" #include "snake.h" #include "pixServer.h" QBitArray gameState(5); QLabel *label = 0; int speed[4] = { 85, 75, 55, 40 }; Rattler::Rattler( QWidget *parent, const char *name ) : QWidget( parent, name ) { setFocusPolicy(QWidget::StrongFocus); KConfig *conf = kapp->getConfig(); numBalls = conf->readNumEntry("Balls", 1); numSnakes = conf->readNumEntry("ComputerSnakes", 1); skill = conf->readNumEntry("Skill", 1); room = conf->readNumEntry("StartingRoom", 1); initKeys(); board = new Board(35*35); level = new Level(board); pix = new PixServer(board, this); setFixedSize(pix->levelPix().size()); basket = new Basket(board, pix); samy = new SamySnake(board, pix); computerSnakes = new QList; computerSnakes->setAutoDelete( TRUE ); balls = new QList; balls->setAutoDelete( TRUE ); connect( samy, SIGNAL(closeGate(int)), this, SLOT(closeGate(int))); connect( samy, SIGNAL(score(bool, int)), this, SLOT(scoring(bool,int))); connect( samy, SIGNAL(goingOut()), this, SLOT(speedUp())); connect( basket, SIGNAL(openGate()), this, SLOT(openGate())); QTime midnight( 0, 0, 0 ); srandom( midnight.secsTo(QTime::currentTime()) ); gameState.fill(FALSE); gameState.setBit(Demo); timerCount = 0; QTimer::singleShot( 2000, this, SLOT(demo()) ); } void Rattler::paintEvent( QPaintEvent *e) { QRect rect = e->rect(); bool dirty = FALSE; if (!rect.isEmpty()) { dirty = TRUE; QPixmap levelPix = pix->levelPix(); bitBlt(this, rect.x(), rect.y(), &levelPix, rect.x(), rect.y(), rect.width(), rect.height()); } if (!gameState.testBit(Init) && !gameState.testBit(Over)) { basket->repaint( dirty ); if(!gameState.testBit(Demo))samy->repaint( dirty ); for (CompuSnake *as = computerSnakes->first(); as != 0; as = computerSnakes->next()) if (as) as->repaint( dirty ); for (Ball *b = balls->first(); b != 0; b = balls->next()) if (b) b->repaint(); } } void Rattler::timerEvent( QTimerEvent * ) { timerCount++; if ( !leaving ) // advance progressBar unless Samy emit advance(); // is going out for (CompuSnake *c = computerSnakes->first(); c != 0; c = computerSnakes->next()) if(c) c->nextMove(); for (Ball *b = balls->first(); b != 0; b = balls->next()) if (b) b->nextMove(); samyState state = ok; if(!gameState.testBit(Demo)) state = samy->nextMove(direction); repaint(0,0,0,0, FALSE); if (state == ko) newTry(); else if (state == out) levelUp(); } void Rattler::initKeys() { KConfig *conf = kapp->getConfig(); QString up("Up"); up = conf->readEntry("upKey", (const char*) up); UpKey = stringToKey(up); QString down("Down"); down = conf->readEntry("downKey", (const char*) down); DownKey = stringToKey(down); QString left("Left"); left = conf->readEntry("leftKey", (const char*) left); LeftKey = stringToKey(left); QString right("Right"); right = conf->readEntry("rightKey", (const char*) right); RightKey = stringToKey(right); } void Rattler::keyPressEvent( QKeyEvent *k ) { if (gameState.testBit(Paused)) return; uint key = k->key(); if (key == UpKey) direction = N; else if (key == DownKey) direction = S; else if (key == RightKey) direction = E; else if (key == LeftKey) direction = W; else { k->ignore(); return; } k->accept(); /* switch ( k->key()) { case (const int)UpKey: direction = N; break; case DownKey: direction = S; break; case RightKey: direction = E; break; case LeftKey: direction = W; break; default: k->ignore(); return; } k->accept(); */ } void Rattler::closeGate(int i) { board->set(i, brick); pix->restore(i); } void Rattler::openGate() { board->set(NORTH_GATE, empty); pix->erase(NORTH_GATE); } void Rattler::scoring(bool win, int i) { Fruits fruit = basket->eaten(i); if (gameState.testBit(Demo)) win = TRUE; int p = 0; switch (fruit) { case Red: if (win) { if (!timerHasRunOut) p = 1 + skill*2; else p = 1; } else p = -2; break; case Golden: if (win) { if (!timerHasRunOut) p = 2 + (skill*2) + (numSnakes*2) + (numBalls+2); else p = 2; } else p = -5; break; default: break; } score(p); } void Rattler::score(int p) { points += p; points = (points < 0 ? 0 : points); emit setPoints(points); while (points > check*50) { check++; if (trys < 7 && !gameState.testBit(Demo)) emit setTrys(++trys); } } void Rattler::killedComputerSnake() { if (!gameState.testBit(Demo)) score(20); } void Rattler::pause() { if (gameState.testBit(Init)) return; if (gameState.testBit(Playing)) { gameState.toggleBit(Playing); gameState.setBit(Paused); stop(); label = new QLabel(this); label->setFont( QFont( "Times", 16, QFont::Bold ) ); label->setText(klocale->translate("Game Paused\n Press F3 to resume\n")); label->setAlignment( AlignCenter ); label->setFrameStyle( QFrame::Panel | QFrame::Raised ); label->setGeometry(182, 206, 198, 80); label->show(); emit togglePaused(); } else if (gameState.testBit(Paused)) { gameState.toggleBit(Paused); gameState.setBit(Playing); start(); cleanLabel(); emit togglePaused(); } } void Rattler::cleanLabel() { if (label) { delete label; label = 0; } } void Rattler::restartDemo() { if (!gameState.testBit(Demo)) return; int r = 50000+ (random() % 30000); QTimer::singleShot( r, this, SLOT(restartDemo()) ); stop(); level->create(Intro); init(FALSE); repaint(); start(); } void Rattler::demo() { static bool first_time = TRUE; if(gameState.testBit(Init) || gameState.testBit(Playing)) return; stop(); QTimer::singleShot( 60000, this, SLOT(restartDemo()) ); gameState.fill(FALSE); gameState.setBit(Init); gameState.setBit(Demo); resetFlags(); if(!first_time) { level->create(Intro); pix->initRoomPixmap(); } repaint(rect(), FALSE); init(FALSE); run(); first_time = FALSE; } void Rattler::restart() { if (gameState.testBit(Init)) return; stop(); if (gameState.testBit(Paused) || gameState.testBit(Playing)) { switch( QMessageBox::information( this, klocale->translate("Snake Race"), klocale->translate("A game is already started\n" "Start a new one ?\n"), klocale->translate("&Yes"), klocale->translate("&No"), 0, 1 ) ) { case 0: if ( gameState.testBit(Paused)) emit togglePaused(); break; case 1: if ( !gameState.testBit(Paused)) start(); return; } } gameState.fill(FALSE); gameState.setBit(Init); gameState.setBit(Playing); resetFlags(); level->set(room); level->create(Banner); pix->initRoomPixmap(); cleanLabel(); repaint(); QTimer::singleShot( 2000, this, SLOT(showRoom()) ); } void Rattler::newTry() { stop(); if(trys==0) { gameState.fill(FALSE); gameState.setBit(Over); level->create(GameOver); pix->initRoomPixmap(); repaint(); QTimer::singleShot( 5000, this, SLOT(demo()) ); emit setScore(points); return; } --trys; gameState.fill(FALSE); gameState.setBit(Init); gameState.setBit(Playing); level->create(Room); pix->initRoomPixmap(); init(TRUE); repaint(); QTimer::singleShot( 1000, this, SLOT(run()) ); } void Rattler::levelUp() { stop(); gameState.fill(FALSE); gameState.setBit(Init); gameState.setBit(Playing); score (2*(level->get())+(2*numSnakes)+(2*numBalls)+(2*skill)); level->up(); level->create(Banner); pix->initRoomPixmap(); repaint(); QTimer::singleShot( 2000, this, SLOT(showRoom()) ); } /* this slot is called by the progressBar when value() == 0 or by a compuSnake wich manages to exit */ void Rattler::restartTimer() { timerHasRunOut = TRUE; timerCount = 0; emit rewind(); if ( board->isEmpty(NORTH_GATE) ) closeGate(NORTH_GATE); basket->newApples(); } void Rattler::speedUp() { leaving = TRUE; stop(); start( 30 ); } void Rattler::resetFlags() { trys = 2; check = 1; points = 0; } void Rattler::showRoom() { level->create(Room); pix->initRoomPixmap(); init(TRUE); repaint(); QTimer::singleShot( 1000, this, SLOT(run()) ); } void Rattler::init(bool play) { leaving = FALSE; timerHasRunOut = FALSE; timerCount = 0; emit rewind(); emit setTrys(trys); emit setPoints(points); basket->clear(); basket->newApples(); restartBalls(play); restartComputerSnakes(play); if(play) samy->init(); } void Rattler::run() { direction = N; gameState.toggleBit(Init); start(); } void Rattler::start() { gameTimer = startTimer( speed [skill] ); } void Rattler::start(int t) { gameTimer = startTimer(t); } void Rattler::stop() { killTimers (); } void Rattler::restartComputerSnakes(bool play) { if( !computerSnakes->isEmpty()) computerSnakes->clear(); int i = (play == FALSE && numSnakes == 0 ? 1 : numSnakes); for (int x = 0; x < i; x++) { CompuSnake *as = new CompuSnake(board, pix); connect( as, SIGNAL(closeGate(int)), this, SLOT(closeGate(int))); connect( as, SIGNAL(restartTimer()), this, SLOT(restartTimer())); connect( as, SIGNAL(score(bool, int)), this, SLOT(scoring(bool,int))); connect( as, SIGNAL(killed()), this, SLOT(killedComputerSnake())); computerSnakes->append(as); } } void Rattler::restartBalls(bool play) { if( !balls->isEmpty()) balls->clear(); int i = (play == FALSE && numBalls == 0 ? 1 : numBalls); for (int x = 0; x < i; x++) { Ball *b = new Ball(board, pix); balls->append(b); } } void Rattler::setBalls(int i) { Ball *b; numBalls = i; int count = balls->count(); if (gameState.testBit(Playing) || gameState.testBit(Demo)) { if ( i > count) { while ( i > count) { Ball *b = new Ball(board, pix); balls->append(b); i--; } } else if (i < count) { while (i < count) { b = balls->getLast(); b->zero(); balls->removeLast(); i++; } } } } void Rattler::setCompuSnakes(int i) { CompuSnake *cs; numSnakes = i; int count = computerSnakes->count(); if (gameState.testBit(Playing) || gameState.testBit(Demo)) { if ( i > count) { while ( i > count) { CompuSnake *as = new CompuSnake(board, pix); connect( as, SIGNAL(closeGate(int)), this, SLOT(closeGate(int))); connect( as, SIGNAL(restartTimer()), this, SLOT(restartTimer())); connect( as, SIGNAL(score(bool, int)), this, SLOT(scoring(bool,int))); connect( as, SIGNAL(killed()), this, SLOT(killedComputerSnake())); computerSnakes->append(as); i--; } } else if (i < count) { while (i < count) { cs = computerSnakes->getLast(); cs->zero(); computerSnakes->removeLast(); i++; } } } } void Rattler::setSkill(int i) { skill = i; if (gameState.testBit(Playing) || gameState.testBit(Demo)) { stop(); start(); } } void Rattler::setRoom(int i) { room = i; } void Rattler::reloadRoomPixmap() { pix->initbackPixmaps(); pix->initRoomPixmap(); demo(); } + +#include "rattler.moc" diff --git a/ksnake/score.cpp b/ksnake/score.cpp index 0f367f9..bb6c5b9 100644 --- a/ksnake/score.cpp +++ b/ksnake/score.cpp @@ -1,278 +1,280 @@ #include #include #include #include #include #include #include #include #include #include #include #include #include "score.h" Score::Score( QWidget *parent, const char *name ) :QObject( parent, name ) { QString libDir; libDir.setStr(KApplication::kde_datadir().copy()); libDir.append("/ksnake/"); file.setName( libDir + "highScores"); playerName = getenv("LOGNAME"); read(); } QString Score::formatDate(int d, int m, int y) { QString s; s.sprintf("%d/%d/%d", d, m, y); if(d < 10) s.insert(0,'0'); if(m < 10) s.insert(3,'0'); s.remove(6,2); return s; } void Score::display(int newHall = -1, int newToday = -1) { QDialog *dlg = new QDialog(0, "Hall Of Fame", TRUE); dlg->setCaption(klocale->translate("Snake Race High Scores")); ScoreBox *sb1 = new ScoreBox(dlg, 0, newHall); sb1->setGeometry(10, 10, 400, 225); sb1->setTitle(klocale->translate("Hall of Fame")); ScoreBox *sb2 = new ScoreBox(dlg, 0, newToday); sb2->setGeometry(10, 240, 400, 225); sb2->setTitle(klocale->translate("Today's High Scores")); QPushButton *b = new QPushButton( dlg); b->setText(klocale->translate("OK")); b->setAutoDefault(TRUE); b->setFocus(); b->move(300, 480); connect( b, SIGNAL(clicked()),dlg, SLOT(accept()) ); for ( int x = 0; x < 5; x++) { QString s = formatDate( hall[x].date.day(), hall[x].date.month(), hall[x].date.year()); sb1->setScore(x, hall[x].points, hall[x].player, s.data()); sb2->setScore(x, today[x].points, today[x].player, ""); } dlg->exec(); delete dlg; } QString Score::getPlayerName() { QDialog *dlg = new QDialog(0, "Hall Of Fame", TRUE); dlg->resize(300, 175); dlg->setCaption(klocale->translate("Snake Race High Scores")); QLabel *label = new QLabel(klocale->translate("you have achieved a high score!\n please enter your name"), dlg); label->setAlignment(AlignCenter); label->setFont( QFont( "Times", 16, QFont::Bold ) ); QLineEdit *le = new QLineEdit(dlg); le->setFocus(); le->setText(playerName); le->selectAll(); QFrame *sep = new QFrame( dlg); sep->setFrameStyle( QFrame::HLine | QFrame::Sunken ); QPushButton *b = new QPushButton(klocale->translate("OK"), dlg); b->setDefault(TRUE); b->setAutoDefault(TRUE); connect(b, SIGNAL(released()), dlg, SLOT(accept())); connect(le, SIGNAL(returnPressed()), dlg, SLOT(accept())); label->setGeometry(0, 0, 300, 50 ); le->setGeometry(50, 65, 200, 25 ); sep->setGeometry(0, 100, 400, 25 ); b->setGeometry(110, 125, 80, 32 ); dlg->exec(); QString s = le->text(); delete dlg; return s; } void Score::setScore(int s) { read(); bool checkHall = FALSE; bool checkToday = FALSE; int x, xx; for ( x = 0; x < 5; x++) if ( s > hall[x].points) { checkHall = TRUE; break; } for ( xx = 0; xx < 5; xx++) if ( s > today[xx].points) { checkToday = TRUE; break; } if (checkHall == TRUE || checkToday == TRUE) { playerName = getPlayerName(); if (checkHall) { for (int i = 4; i > x && i > 0; i--) hall[i] = hall[i-1]; hall[x].points = s; hall[x].player = playerName.data() ; hall[x].date = QDate::currentDate(); } else x = -1; if (checkToday) { for (int i = 4; i > xx && i > 0; i--) today[i] = today[i-1]; today[xx].points = s; today[xx].player = playerName.data(); today[xx].date = QDate::currentDate(); } else xx = -1; display(x, xx); write(); } } void Score::read() { if ( file.exists() ) { if (file.open( IO_ReadOnly )) { QDataStream s( &file ); for ( int x = 0; x < 5; x++) s >> hall[x].points >> hall[x].player >> hall[x].date; for ( int x = 0; x < 5; x++) { s >> today[x].points >> today[x].player >> today[x].date; if ( today[x].date != QDate::currentDate()) today[x].points = 0; } file.close(); } } else { for( int x = 0; x < 5; x++) { hall[x].points = 0; hall[x].player = ""; hall[x].date = QDate::currentDate(); today[x].points = 0; today[x].player = ""; today[x].date = QDate::currentDate(); } write(); } } void Score::write() { if (file.open( IO_WriteOnly )) { QDataStream s( &file ); for ( int x = 0; x < 5; x++) s << hall[x].points << hall[x].player << hall[x].date; for ( int x = 0; x < 5; x++) s << today[x].points << today[x].player << today[x].date; file.close(); } } ScoreBox::ScoreBox( QWidget *parent, const char *name , int current) : QWidget( parent, name ) { box = new QGroupBox(this); label = new QLabel(this); label->setFrameStyle( QFrame::Panel | QFrame::Raised ); label->setFont( QFont( "Times", 18, QFont::Bold ) ); label->setAlignment( AlignCenter ); for ( int x = 0; x < 5; x++) { QLabel *l = new QLabel(this); CHECK_PTR(l); l->setFont( QFont( "Times", 16, QFont::Bold ) ); l->setAlignment( AlignRight ); date[x] = l; QLabel *l1 = new QLabel(this); CHECK_PTR(l1); l1->setFont( QFont( "Times", 16, QFont::Bold ) ); l1->setAlignment( AlignRight ); points[x] = l1; QLabel *l2 = new QLabel(this); CHECK_PTR(l2); l2->setFont( QFont( "Times", 16, QFont::Bold ) ); l2->setAlignment( AlignLeft ); player[x] = l2; } if (current >= 0) { QColorGroup colgrp(black, backgroundColor(), black, black, black, blue, black); date[current]->setPalette( QPalette(colgrp,colgrp,colgrp) ); points[current]->setPalette( QPalette(colgrp,colgrp,colgrp) ); player[current]->setPalette( QPalette(colgrp,colgrp,colgrp) ); } } void ScoreBox::setTitle( const char *s ) { label->setText( s ); } void ScoreBox::setScore( int x, int p, const char * pl, const char *dt) { if (x > 5) return; if (p == 0) { points[x]->setText(""); player[x]->setText(""); } else { QString s; s.sprintf("%d",p); date[x]->setText(dt); points[x]->setText(s.data()); player[x]->setText(pl); } } void ScoreBox::resizeEvent( QResizeEvent * ) { box->resize( width(), height() - 25 ); box->setGeometry(0, 25, width(), height()-25 ); label->setGeometry(100, 10, 200, 30 ); int p = 65; for ( int x = 0; x < 5; x++) { date[x]->setGeometry(25, p, 80, 25); points[x]->setGeometry(105, p, 70, 25); player[x]->setGeometry(195, p, 170, 25); p+= 30; } } + +#include "score.moc" diff --git a/ksnake/snake.cpp b/ksnake/snake.cpp index 60c318a..a6bf1aa 100644 --- a/ksnake/snake.cpp +++ b/ksnake/snake.cpp @@ -1,377 +1,379 @@ #include #include #include #include "snake.h" #include "board.h" #include "pixServer.h" int opposite[4] = { S, N , W, E }; int emptySq[4][4]={ { N, E, W, N }, { S, W, E, S }, { E, N, S, E }, { W, S, N, W } }; Snake::Snake(Board *b, PixServer *p, Gate g, PixMap x) { list.setAutoDelete( TRUE ); pixServer = p; board = b; gate = g; pixmap = x; } void Snake::updateSamy() { int x = tail(); while ( x > 0) *list.at(x) = *list.at(--x); } void Snake::zero() { for ( Samy *sam = list.first(); sam != 0; sam = list.next() ) { board->set(sam->index, empty); pixServer->erase(sam->index); } } void Snake::appendSamy() { Samy *sam = new Samy; list.append(sam); int x = tail(); while ( x > 0) *list.at(x) = *list.at(--x); grow--; } void Snake::reset(int index, int border) { Samy *sam = list.first(); switch (border) { case N: sam->pixmap = (tail() == 0 ? HtailUp : HeadUp); break; case S: sam->pixmap = (tail() == 0 ? HtailDown : HeadDown); break; case E: sam->pixmap = (tail() == 0 ? HtailRight : HeadRight); break; case W: sam->pixmap = (tail() == 0 ? HtailLeft : HeadLeft); break; } sam->index = index; sam->direction = border; if (tail() > 1) { sam = list.next(); if (sam->direction == border) { if (border == N || border == S) sam->pixmap = BodyVt; else sam->pixmap = BodyHz; } else { if (border == W && sam->direction == S || border == N && sam->direction == E) sam->pixmap = AngleNw; if (border == E && sam->direction == S || border == N && sam->direction == W) sam->pixmap = AngleNe; if(border == W && sam->direction == N || border == S && sam->direction == E) sam->pixmap = AngleSw; if(border == E && sam->direction == N || border == S && sam->direction == W) sam->pixmap = AngleSe; } } //end if (tail() > 1) if (tail() > 0) { sam = list.last(); switch (list.at(tail()-1)->direction) { case N: sam->pixmap = TailUp; break; case S: sam->pixmap = TailDown; break; case E: sam->pixmap = TailRight; break; case W: sam->pixmap = TailLeft; break; } } } void Snake::repaint( bool dirty) { int x = 0; for ( Samy *sam = list.first(); sam != 0; sam = list.next(), x++) { if (sam->index != OUT ) { if(!dirty && x > 1 && x < tail()) continue; pixServer->draw(sam->index, pixmap, sam->pixmap); } } if (!growing() && hold != OUT && hold != gate) { pixServer->erase(hold); } } CompuSnake::CompuSnake( Board *b, PixServer *p) : Snake( b, p, NORTH_GATE, CompuSnakePix ) { init(); } bool CompuSnake::init() { if( !list.isEmpty()) { list.clear(); } int index = NORTH_GATE; int length = 12; grow = 0; hold = OUT; if ( !board->isBrick(gate) ) return FALSE; Samy *sam; for ( int x = 0; x < length; x++) { board->set(index, snake); sam = new Samy; sam->direction = S; sam->index = index; sam->pixmap = (x == 0 ? HeadDown : BodyVt); list.append(sam); index = -1; } return TRUE; } bool CompuSnake::permission() { if( list.isEmpty() ){ if ( hold != OUT) { emit killed(); hold = OUT; } if(board->isBrick(gate)){ static int skip = 12; if (skip < 12) { skip++; return FALSE; } else { skip = 0; return init(); } } else return FALSE; } else return TRUE; } void CompuSnake::nextMove() { if (!permission()) return; Samy *sam = list.first(); int index = sam->index; int dir = sam->direction; static bool varies = FALSE; bool found = FALSE; for ( int x = 0; x < 4 ; x++) { int next = board->getNext(x, sam->index); if (board->isApple(next)){ index = next; dir = x; found = TRUE; grow+=6; emit score(FALSE, index); break; } } if(!found) for ( int x = 0; x < 4 ; x++) { int sq = emptySq[sam->direction][x]; if (varies && (x > 0 && x < 3)) sq = opposite[sq]; int next = board->getNext(sq, sam->index); if (findEmpty(next, x)) { index = next; dir = sq; found = TRUE; break; } } varies = !varies; if(!found) { hold = list.last()->index; if (board->isSnake(hold)) board->set(hold, empty); removeSamy(); } else if(growing()) appendSamy(); else if (!growing() && found) { hold = list.last()->index; if (board->isSnake(hold)) board->set(hold, empty); updateSamy(); } if( !list.isEmpty()) { board->set(index, snake); reset(index, dir); } if ( hold == gate) out(); } bool CompuSnake::findEmpty(int i, int it) { bool found = FALSE; bool change = FALSE; static int s_random = random() % BoardWidth/2; static int moves = 0; if (moves > s_random) { s_random = random() % BoardWidth/2; moves = 0; change = TRUE; } found = ( ( board->isEmpty(i) && it > 0) || ( board->isEmpty(i) && !change && it == 0) ); moves++; change = FALSE; return found; } void CompuSnake::removeSamy() { list.remove(); grow = 0; } void CompuSnake::out() { emit closeGate( gate ); if( list.isEmpty() ) return; if(list.first()->index == OUT) { emit restartTimer(); list.clear(); } } SamySnake::SamySnake( Board *b, PixServer *p) : Snake( b, p, SOUTH_GATE, SamyPix ) { } void SamySnake::init() { if( !list.isEmpty()) { list.clear(); } Samy *sam; int index = SOUTH_GATE; int length = 12; grow = 0; hold = 0; for ( int x = 0; x < length; x++) { board->set(index, head); sam = new Samy; sam->direction = N; sam->index = index; sam->pixmap = (x == 0 ? HeadUp : BodyVt); list.append(sam); index = -1; } } samyState SamySnake::nextMove(int direction) { Samy *sam = list.first(); if(!board->isHead(sam->index) && sam->index != OUT) return ko; if ( direction == opposite[sam->direction]) direction = sam->direction; if(sam->index == gate || sam->index == OUT ) direction = N; if (sam->index == NORTH_GATE) { emit goingOut(); direction = N; } int index = board->getNext(direction, sam->index); if (board->isApple(index)) { grow+=6; emit score(TRUE, index); } else if (!board->isEmpty(index)) return ko; if(growing()) appendSamy(); else { hold = list.last()->index; board->set(hold, empty); updateSamy(); } board->set(sam->index, snake); reset(index, direction); board->set(index, head); if ( hold == gate) emit closeGate( gate ); else if ( hold == NORTH_GATE) return out; return ok; } + +#include "snake.moc" diff --git a/ksnake/snake.h b/ksnake/snake.h index f9d4195..0062ca5 100644 --- a/ksnake/snake.h +++ b/ksnake/snake.h @@ -1,76 +1,76 @@ #ifndef SAMY_H #define SAMY_H #include #include #include #include #include #include "board.h" #include "pixServer.h" class Snake : public QObject { Q_OBJECT public: Snake(Board *b, PixServer *p, Gate g, PixMap x); Snake::~Snake() {} void repaint( bool ); void zero(); signals: void score(bool, int); void killed(); void closeGate(int); void restartTimer(); void goingOut(); protected: Board *board; PixServer *pixServer; Gate gate; PixMap pixmap; struct Samy { - int direction; + int direction{}; SnakePix pixmap; - int index; + int index{}; }; QList list; void reset(int index, int border); void appendSamy(); void updateSamy(); int tail() { return (list.count() -1 ); } bool growing() { return (grow > 0 ? TRUE : FALSE); } int hold; int grow; }; class CompuSnake : public Snake { public: CompuSnake(Board *b, PixServer *p); void nextMove(); private: bool init(); void removeSamy(); bool findEmpty(int i, int it); bool permission(); void out(); }; enum samyState { ok, ko, out }; class SamySnake : public Snake { public: SamySnake(Board *, PixServer *); samyState nextMove(int direction); void init(); }; #endif // SAMY_H diff --git a/ksnake/startroom.cpp b/ksnake/startroom.cpp index 1d3b054..06cccff 100644 --- a/ksnake/startroom.cpp +++ b/ksnake/startroom.cpp @@ -1,73 +1,75 @@ #include #include #include #include #include #include #include #include #include #include #include "levels.h" #include "startroom.h" #include "lcdrange.h" StartRoom::StartRoom( int init, int *newRoom, QWidget *parent, const char *name) : QDialog( parent, name, TRUE ) { setCaption(klocale->translate("Snake Race Starting Room")); nr = newRoom; QPushButton *okButton = new QPushButton(this); okButton->setText(klocale->translate("OK")); okButton->setFixedSize(okButton->size()); okButton->setGeometry(60,170, 100, 100); connect( okButton, SIGNAL(clicked()), SLOT(ok()) ); QPushButton *cancelButton = new QPushButton(this); cancelButton->setText(klocale->translate("Cancel")); connect( cancelButton, SIGNAL(clicked()), SLOT(accept()) ); cancelButton->setFixedSize(cancelButton->size()); cancelButton->setGeometry(180,170, 100, 100); roomRange = new LCDRange(this); roomRange->setRange(1, leV->max()); roomRange->setText(klocale->translate("Starting Room")); roomRange->setFixedSize(100, 100); roomRange->setGeometry(60,30, 115, 125); picture = new QLabel(this); picture->setFrameStyle( QFrame::Panel | QFrame::Raised ); picture->setGeometry(180,10, 115, 115); QFrame *separator = new QFrame(this); separator->setFrameStyle( QFrame::HLine | QFrame::Sunken ); separator->setGeometry( 20, 150, 300, 4 ); connect( roomRange, SIGNAL(valueChanged(int)), SLOT(loadPixmap(int))); roomRange->setValue( init ); loadPixmap( init ); setFixedSize(340, 220); } void StartRoom::ok() { *nr = roomRange->value(); accept(); } void StartRoom::loadPixmap(int i) { QPixmap pixmap = leV->getPixmap(i); QWMatrix m; m.scale( (double)3, (double)3 ); pixmap = pixmap.xForm( m ); picture->setPixmap(pixmap); } + +#include "startroom.moc" diff --git a/ksnake/trys.cpp b/ksnake/trys.cpp index b63e27c..265d959 100644 --- a/ksnake/trys.cpp +++ b/ksnake/trys.cpp @@ -1,30 +1,32 @@ #include #include #include #include "trys.h" Trys::Trys( QWidget *parent, const char *name ) : QWidget( parent, name ) { QString pixDir; pixDir.setStr(KApplication::kde_datadir().copy()); pixDir.append("/ksnake/pics/"); pixmap.load(pixDir + "samy.xpm"); snakes = 2; repaint(); } void Trys::paintEvent( QPaintEvent *) { for ( int x = 0; x < snakes; x++) bitBlt(this, 30+ ( (pixmap.width()+16)*x), 2, &pixmap, 0, 0, pixmap.width(), pixmap.height()); } void Trys::set(int i) { snakes = i; repaint(); } + +#include "trys.moc" diff --git a/ksnake/view.cpp b/ksnake/view.cpp index cf1cd7b..09bb512 100644 --- a/ksnake/view.cpp +++ b/ksnake/view.cpp @@ -1,27 +1,29 @@ #include #include "trys.h" #include "progress.h" #include "view.h" #include "rattler.h" View::View( QWidget *parent, const char *name ) : QWidget( parent, name ) { lcd = new QLCDNumber( this); lcd->setFrameStyle( QFrame::Panel | QFrame::Sunken ); trys = new Trys(this); pg = new Progress(this); rattler = new Rattler( this); setFixedSize(560, 560+68); } void View::resizeEvent( QResizeEvent * ) { lcd->setGeometry(420, 5, 135, 42); trys->setGeometry(0, 0, 405, 50); pg->setGeometry(5, 52, 550, 12); rattler->setGeometry(0, 68, rattler->width(), rattler->height()); } + +#include "view.moc"