From: Ricardo Cruz Date: Tue, 14 Sep 2004 22:31:46 +0000 (+0000) Subject: Ooops, forgot to upload the actual Statistics implementation. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=2f0b7399772742750fde12c194ee9beef0a472dc;p=supertux.git Ooops, forgot to upload the actual Statistics implementation. SVN-Revision: 1912 --- diff --git a/src/statistics.cpp b/src/statistics.cpp new file mode 100644 index 000000000..ab97add20 --- /dev/null +++ b/src/statistics.cpp @@ -0,0 +1,75 @@ +// SuperTux +// Copyright (C) 2004 SuperTux Development Team, see AUTHORS for details +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. + +#include "utils/lispreader.h" +#include "utils/lispwriter.h" +#include "statistics.h" + +Statistics global_stats; + +Statistics::Statistics() +{ + reset(); +} + +Statistics::~Statistics() +{ +} + +void +Statistics::parse(LispReader& reader) +{ + reader.read_int("score", stats[SCORE_STAT]); +} + +void +Statistics::write(LispWriter& writer) +{ + writer.write_int("score", stats[SCORE_STAT]); +} + +void +Statistics::add_points(int stat, int points) +{ + stats[stat] += points; +} + +int +Statistics::get_points(int stat) +{ + return stats[stat]; +} + +void +Statistics::reset() +{ + for(int i = 0; i < MAX_STATS; i++) + stats[i] = 0; +} + +void +Statistics::merge(Statistics& stats_) +{ + stats[SCORE_STAT] = std::max(stats[SCORE_STAT], stats_.stats[SCORE_STAT]); +} + +void +Statistics::operator+=(const Statistics& stats_) +{ + stats[SCORE_STAT] += stats_.stats[SCORE_STAT]; +} diff --git a/src/statistics.h b/src/statistics.h new file mode 100644 index 000000000..d22c77349 --- /dev/null +++ b/src/statistics.h @@ -0,0 +1,68 @@ +// SuperTux +// Copyright (C) 2004 SuperTux Development Team, see AUTHORS for details +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. + +#ifndef SUPERTUX_STATISTICS_H +#define SUPERTUX_STATISTICS_H + +using namespace SuperTux; + +namespace SuperTux { +class LispReader; +class LispWriter; +} + +enum { + SCORE_STAT, + MAX_STATS +}; + +/** This class is a layer between level and worldmap to keep + * track of stuff like scores, and minor, but funny things, like + * number of jumps and stuff */ + +class Statistics +{ +public: + Statistics(); + ~Statistics(); + + /// read statistics from lisp file + void parse(LispReader& reader); + /// write statistics to lisp file + void write(LispWriter& writer); + + // TODO: add drawing functions to draw stats on WorldMap + + void add_points(int stat, int points); + int get_points(int stat); + + void reset(); + + /* Give another Statistics object, find the best of each one */ + void merge(Statistics& stats); + + /* Add two statistic objects */ + void operator+=(const Statistics& o); + +private: + int stats[MAX_STATS]; +}; + +extern Statistics global_stats; + +#endif /*SUPERTUX_STATISTICS_H*/