View Full Version: My First Game ( TEXT RPG GAME )

C++ Learning Community > C++ Creations > My First Game ( TEXT RPG GAME )


Title: My First Game ( TEXT RPG GAME )
Description: No MOFO fixed the BUG thxz MOFO


Shonoby - November 24, 2006 07:21 AM (GMT)
Well this is my final version for a while cause i want to get better and make a even better vesion,
This version includes:
  • Leveling system
  • Naming system
  • Skill system
  • Randome monster system( well randome stats like diffrent HP, Str, Ex not name tho..)
  • Resting system
  • Checking your stats
  • Infinate lv.....
  • Skill text graphics.....all i can do for now...
  • Dieing system ( like your stats are returned to normal if you die )
  • Battle system like real RPG games
  • Ex given when you win a battle
  • When you level it displays what you get and what level you are
  • Boss battle based on lv..
  • and more.... i think ... cant remember
  • NO INLINE ANYMORE!!!!
Well here's the code ( it's huge for real....586 lines..... ):
CODE

// Text RPG Game
// By: Darwin Aguirre
// Thxz To MOFO

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int battle( void );
int attack( void );
int skill( void );
int skill1( void );
int skill2( void );
int skill3( void );
int end( void );
int stats( void );
int rest( void );
int path( void );
int levelsystem( void );
int randome( void );
int higherRandome( void );
int highestRandome( void );
int all( void );
int bossGen( void );

char heroname[ 20 ];
int HP = 100;
int fHP = HP;
int MP = 10;
int fMP = MP;
int Str = 5;
int Exp = 0;
int TExp = 50;
int lv = 1;

const char Monstername[ 10 ] = { "Korishi: " };
int HP1;
int Str1;
int Ex;

template < class R >
R Randome ( R value1, R value2, R value3 )
{

   HP1 = value1;

   Str1 = value2;

   Ex = value3;
   
   return HP1, Str1, Ex;
}

int main()
{  
   cout << "Hello and welcome to my \"RPG GAME\" hope you enjoy it!!\nThxz To MOFO\n";
   cout << "Version 3.7\n\n\n";
   cout << "Please enter your hero's name: ";
   cin >> heroname;

   srand( time( 0 ) );

   path();

   return 0;
}

int path( void )
{
   int respond;

   while (1) {

   while ( Exp >= TExp )
       levelsystem();

       cout << "\nHello " << heroname << ", what would you like to do?\n";
       cout << "1)Train\n2)Check Stats\n3)Rest\n4)Exit\nChoose: ";
       cin >> respond;

       switch ( respond ) {
       case 1:
           battle();
           break;

       case 2:
           stats();
           break;

       case 3:
           rest();
           break;

       case 4:
           return 0;
           break;

       default:
           cout << "Invailed choice\n";
           break;
       }
   }
return 0;
}

int battle( void )
{
   int answer = 0;

   switch ( lv ) {
   case 1:
   case 2:
   case 3:
   case 4:
   case 5:
      randome();
      break;

   case 6:
   case 7:
   case 8:
   case 9:
   case 10:
       higherRandome();
       break;

   case 11:
   case 12:
   case 13:
   case 14:
   case 15:
       highestRandome();

   default:
       all();
       break;
   }

   while (1) {
        cout << "\n\nBATTLE\n\n\n";
        cout << Monstername <<"\nHP: " << HP1 << "\n\n\n";
        cout << heroname << ":";
        cout << "\nHP: " << HP << endl;
        cout << "MP: " << MP << endl;
        cout << "1) Attack\n2) Skills\n";
        cout << "Choose: ";
        cin >> answer;

       switch ( answer ) {
           case 1:
               attack();
               break;

           case 2:
               skill();
               break;

           default:
               cout << "Invalid choice, try agian.\n";
               break;
       }

    if ( HP <= 0 || HP1 <= 0 ) {
       end();
       return 0;
    }
   }
return 0;
}

int attack( void )
{
   int Att = ( 1 + rand() % Str );
   int Att1 = ( 1 + rand() % Str1 );
   int critical = ( 1 + rand() % 20 );

   switch ( critical ) {
       case 7:
           cout << "\n\nCRITICAL hit: " << ( Att + 10 );
           HP1 -= ( Att + 10 );
           break;

   default:
           cout << "\n\nYou hit: " << Att;
           HP1 -= Att;
           break;
   }

   cout << "\nMonster hit: " << Att1;
   HP -= Att1;

   return 0;
}

