Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

NAMA : Zulfikar Ali Osman Alhamid

NIM : 2017-08-01-196

#include <iostream>
#include <conio.h>
#include <fstream> using
namespace std;

int choicemonster,attackchoice,levels,setlifechoice,increasechoice,senjata,orang; string


name,senjata1,orang1,z;
class
Menu {
private :
struct warrior
{
int life = 100; int power =
70; int def = 50; int
magic = 40; int spirit = 60; int
exp = 0; int money =100;
}warrior;

struct monster
{
int m1life = 150;
int m1attack = 15;
int m2life = 100; int
m2attack = 20;
}monster;

public : void status() ;


void battle() ; void level() ;
void setlife(); void increase();
void exit();
};
class basic
{ private
:
int weapon;
string name;
int characters;

public :
void character();
void yourweapon();
void yourname ();
};
void Menu::exit()
{ ofstream output; output.open("Data
Games.Txt"); output<<"Name = "<<z<<endl;
output<<"Character= "<<orang1<<endl;
output<<"Weapon =
"<<senjata1<<endl; output<<"Life =
"<<warrior.life<<endl; output<<"power
= "<<warrior.power<<endl; output<<"Magic
= "<<warrior.magic<<endl; output<<"def
= "<<warrior.def<<endl; output<<"Spirit
= "<<warrior.spirit<<endl;
output.close();
}
void Menu::status()
{ system("cls");
cout<<"Your Status : "<<endl; cout<<"Life
= "<<warrior.life<<endl; cout<<"Power =
"<<warrior.power<<endl; cout<<"Def =
"<<warrior.def<<endl; cout<<"Magic =
"<<warrior.magic<<endl; cout<<"Spirit =
"<<warrior.spirit<<endl; cout<<"Exp =
"<<warrior.exp<<endl; cout<<"Money =
"<<warrior.money<<endl; getch();
}
void Menu::battle()
{ system("cls");
cout<<"Choice the Monster : "<<endl;
cout<<"1.Cornex"<<endl; cout<<"2.Gordox"<<endl;
cout<<"Your Choice(1/2) :";cin>>choicemonster;

if(choicemonster==1)
{
system("cls");
cout<<"Your life : "<<warrior.life<<endl; cout<<"Cornex
Life :"<<monster.m1life<<endl<<endl;

for(int i=0;i<100;i++)
{
serang :
{
system("cls"); cout<<"Your
Turn!"<<endl; cout<<"Select Your
Action"<<endl; cout<<"1.Attack with
Weapon"<<endl; cout<<"2.Attack with
Magic"<<endl; cout<<"3.Cancel
attack"<<endl; cout<<"Your Choice =
";cin>>attackchoice;

if(attackchoice==1)
{
system("cls");
monster.m1life = monster.m1life-((0.2*warrior.power)+(0.1*warrior.spirit)) ;
cout<<"ATTACK SUCCESS!"<<endl;

if(monster.m1life<=0)
{
warrior.exp = warrior.exp + 150 ;
warrior.money= warrior.money + 300;
cout<<"You WIN THE GAME!!"<<endl;
cout<<"Reward : "<<endl; cout<<"150xp &
300 Money"<<endl;
getch();
Menu::level(); break;

}
else
{
cout<<"Cornex Life = "<<monster.m1life<<endl;
getch();
}
}

else if(attackchoice==2)
{
system("cls");
monster.m1life = monster.m1life-((0.4*warrior.magic)+(0.1*warrior.spirit)) ;
cout<<"ATTACK SUCCESS!"<<endl;

if(monster.m1life<=0)
{
warrior.exp = warrior.exp + 150 ;
warrior.money= warrior.money + 300;
cout<<"You WIN THE GAME!!"<<endl;
cout<<"Reward : "<<endl; cout<<"150xp &
300 Money"<<endl; Menu::level();
getch();
break;
}
else
{
cout<<"Cornex Life = "<<monster.m1life<<endl;
getch();
}

else if(attackchoice==3)
{
break;
}

}
system("cls");
cout<<"Cornex Turn"<<endl;
warrior.life = warrior.life - (monster.m1attack - (0.1*warrior.def));
getch();
if(warrior.life<=0)
{
warrior.exp = warrior.exp + 50 ;
warrior.money= warrior.money + 100;

cout<<"YOU LOSE!"<<endl;
cout<<"Reward : "<<endl; cout<<"50xp & 100
money"<<endl;
Menu::level();
getch();
break;
}
else
{
cout<<"DEFFEND SUCCESS"<<endl;
cout<<"Your Life = "<<warrior.life;
getch();
}

}
}
if(choicemonster==2)
{
system("cls");
cout<<"Your life : "<<warrior.life<<endl; cout<<"Gordox
Life :"<<monster.m2life<<endl<<endl;

for(int i=0;i<100;i++)
{
hajar :
{
system("cls"); cout<<"Your
Turn!"<<endl; cout<<"Select Your
Action"<<endl; cout<<"1.Attack with
Weapon"<<endl; cout<<"2.Attack with
Magic"<<endl; cout<<"3.Cancel
attack"<<endl; cout<<"Your Choice =
";cin>>attackchoice;

if(attackchoice==1)
{
system("cls");
monster.m2life = monster.m2life-((0.2*warrior.power)+(0.1*warrior.spirit)) ;
cout<<"ATTACK SUCCESS!"<<endl;

if(monster.m2life<=0)
{
warrior.exp = warrior.exp + 150 ;
warrior.money= warrior.money + 300; cout<<"You
WIN THE GAME!!"<<endl; cout<<"Reward : "<<endl;
cout<<"150xp & 300 Money"<<endl;
Menu::level();
getch();
break;
}
else
{
cout<<"Gordox Life = "<<monster.m2life<<endl;
getch();
}
}

else if(attackchoice==2)
{
system("cls");
monster.m2life = monster.m2life-((0.4*warrior.magic)+(0.1*warrior.spirit)) ;
cout<<"ATTACK SUCCESS!"<<endl;

if(monster.m2life<=0)
{
warrior.exp = warrior.exp + 150 ;
warrior.money= warrior.money + 300;
cout<<"You WIN THE GAME!!"<<endl;
cout<<"Reward : "<<endl;
cout<<"150xp & 300 Money"<<endl;
Menu::level();
getch();
break;
}
else
{
cout<<"Gordox Life = "<<monster.m2life<<endl;
getch();
}

else if(attackchoice==3)
{
break;
}

}
system("cls");
cout<<"Gordox Turn"<<endl;
warrior.life = warrior.life - (monster.m2attack - (0.1*warrior.def));
getch();
if(warrior.life<=0)
{
warrior.exp = warrior.exp + 50 ;
warrior.money= warrior.money + 100;

cout<<"YOU LOSE!"<<endl;
cout<<"Reward : "<<endl;
cout<<"50xp & 100 money"<<endl;
getch();
Menu::level();
break;
}

else
{
cout<<"DEFFEND SUCCESS"<<endl;
cout<<"Your Life = "<<warrior.life;
getch();
}

}
}
}
void Menu::level()
{
levels = (warrior.exp/100); cout<<"Your
Level = "<<levels<<endl;
}
void Menu::setlife()
{ system("cls");
cout<<"Your Money : "<<warrior.money<<endl;
cout<<"Whic one you will buy : "<<endl; cout<<"1.
50% life, price : 30 "<<endl; cout<<"2. 100%
life,price : 50 "<<endl; cout<<"Your Choice(1/2)
: ";cin>>setlifechoice;

if(setlifechoice==1)
{
if(warrior.money>=30)
{
warrior.money = warrior.money - 30;
warrior.life = warrior.life + 30;
cout<<"BUY SUCCESS,Your New Life = "<<warrior.life<<endl;
getch();
}
else if(warrior.money<30)
{
cout<<"You Don`t have enough Money!"<<endl;
getch();
}
}
else if(setlifechoice==2)
{
if(warrior.money>=50)
{
warrior.money = warrior.money - 50;
warrior.life = warrior.life + 50;
cout<<"BUY SUCCESS,Your New Life = "<<warrior.life<<endl;
getch();
}
else if(warrior.money<50)
{
cout<<"You Don`t have enough Money!"<<endl;
getch();
}
}
}
void Menu::increase()
{ system("cls");
cout<<"Your Money = "<<warrior.money;
cout<<"\nSpent 200 money for increase you character status ?
"<<endl; cout<<"1.YES"<<endl; cout<<"2.NO"<<endl;
cout<<"\nYour Choice(1/2) = ";cin>>increasechoice;
cout<<endl;
if(warrior.money>=200 && increasechoice==1)
{
warrior.power = warrior.power + 10 ;
warrior.magic = warrior.magic + 10 ;
warrior.spirit = warrior.spirit + 10 ; warrior.def
= warrior.def + 10 ;
warrior.money==warrior.money-200; cout<<"BUY
SUCCESS,Your New Status Is = "<<endl;
cout<<"Power = "<<warrior.power<<endl;
cout<<"Magic = "<<warrior.magic<<endl;
cout<<"Spirit = "<<warrior.spirit<<endl;
cout<<"Def = "<<warrior.def<<endl;
}
else if(warrior.money<200&&increasechoice==1)
{
cout<<"Failed,You Don`t Have enough Money!"<<endl;
}
else
if(increasechoice==2)
{
cout<<"Canceled!"<<endl;
}
getch();
}
void basic::yourname()
{
cout<<"Before you start The Game,Please write your name here = ";
cin.sync(); getline(cin,name); z=name;
}
void basic::character()
{ system("cls");
cout<<"HELLO,WELCOME TO LOLY&LILY GAMES"<<endl;
cout<<"First,Choice Your Character : "<<endl;
cout<<"1.Loly"<<endl; cout<<"2.Lily"<<endl;
cout<<"Your Choice(1/2) = ";cin>>characters;
orang=characters; if(characters==1)
{
orang1="Loly";
system("cls");
cout<<"Hello Loly,Set Find Your equipment Weapon"<<endl;
cout<<"1.Sword"<<endl;
cout<<"2.Axe"<<endl;
cout<<"3.Arrow"<<endl; cout<<"4.Magic
Wand"<<endl;
cout<<endl<<"Your Weapon(1/2/3/4) = ";cin>>weapon;
senjata=weapon;
if(weapon==1)
{
senjata1="sword";
}
else if(weapon==2)
{
senjata1="Axe";
}
else if(weapon==3)
{
senjata1="Arrow";
}
else if(weapon==4)
{
senjata1="Magic Wand";
}
cout<<"Wow..That`s a great Choice!"<<endl;
}
if(characters==2)
{
orang1="Lily";
system("cls");
cout<<"Hello Lily,Set Find Your equipment Weapon"<<endl;
cout<<"1.Sword"<<endl;
cout<<"2.Axe"<<endl;
cout<<"3.Arrow"<<endl;
cout<<"4.Magic Wand"<<endl; cout<<endl<<"Your
Weapon(1/2/3/4) = ";cin>>weapon;
senjata=weapon;
if(weapon==1)
{
senjata1="sword";
}
else if(weapon==2)
{
senjata1="Axe";
}
else if(weapon==3)
{
senjata1="Arrow";
}
else if(weapon==4)
{
senjata1="Magic Wand";
}
cout<<"Wow..That`s a great Choice!"<<endl;
}
getch();
} int main()
{ int
pil,save; Menu
M; basic b;
system("cls");
b.yourname();
b.character(); do { system("cls");
cout<<"ATLANTIS VILLAGE"<<endl;
cout<<"Menu : "<<endl; cout<<"1.Cek
Status"<<endl; cout<<"2.Battle With
Enemy"<<endl; cout<<"3.Set Full Your
Life"<<endl; cout<<"4.Increase Your
Status"<<endl; cout<<"5.EXIT"<<endl;
cout<<"\n\nYour Choice : ";cin>>pil;
switch(pil)
{
case 1:M.status();break;
case 2:M.battle();break;
case 3:M.setlife();break;
case 4:M.increase();break;
}
}
while(pil!=5); if(pil==5)
{
cout<<"Do you want to save your game : "<<endl;
cout<<"1.YES"<<endl;
cout<<"2.NO"<<endl; cout<<"Your
Choice(1/2) = ";cin>>save; if(save==1)
{
M.exit();
}
}
}

SCREENSHOT HASIL PROGRAM

You might also like