|
From: Markus R. <god...@us...> - 2009-07-29 15:35:22
|
Module: performous
Branch: master
Commit: 10ffe1bca8ff11bc9563bb892bc40e0ca87c452b
Author: Markus Raab <un...@ma...>
Date: Fri Jul 24 12:31:27 2009 +0200
a very very basic Players implementation
---
game/.gitignore | 2 ++
game/player.hh | 15 ---------------
game/players.cc | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
game/players.hh | 26 ++++++++++++++++++++++++--
4 files changed, 72 insertions(+), 19 deletions(-)
diff --git a/game/.gitignore b/game/.gitignore
index 179d259..13ba250 100644
--- a/game/.gitignore
+++ b/game/.gitignore
@@ -2,3 +2,5 @@
Makefile
highscore
highscore.txt
+players
+players.txt
diff --git a/game/player.hh b/game/player.hh
index 5d3e7eb..8c49384 100644
--- a/game/player.hh
+++ b/game/player.hh
@@ -41,18 +41,3 @@ struct Player {
return 10000.0 * m_score;
}
};
-
-/** Static Information of a player, not
- dependent from current song.
-
- Used for Players Management.
- */
-struct PlayerItem
-{
- std::string name; /// unique name, link to highscore
-/* Future ideas
- std::string displayedName; /// artist name, short name, nick (can be changed)
- std::string picture; /// a path to a picture shown
- std::map<std::string, int> scores; /// map between a Song and the highest score the Player achieved
-*/
-};
diff --git a/game/players.cc b/game/players.cc
index e9eb96c..eb33f87 100644
--- a/game/players.cc
+++ b/game/players.cc
@@ -1,7 +1,51 @@
#include "players.hh"
-void Players::load()
+#include <fstream>
+
+Players::Players(std::string filename):
+ m_filename(filename)
{}
-void Players::save()
+Players::~Players()
{}
+
+void Players::load()
+{
+ std::ifstream in (m_filename.c_str());
+
+ std::string str;
+ while (getline(in, str))
+ {
+ addPlayer(str);
+ }
+}
+
+void Players::save()
+{
+ std::ofstream out (m_filename.c_str());
+
+ for (players_t::const_iterator it = m_players.begin(); it!=m_players.end(); ++it)
+ {
+ out << it->name << std::endl;
+ }
+}
+
+void Players::addPlayer (std::string name)
+{
+ PlayerItem pi;
+ pi.name = name;
+ m_players.push_back(pi);
+}
+
+#include <iostream>
+
+int main(int argc, char** argv)
+{
+ if (argc != 2) return 1;
+
+ std::string name = argv[1];
+ Players p("players.txt");
+ p.load();
+ p.addPlayer(name);
+ p.save();
+}
diff --git a/game/players.hh b/game/players.hh
index 8d3187d..ac94092 100644
--- a/game/players.hh
+++ b/game/players.hh
@@ -1,6 +1,22 @@
#pragma once
+#include <list>
+#include <string>
-#include "player.hh"
+
+/** Static Information of a player, not
+ dependent from current song.
+
+ Used for Players Management.
+ */
+struct PlayerItem
+{
+ std::string name; /// unique name, link to highscore
+/* Future ideas
+ std::string displayedName; /// artist name, short name, nick (can be changed)
+ std::string picture; /// a path to a picture shown
+ std::map<std::string, int> scores; /// map between a Song and the highest score the Player achieved
+*/
+};
/**A collection of all Players.
@@ -8,9 +24,15 @@
be retrieved with Engine::getPlayers().*/
class Players
{
+ public:
+ typedef std::list<PlayerItem> players_t;
private:
- std::list<PlayerItem> m_players;
+ players_t m_players;
+ std::string m_filename;
public:
+ Players(std::string filename);
+ ~Players();
void load();
void save();
+ void addPlayer (std::string name);
};
|