#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2007
    Posts
    2
    Rep Power
    0

    Text-Based game question (C++)


    Hello. I'm in the early learning and planning stages of a series of very small text-based D&D like games. I plan to write them in C++ and have them run in the command line window. I made a couple different searches and didn't find what I was looking for so I chose to make a post.

    I have learned some techniques in C++ such as loops, several functions, and I'm currently studying dll's. However, I have no clue how they would be useful for my purposes. (I understand what they do, but I'm a little slow when it comes to thinking of ways to utilize them.)

    For example, one specific question I have is how to set it up so that game characters can gain and lose objects from their inventory? Not to mention how can they gain experience and character levels, adding and improving skills and abilities? I think there must be some way to do this without making insanely long IF THEN ELSE type statements, which would just be retarded.

    By the way, I am keenly aware of the fact that this is a lot of work, and luckily I have the patience and determination of erosion. So a detailed answer would be very nice, but it would also be great if someone could just point me in the right direction or refer me to some good resources that are specific to text-based game programming. I have money and I'm willing to spend it.

    Thanks in advance!
    Mikhail
  2. #2
  3. Paris est magique!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    France!
    Posts
    370
    Rep Power
    96
    Have you ever heard of 'classes' ('objects'), or at least data 'structures'?

    If not, you'll have to practice a bit more before throwing yourself into this.
    Otherwise, the answer seems quite clear...
    etienne:~ > %blow
    fg: %blow: no such job


    There are 10 kind of people:
    - those who know binary
    - those who don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2007
    Posts
    2
    Rep Power
    0

    Yes, I have


    Yes I have heard of these things. However, I'm not the sharpest tool in the shed, and while I can write out the examples I've studied and make new ones on my own, I haven't the silghtest clue on what to actually use them for-- or how to actually use them for what I want to accomplish.

    Thanks anyway.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0
    You could have a class for player a class for monsters, a class for a simple game map that tracks x,y coordinates, however you want to design it really. the player class should have private members for things like hp, max hp, strength, accuracy, etc. Monster class would be similiar. to add items you would just increment whatever player member tracks that item. IE. mPotionCount = 0; then you could have an accessor function that is public and looks something like this:

    void addPotion() { mPotionCount++; }

    now whenever your at a store or whatever in your game and you buy a poition you just call player.addPotion() within an if statement and you automattically have a potion in your inventory.

    when your in battle and you want to use a potion you could call another accessor function

    void usePotion() { mPotionCount--; mHP + 30; }

    the easiest way to do it is make monster and player classes with all their respective stats public and accessor functions for every stat you will need access to.
    some examples

    int getStrength() { return mStrength; }
    void modifyStrength(int mod) { mStrength += mod; }

    int getHp() { return mHp; }
    void dmgHp(int damage) { mHp -= damage; }

    you'll want to make accessor functions like that for all stats in player and monster classes

    now make a battle class and have them fight it out
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    21
    Rep Power
    0
    Originally Posted by Mikhail Rahl
    For example, one specific question I have is how to set it up so that game characters can gain and lose objects from their inventory?
    I'd suggest setting up a data structure, or a class, called "GameObjects."

    Each character in the game would have a linked list of these "GameObjects," which would represent that character's inventory.


    Originally Posted by Mikhail Rahl
    Not to mention how can they gain experience and character levels, adding and improving skills and abilities? I think there must be some way to do this without making insanely long IF THEN ELSE type statements, which would just be retarded.
    You'd have a struct, or class, to represent a character. And each character would represent an instance of that class.

    And each of those stats (experience, class, levels, etc) would probably be represented by a variable in that data structure.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    132
    Rep Power
    247
    Originally Posted by etienne141
    Have you ever heard of 'classes' ('objects'), or at least data 'structures'?

    If not, you'll have to practice a bit more before throwing yourself into this.
    Otherwise, the answer seems quite clear...
    Mikhail,
    The key here is that this approach utilizes a programming paradigm called OOP (Object Oriented Programming). The goal being to model your code after real world objects and relationships those real world objects might have. What you do is try and abstractly define the different elements of your game as objects, then try and describe the relationships your objects share.

    For example, you might define weapons as objects that have a couple variables, "attack" and "power". When you create your weapon class, you may decide to use two integers to represent these variables. You could then define the player as a collection of different stats as well as having an "inventory". This inventory could be simply a list of all "Weapon" object he's picked up during the game. You see how this inventory simply becomes a linked list of Weapon objects in your code.

    Try to first define your game in real world terms and then abstract these into simple views of real world objects, e.g. weapons are a few variables which represent attack and power, and inventory is simply a list of weapons. Then, work on defining the relationships your objects have between each other. For example, the player object would have an inventory object. You would then code this as the player class having a member variable of type "Inventory".

IMN logo majestic logo threadwatch logo seochat tools logo