[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r4165 - branches/pingus-hanusz/src
From: |
grumbel |
Subject: |
[Pingus-CVS] r4165 - branches/pingus-hanusz/src |
Date: |
Fri, 17 Jun 2011 19:22:54 +0200 |
Author: grumbel
Date: 2011-06-17 19:22:53 +0200 (Fri, 17 Jun 2011)
New Revision: 4165
Modified:
branches/pingus-hanusz/src/game_session.cpp
branches/pingus-hanusz/src/level_menu.cpp
branches/pingus-hanusz/src/levelset.cpp
branches/pingus-hanusz/src/levelset.hpp
branches/pingus-hanusz/src/start_screen.cpp
branches/pingus-hanusz/src/statistics.cpp
branches/pingus-hanusz/src/statistics.hpp
Log:
Moved Statistics tracking out of LevelSet and into Statistics class
Modified: branches/pingus-hanusz/src/game_session.cpp
===================================================================
--- branches/pingus-hanusz/src/game_session.cpp 2011-05-25 14:44:10 UTC (rev
4164)
+++ branches/pingus-hanusz/src/game_session.cpp 2011-06-17 17:22:53 UTC (rev
4165)
@@ -54,6 +54,9 @@
left_over_time = 0;
pout(PINGUS_DEBUG_LOADING) << "PingusGameSession" << std::endl;
+
+ LevelStat& stat = Statistics::instance()->get_level_stat(plf.get_resname());
+ stat.incr_play_count();
}
PingusGameSession::~PingusGameSession ()
Modified: branches/pingus-hanusz/src/level_menu.cpp
===================================================================
--- branches/pingus-hanusz/src/level_menu.cpp 2011-05-25 14:44:10 UTC (rev
4164)
+++ branches/pingus-hanusz/src/level_menu.cpp 2011-06-17 17:22:53 UTC (rev
4165)
@@ -123,7 +123,7 @@
gc.print_left(Fonts::chalk_normal, 85+30, 15 + y,
_((*i)->get_title()));
gc.print_left(Fonts::chalk_small, 85+50, 40 + y,
_((*i)->get_description()));
- gc.print_right(Fonts::chalk_normal, rect.get_width() - 30, 15 + y,
(boost::format("%1% %2%%%") % _("Solved:") % (*i)->get_completion()).str());
+ //gc.print_right(Fonts::chalk_normal, rect.get_width() - 30, 15 + y,
(boost::format("%1% %2%%%") % _("Solved:") % (*i)->get_completion()).str());
gc.print_right(Fonts::chalk_small, rect.get_width() - 30, 60 + y,
(boost::format("%1% %2%") % (*i)->get_level_count() % _("levels")).str());
//gc.draw(ok_button, 620, y);
@@ -196,12 +196,14 @@
gc.print_left(Fonts::chalk_normal, 30, -32, _("Title"));
gc.print_right(Fonts::chalk_normal, rect.get_width() - 30, - 32,
_("Status"));
- gc.print_center(Fonts::chalk_normal, rect.get_width() - 165, - 32,
_("Retries Left"));
+ gc.print_center(Fonts::chalk_normal, rect.get_width() - 165, - 32,
_("Tries Left"));
int y = 0;
for(int i = 0; i < levelset->get_level_count(); ++i)
{
- if (!levelset->get_level(i)->is_accessible())
+ LevelStat& level_stat =
Statistics::instance()->get_level_stat(levelset->get_level(i)->resname);
+
+ if (!level_stat.is_accessible())
gc.draw(marker_locked, Vector2i(0, y));
else if (i == current_level)
gc.draw(marker, Vector2i(0, y));
@@ -211,13 +213,14 @@
else
gc.print_left(Fonts::chalk_small, 30, y+4,
_(levelset->get_level(i)->plf.get_levelname()));
- if (levelset->get_level(i)->finished)
+ if (level_stat.is_finished())
gc.print_right(Fonts::chalk_small, rect.get_width() -30, y+4,
_("solved"));
else
gc.print_right(Fonts::chalk_small, rect.get_width() -30, y+4,
_("unsolved"));
gc.print_right(Fonts::chalk_small, rect.get_width() -30 -125, y+4,
- (boost::format("%d") % (3 -
levelset->get_level(i)->play_count)).str());
+ (boost::format("%d")
+ % (level_stat.get_max_play_count() -
level_stat.get_play_count())).str());
y += 32;
}
@@ -251,9 +254,8 @@
{
if (current_level != -1)
{
- if (levelset->get_level(current_level)->is_accessible())
+ if
(Statistics::instance()->get_level_stat(levelset->get_level(current_level)->resname).is_accessible())
{
- levelset->get_level(current_level)->play_count += 1;
ScreenManager::instance()->push_screen(new
StartScreen(levelset->get_level(current_level)->plf), true);
}
}
@@ -309,6 +311,15 @@
m_abort_button->show();
level_selector->hide();
}
+ else if (level_selector->get_levelset() &&
level_selector->get_levelset()->is_failed())
+ {
+ // time limit reached
+ gc.print_center(Fonts::chalk_large, gc.get_width()/2, gc.get_height()/2
- 60,
+ "Game Over");
+
+ m_abort_button->show();
+ level_selector->hide();
+ }
else if (ScreenManager::instance()->time_limit_over())
{
// time limit reached
@@ -360,7 +371,7 @@
{
m_mode = kLevelSelector;
- Statistics::instance()->set_username(m_username_inputbox->get_string());
+ Statistics::instance()->start_session(m_username_inputbox->get_string());
int time_limit;
if (!StringUtil::from_string(m_time_inputbox->get_string(), time_limit))
Modified: branches/pingus-hanusz/src/levelset.cpp
===================================================================
--- branches/pingus-hanusz/src/levelset.cpp 2011-05-25 14:44:10 UTC (rev
4164)
+++ branches/pingus-hanusz/src/levelset.cpp 2011-06-17 17:22:53 UTC (rev
4165)
@@ -25,9 +25,10 @@
#include "savegame_manager.hpp"
#include "resource.hpp"
#include "math.hpp"
+#include "statistics.hpp"
-Levelset::Levelset(const Pathname& pathname)
- : completion(0)
+Levelset::Levelset(const Pathname& pathname) :
+ completion(0)
{
FileReader reader = FileReader::parse(pathname);
if (reader.get_name() != "pingus-levelset")
@@ -53,11 +54,7 @@
if (i->read_string("filename", level->resname))
{
level->plf = PLFResMgr::load_plf(level->resname);
-
- level->accessible = true;
- level->finished = false;
- level->play_count = 0;
-
+
levels.push_back(level);
}
else
@@ -107,12 +104,6 @@
return levels.size();
}
-int
-Levelset::get_completion() const
-{
- return completion;
-}
-
Sprite
Levelset::get_image() const
{
@@ -122,6 +113,7 @@
void
Levelset::refresh()
{
+#if 0
for(std::vector<Level*>::iterator i = levels.begin(); i != levels.end(); ++i)
{
Savegame* savegame = SavegameManager::instance()->get((*i)->resname);
@@ -146,6 +138,7 @@
if ((*i)->finished)
completion += 1;
completion = Math::clamp(0, completion * 100 / int(levels.size()), 100);
+#endif
}
bool
@@ -153,7 +146,7 @@
{
for(std::vector<Level*>::const_iterator i = levels.begin(); i !=
levels.end(); ++i)
{
- if (!(*i)->finished)
+ if (!Statistics::instance()->get_level_stat((*i)->resname).is_finished())
{
return false;
}
@@ -161,4 +154,17 @@
return true;
}
+bool
+Levelset::is_failed() const
+{
+ for(std::vector<Level*>::const_iterator i = levels.begin(); i !=
levels.end(); ++i)
+ {
+ if (Statistics::instance()->get_level_stat((*i)->resname).is_accessible())
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
/* EOF */
Modified: branches/pingus-hanusz/src/levelset.hpp
===================================================================
--- branches/pingus-hanusz/src/levelset.hpp 2011-05-25 14:44:10 UTC (rev
4164)
+++ branches/pingus-hanusz/src/levelset.hpp 2011-06-17 17:22:53 UTC (rev
4165)
@@ -32,14 +32,7 @@
public:
struct Level {
std::string resname;
- bool accessible;
- bool finished;
- int play_count;
PingusLevel plf;
-
- bool is_accessible() const {
- return (play_count < 3) && !finished;
- }
};
private:
@@ -61,9 +54,10 @@
int get_level_count() const;
/** Return the number of completed levels */
- int get_completion() const;
+ //int get_completion() const;
bool is_finished() const;
+ bool is_failed() const;
void refresh();
private:
Modified: branches/pingus-hanusz/src/start_screen.cpp
===================================================================
--- branches/pingus-hanusz/src/start_screen.cpp 2011-05-25 14:44:10 UTC (rev
4164)
+++ branches/pingus-hanusz/src/start_screen.cpp 2011-06-17 17:22:53 UTC (rev
4165)
@@ -216,7 +216,7 @@
StartScreenComponent* comp = new StartScreenComponent(plf);
gui_manager->add(comp, true);
gui_manager->add(new StartScreenOkButton(this), true);
- //gui_manager->add(new StartScreenAbortButton(this), true);
+ gui_manager->add(new StartScreenAbortButton(this), true);
}
void
Modified: branches/pingus-hanusz/src/statistics.cpp
===================================================================
--- branches/pingus-hanusz/src/statistics.cpp 2011-05-25 14:44:10 UTC (rev
4164)
+++ branches/pingus-hanusz/src/statistics.cpp 2011-06-17 17:22:53 UTC (rev
4165)
@@ -21,6 +21,48 @@
Statistics* Statistics::s_instance = 0;
+LevelStat::LevelStat() :
+ m_play_count(0),
+ m_finished(false)
+{
+}
+
+bool
+LevelStat::is_accessible() const
+{
+ return (m_play_count < get_max_play_count()) && !m_finished;
+}
+
+bool
+LevelStat::is_finished() const
+{
+ return m_finished;
+}
+
+void
+LevelStat::set_finished(bool v)
+{
+ m_finished = v;
+}
+
+int
+LevelStat::get_play_count() const
+{
+ return m_play_count;
+}
+
+void
+LevelStat::incr_play_count()
+{
+ m_play_count += 1;
+}
+
+int
+LevelStat::get_max_play_count() const
+{
+ return 3;
+}
+
Statistics::Statistics() :
m_filename("statistics.txt"),
m_username("<unset>")
@@ -47,6 +89,13 @@
void
Statistics::save_result(const Result& result, int actions_used)
{
+ // transfer the state from result to level_stats
+ LevelStat& stat = get_level_stat(result.plf.get_resname());
+ if (result.success())
+ {
+ stat.set_finished(true);
+ }
+
//m_out << "# username, levelname, saved, killed, time, success" <<
std::endl;
std::ofstream m_out(m_filename.c_str(), std::ios::app);
if (!m_out)
@@ -66,8 +115,11 @@
}
void
-Statistics::mark_session_end()
+Statistics::start_session(const std::string& username)
{
+ clear();
+ set_username(username);
+
std::ofstream m_out(m_filename.c_str(), std::ios::app);
if (!m_out)
{
@@ -75,12 +127,12 @@
}
else
{
- m_out << "### session end: " << m_username << " ###\n" << std::endl;
+ m_out << "### session start: " << m_username << " ###\n" << std::endl;
}
}
void
-Statistics::mark_session_start()
+Statistics::end_session()
{
std::ofstream m_out(m_filename.c_str(), std::ios::app);
if (!m_out)
@@ -89,8 +141,20 @@
}
else
{
- m_out << "### session start: " << m_username << " ###\n" << std::endl;
+ m_out << "### session end: " << m_username << " ###\n" << std::endl;
}
}
+void
+Statistics::clear()
+{
+ m_level_stats.clear();
+}
+
+LevelStat&
+Statistics::get_level_stat(const std::string& resname)
+{
+ return m_level_stats[resname];
+}
+
/* EOF */
Modified: branches/pingus-hanusz/src/statistics.hpp
===================================================================
--- branches/pingus-hanusz/src/statistics.hpp 2011-05-25 14:44:10 UTC (rev
4164)
+++ branches/pingus-hanusz/src/statistics.hpp 2011-06-17 17:22:53 UTC (rev
4165)
@@ -21,6 +21,26 @@
class Result;
+class LevelStat
+{
+private:
+ int m_play_count;
+ bool m_finished;
+
+public:
+ LevelStat();
+
+ bool is_accessible() const;
+ bool is_finished() const;
+ int get_play_count() const;
+ void incr_play_count();
+
+ void set_finished(bool v);
+
+ /** Maximum number of times a user is allowed to retry the given level */
+ int get_max_play_count() const;
+};
+
class Statistics
{
private:
@@ -37,17 +57,26 @@
std::string m_filename;
std::string m_username;
+ typedef std::map<std::string, LevelStat> LevelStats;
+ LevelStats m_level_stats;
+
public:
Statistics();
~Statistics();
- void set_username(const std::string& username);
+ void clear();
+
void save_result(const Result& result, int actions_used);
- void mark_session_start();
- void mark_session_end();
+ LevelStat& get_level_stat(const std::string& resname);
+ void start_session(const std::string& username);
+ void end_session();
+
private:
+ void set_username(const std::string& username);
+
+private:
Statistics(const Statistics&);
Statistics& operator=(const Statistics&);
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r4165 - branches/pingus-hanusz/src,
grumbel <=