int skill( void )
{
   int Att1 = ( 1 + rand() % Str1 );

   if ( lv < 7 )
       skill1();

   if( lv <= 14 && lv >= 7)
       skill2();

   if ( lv >= 15 )
       skill3();

   cout << "\nMonster hit: " << Att1;
   HP -= Att1;

   return 0;
}

int end( void )
{
   if ( HP <= 0 ) {
       cout << "\n\n\n\nYou have DIED!!\n";
       cout << heroname << "'s has been returned to what they were when you started!!\n\n";
       fHP = 100;
       fMP = 10;
       HP = fHP;
       MP = fMP;
       lv = 1;
       Exp = 0;
       TExp = 50;
   }

   if ( HP1 <= 0 ) {
       cout << "\n\n\n\nYou have WON!!\n";
       cout << "You gained " << Ex << " EX!!\n\n\n\n";
       HP1 = 25;
       Exp += Ex;
   }
   return 0;
}

int stats( void )
{
   cout << endl;
   cout << heroname << "'s Stats\n";
   cout << "Level: " << lv << endl;
   cout << "HP: " << HP << "/" << fHP << endl;
   cout << "MP: " << MP << "/" << fMP << endl;
   cout << "Strength: " << Str << endl;
   cout << "Ex: " << Exp << "/" << TExp << endl;

   return 0;
}

int rest( void )
{
   HP = fHP;
   MP = fMP;

   cout << "\nYou are fully rested now!\n";

   return 0;
}

int levelsystem( void )
{
   cout << "You went up a level!!\n";
   cout << "You are now level " << ( lv += 1 ) << endl;;
   cout << "HP + 25!!\n";
   cout << "MP + 10!!\n";
   cout << "Str + 5!!\n";
   fHP += 25;
   fMP += 10;
   Str += 5;
   TExp += ( 50 * lv );
   cout << endl;

   switch ( lv ) {
   case 7:
       cout << "You have learned a new skill!!\n";
       break;

   case 15:
       cout << "You learned the final skill!!\n";
       break;

   default:
       break;
   }

   return 0;
}

int randome( void )
{
   int HPGen = ( rand() % 25 );
   int StrGen = ( 2 + rand() % 4 );
   int ExGen = ( rand() % 20 );

   if ( HPGen < 10 ) {
       int y = 10;
       int p;

       p = y - HPGen;
       HPGen += p;
   }

   if ( ExGen < 10 ) {
       int z = 10;
       int f;

       f = z - ExGen;
       ExGen += f;
   }
       
   Randome ( HPGen, StrGen, ExGen );

   return 0;
}

int  higherRandome( void )
{
   int HPGen = (50 + rand() % 100 );
   int StrGen = ( 15 + rand() % 15 );
   int ExGen = ( 25 + rand() % 50 );

   if ( HPGen < 50 ) {
       int y = 50;
       int p;

       p = y - HPGen;
       HPGen += p;
   }

   if ( ExGen < 25 ) {
       int z = 25;
       int f;

       f = z - ExGen;
       ExGen += f;
   }
       
   Randome ( HPGen, StrGen, ExGen );

   return 0;
}

int highestRandome( void )
{
   int HPGen = (100 + rand() % 200 );
   int StrGen = ( 20 + rand() % 25 );
   int ExGen = ( 50 + rand() % 100 );

   if ( HPGen < 100 ) {
       int y = 100;
       int p;

       p = y - HPGen;
       HPGen += p;
   }

   if ( ExGen < 50 ) {
       int z = 50;
       int f;

       f = z - ExGen;
       ExGen += f;
   }
       
   Randome ( HPGen, StrGen, ExGen );

   return 0;
}

int all( void )
{
   int BossRanz = ( 1 + rand() % 10 );

   if ( BossRanz == 1 ) {
       bossGen();
       return 0;
   }

   int HPGen = (200 + rand() % 300 );
   int StrGen = ( 30 + rand() % 40 );
   int ExGen = ( 50 + rand() % 100 );

   if ( HPGen < 200 ) {
       int y = 200;
       int p;

       p = y - HPGen;
       HPGen += p;
   }

   if ( ExGen < 50 ) {
       int z = 50;
       int f;

       f = z - ExGen;
       ExGen += f;
   }
       
   Randome ( HPGen, StrGen, ExGen );

   return 0;
}

