Esempio n. 1
0
void unitTests() {

    HighScore scores;
    scores.addScore("Robert", 10);
    scores.addScore("Phillip", 30);
    scores.addScore("Michael", 20);
    Score* s = scores.getScores().at(0);

    assert(s->getName() == "Phillip");
    scores.addScore("Rebecca", 5);
    s = scores.getScores().back();
    assert(s->getName() == "Rebecca");
    scores.save();

    HighScore testScores;
    testScores.load();
    testScores.addScore("Rhonda", 65);
    s = testScores.getScores().at(0);

    assert(s->getName() == "Rhonda");
    assert(s->getScore() == 65);
    testScores.save();
    remove ("highscores.txt");

    //model test for starting a new game.
    Model::instance()->singleGameStart("easy", false);
    assert(Model::instance()->getById(0) != NULL);

    assert(Model::instance()->load());
}
Esempio n. 2
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //populate highscores list
    HighScore* scores = new HighScore();
    if(scores->load()){
        for(unsigned int i = 0; i < scores->getScores().size(); ++i ) {
            Score *score = scores->getScores().at(i);
            QString QName = QString::fromStdString(score->getName());
            QString QScore = QString::number(score->getScore());
            ui->lstScores->addItem(QName + " -- " + QScore);

        }
    }
    else                //no file exists
        scores->save(); //creates new highscores file file

    //connect(ui->btnNewGame, SIGNAL(click()), this, SLOT(openGameWindow()));
    //set the help and score screens to be invisible
    ui->brwHelp->hide();
    ui->boxHighScores->hide();
}