Skip to content

Commit

Permalink
attempt at adding beginning of a keying invaders game; minimal functi…
Browse files Browse the repository at this point in the history
…ons implemented
  • Loading branch information
hardaker committed May 25, 2011
1 parent 0b2844c commit 9ea63d0
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Morse.cpp
Expand Up @@ -20,6 +20,7 @@
#include "modes/GroupingMode.h"
#include "modes/games/WordGame.h"
#include "modes/games/GroupGame.h"
#include "modes/games/KeyInvaders.h"

#define WPMGOAL 20
#define WPMACCEPT 2
Expand Down Expand Up @@ -63,6 +64,7 @@ Morse::Morse(MainWindow *parent, QAudioOutput *output, Ui::MainWindow *ui)
m_modes.insert(WORDGAME, new WordGame(this, m_ui));
m_modes.insert(GROUPGAME, new GroupGame(this, m_ui));
m_modes.insert(READ, new ReadMode(this, m_ui));
m_modes.insert(KEYINVADERS, new KeyInvaders(this, m_ui));

loadSettings();

Expand Down
4 changes: 2 additions & 2 deletions Morse.h
Expand Up @@ -37,8 +37,8 @@ class Morse : public QObject

enum ditdah{ DIT, DAH, SPACE, PAUSE };

enum TrainingMode { FRONTPAGE, PLAY, TRAIN, SPEEDTRAIN, WORDS, GROUPS, KEYING, WORDGAME, GROUPGAME, READ, // eventually: TEST
TM_FIRST = FRONTPAGE, TM_LAST = READ };
enum TrainingMode { FRONTPAGE, PLAY, TRAIN, SPEEDTRAIN, WORDS, GROUPS, KEYING, WORDGAME, GROUPGAME, READ, KEYINVADERS, // eventually: TEST
TM_FIRST = FRONTPAGE, TM_LAST = KEYINVADERS };
static const int maximumTrainingMode = READ;
enum AudioMode { STOPPED, PLAYING, PAUSED };
enum BadLetterWeighting { LOW = 1, HIGH = 2 };
Expand Down
2 changes: 1 addition & 1 deletion modes/FrontPage.cpp
Expand Up @@ -51,7 +51,7 @@ void FrontPage::setupWidgets() {
QPushButton *button;
QList<Morse::TrainingMode> leftContents, rightContents;
leftContents << Morse::TRAIN << Morse::SPEEDTRAIN << Morse::WORDS << Morse::GROUPS << Morse::KEYING;
rightContents << Morse::PLAY << Morse::READ << Morse::WORDGAME << Morse::GROUPGAME;
rightContents << Morse::PLAY << Morse::READ << Morse::WORDGAME << Morse::GROUPGAME << Morse::KEYINVADERS;

foreach(Morse::TrainingMode themode, leftContents) {
button = new QPushButton(QIcon(m_morse->getMode(themode)->icon()), m_morse->getMode(themode)->name());
Expand Down
60 changes: 59 additions & 1 deletion modes/games/KeyInvaders.cpp
@@ -1,9 +1,67 @@
#include "KeyInvaders.h"
#include <QtGui/QMenu>

KeyInvaders::KeyInvaders()
KeyInvaders::KeyInvaders(Morse *parent, Ui::MainWindow *main)
: MorseMode(parent, main), m_scores("Key Invaders")
{
}

void
KeyInvaders::advanceFrame() {

}

void KeyInvaders::switchToMode() {
m_ui->helpBar->setText(tr("<font color=\"green\">Key the letters using a st.</font>"));
m_ui->changeSequence->hide();
setupWidgets();
}

void KeyInvaders::modeMenus() {
// Create the high scores button
QAction *action = menu()->addAction("HighScores");
connect(action, SIGNAL(triggered()), &m_scores, SLOT(showScores()));
}

void KeyInvaders::setupWidgets() {

}

void KeyInvaders::handleKeyPress(QChar letterPressed)
{
Q_UNUSED(letterPressed);

// memorize keypress timing
if (m_keyCount == 0) {
m_startTime.start();
m_keyedTimes.push_back(0);
} else {
m_keyedTimes.push_back(m_startTime.elapsed());
}
}

void KeyInvaders::handleKeyRelease(QChar letterPressed)
{
handleKeyPress(letterPressed); // doesn't really matter whether it's up/down
}


void KeyInvaders::gameOver()
{
m_scores.addScore("", score());
}

QString KeyInvaders::helpText()
{
return tr("<p>Shoot letters falling from the sky by keying them appropriately.</p>");
}

QString KeyInvaders::name()
{
return tr("Key Invaders");
}

QString KeyInvaders::icon()
{
return ":/icons/64x64/game.png";
}
33 changes: 30 additions & 3 deletions modes/games/KeyInvaders.h
@@ -1,13 +1,40 @@
#ifndef KEYINVADERS_H
#define KEYINVADERS_H

class KeyInvaders : public MorseMode
#include "../MorseMode.h"
#include "MGameMode.h"
#include "HighScores.h"

#include <QtCore/QList>
#include <QtCore/QList>
#include <QtCore/QTime>

class KeyInvaders : public MorseMode, MGameMode
{
public:
KeyInvaders();
KeyInvaders(Morse *parent, Ui::MainWindow *main);

public slots:
void advanceFrame();

virtual void switchToMode();
virtual void modeMenus();
void setupWidgets();

// standard functions
virtual QString helpText();
virtual QString name();
virtual QString icon();
virtual void gameOver();

public slots:
virtual void handleKeyPress(QChar letterPressed);
virtual void handleKeyRelease(QChar letterPressed);

private:
HighScores m_scores;
int m_keyCount;
QTime m_startTime;
QList<int> m_keyedTimes;
};

#endif // KEYINVADERS_H

0 comments on commit 9ea63d0

Please sign in to comment.