Exemple #1
0
World::World(): window(sf::VideoMode(xSize, ySize), "Hot Air"), ballon(xSize, ySize), fps("Resources/Font.ttf"), score(305, 178), maxScore(160, 130), paused(true) {
	music.setVolume(30);
	music.openFromFile("Resources/ms.ogg");
	music.setLoop(true);

	backgroundTexture.loadFromFile("Resources/background.png");
	background.setTexture(backgroundTexture);

	for(int i(maxScore.getScore()); i < getMaxScore(); i++)
		maxScore.addOne();

	std::srand(time(NULL));
}
int main(int argc, char * argv[])
{
    //checks to make sure that there are 2 arguments - one for input and output
    inputCheck(argv);
    
    //Get the input file name...
    char *inputFileName = *(argv + 1);
    char *outputFileName = *(argv + 2);
    
    //Find out how many students are on the input file...
    int numberOfStudents = getRecordCount(inputFileName);
    
    //Create the number of students depending on the record count...
    Student listOfStudents[numberOfStudents];
    createStudents(listOfStudents, numberOfStudents);
    
    //Read the data of the input file...
    FILE *myFile = openFile(inputFileName);
    
    //Fill out all the student's info...
    fillStudentRecord(myFile, listOfStudents, numberOfStudents);
    
    //sortStudents using the array of student struct
    sortStudents(listOfStudents, numberOfStudents);
    
    //Calculate each student's GPA and recorded in the structure...
    getGPA(listOfStudents, numberOfStudents);
    
    //Calculate each student's Letter Grade and record in the structure...
    getGrade(listOfStudents, numberOfStudents);
    
    //Create ClassGrade structure pointer...
    ClassGrade *classGrade;
    classGrade = (ClassGrade *)malloc((sizeof classGrade) * 20);
    
    //Call functions to calculate the scores...
    getScoreAverage(listOfStudents, classGrade, numberOfStudents);
    getMinScore(listOfStudents, classGrade, numberOfStudents);
    getMaxScore(listOfStudents, classGrade, numberOfStudents);
    
    //Generate and output file with the student grade information
    generateOutputFile(outputFileName, inputFileName, listOfStudents, numberOfStudents);
    
    //Print out student's info...
    printAllStudents(listOfStudents, classGrade, numberOfStudents, inputFileName, outputFileName);
    
    return 0;
}
Exemple #3
0
int AI::getMinScore(GameStartLayer *game, int level, int curMinScore)
{
    if (level == 0)
    {
        return getScore(game);
    }
    int minScore = 3000;

    vector<Step*> allMove = getAllPossibleMove(game);
    vector<Step*>::iterator it;
    for (it = allMove.begin(); it != allMove.end(); ++it)
    {
        Step* step = *it;
        fakeMove(game, step);
        int score = getMaxScore(game, level - 1, minScore);
        unfakeMove(game, step);

        //! 剪枝算法
        if (score <= curMinScore)
        {
            minScore = score;
            break;
        }

        if (score < minScore)
        {
            minScore = score;
        }
    }

    for (it = allMove.begin(); it != allMove.end(); ++it)
    {
        Step* step = *it;
        delete step;
    }

    return minScore;
}
Exemple #4
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());

}
Exemple #5
0
/*********************************************************************
** Function: void summary(struct student* students)
** Description: Outputs the lowest, highest and average student scores
** Parameters: students - pointer to a struct student or array of
** struct students
** Pre-Conditions: A pointer to a struct student
** Post-Conditions: Output of lowest, highest and average student scores
*********************************************************************/
void summary(struct student* students)
{
	printf("%d %d %f\n", getMinScore(students), getMaxScore(students), getAverage(students));
}