CMPC
Would you like to react to this message? Create an account in a few clicks or log in to continue.

My C++ RPG TEXT GAME

5 posters

CMPC :: Computing :: Programming :: C++

Page 1 of 2 1, 2  Next

Go down

My C++ RPG TEXT GAME Empty My C++ RPG TEXT GAME

Post by Admin Wed Dec 09, 2009 3:29 am

Yeah I know it's a bit messy, and the story is incomplete (got bored).

Check it out.

I think I have an extra header (conio) but whatever. It's EXTREMELY messy. Takes a while to understand the if statements when it comes to the village variable.


Main: 371 lines

Code:
#include <iostream>
#include <ctime>
#include <conio.h>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <windows.h>
#include "ascii.cpp"
#include "randnum.cpp"
#include "randattack.cpp"

using namespace std;

string username;
string Oname;


//*********************************************

class Avatar

{
public:
   int health;
   int strength;
   int defence;
   int attack;
   string attackname1;
   string attackname2;
   string attackname3;
   
   void avatarstrdefinit(int x, int y, int a, int b)//initializes strength and defence of avatars.
   {
      strength=randnum(x,y);//this needs revision:Needs to be passed to another function that decides what the stats should be. possibly a function which uses the randnum function to make a random data member so the game is even more replayable! 
      defence=randnum(a,b);//this needs revision also, same problem.
   }
   
   void avatarattnameinit(string x,string y,string z)//initializes the attack names
   {
      attackname1=x;
      attackname2=y;
      attackname3=z;
   }
   
   void attack1init()
   {
      attack=randnum(1,10);
   }
   void attack2init()
   {
      attack=randnum(3,8);
   }       
   void attack3init()
   {
      attack=randnum(4,7);
   }

};

//********************************************************************************************

void battle(int playerstrlow,int playerstrhigh,int playerdeflow,int playerdefhigh, int oppstrlow,int oppstrhigh, int oppdeflow,int oppdefhigh,string playerattname1,string playerattname2,string playerattname3,string oppattname1,string oppattname2,string oppattname3)//parameters here are passed to class functions
{
Avatar player;
Avatar opponent;
player.health=100;
opponent.health=100;

player.avatarstrdefinit(playerstrlow,playerstrhigh,playerdeflow,playerdefhigh);
player.avatarattnameinit(playerattname1,playerattname2,playerattname3);
   
opponent.avatarstrdefinit(oppstrlow,oppstrhigh,oppdeflow,oppdefhigh);
opponent.avatarattnameinit(oppattname1,oppattname2,oppattname3);
   
cout<<endl<<endl<<endl<<"You are battling "<<Oname<<"."<<endl;
cout<<"You have "<<player.health<<" health and "<<Oname<<" has "<<opponent.health<<" health."<<endl<<endl;
int damagetoplayer=10;
int damagetoopponent=10;
int battleloop=0;
while(battleloop==0)
{
   
   Sleep(1000);
   int randatt=randattack();
      
   if(randatt==1)
   {
   cout<<"\n"<<Oname<<" has attacked you with "<<opponent.attackname1<<"!"<<endl;
   opponent.attack1init();
   damagetoplayer=(opponent.attack+(opponent.strength/player.defence));
   }
   else if(randatt==2)
   {
   cout<<"\n"<<Oname<<" has attacked you with "<<opponent.attackname2<<"!"<<endl;
   opponent.attack2init();
   damagetoplayer=(opponent.attack+(opponent.strength/player.defence));
   }
   else if(randatt==3)
   {
   cout<<"\n"<<Oname<<" has attacked you with "<<opponent.attackname3<<"!"<<endl;
   opponent.attack3init();
   damagetoplayer=(opponent.attack+(opponent.strength/player.defence));
   }
   
   if(damagetoplayer==0)
   {
      cout<<Oname<<" has missed!"<<endl;
   }
   else
   {
      player.health=(player.health-damagetoplayer);
   
      cout<<Oname<<" has done "<<damagetoplayer<<" damage to you!"<<endl;
      cout<<"You have "<<player.health<<" health left."<<endl<<endl;    
   }
   
   if(player.health<=0)
   {
      player.health=0;
      cout<<"You have died! :( You are a terrible ninja!"<<endl;
      Sleep(1000);
      battleloop=1;
   }
   
   Sleep(1500);
      
   cout<<"You have attacked "<<Oname<<"!"<<endl;
   
   int playerattackchoice;
   
   playerattackagain:
   
   cout<<"Which attack will you use?"<<endl;
   cout<<"1. "<<player.attackname1<<endl<<"2. "<<player.attackname2<<endl<<"3. "<<player.attackname3<<endl<<endl;
   cin>>playerattackchoice;
   
   if(playerattackchoice==1)
   {
      player.attack1init();
      damagetoopponent=(player.attack+(player.strength/opponent.defence));
   }
   else if(playerattackchoice==2)
   {
      player.attack2init();
      damagetoopponent=(player.attack+(player.strength/opponent.defence));
   }
   else if(playerattackchoice==3)
   {
      player.attack3init();
      damagetoopponent=(player.attack+(player.strength/opponent.defence));
   }
   else
   {
      cout<<"Please enter a valid attack!"<<endl;
      goto playerattackagain;
   }
   
   if(damagetoopponent==0)
   {
      cout<<Oname<<" has missed!"<<endl;
   }
   else
   {   
      opponent.health=(opponent.health-damagetoopponent);
      
      if(playerattackchoice==1)
      {
         cout<<"You used "<<player.attackname1<<" and have done "<<damagetoopponent<<" damage to "<<Oname<<"!"<<endl;
      }
      if(playerattackchoice==2)
      {
         cout<<"You used "<<player.attackname2<<" and have done "<<damagetoopponent<<" damage to "<<Oname<<"!"<<endl;
      }
      if(playerattackchoice==3)
      {
         cout<<"You used "<<player.attackname3<<" and have done "<<damagetoopponent<<" damage to "<<Oname<<"!"<<endl;
      }
      
      if(opponent.health<=0)
      {
         opponent.health=0;
         cout<<Oname<<" has "<<opponent.health<<" health left"<<endl<<endl;
      }
      
   }
   
   if(opponent.health<=0)
   {
      opponent.health=0;
      cout<<Oname<<" is dead! REJOICE!"<<endl;
      Sleep(1000);
      battleloop=1;
   }

}


if(player.health<=0)
{
   Sleep(500);
   cout<<"\nYou have died. You failed your mission. You are dead. You're family is dead. Your pets have been skinned to death. You lose. Game over."<<endl;
   Sleep(1000);
   battleloop=1;
   
}
else if(opponent.health<=0)
{
   Sleep(500);
   cout<<"\nYou won! You have defeated your opponent, good job. Now you have proved your worth to the Kazekage."<<endl;
   Sleep(1000);
   
}

}

