Code:
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <string.h>
typedef char string[25];
typedef string string2[5];
string2 inventory;
class Digimon
{
private:
string name;
int health;
int stamina;
int atthp;
public:
Digimon(string="nothing", int=0, int=0, int=0);
void SetValue(string, int, int, int);
friend ostream& operator<<(ostream& out, Digimon& digi);
friend void Play(Digimon&, Digimon&);
void AttLost(int);
void StaLost(int);
friend void EvilVillage(Digimon&);
friend void DigmonHouse(Digimon&);
};
Digimon::Digimon(string n, int hp, int sp, int ahp)
{
strcpy(name,n);
health=hp;
stamina=sp;
atthp=ahp;
}
void Digimon::SetValue(string n, int hp, int sp, int ahp)
{
strcpy(name,n);
health=hp;
stamina=sp;
atthp=ahp;
}
ostream& operator<<(ostream& out, Digimon& digi)
{
out<<"Your Digimon STATS"<<endl;
out<<"Your Digimon : "<<digi.name<<endl;
out<<"Your HP : "<<digi.health<<endl;
out<<"Your SP : "<<digi.stamina<<endl;
return out;
}
void DisplayInventory(); //Normal Function Prototype
void Play(Digimon& enem, Digimon& you)
{
int res;
cout<<"Choose an option"<<endl;
cout<<"1.Attack Opponent"<<endl;
cout<<"2.Not Moving"<<endl;
cout<<"3.Defend"<<endl;
cout<<"4.Inventory"<<endl;
cin>>res;
while ((enem.health>0)&&(you.health>0))
{
if (res==1)
{
cout<<you.name<<" ATTACK!!!"<<endl;
if (enem.stamina >= you.stamina)
{
cout<<"attack fail"<<endl;
you.StaLost(2);
}
else
{
enem.AttLost(you.atthp);
you.StaLost(2);
cout<<"Enemy lose "<<you.atthp<<" HP"<<endl;
cout<<enem;
}
}
else if (res==2)
{
cout<<"Your digimon is not moving"<<endl;
cout<<"Suddenly...";
cout<<enem.name<<" WOOF!!"<<endl;
if (you.stamina >= enem.stamina)
{
cout<<"He fail!";
}
else
{
you.AttLost(enem.atthp);
enem.StaLost(2);
cout<<"You lose "<<enem.atthp<<" HP";
cout<<you;
}
}
else if (res==3)
{
cout<<"I defend"<<endl;
if (enem.stamina >= you.stamina)
{
cout<<"But you fail!";
cout<<"He attacks"<<enem.atthp<<" of your life points"<<endl;
you.AttLost(enem.atthp);
enem.StaLost(2);
}
else
{
cout<<"I defend"<<endl;
cout<<"Defend Successuful!!"<<endl;
enem.StaLost(2);
}
}
else
{
int option;
cout<<"Select an Option"<<endl<<endl;
DisplayInventory();
cin>>option;
if (option == 1)
{
cout<<"Attack With Magic Rod!!"<<endl;
if ((you.stamina >= enem.stamina)&&(you.stamina >5))
{
enem.AttLost(5);
cout<<"He lost 5 hp point";
}
else if (you.stamina >= enem.stamina)
{
cout<<"Not enough Stamina"<<endl;
}
else if (you.stamina > 5)
cout<<"You missed"<<endl;
else
cout<<"Not enought Stamina"<<endl;
}
else
cout<<"Will be available soon"<<endl;
}
cout<<"Choose an option"<<endl;
cout<<"1.Attack Opponent"<<endl;
cout<<"2.Not Moving"<<endl;
cout<<"3.Defend"<<endl;
cout<<"4.Inventory"<<endl;
cin>>res;
}
if (enem.health<=0)
{
cout<<"YOU WIN!!"<<endl;
}
else
cout<<"YOU LOST!!"<<endl;
}
void Digimon::AttLost(int lostHP)
{
health=health-lostHP;
}
void Digimon::StaLost(int lostSP)
{
stamina=stamina-lostSP;
}
void ChooseCharacter(int&);
void DefaultInventory();
void InputInventory(string invent); //Function prototype
int main()
{
int ans;
DefaultInventory();
Digimon obj;
ChooseCharacter(ans);
if (ans==1)
{
obj.SetValue("Guilmon", 25, 10, 4);
cout<<obj;
}
else if (ans==2)
{
obj.SetValue("Renamon", 20, 20, 2);
cout<<obj;
}
else
{
obj.SetValue("Terriermon", 22, 15,3);
cout<<obj;
}
int dest;
cout<<"Choose your destination"<<endl;
cout<<"1. Evil Village"<<endl;
cout<<"2. Darkness Forest"<<endl;
cout<<"3. Rubymon's Dungeon"<<endl;
cout<<"4. The Shadow Realm"<<endl;
cin>>dest;
if (dest==1)
{
EvilVillage(obj);
}
/*cout<<"You found a magic rod!!"<<endl;
InputInventory("MAGICROD");
cout<<"You found a magic stone"<<endl;
InputInventory("STONE");
cout<<"\nYou encounter a crazy stupid yet powerful digiMONSTER!!"<<endl;
cout<<"IT is RUBYMON!!!"<<endl;
Digimon enemy1("Rubymon", 12, 22, 2);
Play(enemy1, obj);
cout<<obj;
cout<<enemy1;*/
return 0;
}
void ChooseCharacter(int& ans)
{
cout<<"Welcome to The Digital World"<<endl;
cout<<"Please choose your favorite digimon to travel with you!"<<endl;
cout<<"1.Guilmon"<<endl;
cout<<"2.Renamon"<<endl;
cout<<"3.Terriermon"<<endl;
cin>>ans;
}
void DefaultInventory()
{
for (int k=0;k<5;k++)
strcpy(inventory[k], "??");
}
void InputInventory(string invent)
{
static int i=0;
strcpy(inventory[i], invent);
i++;
}
void DisplayInventory()
{
for (int j=0;j<5;j++)
cout<<j+1<<". "<<inventory[j]<<endl;
}
void EvilVillage(Digimon& obj) //Friend Function
{
int dec1;
cout<<"You are now walking in Evil Village....there are no people but old and abandoned house...";
cout<<"\nUnfortunately, all the door are lock except the big house in front of you, which has no front door";
cout<<"Enter in or not?"<<endl<<endl;
cout<<"1.Yes ENTER IN NOW!!";
cout<<"\n2.No I am afraid"<<endl;
cin>>dec1;
if (dec1==1)
{
DigmonHouse(obj);
}
}
void DigmonHouse(Digimon& obj) //Friend Function
{
cout<<"When you enter into the house, you see an empty table and a big television"<<endl;
cout<<"It seem that nobody are here...SUDDENTLY"<<endl;
cout<<"The TV turns on automatically...and you see a Digimon";
cout<<"He says: YOU ARE THE CHOSEN ONE...OUR VILLAGE IS DESTROY BY THE EVIL DIGIMON 'RUBY'";
cout<<"WHO EAT ALL MY PEOPLE AND DESTROY OUR VILLAGE POLUTE OUR WORLD AND DESTROY OTHERS!!";
cout<<"He says: My name is DIGMON, i am currently using my magic power to communicate with you through this TV..";
cout<<" DIGMON: I am now in a safe place(somewhere in the digital World), but you gotta help to save the digital world";
cout<<" DIGMON: The Evil Ruby will DESTROY the whole Digital World, so you gotta fight him and save the digital world..";
cout<<"....beep....beep"<<endl<<endl;
cout<<"Digmon dissappear in TV and the TV turns off...."<<endl;
cout<<"I say: What can we do now?"<<endl;
cout<<obj.name<<" says: "<<"well, i think he says that we are the chosen one, so we must destroy RUBY and SAVE THE DIGITAL WORLD!!"<<endl;
cout<<"I say: Well, what are we waiting for?....LET'S GO!!"<<endl;
}
Thanks