示例#1
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();
}
示例#2
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());
}
示例#3
0
文件: native.cpp 项目: bgotthart/CPGD
JNIEXPORT jint JNICALL Java_com_cpgd_arrowshooting3000_components_ScoreProxy_getScore
  (JNIEnv * env, jobject obj, jlong ref){
          Score* score = (Score*)ref;
          return score->getScore();       
  }
void ShakeManager::startGame(Joueur *j, QMediaPlayer* music, string nomPiste){

    Score *scoreJoueur = new Score();
    scoreJoueur->setPiste(nomPiste);

    joueur = *j;

    music->play();

    bool musicEnCours = true;

    Mat cameraFeed;
    Mat threshold;
    Mat HSV;

    VideoCapture capture;

    capture.open(0);

    if (!capture.isOpened()){
        //Une erreur est survenue lors de l'activation de la webcam
        return;
    }

    Mat imageno = imread("Images/no.png", 0);
    Mat imagene = imread("Images/ne.png", 0);
    Mat imagese = imread("Images/se.png", 0);
    Mat imageso = imread("Images/so.png", 0);

    if (!imageno.data && !imagene.data && !imagese.data && !imageso.data)
    {
        //Pas d'image
        return;
    }

    resize(imageno, imageno, Size(70, 70));
    resize(imagene, imagene, Size(70, 70));
    resize(imagese, imagese, Size(70, 70));
    resize(imageso, imageso, Size(70, 70));

    capture.set(CV_CAP_PROP_FRAME_WIDTH, FRAME_WIDTH);
    capture.set(CV_CAP_PROP_FRAME_HEIGHT, FRAME_HEIGHT);

    boolean mouvementTrouver = false;

    int idRect = std::rand()%4;
    Rect randomRect;
    Mat srcBGR;

    while (musicEnCours){
        capture.read(cameraFeed);
        cvtColor(cameraFeed, HSV, COLOR_BGR2HSV);

        int camRows = cameraFeed.rows;
        int camCols = cameraFeed.cols;

        Rect no = Rect(0, 0, 70, 70);
        Rect so = Rect(0, camRows - 70, 70, 70);
        Rect ne = Rect(camCols - 70, 0, 70, 70);
        Rect se = Rect(camCols - 70, camRows - 70, 70, 70);
        Rect rectPositions[] ={no,ne,so,se};

        if(mouvementTrouver){
            idRect = std::rand()%4;
        }
        randomRect = rectPositions[idRect];

        cvtColor(cameraFeed, HSV, COLOR_BGR2HSV);
        inRange(HSV, joueur.getHSVmin(), joueur.getHSVmax(), threshold);
        morphOps(threshold);
        mouvementTrouver = rechercherMouvement(scoreJoueur, threshold, HSV, cameraFeed, randomRect);

        switch(idRect){
            case 0:
                srcBGR = Mat(imageno.size(), CV_8UC3);
                cvtColor(imageno, srcBGR, CV_GRAY2BGR);
                break;

            case 1:
                srcBGR = Mat(imagene.size(), CV_8UC3);
                cvtColor(imagene, srcBGR, CV_GRAY2BGR);
                break;

            case 2:
                 srcBGR = Mat(imageso.size(), CV_8UC3);
                 cvtColor(imageso, srcBGR, CV_GRAY2BGR);
                 break;

            default:
                 srcBGR = Mat(imagese.size(), CV_8UC3);
                 cvtColor(imagese, srcBGR, CV_GRAY2BGR);
                 break;
        }

        Mat ImageFeed = cameraFeed(randomRect);
        srcBGR.copyTo(ImageFeed);

        flip(cameraFeed,cameraFeed,1);
        string score = "Score : " + std::to_string(scoreJoueur->getScore());
        putText(cameraFeed, score, Point(270, 30), 1, 2, Scalar(0, 0, 255), 2);
        imshow(nomFenetre, cameraFeed);

        if(waitKey(10) == 27){
            music->stop();
            destroyWindow("Can You Shake It ? ");
            return;
        }

        if(music->state() == QMediaPlayer::StoppedState)
            musicEnCours = false;
    }

    joueur.addScore(*scoreJoueur);

}