Source Code (Use browser search to find items of interest.)

Class Index

ksnake'Game (./kdegames/ksnake/game.h:19)

class Game : public KTMainWindow
  {
    Q_OBJECT
public:
    Game();
    ~Game() {}
protected:
    //   void keyPressEvent( QKeyEvent * );
private slots:
    void ballsChecked(int);
    void skillChecked(int);
    void snakesChecked(int);
    void pixChecked(int);

    void newGame();
    void pauseGame();
    void togglePaused();
    void quitGame();

    void backgroundColor();
    void confKeys();

    void showHighScores();
    void startingRoom();

private:

    Rattler *rattler;
    QLCDNumber *lcd;

    Trys *trys;
    Score   *score;
    Progress *pg;
    Levels *levels;

    KConfig *conf;

    void menu();
    void checkMenuItems();
    void lookupBackgroundPixmaps();

    KMenuBar *menubar;
    QPopupMenu *game;
    QPopupMenu *options;
    QPopupMenu *balls;
    QPopupMenu *snakes;
    QPopupMenu *pix;

    int pauseID;

    int ballsID[4];
    int snakesID[4];
    int skillID[4];

    QArray<int> pixID;


    QStringList backgroundPixmaps;
};

ksnake'Game::Game() (./kdegames/ksnake/game.cpp:44)

Game::Game() :  KTMainWindow()
{
    setCaption( kapp->caption() );

    setIcon(i18n("Snake Race"));

    conf = kapp->config();
    if(conf == NULL) {
	printf("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();
    view->show();
    setView(view);
}



ksnake'Game::menu() (./kdegames/ksnake/game.cpp:80)

void Game::menu()
{

    game = new QPopupMenu();
    CHECK_PTR( game );
    game->insertItem( i18n("New"), this, SLOT(newGame()),Key_F2);
    pauseID = game->insertItem( i18n("Pause"), this , SLOT(pauseGame()), Key_F3);
    game->insertItem( i18n("High Scores..."), this, SLOT(showHighScores()));
    game->insertSeparator();
    game->insertItem( i18n("&Quit"),  this, SLOT(quitGame()), CTRL+Key_Q );
    game->setCheckable( TRUE );

    balls = new QPopupMenu;
    CHECK_PTR( balls );
    ballsID[0] = balls->insertItem( i18n("0"));
    ballsID[1] = balls->insertItem( i18n("1"));
    ballsID[2] = balls->insertItem( i18n("2"));
    ballsID[3] = balls->insertItem( i18n("3"));
    balls->setCheckable( TRUE );
    connect(balls, SIGNAL(activated(int)), this, SLOT ( ballsChecked(int) ));

    snakes = new QPopupMenu;
    CHECK_PTR( snakes );
    snakesID[0] = snakes->insertItem( i18n("0"));
    snakesID[1] = snakes->insertItem( i18n("1"));
    snakesID[2] = snakes->insertItem( i18n("2"));
    snakesID[3] = snakes->insertItem( i18n("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(i18n("none"));
    } else {
        QStringList::ConstIterator it = backgroundPixmaps.begin();
        for(unsigned i = 0; it != backgroundPixmaps.end(); i++, it++) {
	    // since the filename may contain underscore, they
	    // are replaced with spaces in the menu entry
            QString s = QFileInfo( *it ).baseName();
	    s = s.replace(QRegExp("_"), " ");
	    pixID[i] = pix->insertItem(s, i);
	}
    }
    pix->setCheckable( TRUE );
    connect(pix, SIGNAL(activated(int)), this,
	    SLOT ( pixChecked(int) ));

    options = new QPopupMenu();
    CHECK_PTR( options );
    skillID[0] = options->insertItem( i18n("Beginner"));
    skillID[1] = options->insertItem( i18n("Intermediate"));
    skillID[2] = options->insertItem( i18n("Advanced"));
    skillID[3] = options->insertItem( i18n("Expert"));
    options->insertSeparator();
    options->insertItem(i18n("Balls"), balls);
    options->insertItem(i18n("Computer Snakes"), snakes);
    options->insertSeparator();
    options->insertItem(i18n("Select background color..."), this, SLOT(backgroundColor()));
    options->insertItem(i18n("Select background pixmap"), pix);
    options->insertSeparator();
    options->insertItem(i18n("Change keys..."),this, SLOT(confKeys()));
    options->insertSeparator();
    options->insertItem(i18n("Starting Room..."), this, SLOT(startingRoom()));

    options->setCheckable( TRUE );
    connect(options, SIGNAL(activated(int)), this, SLOT ( skillChecked(int) ));

    QPopupMenu *help = helpMenu(i18n("Snake Race")
                                      + " " + KSNAKE_VERSION
                                      + i18n("\n\nby Michel Filippi"
                                             " (mfilippi@sade.rhein-main.de)")
                                      + i18n("\n\nWith new hacks by\n Andrew Chant (achant@home.com)"));
    menubar = menuBar(); // auto-managed.
    CHECK_PTR( menubar );
    menubar->insertItem( i18n("&Game"), game );
    menubar->insertItem( i18n("&Options"), options );
    menubar->insertSeparator();
    menubar->insertItem( i18n("&Help"), help);
}


ksnake'Game::ballsChecked() (./kdegames/ksnake/game.cpp:165)

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);
	}
}


ksnake'Game::snakesChecked() (./kdegames/ksnake/game.cpp:176)

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);
	}
}


ksnake'Game::skillChecked() (./kdegames/ksnake/game.cpp:187)

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);
	}
}


ksnake'Game::pixChecked() (./kdegames/ksnake/game.cpp:201)

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));

	rattler->reloadRoomPixmap();
}


ksnake'Game::checkMenuItems() (./kdegames/ksnake/game.cpp:213)

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)) {
	    pix->setItemChecked( x , TRUE );
	    break;
	}
    }
}


ksnake'Game::quitGame() (./kdegames/ksnake/game.cpp:228)

void Game::quitGame()
{
    kapp->quit();
}


ksnake'Game::showHighScores() (./kdegames/ksnake/game.cpp:233)

void Game::showHighScores()
{
    score->display(-1);  // Magic number because bug in moc doesn't let us
                         // default 2 parameters.
}


ksnake'Game::newGame() (./kdegames/ksnake/game.cpp:239)

void Game::newGame()
{
    rattler->restart();
}


ksnake'Game::pauseGame() (./kdegames/ksnake/game.cpp:244)

void Game::pauseGame()
{
    rattler->pause();
}


ksnake'Game::togglePaused() (./kdegames/ksnake/game.cpp:249)

void Game::togglePaused()
{
    static bool checked = FALSE;
    checked = !checked;
    game->setItemChecked( pauseID, checked );
}


ksnake'Game::startingRoom() (./kdegames/ksnake/game.cpp:256)

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);
    }
}


ksnake'Game::confKeys() (./kdegames/ksnake/game.cpp:269)

void Game::confKeys()
{
    Keys *keys = new Keys();
    if (keys->exec() == QDialog::Accepted)
	rattler->initKeys();
    delete keys;
}

//taken from KReversi

ksnake'Game::backgroundColor() (./kdegames/ksnake/game.cpp:278)

void Game::backgroundColor()
{
    QString s;
    QColor c;
      if(KColorDialog::getColor(c)) {
	conf->writeEntry("Background", 1);
	conf->writeEntry("BackgroundColor", c);
	rattler->reloadRoomPixmap();
      }
}


ksnake'Game::lookupBackgroundPixmaps() (./kdegames/ksnake/game.cpp:289)

void Game::lookupBackgroundPixmaps()
{
    backgroundPixmaps = KGlobal::dirs()->
	findAllResources("appdata", "backgrounds/*.xpm");
}






/************************** main ******************************/