int bossGen( void )
{
   cout << "\nBOSS!!";
   int HPGen = (700 + rand() % 1000 );
   int StrGen = ( 100 + rand() % 120 );
   int ExGen = ( 700 + rand() % 1000 );

   if ( HPGen < 700 ) {
       int y = 700;
       int p;

       p = y - HPGen;
       HPGen += p;
   }

   if ( ExGen < 700 ) {
       int z = 700;
       int f;

       f = z - ExGen;
       ExGen += f;
   }
       
   Randome ( HPGen, StrGen, ExGen );

   return 0;
}

int skill1( void )
{
   int choose;
   int skillA = Str * 2;
   int skill1 = ( 1 + rand() % skillA );
   int Att1 = ( 1 + rand() % Str1 );
   int critical = ( 1 + rand() % 20 );

       cout << "Skills:\n1)Tera Slash\nChoose: ";
       cin >> choose;
       if ( choose == 1 ) {
              switch ( critical ) {
              case 7:
                  cout << "TERA SLASH - @#@#@#//\\\n";
                  cout << "CRITICAL TERA SLASH hit: " << ( skill1 + 10 );
                  HP1 -= ( skill1 + 10 );
                  MP -= 1;
                  break;
              default:
                  cout << "TERA SLASH - @#@#@#//\\\n";
                  cout << "TERA SLASH hit: " << skill1;
                  HP1 -= skill1;
                  MP -= 1;
                  return 0;
                  break;
              }
       }
       else {
           cout << "Invaild Choice\n";
           battle();
            }
   return 0;
}


int skill2( void )
{
   int choose;
   int skillA = Str * 2;
   int skillB = Str * 5;
   int skill1 = ( 1 + rand() % skillA );
   int skill2 = ( 1 + rand() % skillB );
   int Att1 = ( 1 + rand() % Str1 );
   int critical = ( 1 + rand() % 20 );

           cout << "Skills:\n1)Tera Slash\n2)Double Edge\nChoose: ";
           cin >> choose;
            if ( choose == 1 ) {
              switch ( critical ) {
              case 7:
                  cout << "TERA SLASH - @#@#@#//\\\n";
                  cout << "CRITICAL TERA SLASH hit: " << ( skill1 + 10 );
                  HP1 -= ( skill1 + 10 );
                  MP -= 1;
                  break;
              default:
                  cout << "TERA SLASH - @#@#@#//\\\n";
                  cout << "TERA SLASH hit: " << skill1;
                  HP1 -= skill1;
                  MP -= 1;
                  break;
              }
            }
            if ( choose == 2 ) {
               switch ( critical ) {
               case 7:
                  cout << "DOUBLE EDGE - ---@@$$$^^&& \n";
                  cout << "CRITICAL DOUBLE EDGE hit: " << ( skill2 + 10 );
                  HP1 -= ( skill2 + 10 );
                  MP -= 5;
                  break;
               default:
                  cout << "DOUBLE EDGE - ---@@$$$^^&& \n";
                  cout << "DOUBLE EDGE hit: " << skill2;
                  HP1 -= skill2;
                  MP -= 5;
                  break;
              }
           }
           else {
               cout << "Invaild Choice\n";
               battle();
            }

   return 0;
}

