Adventure Game (text based) in C++Text-based adventure gameThe Mysts of Altair - text-based adventure gameText-based adventure survival horror gameFirst text-based adventure gameText based adventure game navigationText-based Adventure-Game EngineHaskell Text-Adventure GameJava text-based adventure gameShort text-based adventure gameText-based adventure and combat game

How to create the Curved texte?

My adviser wants to be the first author

What is the significance behind "40 days" that often appears in the Bible?

Why would a flight no longer considered airworthy be redirected like this?

It's a yearly task, alright

What did Alexander Pope mean by "Expletives their feeble Aid do join"?

Why did it take so long to abandon sail after steamships were demonstrated?

Can I use USB data pins as power source

What are substitutions for coconut in curry?

Credit cards used everywhere in Singapore or Malaysia?

Awsome yet unlucky path traversal

My Graph Theory Students

What's the meaning of “spike” in the context of “adrenaline spike”?

How to deal with a cynical class?

Why do passenger jet manufacturers design their planes with stall prevention systems?

How to simplify this time periods definition interface?

how to write formula in word in latex

how to draw discrete time diagram in tikz

Recruiter wants very extensive technical details about all of my previous work

Is a party consisting of only a bard, a cleric, and a warlock functional long-term?

If I can solve Sudoku can I solve Travelling Salesman Problem(TSP)? If yes, how?

Why do Australian milk farmers need to protest supermarkets' milk price?

Python if-else code style for reduced code for rounding floats

Existence of subset with given Hausdorff dimension



Adventure Game (text based) in C++


Text-based adventure gameThe Mysts of Altair - text-based adventure gameText-based adventure survival horror gameFirst text-based adventure gameText based adventure game navigationText-based Adventure-Game EngineHaskell Text-Adventure GameJava text-based adventure gameShort text-based adventure gameText-based adventure and combat game













3












$begingroup$


I'm working on a simple text based adventure game. I've just finished working on the character creation portion. The code works perfectly fine when run, but I would just like to get some feedback to ensure that it checks off from a professional and efficient standpoint.



The values of the materials, weapons, and spells are representing the amount of damage points each does for further and future calculations with the characters stats later in the game.



The code itself essentially allows you to input a characters name. Then, the strength, stamina, and intellect is randomly generated so that your character build is different at the beginning of each game. Then, once that has finished, the code takes into account the weapon type, the material of the weapon, the spell type and adds additional damage based on the players stats.



I would just like to know if there is a better way of writing my code to make it look cleaner, or if there possibly any concerns that might cause me issues down the road when I add more functionality to the game. Seeing as I am a beginner to C++, I am not incredibly great at determining whether my code is optimal or not.



#include <iostream>
#include <string>
#include <ctime>

using namespace std;

/* Materials Structure */

typedef struct materials
int wood = 1, oak = 2, maple = 3, ash = 4, bronze = 2, iron = 3, steel = 4, mithril = 5, dragon = 6;
;

/* Weapon Structure */

typedef struct weapons
int dagger = 2, sword = 3, axe = 4, mace = 5, bow = 3, arrows = 2;
weapons;

/* Spell Structure */

typedef struct spells
int fire = 4, frost = 6, dark = 8, chaos = 10;
spells;


/* Character Structure */

typedef struct character
string name;
int health = 100, mana = 100, strength, stamina, intellect, weaponAttack, spellAttack, souls = 0;
spells spell;
weapons weapon;
materials material;
character;

/* Function Declaration */

character characterCreation(string name);
void printInfo(character createChar);

/* Main Function */

int main()
string characterName;
cout << "Please input character name: ";
cin >> characterName;

srand(time(NULL));
character player = characterCreation(characterName);
printInfo(player);

system("pause");
return 0;


/* Function Definition */

character characterCreation(string name)
character createChar;
createChar.name = name;
createChar.strength = rand() % 5 + 5;
createChar.stamina = rand() % 5 + 5;
createChar.intellect = rand() % 5 + 5;
createChar.health += 2 * createChar.stamina;
createChar.mana += 3 * createChar.intellect;
createChar.weaponAttack = (createChar.weapon.dagger * createChar.material.bronze) + (2 * createChar.strength);
createChar.spellAttack = (createChar.spell.fire + (createChar.intellect * 2));
return createChar;