//****************************************************************************************


int sandstory()
{
Oname=("Gaara");

system("cls");
gaaraascii();
cout<<"- Welcome "<<username<<" to the sand village."<<endl;
cout<<".... ";
cout<<"- ...hmm? Morning already."<<endl;
Sleep(1000);
cout<<"- Oh that's right! I have a mission to complete today!"<<endl;
cout<<"- Right, can't be late!"<<endl<<endl;
Sleep(1000);
cout<<"- ... *You rush into the Kazekage's office* 'Sir "<<username<<" reporting for the mission!'"<<endl;
cout<<"-'Ah yes, "<<username<<", I have been awaiting your arrival for some time now. Are you ready?"<<endl;
Sleep(1000);
cout<<"-'Yes Sir!'";
cout<<"Good...good...perhaps you'd like to show me your talents? Please show my friend here what you can really do!"<<endl;
Sleep(1000);
battle(60,120,4,9,40,100,4,8,"sand shuriken","sand burial","sand tsuname","shuriken","puppet spike","poison gas bomb");
cin.get();
return 0;
}
//**************************************************************************************
int konohastory()
{
system("cls");
konohasymbolascii();
cout<<"This is the konohastory function :D good job!"<<endl<<endl;
cin.get();
return 0;
}



//******************************************************************************************

