3
* Copyright (C) Remigiusz Dybka 2009 <remigiusz.dybka@gmail.com>
5
Zaz is free software: you can redistribute it and/or modify it
6
under the terms of the GNU General Public License as published by the
7
Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
10
Zaz is distributed in the hope that it will be useful, but
11
WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
See the GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License along
16
with this program. If not, see <http://www.gnu.org/licenses/>.
31
HiScores::HiScores(string filename)
34
ifstream inph(filename.c_str());
35
if (!inph) // may be empty or not exist
39
while (!getline(inph, l).fail())
51
bool ok = (!getline(inph, l).fail());
55
ok = ok && (!getline(inph, l).fail());
60
scores.push_back(HiScoreEntry(score, name, level));
67
ofstream oph(filename.c_str());
70
ERR(filename + ": could not save hi scores");
73
vector<HiScoreEntry>::iterator i;
76
for (i = scores.begin(); i != scores.end(); ++i)
78
if ((f < 10) && (i->score > 0))
80
oph << i->score << std::endl;
81
oph << i->name << std::endl;
82
oph << i->level << std::endl;
90
void HiScores::SubmitHiScore(HiScoreEntry ent)
92
vector<HiScoreEntry>::iterator i;
93
vector<HiScoreEntry>::iterator ii;
96
for (i = scores.begin(); i != scores.end(); ++i)
98
if (i->score > ent.score)
104
scores.insert(ii, ent);
107
bool HiScores::GoodEnough(int s)
109
vector<HiScoreEntry>::iterator i;
114
if (scores.size() < 10)
118
for (i = scores.begin(); i != scores.end(); ++i)