void printInfo(character createChar)
cout << createChar.name << endl;
cout << createChar.health << endl;
cout << createChar.mana << endl;
cout << createChar.strength << endl;
cout << createChar.stamina << endl;
cout << createChar.intellect << endl;
cout << createChar.weaponAttack << endl;
cout << createChar.spellAttack << endl;
cout << createChar.souls << endl;










share|improve this question









New contributor




Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$
















    3












    $begingroup$


    I'm working on a simple text based adventure game. I've just finished working on the character creation portion. The code works perfectly fine when run, but I would just like to get some feedback to ensure that it checks off from a professional and efficient standpoint.



    The values of the materials, weapons, and spells are representing the amount of damage points each does for further and future calculations with the characters stats later in the game.



    The code itself essentially allows you to input a characters name. Then, the strength, stamina, and intellect is randomly generated so that your character build is different at the beginning of each game. Then, once that has finished, the code takes into account the weapon type, the material of the weapon, the spell type and adds additional damage based on the players stats.



    I would just like to know if there is a better way of writing my code to make it look cleaner, or if there possibly any concerns that might cause me issues down the road when I add more functionality to the game. Seeing as I am a beginner to C++, I am not incredibly great at determining whether my code is optimal or not.



    #include <iostream>
    #include <string>
    #include <ctime>

    using namespace std;

    /* Materials Structure */

    typedef struct materials
    int wood = 1, oak = 2, maple = 3, ash = 4, bronze = 2, iron = 3, steel = 4, mithril = 5, dragon = 6;
    ;

    /* Weapon Structure */

    typedef struct weapons
    int dagger = 2, sword = 3, axe = 4, mace = 5, bow = 3, arrows = 2;
    weapons;

    /* Spell Structure */

    typedef struct spells
    int fire = 4, frost = 6, dark = 8, chaos = 10;
    spells;


    /* Character Structure */

    typedef struct character
    string name;
    int health = 100, mana = 100, strength, stamina, intellect, weaponAttack, spellAttack, souls = 0;
    spells spell;
    weapons weapon;
    materials material;
    character;

    /* Function Declaration */

    character characterCreation(string name);
    void printInfo(character createChar);

    /* Main Function */

    int main()
    string characterName;
    cout << "Please input character name: ";
    cin >> characterName;

    srand(time(NULL));
    character player = characterCreation(characterName);
    printInfo(player);

    system("pause");
    return 0;


    /* Function Definition */

    character characterCreation(string name)
    character createChar;
    createChar.name = name;
    createChar.strength = rand() % 5 + 5;
    createChar.stamina = rand() % 5 + 5;
    createChar.intellect = rand() % 5 + 5;
    createChar.health += 2 * createChar.stamina;
    createChar.mana += 3 * createChar.intellect;
    createChar.weaponAttack = (createChar.weapon.dagger * createChar.material.bronze) + (2 * createChar.strength);
    createChar.spellAttack = (createChar.spell.fire + (createChar.intellect * 2));
    return createChar;


    void printInfo(character createChar)
    cout << createChar.name << endl;
    cout << createChar.health << endl;
    cout << createChar.mana << endl;
    cout << createChar.strength << endl;
    cout << createChar.stamina << endl;
    cout << createChar.intellect << endl;
    cout << createChar.weaponAttack << endl;
    cout << createChar.spellAttack << endl;
    cout << createChar.souls << endl;










    share|improve this question









    New contributor




    Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$














      3












      3








      3





      $begingroup$


      I'm working on a simple text based adventure game. I've just finished working on the character creation portion. The code works perfectly fine when run, but I would just like to get some feedback to ensure that it checks off from a professional and efficient standpoint.



      The values of the materials, weapons, and spells are representing the amount of damage points each does for further and future calculations with the characters stats later in the game.



      The code itself essentially allows you to input a characters name. Then, the strength, stamina, and intellect is randomly generated so that your character build is different at the beginning of each game. Then, once that has finished, the code takes into account the weapon type, the material of the weapon, the spell type and adds additional damage based on the players stats.



      I would just like to know if there is a better way of writing my code to make it look cleaner, or if there possibly any concerns that might cause me issues down the road when I add more functionality to the game. Seeing as I am a beginner to C++, I am not incredibly great at determining whether my code is optimal or not.



      #include <iostream>
      #include <string>
      #include <ctime>

      using namespace std;

      /* Materials Structure */

      typedef struct materials
      int wood = 1, oak = 2, maple = 3, ash = 4, bronze = 2, iron = 3, steel = 4, mithril = 5, dragon = 6;
      ;

      /* Weapon Structure */

      typedef struct weapons
      int dagger = 2, sword = 3, axe = 4, mace = 5, bow = 3, arrows = 2;
      weapons;

      /* Spell Structure */

      typedef struct spells
      int fire = 4, frost = 6, dark = 8, chaos = 10;
      spells;


      /* Character Structure */

      typedef struct character
      string name;
      int health = 100, mana = 100, strength, stamina, intellect, weaponAttack, spellAttack, souls = 0;
      spells spell;
      weapons weapon;
      materials material;
      character;

      /* Function Declaration */

      character characterCreation(string name);
      void printInfo(character createChar);

      /* Main Function */

      int main()
      string characterName;
      cout << "Please input character name: ";
      cin >> characterName;

      srand(time(NULL));
      character player = characterCreation(characterName);
      printInfo(player);

      system("pause");
      return 0;


      /* Function Definition */

      character characterCreation(string name)
      character createChar;
      createChar.name = name;
      createChar.strength = rand() % 5 + 5;
      createChar.stamina = rand() % 5 + 5;
      createChar.intellect = rand() % 5 + 5;
      createChar.health += 2 * createChar.stamina;
      createChar.mana += 3 * createChar.intellect;
      createChar.weaponAttack = (createChar.weapon.dagger * createChar.material.bronze) + (2 * createChar.strength);
      createChar.spellAttack = (createChar.spell.fire + (createChar.intellect * 2));
      return createChar;


      void printInfo(character createChar)
      cout << createChar.name << endl;
      cout << createChar.health << endl;
      cout << createChar.mana << endl;
      cout << createChar.strength << endl;
      cout << createChar.stamina << endl;
      cout << createChar.intellect << endl;
      cout << createChar.weaponAttack << endl;
      cout << createChar.spellAttack << endl;
      cout << createChar.souls << endl;










      share|improve this question









      New contributor




      Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      I'm working on a simple text based adventure game. I've just finished working on the character creation portion. The code works perfectly fine when run, but I would just like to get some feedback to ensure that it checks off from a professional and efficient standpoint.



      The values of the materials, weapons, and spells are representing the amount of damage points each does for further and future calculations with the characters stats later in the game.



      The code itself essentially allows you to input a characters name. Then, the strength, stamina, and intellect is randomly generated so that your character build is different at the beginning of each game. Then, once that has finished, the code takes into account the weapon type, the material of the weapon, the spell type and adds additional damage based on the players stats.



      I would just like to know if there is a better way of writing my code to make it look cleaner, or if there possibly any concerns that might cause me issues down the road when I add more functionality to the game. Seeing as I am a beginner to C++, I am not incredibly great at determining whether my code is optimal or not.



      #include <iostream>
      #include <string>
      #include <ctime>

      using namespace std;

      /* Materials Structure */

      typedef struct materials
      int wood = 1, oak = 2, maple = 3, ash = 4, bronze = 2, iron = 3, steel = 4, mithril = 5, dragon = 6;
      ;

      /* Weapon Structure */

      typedef struct weapons
      int dagger = 2, sword = 3, axe = 4, mace = 5, bow = 3, arrows = 2;
      weapons;

      /* Spell Structure */

      typedef struct spells
      int fire = 4, frost = 6, dark = 8, chaos = 10;
      spells;


      /* Character Structure */

      typedef struct character
      string name;
      int health = 100, mana = 100, strength, stamina, intellect, weaponAttack, spellAttack, souls = 0;
      spells spell;
      weapons weapon;
      materials material;
      character;

      /* Function Declaration */

      character characterCreation(string name);
      void printInfo(character createChar);

      /* Main Function */

      int main()
      string characterName;
      cout << "Please input character name: ";
      cin >> characterName;

      srand(time(NULL));
      character player = characterCreation(characterName);
      printInfo(player);

      system("pause");
      return 0;


      /* Function Definition */

      character characterCreation(string name)
      character createChar;
      createChar.name = name;
      createChar.strength = rand() % 5 + 5;
      createChar.stamina = rand() % 5 + 5;
      createChar.intellect = rand() % 5 + 5;
      createChar.health += 2 * createChar.stamina;
      createChar.mana += 3 * createChar.intellect;
      createChar.weaponAttack = (createChar.weapon.dagger * createChar.material.bronze) + (2 * createChar.strength);
      createChar.spellAttack = (createChar.spell.fire + (createChar.intellect * 2));
      return createChar;


      void printInfo(character createChar)
      cout << createChar.name << endl;
      cout << createChar.health << endl;
      cout << createChar.mana << endl;
      cout << createChar.strength << endl;
      cout << createChar.stamina << endl;
      cout << createChar.intellect << endl;
      cout << createChar.weaponAttack << endl;
      cout << createChar.spellAttack << endl;
      cout << createChar.souls << endl;







      c++ beginner game adventure-game






      share|improve this question









      New contributor




      Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 13 mins ago







      Justin













      New contributor




      Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 3 hours ago









      JustinJustin

      162




      162




      New contributor




      Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          1 Answer
          1






          active

          oldest

          votes


















          2












          $begingroup$

          It's extremely unclear what you're asking (or whether your post might just be a troll post), so expect it to get closed shortly.




          typedef struct weapons 
          int dagger = 2, sword = 3, axe = 4, mace = 5, bow = 3, arrows = 2;
          weapons;


          The typedef struct X ... X; pattern is a C-ism; in C++ you don't need the typedef and can just write struct X ... ;.



          You're creating a struct type named weapons with a bunch of per-instance member variables. This is almost certainly not what you meant to do. Probably what you meant was



          enum class Weapon 
          dagger = 2,
          sword = 3,
          axe = 4,
          mace = 5,
          ;


          so that you could later write



          Weapon w = Weapon::sword;
          if (w == Weapon::axe) ...


          What you actually wrote, unfortunately, is simply nonsense.




          character characterCreation(string name);


          Look up the C++ notion of "constructors" (and also destructors). What you have here would normally be spelled something like



          Character::Character(const std::string& name) 
          this->name = name;
          this->strength = rand() % 5 + 5;



          and so on.



          Also consider writing yourself a helper function



          int randint(int lo, int hi) 
          return rand() % (hi - lo) + lo;



          so that you can write simply



           this->strength = randint(5, 10);


          Ninety percent of what we call "programming" is just finding sources of repetition and eliminating them.






          share|improve this answer









          $endgroup$












          • $begingroup$
            I apologize, I should have clarified what my code is doing and what my expectations were. My post is not a troll, I prefer not to waste peoples time if I do not have to. I will make edits to the question. The numbers on the materials, weapons, and spells simply represent the amount of damage.
            $endgroup$
            – Justin
            47 mins ago











          • $begingroup$
            Thank you for the insight and helpful post though. I will take a look at more constructors and destructors. I used the struct with the hopes that I would be able to create a large combination of different weapon types/spells, being that my class has only just begun using structs I am not too familiar with constructors/destructors.
            $endgroup$
            – Justin
            27 mins ago











          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Justin is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215542%2fadventure-game-text-based-in-c%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2












          $begingroup$

          It's extremely unclear what you're asking (or whether your post might just be a troll post), so expect it to get closed shortly.




          typedef struct weapons 
          int dagger = 2, sword = 3, axe = 4, mace = 5, bow = 3, arrows = 2;
          weapons;


          The typedef struct X ... X; pattern is a C-ism; in C++ you don't need the typedef and can just write struct X ... ;.



          You're creating a struct type named weapons with a bunch of per-instance member variables. This is almost certainly not what you meant to do. Probably what you meant was



          enum class Weapon 
          dagger = 2,
          sword = 3,
          axe = 4,
          mace = 5,
          ;


          so that you could later write



          Weapon w = Weapon::sword;
          if (w == Weapon::axe) ...


          What you actually wrote, unfortunately, is simply nonsense.




          character characterCreation(string name);


          Look up the C++ notion of "constructors" (and also destructors). What you have here would normally be spelled something like



          Character::Character(const std::string& name) 
          this->name = name;
          this->strength = rand() % 5 + 5;



          and so on.



          Also consider writing yourself a helper function



          int randint(int lo, int hi) 
          return rand() % (hi - lo) + lo;



          so that you can write simply



           this->strength = randint(5, 10);


          Ninety percent of what we call "programming" is just finding sources of repetition and eliminating them.






          share|improve this answer









          $endgroup$












          • $begingroup$
            I apologize, I should have clarified what my code is doing and what my expectations were. My post is not a troll, I prefer not to waste peoples time if I do not have to. I will make edits to the question. The numbers on the materials, weapons, and spells simply represent the amount of damage.
            $endgroup$
            – Justin
            47 mins ago











          • $begingroup$
            Thank you for the insight and helpful post though. I will take a look at more constructors and destructors. I used the struct with the hopes that I would be able to create a large combination of different weapon types/spells, being that my class has only just begun using structs I am not too familiar with constructors/destructors.
            $endgroup$
            – Justin
            27 mins ago
















          2












          $begingroup$

          It's extremely unclear what you're asking (or whether your post might just be a troll post), so expect it to get closed shortly.




          typedef struct weapons 
          int dagger = 2, sword = 3, axe = 4, mace = 5, bow = 3, arrows = 2;
          weapons;


          The typedef struct X ... X; pattern is a C-ism; in C++ you don't need the typedef and can just write struct X ... ;.



          You're creating a struct type named weapons with a bunch of per-instance member variables. This is almost certainly not what you meant to do. Probably what you meant was



          enum class Weapon 
          dagger = 2,
          sword = 3,
          axe = 4,
          mace = 5,
          ;


          so that you could later write



          Weapon w = Weapon::sword;
          if (w == Weapon::axe) ...


          What you actually wrote, unfortunately, is simply nonsense.




          character characterCreation(string name);


          Look up the C++ notion of "constructors" (and also destructors). What you have here would normally be spelled something like



          Character::Character(const std::string& name) 
          this->name = name;
          this->strength = rand() % 5 + 5;



          and so on.



          Also consider writing yourself a helper function



          int randint(int lo, int hi) 
          return rand() % (hi - lo) + lo;



          so that you can write simply



           this->strength = randint(5, 10);


          Ninety percent of what we call "programming" is just finding sources of repetition and eliminating them.






          share|improve this answer









          $endgroup$












          • $begingroup$
            I apologize, I should have clarified what my code is doing and what my expectations were. My post is not a troll, I prefer not to waste peoples time if I do not have to. I will make edits to the question. The numbers on the materials, weapons, and spells simply represent the amount of damage.
            $endgroup$
            – Justin
            47 mins ago











          • $begingroup$
            Thank you for the insight and helpful post though. I will take a look at more constructors and destructors. I used the struct with the hopes that I would be able to create a large combination of different weapon types/spells, being that my class has only just begun using structs I am not too familiar with constructors/destructors.
            $endgroup$
            – Justin
            27 mins ago














          2












          2








          2





          $begingroup$

          It's extremely unclear what you're asking (or whether your post might just be a troll post), so expect it to get closed shortly.




          typedef struct weapons 
          int dagger = 2, sword = 3, axe = 4, mace = 5, bow = 3, arrows = 2;
          weapons;


          The typedef struct X ... X; pattern is a C-ism; in C++ you don't need the typedef and can just write struct X ... ;.



          You're creating a struct type named weapons with a bunch of per-instance member variables. This is almost certainly not what you meant to do. Probably what you meant was



          enum class Weapon 
          dagger = 2,
          sword = 3,
          axe = 4,
          mace = 5,
          ;


          so that you could later write



          Weapon w = Weapon::sword;
          if (w == Weapon::axe) ...


          What you actually wrote, unfortunately, is simply nonsense.




          character characterCreation(string name);


          Look up the C++ notion of "constructors" (and also destructors). What you have here would normally be spelled something like



          Character::Character(const std::string& name) 
          this->name = name;
          this->strength = rand() % 5 + 5;



          and so on.



          Also consider writing yourself a helper function



          int randint(int lo, int hi) 
          return rand() % (hi - lo) + lo;



          so that you can write simply



           this->strength = randint(5, 10);


          Ninety percent of what we call "programming" is just finding sources of repetition and eliminating them.






          share|improve this answer









          $endgroup$



          It's extremely unclear what you're asking (or whether your post might just be a troll post), so expect it to get closed shortly.




          typedef struct weapons 
          int dagger = 2, sword = 3, axe = 4, mace = 5, bow = 3, arrows = 2;
          weapons;


          The typedef struct X ... X; pattern is a C-ism; in C++ you don't need the typedef and can just write struct X ... ;.



          You're creating a struct type named weapons with a bunch of per-instance member variables. This is almost certainly not what you meant to do. Probably what you meant was



          enum class Weapon 
          dagger = 2,
          sword = 3,
          axe = 4,
          mace = 5,
          ;


          so that you could later write



          Weapon w = Weapon::sword;
          if (w == Weapon::axe) ...


          What you actually wrote, unfortunately, is simply nonsense.




          character characterCreation(string name);


          Look up the C++ notion of "constructors" (and also destructors). What you have here would normally be spelled something like



          Character::Character(const std::string& name) 
          this->name = name;
          this->strength = rand() % 5 + 5;



          and so on.



          Also consider writing yourself a helper function



          int randint(int lo, int hi) 
          return rand() % (hi - lo) + lo;



          so that you can write simply



           this->strength = randint(5, 10);


          Ninety percent of what we call "programming" is just finding sources of repetition and eliminating them.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 hours ago









          QuuxplusoneQuuxplusone

          12.5k12061




          12.5k12061











          • $begingroup$
            I apologize, I should have clarified what my code is doing and what my expectations were. My post is not a troll, I prefer not to waste peoples time if I do not have to. I will make edits to the question. The numbers on the materials, weapons, and spells simply represent the amount of damage.
            $endgroup$
            – Justin
            47 mins ago











          • $begingroup$
            Thank you for the insight and helpful post though. I will take a look at more constructors and destructors. I used the struct with the hopes that I would be able to create a large combination of different weapon types/spells, being that my class has only just begun using structs I am not too familiar with constructors/destructors.
            $endgroup$
            – Justin
            27 mins ago

















          • $begingroup$
            I apologize, I should have clarified what my code is doing and what my expectations were. My post is not a troll, I prefer not to waste peoples time if I do not have to. I will make edits to the question. The numbers on the materials, weapons, and spells simply represent the amount of damage.
            $endgroup$
            – Justin
            47 mins ago











          • $begingroup$
            Thank you for the insight and helpful post though. I will take a look at more constructors and destructors. I used the struct with the hopes that I would be able to create a large combination of different weapon types/spells, being that my class has only just begun using structs I am not too familiar with constructors/destructors.
            $endgroup$
            – Justin
            27 mins ago
















          $begingroup$
          I apologize, I should have clarified what my code is doing and what my expectations were. My post is not a troll, I prefer not to waste peoples time if I do not have to. I will make edits to the question. The numbers on the materials, weapons, and spells simply represent the amount of damage.
          $endgroup$
          – Justin
          47 mins ago





          $begingroup$
          I apologize, I should have clarified what my code is doing and what my expectations were. My post is not a troll, I prefer not to waste peoples time if I do not have to. I will make edits to the question. The numbers on the materials, weapons, and spells simply represent the amount of damage.
          $endgroup$
          – Justin
          47 mins ago













          $begingroup$
          Thank you for the insight and helpful post though. I will take a look at more constructors and destructors. I used the struct with the hopes that I would be able to create a large combination of different weapon types/spells, being that my class has only just begun using structs I am not too familiar with constructors/destructors.
          $endgroup$
          – Justin
          27 mins ago





          $begingroup$
          Thank you for the insight and helpful post though. I will take a look at more constructors and destructors. I used the struct with the hopes that I would be able to create a large combination of different weapon types/spells, being that my class has only just begun using structs I am not too familiar with constructors/destructors.
          $endgroup$
          – Justin
          27 mins ago











          Justin is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          Justin is a new contributor. Be nice, and check out our Code of Conduct.












          Justin is a new contributor. Be nice, and check out our Code of Conduct.











          Justin is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215542%2fadventure-game-text-based-in-c%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

          Prove that NP is closed under karp reduction?Space(n) not closed under Karp reductions - what about NTime(n)?Class P is closed under rotation?Prove or disprove that $NL$ is closed under polynomial many-one reductions$mathbfNC_2$ is closed under log-space reductionOn Karp reductionwhen can I know if a class (complexity) is closed under reduction (cook/karp)Check if class $PSPACE$ is closed under polyonomially space reductionIs NPSPACE also closed under polynomial-time reduction and under log-space reduction?Prove PSPACE is closed under complement?Prove PSPACE is closed under union?

          Is my guitar’s action too high? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Strings too stiff on a recently purchased acoustic guitar | Cort AD880CEIs the action of my guitar really high?Μy little finger is too weak to play guitarWith guitar, how long should I give my fingers to strengthen / callous?When playing a fret the guitar sounds mutedPlaying (Barre) chords up the guitar neckI think my guitar strings are wound too tight and I can't play barre chordsF barre chord on an SG guitarHow to find to the right strings of a barre chord by feel?High action on higher fret on my steel acoustic guitar