24 #include <KActionCollection>
25 #include <KStandardGameAction>
26 #include <KToggleAction>
27 #include <KMessageBox>
28 #include <KConfigDialog>
29 #include <KInputDialog>
32 #include <KgDifficulty>
33 #include <KScoreDialog>
35 #define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API
36 #include <libkdegamesprivate/kgamethemeselector.h>
43 KStandardGameAction::gameNew(
this, SLOT(newGame(
bool)), actionCollection());
44 KStandardGameAction::highscores(
this, SLOT(showHighscores()), actionCollection());
45 KStandardAction::preferences(
this, SLOT(showSettings()), actionCollection());
46 KStandardGameAction::quit(
this, SLOT(close()), actionCollection());
47 KAction* soundAction =
new KToggleAction(i18n(
"&Play sounds"),
this);
49 actionCollection()->addAction( QLatin1String(
"sounds" ), soundAction);
50 connect(soundAction, SIGNAL(triggered(
bool)),
this, SLOT(setSoundsEnabled(
bool)));
51 KAction* levelAction =
new KAction(i18n(
"&Change level"),
this);
52 actionCollection()->addAction( QLatin1String(
"level" ), levelAction);
53 connect(levelAction, SIGNAL(triggered(
bool)),
this, SLOT(changeLevel()));
55 m_statusBar = statusBar();
56 m_statusBar->insertItem(i18nc(
"Used to display the current level of play to the user",
"Level: %1", 1), 1, 1);
57 m_statusBar->insertItem(i18nc(
"Used to inform the user of their current score",
"Score: %1", 0), 2, 1);
58 m_statusBar->insertItem(i18nc(
"Used to tell the user how many lives they have left",
"Lives: %1",
initLives), 4, 1);
62 Kg::difficulty()->addStandardLevelRange(
63 KgDifficultyLevel::Easy, KgDifficultyLevel::Hard,
64 KgDifficultyLevel::Medium
66 KgDifficultyGUI::init(
this);
67 connect(Kg::difficulty(), SIGNAL(currentLevelChanged(
const KgDifficultyLevel*)), SLOT(initGame()));
80 void KapmanMainWindow::initGame() {
84 connect(m_game, SIGNAL(gameOver(
bool)),
this, SLOT(newGame(
bool)));
85 connect(m_game, SIGNAL(levelChanged(uint)),
this, SLOT(displayLevel(uint)));
86 connect(m_game, SIGNAL(scoreChanged(uint)),
this, SLOT(displayScore(uint)));
87 connect(m_game, SIGNAL(livesChanged(uint)),
this, SLOT(displayLives(uint)));
92 m_view =
new GameView(m_game);
93 m_view->setBackgroundBrush(Qt::black);
94 setCentralWidget(m_view);
98 QTimer::singleShot(0, m_view, SLOT(setFocus()));
103 void KapmanMainWindow::newGame(
const bool gameOver) {
106 gameRunning = m_game->
getTimer()->isActive();
115 if (KMessageBox::warningYesNo(
this, i18n(
"Are you sure you want to quit the current game?"), i18n(
"New game")) == KMessageBox::Yes) {
129 KMessageBox::information(
this, i18np(
"Your score is %1 point.",
"Your score is %1 points.", m_game->
getScore()), i18n(
"Game Over"));
132 KMessageBox::information(
this, i18n(
"You cheated, no Highscore for you ;)"), i18n(
"Cheater!"));
136 QPointer<KScoreDialog> dialog =
new KScoreDialog(KScoreDialog::Name | KScoreDialog::Score | KScoreDialog::Level,
this);
137 dialog->initFromDifficulty(Kg::difficulty());
138 KScoreDialog::FieldInfo scoreInfo;
139 scoreInfo[KScoreDialog::Level].setNum(m_game->
getLevel());
140 scoreInfo[KScoreDialog::Score].setNum(m_game->
getScore());
142 if (dialog->addScore(scoreInfo)) {
152 void KapmanMainWindow::changeLevel() {
153 int newLevel = KInputDialog::getInteger(i18n(
"Change level"), i18nc(
"The number of the game level",
"Level"), m_game->
getLevel(), 1, 1000000, 1, 10, 0,
this);
159 void KapmanMainWindow::showHighscores() {
160 QPointer<KScoreDialog> dialog =
new KScoreDialog(KScoreDialog::Name | KScoreDialog::Score | KScoreDialog::Level,
this);
161 dialog->initFromDifficulty(Kg::difficulty());
166 void KapmanMainWindow::setSoundsEnabled(
bool p_enabled) {
170 void KapmanMainWindow::showSettings() {
171 if (KConfigDialog::showDialog(
"settings")) {
174 KConfigDialog* settingsDialog =
new KConfigDialog(
this,
"settings",
Settings::self());
175 settingsDialog->addPage(
new KGameThemeSelector(settingsDialog,
Settings::self(), KGameThemeSelector::NewStuffDisableDownload), i18n(
"Theme"),
"kapman");
176 settingsDialog->setFaceType(KConfigDialog::Plain);
177 connect(settingsDialog, SIGNAL(settingsChanged(QString)),
this, SLOT(loadSettings()));
178 settingsDialog->show();
181 void KapmanMainWindow::loadSettings() {
182 ((
GameScene*)m_view->scene())->loadTheme();
185 void KapmanMainWindow::close() {
188 gameRunning = m_game->
getTimer()->isActive();
195 if(KMessageBox::warningYesNo(
this, i18n(
"Are you sure you want to quit Kapman?"), i18nc(
"To quit Kapman",
"Quit")) == KMessageBox::Yes) {
196 KXmlGuiWindow::close();
207 void KapmanMainWindow::displayLevel(
unsigned int p_level)
209 m_statusBar->changeItem(i18nc(
210 "Used to display the current level of play to the user",
211 "Level: %1", p_level), 1);
214 void KapmanMainWindow::displayScore(
unsigned int p_score)
216 m_statusBar->changeItem(i18nc(
217 "Used to inform the user of their current score",
"Score: %1",
221 void KapmanMainWindow::displayLives(
unsigned int p_lives)
223 m_statusBar->changeItem(i18nc(
224 "Used to tell the user how many lives they have left",
"Lives: %1",
228 void KapmanMainWindow::resetStatusBar()
void setSoundsEnabled(bool p_enabled)
Enables / disables the sounds.
QTimer * getTimer() const
void start()
Starts the Game.
~KapmanMainWindow()
Deletes the KapmanMainWindow instance.
void setLevel(int p_level)
Sets the level to the given number.
This class manages the game main loop : it regularly checks the key press events, computes the charac...
static const int initLives
This class contains all the Game elements to be drawn on the screen by the GameView instance...
static bool sounds()
Get Whether sound effects should be played.
KapmanMainWindow()
Creates a new KapmanMainWindow instance.
void pause(bool p_locked=false)
Pauses the Game.