|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
Simple XML parser needed (Page 2)
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
Overclocker
![]() |
I'm writing a combat system (Text RPG style) in C++ and would like some help with a few things.
1. How to change color of text in the command line 2. Save variables to a file 3. General ideas I want to have a system in place to generate a monster, I'm thinking of a switch case and a random number generator. I want to be able to implement this into a text RPG eventually.
__________________
DD-WRT Firmware Club|Top Gear Fan Club|Microsoft Windows Club|Mozilla FirefoxClub| A MEMBER OF THE RAZER CU|T
Last edited by Darkknight512 : 07-13-09 at 06:46 PM |
|||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
Programmer
![]() |
For writing/reading to files: What you're looking for is fstream: Use #include <fstream>
__________________More info: http://www.cplusplus.com/reference/iostream/fstream/
|
|||||||||||||
|
|
|
|
|
#3 (permalink) | ||||||||||||||
|
Overclocker
![]() |
Is it better for me to keep my variables in a separate file?
Quote:
__________________
DD-WRT Firmware Club|Top Gear Fan Club|Microsoft Windows Club|Mozilla FirefoxClub| A MEMBER OF THE RAZER CU|T
|
||||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||||
|
4.0ghz
![]() |
Look up how to read and write INI or XML. They're both convenient since there are already parsers for them, but XML usually gives less headaches.
__________________
|
|||||||||||
|
|
|
|
#5 (permalink) | |
|
Case Modder
![]() |
Quote:
For example, you could design and implement something like this: Code:
#include <string>
#include <memory>
class IStats
{
public:
virtual ~IStats() {}
// Getters
virtual int Hp() =0;
virtual int Mp() =0;
// etc...
//virtual int Helm() =0;
//virtual int Body() =0;
//virtual int Glove() =0;
//virtual int Legs() =0;
//virtual int Weapon() =0;
// Setters
// Here or in a separate IStateKeeper interface?
// i.e. this is a "read only" interface while
// IStateKeeper is a "writer/updater" interface.
// ...
};
class PlayerMonsterStats : public IStats
{
public:
PlayerMonsterStats()
: m_hp(0), m_mp(0)
{
// ...
}
// IStats
virtual int Hp() { return m_hp; }
virtual int Mp() { return m_mp; }
// etc...
private:
int m_hp;
int m_mp;
// etc...
};
class StatsFactory
{
public:
static IStats* CreateStats(const std::string& objectType)
{
if (objectType == "player")
return new PlayerMonsterStats;
if (objectType == "monster")
return new PlayerMonsterStats;
//if (objectType == "robot")
// return new RobotStats;
return 0;
}
};
int main()
{
std::auto_ptr<IStats> playerStats(StatsFactory::CreateStats("player"));
int hp = playerStats->Hp();
return 0;
}
__________________
Rich
|
|
|
|
|
|
|
#6 (permalink) | |||||||||||||
|
Overclocker
![]() |
Thanks,
Now if I want to make an inventory system what would be a good way to make it? Other then int gold, int potion, int armourid, ect...
__________________
DD-WRT Firmware Club|Top Gear Fan Club|Microsoft Windows Club|Mozilla FirefoxClub| A MEMBER OF THE RAZER CU|T
|
|||||||||||||
|
|
|
|
|
#7 (permalink) |
|
Case Modder
![]() |
If your thinking "in" objects and interfaces, then what is an inventory? What are the properties of a "inventory-able" object/item? What types of "inventory-able" objects will need to be created? Its up to you to design a model that solves your problem. Okay?
Here's something off the top of my head: Code:
class IInventory
{
public:
virtual int
/* These might return references to other objects i.e. IInventoryItem? */
Gold() =0;
// etc.
};
class Inventory : public IInventory
{
public:
// IInventory:
virtual int Gold() { return m_gold; }
// etc..
private:
int m_gold; // These in turn might be references to other objects
// i.e. IInventoryItem ?
int m_potion;
};
__________________
Rich
|
|
|
|
|
|
#8 (permalink) | |||||||||||||
|
Overclocker
![]() |
Right now I'm looking at some XML parsers for equipment stats, monster stats, item stats and saving. I am currently looking at TinyXML, is there a particular XML parser that you would recommend? I use Code Gear C++ Builder 2009.
__________________
DD-WRT Firmware Club|Top Gear Fan Club|Microsoft Windows Club|Mozilla FirefoxClub| A MEMBER OF THE RAZER CU|T
|
|||||||||||||
|
|
|
|
|
#9 (permalink) | |
|
Case Modder
![]() |
Quote:
Whatever mechanism you use to store/retrieve data, minimize the exposer of the mechanism to the rest of the code i.e. the game shouldn't give a hoot if your using XML, an ini or a RDMS. Code:
class IGameRespository
{
public:
std::list<IStats*> GetPlayerStats(char* playerName) =0;
void SavePlayerStats(char* playerName, IStats* state) =0;
};
class GameRepository : public IGameRepository
{
public:
GameRepository(char* filePath)
{
// Open XML doc, prepare for queries
}
// etc...
};
__________________
Rich
|
|
|
|
|
|
|
#10 (permalink) | ||||||||||||||
|
Overclocker
![]() |
I checked out a ini parser and it worked prefectly but I relized that it dosen't do what I need it to but I'm having a lot of trouble getting tinyXML to work, which files am I supposed to put in the project, and how am I actually supposed to get the values and put it into a string or int?
I need to pull values from someting like this, I'm pretty sure XML would be the way to go but I can't make sense of the tutorial. Quote:
__________________
DD-WRT Firmware Club|Top Gear Fan Club|Microsoft Windows Club|Mozilla FirefoxClub| A MEMBER OF THE RAZER CU|T
Last edited by Darkknight512 : 07-12-09 at 07:02 PM |
||||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|