1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

what do you think of the first part of my code?

Discussion in 'C++' started by cpulocksmith, Dec 22, 2008.

  1. cpulocksmith

    cpulocksmith New Member

    Joined:
    Jul 23, 2008
    Messages:
    289
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    student
    Location:
    canada
    well i have spent some time tinkering on this damn thing and i think i have the stats gen ready(well ready enough) i will post the code and i would like to know what you think of it. bear in mind that this is not a finished version, i plan on adding some stuff and making it prettier but these are the basic guts of it. please tell me what you think.

    Code:
    #include <cstdlib> 
    #include <ctime> 
    #include <iostream>
    
    using namespace std;
    
    
    int pick_skills;//makes the little loop go to pick anuther skill
    int skills_add;//the skill you pick to put points in
    int weapon_magic;//the plus from an enchantment ex. +1 or +2
    int sword_attack;//<attack adds>
    int blunt_attack;
    int ranged_attack;
    int thrown_attack;
    int unarmed_attack;//</attack adds>
    int listen=0;//<skills>
    int spot=0;
    int search=0;
    int blades=0;
    int blunt_weapons=0;
    int ranged=0;
    int thrown=0;
    int unarmed=0;
    int arcana=0;//</skills>
    int base_attack;//your base attack bounus
    int level=1;// your current level
    int xp;//how much xp you currently have
    int xp_needed=500;
    int armor_rating=0;//how strong the armor you are wearing is 0 == no armor
    string racename;//name of the race you are
    int dexmod;//dex modifier
    int strmod;//str modifier
    int intelmod;//intel modifier
    int wismod;//wis modifier
    int chamod;//cha modifier
    int conmod;//con modifier
    int hd;//hit dice
    int str;//strength
    int dex;//dextarity
    int con;//constition
    int intel;//intelegance
    int wis;//wisdom
    int cha;//charisma
    int hp;//health
    int ac;//armor
    string name;//your name
    char reroll;//if you will reroll your base stats
    int race;//to chose what race you are
    int skills;//how many skillpoints you have
    int feats=1;//how many feats you have to pick
    
    
    int main() 
    { 
        srand((unsigned)time(0));//thing that makes a random nuber work
    cout<<"to use my damn menu system, when ever you see a number beside an option...enter the number... not the opiton..."<<endl;
    cout<<"welcome to the char generator mark I"<<endl<<"would you please enter your name"<<endl;
    cin>>name;
    cout<<endl<<"thanks you"<<endl<<endl;
    cout<<"your stats are as followed"<<endl<<"*************************"<<endl;
    
    do{
    str = (rand()%15)+3;//<stats are started>
    dex = (rand()%15)+3;
    intel = (rand()%15)+3;
    wis = (rand()%15)+3;
    cha = (rand()%15)+3;
    con = (rand()%15)+3;//</stats end>
    	 
    cout<<"str-"<<str<<endl; 
    cout<<"dex-"<<dex<<endl;
    cout<<"con-"<<con<<endl;
    cout<<"int-"<<intel<<endl;
    cout<<"wis-"<<wis<<endl;
    cout<<"cha-"<<cha<<endl<<endl;
    cout<<"would you like you reroll?"<<endl;
    cin>>reroll;
    }while(reroll == 'y');
    cout<<endl<<endl<<"you must now select a race"<<endl<<endl;
    cout<<"1) human"<<endl<<"2) elf"<<endl<<"3) dwarf"<<endl<<"4) half-orc"<<endl<<"5) gnome"<<endl<<"6) halfling"<<endl<<"witch would you like to be? "<<endl;
    cin>>race;//must be one of the above races
    if (race == 1){
    racename = "human" ;
    }
    if (race == 2){
    racename = "elf";
    }
    if (race == 3){
    racename = "dwarf";
    }
    if (race == 4){
    racename = "half-orc";
    }
    if (race == 5){
    racename = "gnome";
    }
    if (race == 6){
    racename = "halfling";
    }
    
    if (race == 1){//human
    skills = 15;
    feats = feats + 1;//gets one more feat
    hd = 4;
    base_attack=0;
    }
    if (race == 2){//elf
    dex = dex + 2;
    wis = wis + 2;
    hd = 4;
    skills = 15;
    base_attack=0;
    }
    
    if (race == 3){//dwarf
    str = str + 2;
    dex = dex - 2;
    con = con + 2;
    hd = 6;
    skills = 5;
    base_attack=1;
    }
    if (race == 4){//half orc
    str = str + 3;
    intel = intel - 3;
    dex = dex -2;
    cha = cha - 2;
    hd = 8;
    skills = 5;
    base_attack=2;
    }
    if (race == 5){//gnome
    intel = intel + 2;
    str = str - 2;
    hd = 3;
    skills = 10;
    base_attack=-1;
    }
    if (race == 6){//halfling
    str = str - 2;
    dex = dex + 2;
    hd = 4;
    skills = 15;
    base_attack=-1;
    }
    
    do{
    cout<<"you have "<<skills<<" points to place, witch skills would you like to put them in?"<<endl<<endl;
    
    cout<<"1) listen "<<endl;
    cout<<"2) spot "<<endl;
    cout<<"3) search "<<endl;
    cout<<"4) blades "<<endl;
    cout<<"5) blunt weapons "<<endl;
    cout<<"6) ranged weapons "<<endl;
    cout<<"7) thrown weapons "<<endl;
    cout<<"8) unarmed(cqc) "<<endl;
    cout<<"9) arcana "<<endl<<endl;
    cin>>skills_add;
    
    if (skills_add == 1){
    skills = skills - 1;
    listen = listen + 1;
    }
    if (skills_add == 2){
    skills = skills - 1;
    spot =spot + 1;
    }
    if (skills_add == 3){
    skills = skills - 1;
    search = search + 1;
    }
    if (skills_add == 4){
    skills = skills - 1;
    blades = blades + 1;
    }
    if (skills_add == 5){
    skills = skills - 1;
    blunt_weapons = blunt_weapons +1;
    }
    if (skills_add == 6){
    skills = skills - 1;
    ranged = ranged + 1;
    }
    if (skills_add == 7){
    skills = skills - 1;
    thrown = thrown + 1;
    }
    if (skills_add == 8){
    skills = skills - 1;
    unarmed = unarmed + 1;
    }
    if (skills_add == 9){
    skills = skills - 1;
    arcana = arcana + 1;
    }
    
     }while (skills > 0);
    strmod = (str - 10) / 2;
    dexmod = (dex - 10) / 2;
    conmod = (con - 10) / 2;
    intelmod = (intel - 10) / 2;
    wismod = (wis - 10) / 2;
    chamod = (cha - 10) / 2;
    
    hp=hd + conmod;
    ac=armor_rating + dexmod + 10;
    base_attack=(base_attack + strmod) + weapon_magic;
    sword_attack=base_attack + blades;
    blunt_attack=base_attack + blunt_weapons;
    ranged_attack=base_attack + ranged;
    thrown_attack=base_attack + thrown;
    unarmed_attack=base_attack + unarmed;
     
    cout<<endl<<endl<<endl<<"you are "<<name<<" the"<<" level "<<level<<" "<<racename<<endl;
    cout<<"****************"<<endl;
    cout<<"HP = "<<hp<<endl;
    cout<<"AC = "<<ac<<endl;
    cout<<"base attack ="<<base_attack<<endl;
    cout<<"str ="<<str<<"= "<<strmod<<endl; 
    cout<<"dex ="<<dex<<"= "<<dexmod<<endl;
    cout<<"con ="<<con<<"= "<<conmod<<endl;
    cout<<"int ="<<intel<<"= "<<intelmod<<endl;
    cout<<"wis ="<<wis<<"= "<<wismod<<endl;
    cout<<"cha ="<<cha<<"= "<<chamod<<endl;
    cout<<"***************"<<endl; 
    
    cout<<"++skills++"<<endl;
    cout<<"1) listen= "<<listen<<endl;
    cout<<"2) spot= "<<spot<<endl;
    cout<<"3) search= "<<search<<endl;
    cout<<"4) blades= "<<blades<<endl;
    cout<<"5) blunt weapons= "<<blunt_weapons<<endl;
    cout<<"6) ranged weapons= "<<ranged<<endl;
    cout<<"7) thrown weapons= "<<thrown<<endl;
    cout<<"8) unarmed= "<<unarmed<<endl;
    cout<<"9) arcana= "<<arcana<<endl;
    }
    
     
    Last edited: Dec 22, 2008
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    If you have only main function then why do you want to have Global Variables?
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Watch all those uninitialised variables; initialise them to zero unless you have a jolly good reason for letting them default to any old crap. YES as long as they're global you can expect the compiler to do that for you, but as soon as you move one of them into a function its initial value becomes undetermined and the behaviour of any code that depends on it becomes unpredictable.

    Good start. Use functions; what you've got so far would makes a reasonably good initialise function although could be broken down further. One example of where you could use a function is where you initialise all the skills and adjust them according to race; if you select the race first then you can generate the skills in a function using the race-specific strengths/weaknesses as parameters.

    Try to make main() document the overall flow of the program. e.g.:
    Code:
    int main()
    {
      init(); // initialise everything
      game_load(); // load game from disk?
      // Main game loop
      while (1)
      {
        explain_point(); // display stuff about where the player is
        if (!player_move())
          break; // if player_move() returns zero the game ends
      }
      return 0;
    }
    
    You can use ++ and -- instead of x=x+1 or x=x-1.

    The skills part could use a switch to improve readability:
    Code:
    do {
    cout<<1,2,3... // pseudocode
    cin>>skills_add;
    switch (skills_add)
    {
    case 1: listen++; break;
    case 2: spot++; break;
    //etc
    default: // don't forget a default clause in the switches
      break;
    }
    skills--;
    }while (skills > 0);
    
    Question: can you have multiple skill points, e.g. 3 listen points and 2 spot points, or are listen,spot etc yes/no flags? If you can then it should be made clearer to the player. If you can't then it'd be nice to remove from the menu anything the user already has and throw an error if they duplicate a skill.
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Watch all those uninitialised variables; initialise them to zero unless you have a jolly good reason for letting them default to any old crap. YES as long as they're global you can expect the compiler to do that for you, but as soon as you move one of them into a function its initial value becomes undetermined and the behaviour of any code that depends on it becomes unpredictable.

    Good start. Use functions; what you've got so far would makes a reasonably good initialise function although could be broken down further. One example of where you could use a function is where you initialise all the skills and adjust them according to race; if you select the race first then you can generate the skills in a function using the race-specific strengths/weaknesses as parameters.

    Try to make main() document the overall flow of the program. e.g.:
    Code:
    int main()
    {
      init(); // initialise everything
      game_load(); // load game from disk?
      // Main game loop
      while (1)
      {
        explain_point(); // display stuff about where the player is
        if (!player_move())
          break; // if player_move() returns zero the game ends
      }
      return 0;
    }
    
    You can use ++ and -- instead of x=x+1 or x=x-1.

    The skills part could use a switch to improve readability:
    Code:
    do {
    cout<<1,2,3... // pseudocode
    cin>>skills_add;
    switch (skills_add)
    {
    case 1: listen++; break;
    case 2: spot++; break;
    //etc
    default: // don't forget a default clause in the switches
      break;
    }
    skills--;
    }while (skills > 0);
    
    Question: can you have multiple skill points, e.g. 3 listen points and 2 spot points, or are listen,spot etc yes/no flags? If you can then it should be made clearer to the player. If you can't then it'd be nice to remove from the menu anything the user already has and throw an error if they duplicate a skill.
     
  5. cpulocksmith

    cpulocksmith New Member

    Joined:
    Jul 23, 2008
    Messages:
    289
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    student
    Location:
    canada
    thanks for the input i will check out the stuff you told me i should change or add, and as far as explaning more about things such as if you can have multiple skills, i plan on doing that but thi is only an ugly test. so i guess i will get to fixing that up, thanks.^^
     

Share This Page