int main()
{

cout<<"\t - Welcome to Ninja Adventures! A text based adventure game! -"<<endl<<endl;




narutotextascii();



Sleep(2500);
cout<<"- *A tall dark man approaches to find you in a basket on his doorstep*"<<endl<<endl;
Sleep(2000);
cout<<"- 'What's your name little one?' ";
cin>>username;

Sleep(500);

cout<<"- Hm? *There seems to be a note attached to the basket*"<<endl;
Sleep(2000);
cout<<"- 'Ah, it's all here, yes your name is "<<username<<" and you're from the...which village?'";
Sleep(2500);

int village;
chooseagain:
cout<<"\nWhich village are you from? \n\n- 1--Hidden Village of Konoha\n- 2--HIdden Village of Sand"<<endl<<endl;
cin>>village;

Sleep(1000);

switch(village)
{
   case 1:
      cout<<"- 'Oh that's right, you're a Konoha ninja!'"<<endl<<endl;
   break;
   
   case 2:
      cout<<"- 'Oh that's right, you're a Sand ninja!'"<<endl<<endl;
   break;
   
   default:
      cout<<"- Please enter either 1 or 2."<<endl<<endl;
      goto chooseagain;
   break;
}


Sleep(2500);
//if else statements really get nasty here so pay attention to the comments :P
if(village==2)
{
   cout<<"- Are you ready to begin the journy of a command line lifetime? Y/N"<<endl<<endl;
   string yesno1;
   cin>>yesno1;


   if (yesno1=="yes" || yesno1=="Yes" || yesno1=="Y" || yesno1=="y")//SECOND IF STATEMENT
   {
      Sleep(1000);
      cout<<"\n- Excellent!..."<<endl<<endl;
      Sleep(2000);
      sandstory();
      goto exit;//goes to sandstory story. It's basically another story.
   }

   else if(yesno1=="no" || yesno1=="No" || yesno1=="N" || yesno1=="n")
   {
      Sleep(1000);
      cout<<"\n- As you wish";
      Sleep(1500);
      goto exit;
   }

//ok this is where the if(yesno1=="yes") statement ends with it's else. IT'S OVER! NO WORRIES! YOU CAN RELAX!


}/*this is where the if(village==2) statement ends X( SO CONFUSING.
 ok next should be the else statement of the village. so if it's not
  2, it's 1. which means if it's not sand, it's konoha!*/
 
 
else if(village==1)
{
   //this is the else part for village==2. this part is IF VILLAGE==1 which is konoha!
   cout<<"Are you ready to begin the journy of a command line lifetime? yes/no"<<endl;
   string yesno2;
   cin>>yesno2;


   if (yesno2=="yes" || yesno2=="Yes" || yesno2=="Y" || yesno2=="y")//SECOND IF STATEMENT
   {
      Sleep(1000);
      cout<<"\nExcellent!"<<endl<<endl;
      konohastory();
      goto exit;//goes to konoha function. It's basically another story.
   }

   else if(yesno2=="no" || yesno2=="No" || yesno2=="N" || yesno2=="n")
   {
      Sleep(1000);
      cout<<"\n- As you wish";
      Sleep(1500);
      goto exit;
   }

}




cin.get();
exit:
return 0;
}
//*********************************************************************************************



Last edited by Admin on Wed Dec 09, 2009 3:32 am; edited 1 time in total
Admin
Admin
Pirate King

Posts : 559

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Admin Wed Dec 09, 2009 3:29 am

ascii cpp file. many lines - all awesome.

Code:

#include <iostream>
using namespace std;


int konohasymbolascii()
{
cout<<"\n\n";

cout<<"\t##############################\n";
cout<<"\t##############################\n";
cout<<"\t########################  ####\n";
cout<<"\t#############            ####\n";
cout<<"\t############  ################\n";
cout<<"\t###########  #################\n";
cout<<"\t##########  ##################\n";
cout<<"\t#########  #####      #######\n";
cout<<"\t######### #####  ####  ######\n";
cout<<"\t########  ####  #######  #####\n";
cout<<"\t########  #### ######### #####\n";
cout<<"\t#######  #### ##### ###  ####\n";
cout<<"\t#######  #### ##### #### ####\n";
cout<<"\t######    ####  #### #### ####\n";
cout<<"\t###### ## #####      #### ####\n";
cout<<"\t##### ### ######    ####  ####\n";
cout<<"\t####  #### ############# #####\n";
cout<<"\t#### #####  ###########  #####\n";
cout<<"\t###  ######  #########  ######\n";
cout<<"\t####  #####  #####  #######\n";
cout<<"\t######              #########\n";
cout<<"\t#########        ############\n";
cout<<"\t##############################\n";
cout<<"\t##############################\n";

cout<<"\n\n";

return 0;
}


//************************************************************************************

