My Game isn't working...

This is a discussion on My Game isn't working... within the C++ Programming forums, part of the General Programming Boards category; Hey, I'm working on a Samurai Fighting Game for my Online C++ Class, this is a unfinished source code but ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    2

    My Game isn't working...

    Hey, I'm working on a Samurai Fighting Game for my Online C++ Class, this is a unfinished source code but for some reason when I try to do combat it messes up. Try running my code please and help me out, I don't want to go way ahead without fixing this first.

    Code:
    // Final Project
    // 'Way of the Samurai'
    // Version 1.0
    // By Dillan Cobb
    // 11-27-2007
    // -----------------------------------------------------------------------------
    
    // Includes
    #include<iostream>
    #include<cctype>
    using namespace std;
    // -----------------------------------------------------------------------------
    
    // Variables
    // Stats
    int strength;
    int dexterity;
    int health;
    int maxhealth;
    int yen;
    int experience;
    int maxexperience;
    int level;
    char rank;
    char stat;
    char fighthelpfight;
    char retryfighthelp;
    // Areas
    void menu();
    void storyline();
    void storylinetwo();
    void tutorial();
    void fighthelp();
    // Enemys
    void enemybinds();
    // Enemy Stats
    // Lord Niwazuka Tsunori
    int lntstr;
    int lntdex;
    int lnthp;
    int lntmhp;
    // Samurai Adept
    int sastr;
    int sadex;
    int sahp;
    int samhp;
    // Samurai
    int sstr;
    int sdex;
    int shp;
    int smhp;
    // Samurai Veteran
    int svstr;
    int svdex;
    int svhp;
    int svmhp;
    // Guard
    int gstr;
    int gdex;
    int ghp;
    int gmhp;
    // Geisha
    int gastr;
    int gadex;
    int gahp;
    int gamhp;
    // Samurai Captian
    int scstr;
    int scdex;
    int schp;
    int scmhp;
    // Samurai Captain Veteran
    int scvstr;
    int scvdex;
    int scvhp;
    int scvmhp;
    // Shogun
    int snstr;
    int sndex;
    int snhp;
    int snmhp;
    // Emperor
    int estr;
    int edex;
    int ehp;
    int emhp;
    // Clan Leader
    int clstr;
    int cldex;
    int clhp;
    int clmhp;
    // Lord Niwazuka Tsunori Boss
    int bstr;
    int bdex;
    int bhp;
    int bmhp;
    // -----------------------------------------------------------------------------
    
    // Main Function
    int main()
    {
        system("cls");
        strength = 6;
        dexterity = 4;
        health = 20;
        maxhealth = 20;
        yen = 50;
        experience = 0;
        maxexperience = 35;
        level = 1;
        menu();
        storyline();
        storylinetwo();
        tutorial();
        // enemy stats
        // Lord Niwazuka Tsunori
        lntstr = 3;
        lntdex = 5;
        lnthp = 10;
        lntmhp = 10;
        // Samurai Adept
        sastr = 4;
        sadex = 3;
        sahp = 7;
        samhp = 7;
        // Samurai
        sstr = 5;
        sdex = 4;
        shp = 16;
        smhp = 16;
        // Samurai Veteran
        svstr = 6;
        svdex = 6;
        svhp = 19;
        svmhp = 19;
        // Guard
        gstr = 3;
        gdex = 2;
        ghp = 21;
        gmhp = 21;
        // Geisha
        gastr = 4;
        gadex = 7;
        gahp = 27;
        gamhp = 27;
        // Samurai Captian
        scstr = 9;
        scdex = 8;
        schp = 26;
        scmhp = 26;
        // Samurai Captain Veteran
        scvstr = 9;
        scvdex = 10;
        scvhp = 30;
        scvmhp = 30;
        // Shogun
        snstr = 11;
        sndex = 10;
        snhp = 38;
        snmhp = 38;
        // Emperor
        estr = 4;
        edex = 14;
        ehp = 43;
        emhp = 43;
        // Clan Leader
        clstr = 13;
        cldex = 14;
        clhp = 41;
        clmhp = 41;
        // Lord Niwazuka Tsunori Boss
        bstr = 16;
        bdex = 18;
        bhp = 73;
        bmhp = 73;
    }
    // -----------------------------------------------------------------------------
    
    // Void Main
    void menu()
    {
         system("cls");
         cout<<"\t\t\t The Way of the Samuria \n";
         cout<<"\t\t Fictional Japanese Samuria Game by Dillan Cobb \n";
         cout<<"\t\t Note: Game commands are Case Sensitive! \n";
         system("Pause");
         return;
    }
    // -----------------------------------------------------------------------------
    
    // Void Storyline
    void storyline()
    {
         system("cls");
         cout<<"\t In the chaotic days of earlier Japan known as the Muromachi      \n";
         cout<<"Period, when independant states were scattered along the Empire at  \n";
         cout<<"constant war. You are a young Samurai named Mokumada Tsunazo, under \n";
         cout<<"training of the Lord Niwazuka Tsunori, a powerful Samurai leader of \n";
         cout<<"the Tsunori Clan. Nearing the end of your training your dojo is     \n";
         cout<<"viciously attacked by your rival clan, Osuke Clan led by Kawatsuki  \n";
         cout<<"Osuke - another fearless and powerful leader. Unlike the Tsunori    \n";
         cout<<"Clan, the Osuke Clan did not fight for the Emperor Chokei, Monarch  \n";
         cout<<"of the Southern Court. In these darkened days of war and chaotic    \n";
         cout<<"hell, how will your destiny unfold?                                 \n";
         system("pause");
         return;
    }
    // -----------------------------------------------------------------------------
    
    // Void Storylinetwo
    void storylinetwo()
    {
     system("cls");
     cout<<"                                                                        "<<'\n';
     cout<<"           /\\                  Present Day Nagasaki Japan              "<<'\n';
     cout<<"          /++\\                    1379 - Muromachi Period              "<<'\n';
     cout<<"         /++++\\                      Tsunori Clan Dojo                 "<<'\n';
     cout<<"        /+|''|+\\                                                       "<<'\n';
     cout<<"       /++|__|++\\                                                      "<<'\n';
     cout<<"     ''==========''                                                     "<<'\n';
     cout<<"       /|===|===|\\                                                     "<<'\n';
     cout<<"      /+|===|===|+\\                                                    "<<'\n';
     cout<<"     /++|==o|o==|++\\                                                   "<<'\n';
     cout<<"    /+++|===|===|+++\\                                                  "<<'\n';
     cout<<"  ''=================''                                                 "<<'\n';
     cout<<"    /+++|===|===|+++\\                                                  "<<'\n';
     cout<<"   /|+++|==o|o==|+++|\\                                                 "<<'\n';
     cout<<"  / |+++|===|===|+++| \\                                                "<<'\n';
     cout<<"'''|''|''|_____|''|''|'''                                               "<<'\n';
     cout<<"   |__|__|_____|__|__|                                                  "<<'\n';
     cout<<"...|..|..|_____|..|..|...                                               "<<'\n';
     cout<<".........OOOOOOO.........                                               "<<'\n';
     cout<<".........OOOOOOO.........                                               "<<'\n';
     cout<<".........OOOOOOO.........                                               "<<'\n';
     system("pause");
     return;
    }
    // -----------------------------------------------------------------------------
         
    // Void Tutorial
    void tutorial()
    {
         system("cls");
         cout<<"Lord Tsunori: Mokumada, you must parry! You do know I'm quicker    \n";
         cout<<"              then you don't you? Parry, Slice! Comon!              \n";
         cout<<"Mokumada: Sorry my lord, hiya!                                        \n";
         cout<<"[You are about to enter combat!]\n";
         cout<<"\n";
         cout<<"   @      +#'\n";
         cout<<"  @       ##+:\n";
         cout<<"  @       ###;\n";
         cout<<"  @        ##+\n";
         cout<<"  @       ######\n";
         cout<<"   @     ########\n";
         cout<<"   #    +#########+\n";
         cout<<"    #+##+##########+\n";
         cout<<"     #+++ ##### ###\n";
         cout<<"          ####  #\n";
         cout<<"          #@####\n";
         cout<<"         #######\n";
         cout<<"        ########\n";
         cout<<"       +##@#####\n";
         cout<<"      +#########\n";
         cout<<"      +#########\n";
         cout<<"      +#########\n";
         cout<<"      +#########\n";
         cout<<"      #########\n";
         system("pause");
         fighthelp();
    }
    // -----------------------------------------------------------------------------
    
    // Void fighthelp
    void fighthelp()
    {
         system("cls");
         cout<<"[You have encountered: Lord Niwazuka Tsunori!] \n";
         cout<<"Lord Tsunori's Health: "<<lnthp<<" / "<<lntmhp<<"\n"<<endl;
         cout<<"Your Health: "<<health<<" / "<<maxhealth<<"\n"<<endl;
         cout<<"[T]hrust Attack\n";
         cout<<"[S]lash Attack\n";
         cout<<"[P]arry Midway\n";
         cout<<"[D]efend\n";
         cin>>fighthelpfight;
         if(fighthelpfight == 'T')
         {
                           cout<<"[You attempt to Thrust the enemy.]\n";
                           if(lntdex > dexterity)
                           {
                                     cout<<"[As you attempt to Thrust, enemy quickly slices you.]\n";
                                     health = health - lntstr;
                                     cout<<"[You have taken "<<lntstr<<" damage!]\n";
                                     system("pause");
                                     fighthelp();
                           }
                           if(lntdex < dexterity)
                           {
                                     cout<<"[You Thrust the enemy.]\n";
                                     lnthp = lnthp - strength;
                                     cout<<"[You deal "<<strength<<" damage!]\n";
                                     system("pause");
                                     fighthelp();
                           }
                           system("pause");
         }
         if(fighthelpfight == 'S')
         {
                           cout<<"[You attempt to Slash the enemy.]\n";
                           if(lntdex > dexterity)
                           {
                                     cout<<"[As you attempt to Slash, enemy quickly Parry's your attack.]\n";
                                     if(lntstr > strength)
                                     {
                                               cout<<"[You fail to overpower the enemy.]\n";
                                               health = health - (lntstr - 1);
                                               cout<<"[You have taken "<<(lntstr - 1)<<" damage!]\n";
                                               system("pause");
                                               fighthelp();
                                     }
                                     if(lntstr < strength)
                                     {
                                               cout<<"[You overpower the enemy.]\n";
                                               lnthp = lnthp - (strength - 1);
                                               cout<<"[You deal "<<(strength - 1)<<" damage!]\n";
                                               system("pause");
                                               fighthelp();
                                     }
                                     system("pause");
                           }
                           if(lntdex < dexterity)
                           {
                                     cout<<"[You Slash the enemy.]\n";
                                     lnthp = lnthp - (strength + 1);
                                     cout<<"[You deal "<<(strength + 1)<<" damage!]\n";
                                     system("pause");
                                     fighthelp();
                           }
                           system("pause");
         }
         if(fighthelpfight == 'P')
         {
                           cout<<"[You attempt to Parry the enemy's attack.]\n";
                           if(lntdex > dexterity)
                           {
                                     cout<<"[As you attempt to Parry, enemy quickly slices you.]\n";
                                     health = health - (lntstr + 1);
                                     cout<<"[You have taken "<<(lntstr + 1)<<" damage!]\n";
                                     system("pause");
                                     fighthelp();
                           }
                           if(lntdex < dexterity)
                           {
                                     cout<<"[You parry the enemys attack.]\n";
                                     if(lntstr > strength)
                                     {
                                               cout<<"[The enemy overpowers you.]\n";
                                               health = health - (lntstr - 1);
                                               cout<<"[You have taken "<<(lntstr - 1)<<" damage!]\n";
                                               system("pause");
                                               fighthelp();
                                     }
                                     if(lntstr < strength)
                                     {
                                               cout<<"[You overpower the enemy.]\n";
                                               lnthp = lnthp - (strength + 1);
                                               cout<<"[You deal "<<(strength + 1)<<" damage.]\n";
                                               system("pause");
                                               fighthelp();
                                     }
                                     system("pause");
                           system("pause");
                           }
         if(fighthelpfight == 'D')
         {
                           cout<<"[You get into defensive stance.]\n";
                           cout<<"[The enemy attacks, but you deflect his strike.]\n";
                           system("pause");
                           fighthelp();
         }
         if(lnthp < 0)
         {
                           system("cls");
                           cout<<"[You have defeated your opponent.]\n";
                           experience = experience + 30;
                           if(maxexperience > 30)
                           {
                                            cout<<"[You have leveled up!]\n";
                                            maxhealth = maxhealth + 3;
                                            health = maxhealth;
                                            level = level + 1;
                                            cout<<"Select a Stat to add 1 point too.\n";
                                            cout<<"[S]trength\n";
                                            cout<<"[D]exterity\n";
                                            cin>>stat;
                                            if(stat == 'S')
                                            {
                                                    cout<<"[You gain more Strength.]\n";
                                                    strength = strength + 1;
                                                    system("pause");
                                                    return;
                                            }
                                            if(stat == 'D')
                                            {
                                                    cout<<"[You gain more Dexterity.]\n";
                                                    dexterity = dexterity + 1;
                                                    system("pause");
                                                    return;
                                            }
                                            system("pause");
                           system("pause");
                           return;
                           }
                           system("pause");
         system("pause");
         }
         if(health < 0)
         {
                   system("cls");
                   cout<<"[You have been defeated in combat.]\n";
                   cout<<"[Retry battle? Y/N]\n";
                   system("pause");
                   cin>>retryfighthelp;
                   if(retryfighthelp == 'Y')
                   {
                                     fighthelp();
                   }
                   if(retryfighthelp == 'N')
                   {
                                     return;
                   }
         }
         system("pause");
         }
    }

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Horrible, horrible, horrible! You might as well just use C!
    Don't use global variables and turn those freakin' variables into classes and you'll see the it's much better and more readable.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That is not C++. Aside from using cout and cin, it is just plain C. If I were to replace cout with the relevant puts, and cin with a scanf(), I bet it will compile immediately in gcc.

    You also have about a hundred [ok, not quite, but 48] global variables - you should avoid global variables. Also, they are typically what you would put in a class, and instantiate the differen variations of "player".

    Edit: Elysia expressed it a bit briefer and thus answered quicker...

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    Learn how to use classes and structs and maybe enums. You can keep your code clean and manage everything alot easier than what you are doing now.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    266
    use a struct, or create a 'characterplayer' class! and make an object, way cleaner and better!

    Code:
         cout<<"   @      +#'\n";
         cout<<"  @       ##+:\n";
         cout<<"  @       ###;\n";
         cout<<"  @        ##+\n";
         cout<<"  @       ######\n";
         cout<<"   @     ########\n";
         cout<<"   #    +#########+\n";
         cout<<"    #+##+##########+\n";
         cout<<"     #+++ ##### ###\n";
         cout<<"          ####  #\n";
         cout<<"          #@####\n";
         cout<<"         #######\n";
         cout<<"        ########\n";
         cout<<"       +##@#####\n";
         cout<<"      +#########\n";
         cout<<"      +#########\n";
         cout<<"      +#########\n";
         cout<<"      +#########\n";
         cout<<"      #########\n";
    classic

  6. #6
    Registered User
    Join Date
    Nov 2007
    Posts
    2
    Thanks, I'm really knew to this stuff, and the book we use is from 1998. We just sidestep the older stuff by replacing it with new stuff. Like in the book they use #include<iostream.h> and stuff. I know its a really sloppy code, but I'm a newb and I can't help, but to make mistakes.
    You comments are appreciated. If you got any ways of reducing some of the global variables please say so. Thanks again, Kimset.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, create a class called player, that has the four variables that each player uses, then use that class to instantiate your players. If that means nothing to you, you will need to study a bit more C++.

    And I agree with rodrigorules, there's no lack of talent for drawing...

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Nov 2007
    Location
    Free Country, USA
    Posts
    105
    For the fighting problem, try using:
    Code:
    else if(condition)
    That may help.

  9. #9
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    An example of a very simple player class might look like this:

    Code:
    class Player
    {
    public:
       Player(); // constructor - initiliazes all variables to a starting value
       ~Player(); // destructor - not always needed in simple OOP
       
       // these would return the values
       unsigned short getHealth();
       std::string getName();
    
       // these would modify the value
       void setHealth();
       void setName();
    
    private:
       // keep all variables private ( or protected )
       unsigned short m_Health;
       std::string m_Name;
    };
    I'm just trying to be a better person - My Name Is Earl

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    http://www.cprogramming.com/tutorial/lesson12.html
    The whole idea it to simplify it. For example, this can look like:

    Code:
         cout<<"[You have encountered: " << Enemy1.Name() /*Lord Niwazuka Tsunori!*/ << "] \n";
         cout<< Enemy1.Name()/*"Lord Tsunori's Health: "*/<<Enemy1.Health()/*lnthp*/<<" / "<<Enemy1.MaxHealth()/*lntmhp*/<<"\n"<<endl;
         cout<<"Your Health: "<<Player.Health()/*health*/<<" / "<<Player.MaxHealth()/*maxhealth*/<<"\n"<<endl;
         cout<<"[T]hrust Attack\n";
         cout<<"[S]lash Attack\n";
         cout<<"[P]arry Midway\n";
         cout<<"[D]efend\n";
         cin>>fighthelpfight;
         if(fighthelpfight == 'T')
         {
                           cout<<"[You attempt to Thrust the enemy.]\n";
                           if(Enemy1.Dexterity() > Player.Dexterity()/* lntdex > dexterity*/)
                           {
                                     cout<<"[As you attempt to Thrust, enemy quickly slices you.]\n";
                                     Player.SetNewHealth( Player.Health() - Enemy1.Damage() ); //health = health - lntstr;
                                     cout<<"[You have taken "<<Enemy1.Damage()/*lntstr*/<<" damage!]\n";
                                     system("pause");
                                     fighthelp();
                           }
                           if(lntdex < dexterity)
                           {
                                     cout<<"[You Thrust the enemy.]\n";
                                     Enemy1.SetNewHealth( Enemy1.Health() - Player.Strength() ); //lnthp = lnthp - strength;
                                     cout<<"[You deal "<<Player.Strength()/*strength*/<<" damage!]\n";
                                     system("pause");
                                     fighthelp();
                           }
                           system("pause");
         }
    That's a sample of how it should look like. It looks much less messy and much easier to read, doesn't it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please comment on my c++ game
    By MegaManZZ in forum Game Programming
    Replies: 10
    Last Post: 01-22-2008, 10:03 AM
  2. Try my game
    By LuckY in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-15-2004, 11:58 AM
  3. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 04:19 AM
  4. Game Programmer's AIM Circle: Join Today
    By KingZoolerius66 in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 12-20-2003, 11:12 AM
  5. Someone help me with this game??
    By stehigs321 in forum Game Programming
    Replies: 15
    Last Post: 10-30-2003, 08:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21