Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 07-10-09   #1 (permalink)
Overclocker
 
Darkknight512's Avatar
 
intel ati

Join Date: Apr 2008
Location: Toronto, Ontario
Posts: 1,585

Rep: 142 Darkknight512 is acknowledged by manyDarkknight512 is acknowledged by many
Unique Rep: 118
Trader Rating: 0
Default Simple XML parser needed (Page 2)

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.

System: X-Caliber
CPU
Intel Core 2 Duo E4600 @3.0 Ghz
Motherboard
Gigabyte P35 DS3L
Memory
3gb 533 mhz DDR2 (Dual Channel) @560 Mhz
Graphics Card
ATI Radeon HD3850 512MB 720/950
Hard Drive
160 Hitachi HDD
Sound Card
Intergrated 5.1 Audio (Realtek ACL888)
Power Supply
460 watt Coolermaster
Case
Coolermaster Elite
CPU cooling
Stock (MX-2)
GPU cooling
Stock - (Fan Speed [%] = Temp [C]) - Load 70C
OS
Windows Vista - Ultimate (x86)
Monitor
LG E700B 17" CRT

Last edited by Darkknight512 : 07-13-09 at 05:46 PM
Darkknight512 is offline   Reply With Quote
Old 07-10-09   #2 (permalink)
Programmer
 
intel nvidia

Join Date: Nov 2006
Posts: 1,977

Rep: 132 version2 is acknowledged by manyversion2 is acknowledged by many
Unique Rep: 111
Trader Rating: 9
Default

For writing/reading to files: What you're looking for is fstream: Use #include <fstream>

More info:
http://www.cplusplus.com/reference/iostream/fstream/
__________________
System: Duo
CPU
Core 2 Duo E6600 (B2)
Motherboard
Asus P5B Deluxe
Memory
G.SKILL HZ 2x1gb DDR2 800
Graphics Card
EVGA 9600GSO 384mb (G92)
Hard Drive
1TB + WD 640gb, Maxtor 160gb
Sound Card
Audigy 2 ZS
Power Supply
FSP 450W
Case
Ultra Aluminus
CPU cooling
Noctua U12P
GPU cooling
Stock
OS
Win 7 x64, Ubuntu
Monitor
20.1'' SOYO LCD
version2 is offline   Reply With Quote
Old 07-10-09   #3 (permalink)
Overclocker
 
Darkknight512's Avatar
 
intel ati

Join Date: Apr 2008
Location: Toronto, Ontario
Posts: 1,585

Rep: 142 Darkknight512 is acknowledged by manyDarkknight512 is acknowledged by many
Unique Rep: 118
Trader Rating: 0
Default

Is it better for me to keep my variables in a separate file?

Quote:
//Player Stats
int playerhp;
int playermp;

int playerhelm;
int playerbody;
int playerglove;
int playerlegs;

int playerweapon;
//Monster Stats
int monsterhp;
int monstermp;

int monsterhelm;
int monsterbody;
int monsterglove;
int monsterlegs;

int monsterweapon;

System: X-Caliber
CPU
Intel Core 2 Duo E4600 @3.0 Ghz
Motherboard
Gigabyte P35 DS3L
Memory
3gb 533 mhz DDR2 (Dual Channel) @560 Mhz
Graphics Card
ATI Radeon HD3850 512MB 720/950
Hard Drive
160 Hitachi HDD
Sound Card
Intergrated 5.1 Audio (Realtek ACL888)
Power Supply
460 watt Coolermaster
Case
Coolermaster Elite
CPU cooling
Stock (MX-2)
GPU cooling
Stock - (Fan Speed [%] = Temp [C]) - Load 70C
OS
Windows Vista - Ultimate (x86)
Monitor
LG E700B 17" CRT
Darkknight512 is offline   Reply With Quote
Old 07-10-09   #4 (permalink)
4.0ghz
 
Coma's Avatar
 
intel nvidia

Join Date: Jun 2007
Posts: 7,484

Rep: 455 Coma is a proven memberComa is a proven memberComa is a proven memberComa is a proven memberComa is a proven member
Unique Rep: 328
Trader Rating: 0
Default

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.
__________________
System: Akiyama Mio
CPU
E6420 @ stock, 0.98v
Motherboard
Asus P5N-E SLI
Memory
2x1GB OCZ Platinum @ 800MHz 4-4-4-12 1T, 1.9v
Graphics Card
BFG 8800GT 512MB
Hard Drive
WD 250GB, 320GB SATA/3, 16MB Cache
Power Supply
Corsair 520HX
Case
NZXT Apollo Black
CPU cooling
Stock
OS
Ubuntu 9.04 x86 & XP x86
Monitor
Asus VW222U
Coma is offline Overclocked Account   Reply With Quote
Old 07-11-09   #5 (permalink)
Case Modder
 
Spotswood's Avatar
 
Join Date: Jul 2008
Location: New Hampshire, USA
Posts: 236

Rep: 46 Spotswood is acknowledged by some
Unique Rep: 39
Trader Rating: 0
Default