int narutotextascii()
{
cout<<"\n\n";

cout<<"\t*************************************************************\n";
cout<<"\t*                                                          *\n";
cout<<"\t*  **    *  ******  ******  *    *  *********  *******    *\n";
cout<<"\t*  * *    *  *    *  *    *  *    *      *      *    *    *\n";
cout<<"\t*  *  *  *  *    *  *    *  *    *      *      *    *    *\n";
cout<<"\t*  *  *  *  ******  ******  *    *      *      *    *    *\n";
cout<<"\t*  *    * *  *    *  *  *    *    *      *      *    *    *\n";
cout<<"\t*  *    **  *    *  *  *  *    *      *      *    *    *\n";
cout<<"\t*  *      *  *    *  *    *  ******      *      *******    *\n";
cout<<"\t*                                                          *\n";
cout<<"\t*************************************************************\n";

cout<<"\n\n";
return 0;
}


//************************************************************************************

int gaaraascii()
{
cout<<"\n\n";

cout<<"                #EG:              \n";
cout<<"              #EGGGK,            \n";
cout<<"              EGGGGGG            \n";
cout<<"              WEEG#.G              \n";
cout<<"              E...#G              \n";
cout<<"              EL.,;.              \n";
cout<<"              D....;              \n";
cout<<"                i...D              \n";
cout<<"              ..iW.;;;;;          \n";
cout<<"            iG....#;;;;          \n";
cout<<"            WiK....LL;;;          \n";
cout<<"            EEii.ELELt,E          \n";
cout<<"            EEE..#ELLW#W          \n";
cout<<"            WEtft.#Liit;          \n";
cout<<"            .,;#.....jt;          \n";
cout<<"            tGW,#ji.....;          \n";
cout<<"          ;;;;j....;ii..          \n";
cout<<"        ,#;K;W;..;iiWt.          \n";
cout<<"      f,,KKttDWW#fi..            \n";
cout<<"      ;,,K#ttWLWLDi.i.            \n";
cout<<"      ;;;#tttWEDLDi;.f            \n";
cout<<"      D;;#ttt##LLDDKii.            \n";
cout<<"      ;;;;tttKLLLD#if..            \n";
cout<<"      :;;;tt DLLDEi#.i.            \n";
cout<<"      .;;;tt,#LDEEii.Ei            \n";
cout<<"      ;;;tt#f#EEEii.E            \n";
cout<<"        ;;ttt#EEEEi..E            \n";
cout<<"        ttt#WEEEEi.EE            \n";
cout<<"          #tWWEEEEi.EE            \n";
cout<<"            #EEEEE;.EE            \n";
cout<<"            #EEEE ..EE            \n";
cout<<"            WEEEE ..EE            \n";
cout<<"            #EEEE#..WE            \n";
cout<<"            WEEEDi..E#            \n";
cout<<"            WEEE i..E              \n";
cout<<"            WEEE i..E              \n";
cout<<"            #EE  ii              \n";
cout<<"            ii    ii              \n";
cout<<"            iD    ii              \n";
cout<<"            WD    ii              \n";
cout<<"          #E#    WE              \n";
cout<<"          EE    EKE              \n";
cout<<"          G:E    WE.:            \n";
cout<<"          ii,      WW            \n";
cout<<"          #                      \n";

cout<<"\n\n";
return 0;
}



Admin
Admin
Pirate King

Posts : 559

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Admin Wed Dec 09, 2009 3:30 am

randattack cpp file


Code:
int randattack()
{
int randattackswitch=randnum(1,3);

if(randattackswitch==1)
{
   return 1;
}
else if(randattackswitch==2)
{
   return 2;
}
else if(randattackswitch==3)
{
   return 3;
}

}

Admin
Admin
Pirate King

Posts : 559

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Admin Wed Dec 09, 2009 3:31 am

randnum cpp file

Code:

#include <ctime>
#include <cstdlib>

using namespace std;

int randnum(int lownum, int highnum)
{
srand((unsigned)time(0));
   
   return (rand()%(highnum+1)+lownum);

}



Admin
Admin
Pirate King

Posts : 559

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Paul Wed Dec 09, 2009 5:03 am

You should really work on your coding practice.
Paul
Paul
Pickaxe

Posts : 611

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Paul Wed Dec 09, 2009 5:04 am

In particular your naming conventions when it comes to functions.
Paul
Paul
Pickaxe

Posts : 611

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Paul Wed Dec 09, 2009 5:05 am

BTW: those didn't HAVE to be separate posts Wink
Paul
Paul
Pickaxe

Posts : 611

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Admin Wed Dec 09, 2009 5:05 am

what's wrong with the names? they seem to perfectly identify what each function does (sure the functions have long names but i'd be lost with short ones)
Admin
Admin
Pirate King

Posts : 559

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Paul Wed Dec 09, 2009 7:32 am

