⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 highscore.h

📁 小游戏 有碰撞检测和音乐 使用键盘openal
💻 H
字号:
#pragma once
#include "define.h"
#include "engine.h"
#include "font.h"
#include "demo.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <map>
#include <mmsystem.h>

using namespace std;
bool entername;
string player_name;
string highscores_file;
multimap < int, string > high_scores;

void InitHighscore()
{
	entername = false;
	highscores_file = "high_scores.dat";	
}
string IntToString( int n )
{
	ostringstream s;
	s << n;
	return s.str();
}
string ScoreLine(string name, int score) 
{
	ostringstream s;
	s.width(8);
	s << name;
	s.width(5);
	s << score;
	return s.str();
}

bool IsScoreInTop3( int score ) 
{
	multimap < int, string > :: iterator i = high_scores.begin();
	if ( score > (*i).first )
	return true;
	else
	return false;
}
void SaveHighScores()
{
	ofstream ofile( highscores_file.c_str() );
	string text = "";
	int count = 0;
	multimap < int, string >::iterator i = high_scores.end();
	i--;
	for ( ; count < 3; i--,count++)
	{
		if ( count != 0 )
		text = text + "\n";
		text = text + IntToString((*i).first) + " " + (*i).second;
	}
	if (!ofile.fail())
		ofile << text;
	ofile.close();
}
void ReadHighScoresFile() 
{
	ifstream ifile( highscores_file.c_str() );
	if ( !ifile.fail() )
	{
		string line;
		while( getline( ifile, line) ) 
		{
			vector < string > elements;
			elements = Tokenize( line, " " );
			int score_number = atoi ( elements [ 0 ].c_str() );
			string player_name = elements [ 1 ];
			high_scores.insert( multimap < int, string > :: value_type ( score_number, player_name ) );
		}
		ifile.close();
	}
}

void Print(char *s, int x,int y, float r, float g, float b) 
{
	// draw textured font
	glEnable( GL_BLEND );
	glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_TEXTURE_2D);
	glColor3f( r, g, b );
	glBindTexture(GL_TEXTURE_2D, fontTextures[0].id);
	glMatrixMode ( GL_PROJECTION ) ;
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0.0f,640,480,0.0f,-1.0f,1.0f);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
	PrintList(x,y,0,s);
	glMatrixMode ( GL_PROJECTION ) ;
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
	glDisable(GL_TEXTURE_2D);
	glDisable( GL_BLEND );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -