~ubuntu-branches/ubuntu/warty/groundhog/warty

« back to all changes in this revision

Viewing changes to src/score.cc

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2003-06-18 19:46:15 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20030618194615-wigzpze01wc33e9m
Tags: 1.4-5
* Fix build problem w/gcc-3.3, streams use (Closes: Bug#196793)
* Update Policy Version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Groundhog -- a simple logic game
2
 
 * Copyright (C) 1998-2001 Maurits Rijk
 
2
 * Copyright (C) 1998-2002 Maurits Rijk
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
5
5
 * it under the terms of the GNU General Public License as published by
17
17
 */
18
18
 
19
19
#include <iostream>
 
20
using namespace std;
 
21
 
20
22
#include "score.h"
21
23
 
22
 
std::ostream&
23
 
operator<<(std::ostream& s, const Score& score)
 
24
ostream&
 
25
operator<<(ostream& s, const Score& score)
24
26
{
25
27
   return s << "(\"" << score._name << "\" " << score._seconds << ')';
26
28
}
27
29
 
28
 
std::istream&
29
 
operator>>(std::istream& s, Score& score)
 
30
istream&
 
31
operator>>(istream& s, Score& score)
30
32
{
31
33
   char c;
32
 
   std::ios::fmtflags flag = s.flags();
33
 
   s.flags(flag & ~std::ios::skipws);
 
34
   ios::fmtflags flag = s.flags();
 
35
   s.flags(flag & ~ios::skipws);
34
36
 
35
37
   score._name = "";
36
38
   s >> c >> c;
54
56
bool 
55
57
ScoreList::IsNewHighScore(int seconds)
56
58
{
57
 
   std::list<Score>::iterator last = _list.end();
 
59
   list<Score>::iterator last = _list.end();
58
60
   return _list.size() < 10 || seconds < (*--last).GetSeconds();
59
61
}
60
62
 
61
63
void 
62
64
ScoreList::AddHighScore(Score& score)
63
65
{
64
 
   std::list<Score>::iterator i;
 
66
   list<Score>::iterator i;
65
67
   for (i = _list.begin(); i != _list.end(); i++)
66
68
      if (score < *i)
67
69
         break;
74
76
   }
75
77
}
76
78
 
77
 
std::ostream&
78
 
operator<<(std::ostream& s, const ScoreList& slist)
 
79
ostream&
 
80
operator<<(ostream& s, const ScoreList& slist)
79
81
{
80
 
   s << '(' << std::endl;
81
 
   for (std::list<Score>::const_iterator i = slist._list.begin(); 
82
 
        i != slist._list.end(); i++)
83
 
      s << *i << std::endl;
84
 
   return s << ')' << std::endl;
 
82
   s << '(' << endl;
 
83
   for (list<Score>::const_iterator i = slist._list.begin(); 
 
84
            i != slist._list.end(); i++)
 
85
                        s << *i << endl;
 
86
   return s << ')' << endl;
85
87
}
86
88
 
87
 
std::istream&
88
 
operator>>(std::istream& s, ScoreList& slist)
 
89
istream&
 
90
operator>>(istream& s, ScoreList& slist)
89
91
{
90
92
   char c;
91
93
   s >> c;