Quote:
Originally Posted by Darkknight512 View Post
Is it better for me to keep my variables in a separate file?
A better solution would be to package them into objects and manipulate them via interfaces i.e. use an object oriented design.

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;
}
Good luck!
__________________
Rich
Custom Wooden Case Builder
Overclock.net Mod of the Month
Spotswood is offline   Reply With Quote
Old 07-11-09   #6 (permalink)
Overclocker
 
Darkknight512's Avatar
 
intel ati

Join Date: Apr 2008
Location: Toronto, Ontario
Posts: 1,585

Rep: 142 Darkknight512 is acknowledged by manyDarkknight512 is acknowledged by many
Unique Rep: 118
Trader Rating: 0
Default

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...

System: X-Caliber
CPU
Intel Core 2 Duo E4600 @3.0 Ghz
Motherboard
Gigabyte P35 DS3L
Memory
3gb 533 mhz DDR2 (Dual Channel) @560 Mhz
Graphics Card
ATI Radeon HD3850 512MB 720/950
Hard Drive
160 Hitachi HDD
Sound Card
Intergrated 5.1 Audio (Realtek ACL888)
Power Supply
460 watt Coolermaster
Case
Coolermaster Elite
CPU cooling
Stock (MX-2)
GPU cooling
Stock - (Fan Speed [%] = Temp [C]) - Load 70C
OS
Windows Vista - Ultimate (x86)
Monitor
LG E700B 17" CRT
Darkknight512 is offline   Reply With Quote
Old 07-11-09   #7 (permalink)
Case Modder
 
Spotswood's Avatar
 
Join Date: Jul 2008
Location: New Hampshire, USA
Posts: 236

Rep: 46 Spotswood is acknowledged by some
Unique Rep: 39
Trader Rating: 0
Default

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
Custom Wooden Case Builder
Overclock.net Mod of the Month
Spotswood is offline   Reply With Quote
Old 07-12-09   #8 (permalink)
Overclocker
 
Darkknight512's Avatar
 
intel ati

Join Date: Apr 2008
Location: Toronto, Ontario
Posts: 1,585

Rep: 142 Darkknight512 is acknowledged by manyDarkknight512 is acknowledged by many
Unique Rep: 118
Trader Rating: 0
Default

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.

System: X-Caliber
CPU
Intel Core 2 Duo E4600 @3.0 Ghz
Motherboard
Gigabyte P35 DS3L
Memory
3gb 533 mhz DDR2 (Dual Channel) @560 Mhz
Graphics Card
ATI Radeon HD3850 512MB 720/950
Hard Drive
160 Hitachi HDD
Sound Card
Intergrated 5.1 Audio (Realtek ACL888)
Power Supply
460 watt Coolermaster
Case
Coolermaster Elite
CPU cooling
Stock (MX-2)
GPU cooling
Stock - (Fan Speed [%] = Temp [C]) - Load 70C
OS
Windows Vista - Ultimate (x86)
Monitor
LG E700B 17" CRT
Darkknight512 is offline   Reply With Quote
Old 07-12-09   #9 (permalink)
Case Modder
 
Spotswood's Avatar
 
Join Date: Jul 2008
Location: New Hampshire, USA
Posts: 236

Rep: 46 Spotswood is acknowledged by some
Unique Rep: 39
Trader Rating: 0
Default

Quote:
Originally Posted by Darkknight512 View Post
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.
I don't know anything about TinyXML, but after a quick look it seems to be very easy to use.

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
Custom Wooden Case Builder
Overclock.net Mod of the Month
Spotswood is offline   Reply With Quote
Old 07-12-09   #10 (permalink)
Overclocker
 
Darkknight512's Avatar
 
intel ati

Join Date: Apr 2008
Location: Toronto, Ontario
Posts: 1,585

Rep: 142 Darkknight512 is acknowledged by manyDarkknight512 is acknowledged by many
Unique Rep: 118
Trader Rating: 0
Default

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:
<monsters>

<level 1>
<monster 1>
//Hp, mana , defense, attack ect...
</monster 1>

<monster 2>
//Hp, mana , defense, attack ect...
</monster 2>
</level 1>

<level 2>
<monster 1>
//Hp, mana , defense, attack ect...
</monster 1>

<monster 2>
//Hp, mana , defense, attack ect...
</monster 2>
</level 2>

</monsters>
I need it structured in a way that allows me to pull a monster's variables from a certain level.

System: X-Caliber
CPU
Intel Core 2 Duo E4600 @3.0 Ghz
Motherboard
Gigabyte P35 DS3L
Memory
3gb 533 mhz DDR2 (Dual Channel) @560 Mhz
Graphics Card
ATI Radeon HD3850 512MB 720/950
Hard Drive
160 Hitachi HDD
Sound Card
Intergrated 5.1 Audio (Realtek ACL888)
Power Supply
460 watt Coolermaster
Case
Coolermaster Elite
CPU cooling
Stock (MX-2)
GPU cooling
Stock - (Fan Speed [%] = Temp [C]) - Load 70C
OS
Windows Vista - Ultimate (x86)
Monitor
LG E700B 17" CRT

Last edited by Darkknight512 : 07-12-09 at 06:02 PM
Darkknight512 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 11:29 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.18745 seconds with 8 queries