int skill3( void )
{
   int choose;
   int skillA = Str * 2;
   int skillB = Str * 5;
   int skillC = Str * 10;
   int skill1 = ( 1 + rand() % skillA );
   int skill2 = ( 1 + rand() % skillB );
   int skill3 = ( 1 + rand() % skillC );
   int Att1 = ( 1 + rand() % Str1 );
   int critical = ( 1 + rand() % 20 );

           cout << "Skills:\n1)Tera Slash\n2)Double Edge\n3)Dragon Blade\nChoose: ";
           cin >> choose;
            if ( choose == 1 ) {
              switch ( critical ) {
              case 7:
                  cout << "TERA SLASH - @#@#@#//\\\n";
                  cout << "CRITICAL TERA SLASH hit: " << ( skill1 + 20 );
                  HP1 -= ( skill1 + 10 );
                  MP -= 1;
                  break;
              default:
                  cout << "TERA SLASH - @#@#@#//\\\n";
                  cout << "TERA SLASH hit: " << skill1;
                  HP1 -= skill1;
                  MP -= 1;
                  break;
              }
            }
            if ( choose == 2 ) {
               switch ( critical ) {
               case 7:
                  cout << "DOUBLE EDGE - ---@@$$$^^&& \n";
                  cout << "CRITICAL DOUBLE EDGE hit: " << ( skill2 + 10 );
                  HP1 -= ( skill2 + 10 );
                  MP -= 5;
                  break;
               default:
                  cout << "DOUBLE EDGE - ---@@$$$^^&& \n";
                  cout << "DOUBLE EDGE hit: " << skill2;
                  HP1 -= skill2;
                  MP -= 5;
                  return 0;
                  break;
              }
           }
            if ( choose == 3 ) {
                switch ( critical ) {
                case 7:
                    cout << "DRAGON BLADE - %@""""__&==*\n";
                    cout << "CRITICAL DRAGON BLADE hit: " << ( skill3 + 5 );
                    HP1 -= ( skill3 + 5 );
                    MP -= 20;
                    break;
                default:
                    cout << "DRAGON BLADE - %@""""__&==*\n";
                    cout << "DRAGON BLADE Hit: " << skill3;
                    HP1 -= skill3;
                    MP -= 20;
                    break;
                }
            }
            else
               cout << "Invaild Choice\n";
    return 0;
}    

You could always change the stats of either the monsters or your chracters, i do it all the time lol................well that's about it.

Zaqufant - December 3, 2006 11:57 PM (GMT)
Learn an easy gfx library (saaaay allegro) and turn it into graphics. It will be cool.

Shonoby - December 4, 2006 12:18 AM (GMT)
Lol yea i know but.. right now i just want to learn the basics of C++ then learn grphic stuff....so i guess you'll have to wait a while....
^_^ :lol: So how was the game any bugs or just any comments?

AquaFox - December 8, 2006 05:50 PM (GMT)
QUOTE (Zaqufant @ Dec 3 2006, 11:57 PM)
Learn an easy gfx library (saaaay allegro) and turn it into graphics. It will be cool.

I don't think it'd do much. Much recoding will need to be done.

Viper - December 9, 2006 09:20 AM (GMT)
Why inline everything..

Ravotus - December 9, 2006 03:27 PM (GMT)
Agreed. When using inline like you are, it is slowing the code down rather than speeding it up. Inline is designed for functions that act like a macro, which means small. If you are not sure whether or not to use inline, don't.

Zaqufant - December 9, 2006 03:43 PM (GMT)
Yah, only inline when you have like 2 or 3 line long function.

And when you go into graphics use allegro. :D

myork - December 9, 2006 03:55 PM (GMT)


Ignore above advice. Feel free to use inline anywhere.

Things to remember.
1) inline is only a hint to the compiler. It is under no obligation to inline.
2) If the code is inlined. Then it will always be faster than a function call.
3) If the code is inlined. It usually causes the code to be bigger.

The compiler is very good at analysing the code and recognising what the do.
You can tell the compiler to optimise for speed or space and it will perform the appropriate action.

Ravotus - December 9, 2006 04:13 PM (GMT)
I'm sorry, my reply was a bit too general. But you should probably read this as well: http://parashift.com/c++-faq-lite/inline-f...ns.html#faq-9.3

Shonoby - December 13, 2006 04:29 AM (GMT)
Ok, well the reason i used inline is cause i felt like it and wanted to try it out and see if it would make a diffrence, so just use the code at it is and the reason i made it inline is so that everytime the compiler calls the function it goes stright to the source rather than just making a copy of it which it would have done if i did not pui t"inline" so dont say its making it slower, and if i did not use inline it would have to use alot of unessasary space which i need for this giant code so dont tell me something that iam sure of well moslty, so please stop it with the inline thing and if u dont like it then just change it i dont care, yes i know iam begin rude but stop telling me about the inline thing, i know what i did for this code was good and if u dont like it than change it urself, ok, well later

