int World::getMaxScore() const { int maxS = 0; std::ifstream scoreFile(".score.txt"); if(scoreFile.good()) { std::string maxScore; scoreFile >> maxScore; if(maxScore != "") maxS = std::stoi(maxScore); }
// --- void PacmanGame::finalize () { ArcadeGame::finalize (); // When the game finishes, the list is saved std::ofstream scoreFile ("scores.txt"); if (scoreFile) { bool f = true; for (ScoreList::const_iterator i = _scores.begin (); i != _scores.end (); i++) { if (!f) scoreFile << std::endl; scoreFile << (*i).first << std::string ("\t") << (*i).second; f = false; } scoreFile.close (); } }
int main(int argc , char** argv){ srand(time(NULL)); printf("\n\nEnter Player Name:"); scanf("%s",playerName); scoreFile(); glutInit(&argc, argv); glutInitDisplayMode( GLUT_DOUBLE ); glutInitWindowSize( WIDTH , HEIGHT ); glutInitWindowPosition(0,0); glutCreateWindow("First Window"); init(); glutDisplayFunc(display); //glutIdleFunc(display); glutTimerFunc(25, update , 0); glutKeyboardFunc(keyboard); glutMouseFunc(mouseClick); glutMotionFunc(mousePressed); //glutPassiveMotionFunc(mousePassiveMotion); playmusic(); glutMainLoop(); }
void JudgingThread::specialJudge(const QString &fileName) { if (! QFileInfo(inputFile).exists()) { score = 0; result = FileError; message = tr("Cannot find standard input file"); return; } if (! QFileInfo(fileName).exists()) { score = 0; result = FileError; message = tr("Cannot find contestant\'s output file"); return; } if (! QFileInfo(outputFile).exists()) { score = 0; result = FileError; message = tr("Cannot find standard output file"); return; } QProcess *judge = new QProcess(this); QStringList arguments; arguments << inputFile << fileName << outputFile << QString("%1").arg(fullScore); arguments << workingDirectory + "_score"; arguments << workingDirectory + "_message"; judge->start(Settings::dataPath() + task->getSpecialJudge(), arguments); if (! judge->waitForStarted(-1)) { score = 0; result = InvalidSpecialJudge; delete judge; return; } QElapsedTimer timer; timer.start(); bool flag = false; while (timer.elapsed() < specialJudgeTimeLimit) { if (judge->state() != QProcess::Running) { flag = true; break; } QCoreApplication::processEvents(); if (stopJudging) { judge->kill(); delete judge; return; } msleep(10); } if (! flag) { judge->kill(); score = 0; result = SpecialJudgeTimeLimitExceeded; delete judge; return; } else if (judge->exitCode() != 0) { score = 0; result = SpecialJudgeRunTimeError; delete judge; return; } delete judge; QFile scoreFile(workingDirectory + "_score"); if (! scoreFile.open(QFile::ReadOnly)) { score = 0; result = InvalidSpecialJudge; return; } QTextStream scoreStream(&scoreFile); scoreStream >> score; if (scoreStream.status() == QTextStream::ReadCorruptData) { score = 0; result = InvalidSpecialJudge; return; } scoreFile.close(); if (score < 0) { score = 0; result = InvalidSpecialJudge; return; } QFile messageFile(workingDirectory + "_message"); if (messageFile.open(QFile::ReadOnly)) { QTextStream messageStream(&messageFile); message = messageStream.readAll(); messageFile.close(); } if (score == 0) result = WrongAnswer; if (0 < score && score < fullScore) result = PartlyCorrect; if (score >= fullScore) result = CorrectAnswer; scoreFile.remove(); messageFile.remove(); }
// --- void PacmanGame::initialize () { QGAMES::ArcadeGame::initialize (); // Sets the icon to the window... mainScreen () -> setIcon (formBuilder () -> form (__PACMANICOFORM)); // Clean up everything... _artists.clear (); _gameStates.clear (); _worlds.clear (); // The main artist of the game, if they have not been created and inserted before... // The command entity creates the entities and observe them... _pacman = (Pacman*) entity (__ENTITYPACMAN); _artists.insert (QGAMES::Entities::value_type (__ENTITYPACMAN, _pacman)); // The monsters... // Blinky _blinky = (Blinky*) entity (__ENTITYBLINKY); _blinky -> setMyTarget (_pacman); // Target? _monsters.push_back (_blinky); _artists.insert (QGAMES::Entities::value_type (__ENTITYBLINKY, _blinky)); // Pinky _pinky = (Pinky*) entity (__ENTITYPINKY); _pinky -> setMyTarget (_pacman); _monsters.push_back (_pinky); _artists.insert (QGAMES::Entities::value_type (__ENTITYPINKY, _pinky)); // Inky _inky = (Inky*) entity (__ENTITYINKY); _inky -> setMyTarget (_pacman); _monsters.push_back (_inky); _artists.insert (QGAMES::Entities::value_type (__ENTITYINKY, _inky)); // Clyde _clyde = (Clyde*) entity (__ENTITYCLYDE); _clyde -> setMyTarget (_pacman); _monsters.push_back (_clyde); _artists.insert (QGAMES::Entities::value_type (__ENTITYCLYDE, _clyde)); // Assign the collegues... _blinky -> setCollegues (_monsters); _pinky -> setCollegues (_monsters); _inky -> setCollegues (_monsters); _clyde -> setCollegues (_monsters); // Load the states... _gameStates.insert (QGAMES::GameStates::value_type (std::string (__GAMESTATELOADINGNAME), new PacmanGameStateLoading (this))); _gameStates.insert (QGAMES::GameStates::value_type (std::string (__GAMESTATEINITIALNAME), new GameStateInitial (this))); _gameStates.insert (QGAMES::GameStates::value_type (std::string (__GAMESTATEPRELUDENAME), new GameStatePrelude (this))); _gameStates.insert (QGAMES::GameStates::value_type (std::string (__GAMESTATEPRELUDESHORTNAME), new GameStatePreludeShort (this))); _gameStates.insert (QGAMES::GameStates::value_type (std::string (__GAMESTATEPLAYINGNAME), new GameStatePlaying (this))); _gameStates.insert (QGAMES::GameStates::value_type (std::string (__GAMESTATEMAZECLEANNAME), new GameStateMazeClean (this))); _gameStates.insert (QGAMES::GameStates::value_type (std::string (__GAMESTATEPACMANDIESNAME), new GameStatePacmanDies (this))); _gameStates.insert (QGAMES::GameStates::value_type (std::string (__GAMESTATEROUNDENDNAME), new GameStateRoundEnd (this))); _gameStates.insert (QGAMES::GameStates::value_type (std::string (__GAMESTATEENDNAME), new GameStateEnd (this))); _gameStates.insert (QGAMES::GameStates::value_type (std::string (__GAMESTATEINTROLETTERSNAME), new GameStateIntroLetters (this))); _gameStates.insert (QGAMES::GameStates::value_type (std::string (__GAMESTATESEESCORESNAME), new GameStateSeeScore (this))); // When the game starts, the list of the most famous player is loaded // The list is something really simple to read _scores.clear (); std::ifstream scoreFile ("scores.txt"); if (scoreFile) { std::string usr, score; while (!scoreFile.eof ()) { scoreFile >> score >> usr; _scores.insert (std::pair <int, std::string> (atoi (score.c_str ()), usr)); } scoreFile.close (); } // The initial state... setState (std::string (__GAMESTATELOADINGNAME)); // Load the world... _worlds.insert (QGAMES::Worlds::value_type (__WORLDPACMAN, _worldBuilder -> world (__WORLDPACMAN))); // Sets the first level... setLevel (0); }
void World::start() { music.play(); sf::Clock birdSpawnChrono; sf::Clock birdMoveChrono; int birdSpawnTime = (std::rand()%3)+1; sf::Clock scoreChrono; while (window.isOpen()) { if(!paused) { //Spawning birds if(birdSpawnChrono.getElapsedTime().asSeconds() >= birdSpawnTime) { if(std::rand()%2) { birdSpawn(true); birdDirections.push_back(right); } else { birdSpawn(false); birdDirections.push_back(left); } birdSpawnTime = (std::rand()%3)+1; birdSpawnChrono.restart(); } //Moving birds if(birdMoveChrono.getElapsedTime().asMilliseconds() > 20) { for(int i(0); i < birds.size(); i++) { if(birdDirections[i] == left) birds[i]->move(-4); else birds[i]->move(4); } birdMoveChrono.restart(); } birdRemove(); //Score up if(scoreChrono.getElapsedTime().asSeconds() > 1) { scoreChrono.restart(); score.addOne(); } } //Check collisions for(int i(0); i < birds.size(); i++) { if(checkCollisions(birds[i]->getBounds(), ballon.getBounds())) { restart(); paused = true; } } inGameUserInput(); ballon.update(); fps.update(); window.clear(); window.draw(background); window.draw(score); window.draw(maxScore); for(int i(0); i < birds.size(); i++) window.draw(*birds[i]); window.draw(ballon); window.draw(fps); window.display(); } //Save maxScore std::ofstream scoreFile(".score.txt"); if(maxScore.getScore() > getMaxScore()) scoreFile << std::to_string(maxScore.getScore()); }