In general it's a good idea to Identify eachIndividualWord through some means ofSeparation.
Paul
Paul
Pickaxe

Posts : 611

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Paul Wed Dec 09, 2009 7:43 am

HINT HINT
Paul
Paul
Pickaxe

Posts : 611

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by zodiacescuchion Thu Dec 10, 2009 5:53 am

I tried the rpg game but it said there is no such thing as a ascii.cpp include file
zodiacescuchion
zodiacescuchion
Skid

Posts : 28

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Admin Thu Dec 10, 2009 5:56 am

Hasnain wrote:I tried the rpg game but it said there is no such thing as a ascii.cpp include file
you have to save the ascii script to a separate file and put it in the same directory as the main.cpp file.

the main.cpp file uses all those other scripts so you need them in the same directory for the main file to find the rest and include them in your program.
Admin
Admin
Pirate King

Posts : 559

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by zodiacescuchion Thu Dec 10, 2009 6:19 am

I did everything but it still wouldnt work because in randattack it said there was no identifier for randnum. Fullmeyal Alchemit + Naruto? Hagane No renkinjutsu?


Last edited by Hasnain on Thu Dec 10, 2009 6:26 am; edited 1 time in total
zodiacescuchion
zodiacescuchion
Skid

Posts : 28

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Admin Thu Dec 10, 2009 6:25 am

uhh..... :/ i never came across that issue. but then again i use a different compiler for console C++ programs than you guys do.

i use old reliable Quincy 2005 http://codecutter.net/tools/quincy/

works for me. no compiler is created equally i.e. they all differ in what they say is errored and what is not (ridiculous).

for example the C program that Emily Burke wrote does not compile with me because it says the program has like 100 errors while on her compiler it works perfectly. No idea why, it just does. so try my compiler if you can't figure out anything (and from what you've told me, i can't figure out anything either)
Admin
Admin
Pirate King

Posts : 559

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Paul Thu Dec 10, 2009 11:51 pm

Just start deleting randum errored lines of code and hope it works Wink Wink *wink wink*
Paul
Paul
Pickaxe

Posts : 611

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Lunsfordium Tue Dec 15, 2009 4:57 am

that was totally wicked


u gotta make another 1
Lunsfordium
Lunsfordium
[Blankie]

Posts : 194

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Paul Fri Dec 18, 2009 4:09 am

My game is so much better, Anyways. . .

I'm surprised we've actually got a FEW topics with multiple pages.
Paul
Paul
Pickaxe

Posts : 611

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Admin Fri Dec 18, 2009 4:10 am

another_pd wrote:My game is so much better, Anyways. . .

I'm surprised we've actually got a FEW topics with multiple pages.
they're not good topics, but yeah still pretty cool we have multiple pages.
Admin
Admin
Pirate King

Posts : 559

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Paul Fri Dec 18, 2009 4:12 am

I find it funny that Brad assumes that it is just so easy for you to make more games.
Paul
Paul
Pickaxe

Posts : 611

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Admin Fri Dec 18, 2009 4:15 am

more rpgs? eh... it's alot easier when you got one down because you can just makes some major tweaks in the old one and call it a totally new game.
Admin
Admin
Pirate King

Posts : 559

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Paul Fri Dec 18, 2009 4:38 am

OR. . .

If you follow good coding practices for reusable code (one of the things c++ was DESIGNED for) you have a code base that makes it really easy to creatre whatever game you want.
Paul
Paul
Pickaxe

Posts : 611

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by I_don't_know Wed Dec 23, 2009 7:58 pm

i tried the game too and it said it can't find the randnum identifier. is there anyway to fix this because i want to see how it goes.
I_don't_know
I_don't_know
Skid

Posts : 17

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Paul Wed Dec 23, 2009 8:01 pm

Do you have everything in the separate files?
Paul
Paul
Pickaxe

Posts : 611

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by I_don't_know Wed Dec 23, 2009 8:26 pm

yup... should I put them all in one file?
I_don't_know
I_don't_know
Skid

Posts : 17

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Admin Wed Dec 23, 2009 8:31 pm

NO. do it exactly like i did it and it should work.
Admin
Admin
Pirate King

Posts : 559

Back to top Go down

My C++ RPG TEXT GAME Empty Re: My C++ RPG TEXT GAME

Post by Sponsored content


Sponsored content


Back to top Go down

Page 1 of 2 1, 2  Next

Back to top

- Similar topics

CMPC :: Computing :: Programming :: C++

 
Permissions in this forum:
You cannot reply to topics in this forum