myork - December 13, 2006 02:29 PM (GMT)
QUOTE (Shonoby @ Dec 12 2006, 11:29 PM)
OK, well the reason i used inline is cause i felt like it and wanted to try it out and see if it would make a diffrence,
Good
QUOTE (Shonoby @ Dec 12 2006, 11:29 PM)
  so just use the code at it is
OK.
QUOTE (Shonoby @ Dec 12 2006, 11:29 PM)
and the reason i made it inline is so that everytime the compiler calls the function it goes stright to the source
Does not make sense but OK.
QUOTE (Shonoby @ Dec 12 2006, 11:29 PM)
rather than just making a copy of it which it would have done if i did not pui t"inline"
By using inline it is more likely to make a copy not less.
QUOTE (Shonoby @ Dec 12 2006, 11:29 PM)
so dont say its making it slower,
It may make your code bigger not slower.
QUOTE (Shonoby @ Dec 12 2006, 11:29 PM)
  and if i did not use inline it would have to use alot of unessasary space
If the compiler inlines the code it will make the code much bigger not smaller.
QUOTE (Shonoby @ Dec 12 2006, 11:29 PM)
which i need for this giant code
Why?
QUOTE (Shonoby @ Dec 12 2006, 11:29 PM)
so dont tell me something that iam sure of well moslty, so please stop it with the inline thing and if u dont like it then just change it i dont care
If you don't want comments don't post your code
QUOTE (Shonoby @ Dec 12 2006, 11:29 PM)
  yes i know iam begin rude but stop telling me about the inline thing,
Stop being rude then. The input from other coders is not just for your benefit. To think that we put comments here solely for your gratification is very egotistical, you are not the only bad coder in the world that we are trying to help.
QUOTE (Shonoby @ Dec 12 2006, 11:29 PM)
  i know what i did for this code was good
Really. You think it was good!
QUOTE (Shonoby @ Dec 12 2006, 11:29 PM)
  and if u dont like it than change it urself, ok, well later
Well if you don't like people commenting on your code find another forum were people don't spend their own time trying to help you.

C-Man - December 13, 2006 03:45 PM (GMT)
:lol:

Viper - December 15, 2006 01:35 PM (GMT)
Inline can easily make the code slower. Bigger code can be slower, I've experienced that optimizing for size increased performance more than for speed in some cases.
Inline can also make code smaller for really small functions...

Hedgehog - December 15, 2006 04:15 PM (GMT)
QUOTE (Shonoby @ Dec 13 2006, 04:29 AM)
Ok, well the reason i used inline is cause i felt like it and wanted to try it out and see if it would make a diffrence, so just use the code at it is and the reason i made it inline is so that everytime the compiler calls the function it goes stright to the source rather than just making a copy of it which it would have done if i did not pui t"inline" so dont say its making it slower, and if i did not use inline it would have to use alot of unessasary space which i need for this giant code so dont tell me something that iam sure of well moslty, so please stop it with the inline thing and if u dont like it then just change it i dont care, yes i know iam begin rude but stop telling me about the inline thing, i know what i did for this code was good and if u dont like it than change it urself, ok, well later

One sentence... One freaking sentence! :wacko:

Nice code, anyway.
No constructive critisism here :D

Shonoby - December 16, 2006 05:40 AM (GMT)
Umm, Ok....well,than u should just change it but, idk i felt like using the inline thing, cause i was testing my skills to see if i could even make a program like this, but yes ur all right, i was being, rude....BUT were all still learning right, (not every1 is learning others are teaching i guess....)

Shonoby - December 27, 2006 09:30 AM (GMT)
I have some good, bad news,
Good News First:
I will be making a new version of this, game soon depending on...(go to bad news)
Bad News Last:
I MIGHT be not making the game beacuse i am gonna see if one of my friends can help me make a GAME using DM programming (Here is the site for BYOND (DM)) a custom programming ecepcially for games, and i have alrdy made the template for the game i just NEED him to pick up his phone then we will see,
SO stay toon, and see what happens NEXT time on "The Adventures Of The Shinobi Programer" (Ending-Theme Music plays) (then) DON DON DOOOOOON DODOTON!!!!
(Goes to commeriales)




Hosted for free by InvisionFree