master
IoTcat 5 years ago
parent b5e193cfa4
commit 4b919b2335
  1. 41
      as2/ex2/archer.cpp
  2. 39
      as2/ex2/mage.cpp
  3. 2
      as2/ex2/player.h
  4. 179
      as2/ex2/swordsman.cpp

@ -24,7 +24,7 @@ archer::archer(int lv_in, string name_in)
playerdeath=0; playerdeath=0;
EXP=LV*LV*75; EXP=LV*LV*75;
bag.set(lv_in, lv_in); bag.set(lv_in*(rand()%2), lv_in*(rand()%2));
} }
void archer::isLevelUp() void archer::isLevelUp()
@ -37,7 +37,9 @@ void archer::isLevelUp()
HPmax+=8; HPmax+=8;
MPmax+=2; MPmax+=2;
speed+=2; speed+=2;
bag.set(bag.nOfHeal()+LV, bag.nOfMW()+LV);
cout<<name<<" Level UP!"<<endl; cout<<name<<" Level UP!"<<endl;
cout<<"Get " << LV << " Heal and " << LV << " Magic Water!"<<endl;
cout<<"HP improved 8 points to "<<HPmax<<endl; cout<<"HP improved 8 points to "<<HPmax<<endl;
cout<<"MP improved 2 points to "<<MPmax<<endl; cout<<"MP improved 2 points to "<<MPmax<<endl;
cout<<"Speed improved 2 points to "<<speed<<endl; cout<<"Speed improved 2 points to "<<speed<<endl;
@ -54,18 +56,19 @@ bool archer::attack(player &p)
double EXPtemp=0; // player obtained exp double EXPtemp=0; // player obtained exp
double hit=1; // attach factor, probably give critical attack double hit=1; // attach factor, probably give critical attack
srand((unsigned)time(NULL)); // generating random seed based on system time srand((unsigned)time(NULL)); // generating random seed based on system time
int attack = (speed*1.8)/p.DP; //depand on player's speed and p.DP
// If speed greater than opponent, you have some possibility to do double attack // If speed greater than opponent, you have some possibility to do double attack
if ((speed>p.speed) && (rand()%100<(speed-p.speed))) // rand()%100 means generates a number no greater than 100 if ((speed>p.speed) && (rand()%100<(speed-p.speed))) // rand()%100 means generates a number no greater than 100
{ {
HPtemp=(int)((1.0*AP/p.DP)*AP*5/(rand()%4+10)); // opponent's HP decrement calculated based their AP/DP, and uncertain chance HPtemp=(int)((attack)*AP*5/(rand()%4+10)); // opponent's HP decrement calculated based their AP/DP, and uncertain chance
cout<<name<<"'s quick strike hit "<<p.name<<", "<<p.name<<"'s HP decreased "<<HPtemp<<endl; cout<<name<<"'s quick strike hit "<<p.name<<", "<<p.name<<"'s HP decreased "<<HPtemp<<endl;
p.HP=int(p.HP-HPtemp); p.HP=int(p.HP-HPtemp);
EXPtemp=(int)(HPtemp*1.2); EXPtemp=(int)(HPtemp*1.2);
} }
// If speed smaller than opponent, the opponent has possibility to evade // If speed smaller than opponent, the opponent has possibility to evade
if ((speed<p.speed) && (rand()%50<1)) else if ((speed<p.speed) && (rand()%50<1))
{ {
cout<<name<<"'s attack has been evaded by "<<p.name<<endl; cout<<name<<"'s attack has been evaded by "<<p.name<<endl;
system("pause"); system("pause");
@ -73,19 +76,25 @@ bool archer::attack(player &p)
} }
// 10% chance give critical attack // 10% chance give critical attack
if (rand()%100<=10) else
{ {
hit=1.5; if(rand()%100<=10) {
cout<<"Critical attack: "; hit=1.5;
cout<<"Critical attack: ";
}
// Normal attack
//<!-- change
HPtemp=(int)(((attack)*AP*5/(rand()%4+10)) * hit);
//-->
cout<<name<<" uses shoot, "<<p.name<<"'s HP decreases "<<HPtemp<<endl;
EXPtemp=(int)(EXPtemp+HPtemp*1.2);
//<!-- luck
p.HP=(int)(p.HP-HPtemp*((double)(rand() % 100 + 50) / (double)100));
//-->
} }
// Normal attack
HPtemp=(int)((1.0*AP/p.DP)*AP*5/(rand()%4+10));
cout<<name<<" uses bash, "<<p.name<<"'s HP decreases "<<HPtemp<<endl;
EXPtemp=(int)(EXPtemp+HPtemp*1.2);
//<!-- luck
p.HP=(int)(p.HP-HPtemp*((double)(rand() % 100 + 50) / (double)100));
//-->
cout<<name<<" obtained "<<EXPtemp<<" experience."<<endl; cout<<name<<" obtained "<<EXPtemp<<" experience."<<endl;
//<!-- luck //<!-- luck
EXP=(int)(EXP+EXPtemp*((double)(rand() % 100 + 50) / (double)100)); EXP=(int)(EXP+EXPtemp*((double)(rand() % 100 + 50) / (double)100));
@ -109,7 +118,7 @@ bool archer::specialatt(player &p)
//10% chance opponent evades //10% chance opponent evades
if(rand()%100<=10) if(rand()%100<=10)
{ {
cout<<name<<"'s leap attack has been evaded by "<<p.name<<endl; cout<<name<<"'s shoooooooooooot attack has been evaded by "<<p.name<<endl;
system("pause"); system("pause");
return 1; return 1;
} }
@ -120,9 +129,9 @@ bool archer::specialatt(player &p)
//srand(time(NULL)); //srand(time(NULL));
//<!-- // Luck //<!-- // Luck
HPtemp=(int)(AP*1.2*((double)(rand() % 100 + 50) / (double)100)+20); // not related to opponent's DP HPtemp=(int)(AP*1.2*((double)(rand() % 100 + 50) / (double)100)+20); // not related to opponent's DP
//--> //-->
EXPtemp=(int)(HPtemp*1.5); // special attack provides more experience EXPtemp=(int)(HPtemp*1.5); // special attack provides more experience
cout<<name<<" uses leap attack, "<<p.name<<"'s HP decreases "<<HPtemp<<endl; cout<<name<<" uses shoooooooooooot attack, "<<p.name<<"'s HP decreases "<<HPtemp<<endl;
cout<<name<<" obtained "<<EXPtemp<<" experience."<<endl; cout<<name<<" obtained "<<EXPtemp<<" experience."<<endl;
p.HP=(int)(p.HP-HPtemp); p.HP=(int)(p.HP-HPtemp);
EXP=(int)(EXP+EXPtemp); EXP=(int)(EXP+EXPtemp);

@ -24,7 +24,7 @@ mage::mage(int lv_in, string name_in)
playerdeath=0; playerdeath=0;
EXP=LV*LV*75; EXP=LV*LV*75;
bag.set(lv_in, lv_in); bag.set(lv_in*(rand()%2), lv_in*(rand()%2));
} }
void mage::isLevelUp() void mage::isLevelUp()
@ -37,7 +37,9 @@ void mage::isLevelUp()
HPmax+=8; HPmax+=8;
MPmax+=2; MPmax+=2;
speed+=2; speed+=2;
bag.set(bag.nOfHeal()+LV, bag.nOfMW()+LV);
cout<<name<<" Level UP!"<<endl; cout<<name<<" Level UP!"<<endl;
cout<<"Get " << LV << " Heal and " << LV << " Magic Water!"<<endl;
cout<<"HP improved 8 points to "<<HPmax<<endl; cout<<"HP improved 8 points to "<<HPmax<<endl;
cout<<"MP improved 2 points to "<<MPmax<<endl; cout<<"MP improved 2 points to "<<MPmax<<endl;
cout<<"Speed improved 2 points to "<<speed<<endl; cout<<"Speed improved 2 points to "<<speed<<endl;
@ -54,18 +56,19 @@ bool mage::attack(player &p)
double EXPtemp=0; // player obtained exp double EXPtemp=0; // player obtained exp
double hit=1; // attach factor, probably give critical attack double hit=1; // attach factor, probably give critical attack
srand((unsigned)time(NULL)); // generating random seed based on system time srand((unsigned)time(NULL)); // generating random seed based on system time
int attack = (EXP/75 +25)/p.DP;
// If speed greater than opponent, you have some possibility to do double attack // If speed greater than opponent, you have some possibility to do double attack
if ((speed>p.speed) && (rand()%100<(speed-p.speed))) // rand()%100 means generates a number no greater than 100 if ((speed>p.speed) && (rand()%100<(speed-p.speed))) // rand()%100 means generates a number no greater than 100
{ {
HPtemp=(int)((1.0*AP/p.DP)*AP*5/(rand()%4+10)); // opponent's HP decrement calculated based their AP/DP, and uncertain chance HPtemp=(int)((attack)*AP*5/(rand()%4+10)); // opponent's HP decrement calculated based their AP/DP, and uncertain chance
cout<<name<<"'s quick strike hit "<<p.name<<", "<<p.name<<"'s HP decreased "<<HPtemp<<endl; cout<<name<<"'s quick strike hit "<<p.name<<", "<<p.name<<"'s HP decreased "<<HPtemp<<endl;
p.HP=int(p.HP-HPtemp); p.HP=int(p.HP-HPtemp);
EXPtemp=(int)(HPtemp*1.2); EXPtemp=(int)(HPtemp*1.2);
} }
// If speed smaller than opponent, the opponent has possibility to evade // If speed smaller than opponent, the opponent has possibility to evade
if ((speed<p.speed) && (rand()%50<1)) else if ((speed<p.speed) && (rand()%50<1))
{ {
cout<<name<<"'s attack has been evaded by "<<p.name<<endl; cout<<name<<"'s attack has been evaded by "<<p.name<<endl;
system("pause"); system("pause");
@ -73,19 +76,25 @@ bool mage::attack(player &p)
} }
// 10% chance give critical attack // 10% chance give critical attack
if (rand()%100<=10) else
{ {
hit=1.5; if(rand()%100<=10) {
cout<<"Critical attack: "; hit=1.5;
cout<<"Critical attack: ";
}
// Normal attack
//<!-- change
HPtemp=(int)(((attack)*AP*5/(rand()%4+10)) * hit);
//-->
cout<<name<<" uses fire ball, "<<p.name<<"'s HP decreases "<<HPtemp<<endl;
EXPtemp=(int)(EXPtemp+HPtemp*1.2);
//<!-- luck
p.HP=(int)(p.HP-HPtemp*((double)(rand() % 100 + 50) / (double)100));
//-->
} }
// Normal attack
HPtemp=(int)((1.0*AP/p.DP)*AP*5/(rand()%4+10));
cout<<name<<" uses bash, "<<p.name<<"'s HP decreases "<<HPtemp<<endl;
EXPtemp=(int)(EXPtemp+HPtemp*1.2);
//<!-- luck
p.HP=(int)(p.HP-HPtemp*((double)(rand() % 100 + 50) / (double)100));
//-->
cout<<name<<" obtained "<<EXPtemp<<" experience."<<endl; cout<<name<<" obtained "<<EXPtemp<<" experience."<<endl;
//<!-- luck //<!-- luck
EXP=(int)(EXP+EXPtemp*((double)(rand() % 100 + 50) / (double)100)); EXP=(int)(EXP+EXPtemp*((double)(rand() % 100 + 50) / (double)100));
@ -109,7 +118,7 @@ bool mage::specialatt(player &p)
//10% chance opponent evades //10% chance opponent evades
if(rand()%100<=10) if(rand()%100<=10)
{ {
cout<<name<<"'s leap attack has been evaded by "<<p.name<<endl; cout<<name<<"'s ffffffire balls attack has been evaded by "<<p.name<<endl;
system("pause"); system("pause");
return 1; return 1;
} }
@ -122,7 +131,7 @@ bool mage::specialatt(player &p)
HPtemp=(int)(AP*1.2*((double)(rand() % 100 + 50) / (double)100)+20); // not related to opponent's DP HPtemp=(int)(AP*1.2*((double)(rand() % 100 + 50) / (double)100)+20); // not related to opponent's DP
//--> //-->
EXPtemp=(int)(HPtemp*1.5); // special attack provides more experience EXPtemp=(int)(HPtemp*1.5); // special attack provides more experience
cout<<name<<" uses leap attack, "<<p.name<<"'s HP decreases "<<HPtemp<<endl; cout<<name<<" uses ffffffire balls attack, "<<p.name<<"'s HP decreases "<<HPtemp<<endl;
cout<<name<<" obtained "<<EXPtemp<<" experience."<<endl; cout<<name<<" obtained "<<EXPtemp<<" experience."<<endl;
p.HP=(int)(p.HP-HPtemp); p.HP=(int)(p.HP-HPtemp);
EXP=(int)(EXP+EXPtemp); EXP=(int)(EXP+EXPtemp);

@ -50,8 +50,8 @@ public:
void isDead(); // check whether character is dead void isDead(); // check whether character is dead
bool useHeal(); // consume heal, irrelevant to job bool useHeal(); // consume heal, irrelevant to job
bool useMW(); // consume magic water, irrelevant to job bool useMW(); // consume magic water, irrelevant to job
void transfer(player &p); // possess opponent's items after victory
void showRole(); // display character's job void showRole(); // display character's job
void transfer(player &p); // possess opponent's items after victory
private: private:
bool playerdeath; // whether character is dead, doesn't need to be accessed or inherited bool playerdeath; // whether character is dead, doesn't need to be accessed or inherited

@ -29,106 +29,115 @@ swordsman::swordsman(int lv_in, string name_in)
void swordsman::isLevelUp() void swordsman::isLevelUp()
{ {
if(EXP>=LV*LV*75) if(EXP>=LV*LV*75)
{ {
LV++; LV++;
AP+=4; AP+=4;
DP+=4; DP+=4;
HPmax+=8; HPmax+=8;
MPmax+=2; MPmax+=2;
speed+=2; speed+=2;
cout<<name<<" Level UP!"<<endl; bag.set(bag.nOfHeal()+LV, bag.nOfMW()+LV);
cout<<"HP improved 8 points to "<<HPmax<<endl; cout<<name<<" Level UP!"<<endl;
cout<<"MP improved 2 points to "<<MPmax<<endl; cout<<"Get " << LV << " Heal and " << LV << " Magic Water!"<<endl;
cout<<"Speed improved 2 points to "<<speed<<endl; cout<<"HP improved 8 points to "<<HPmax<<endl;
cout<<"AP improved 4 points to "<<AP<<endl; cout<<"MP improved 2 points to "<<MPmax<<endl;
cout<<"DP improved 5 points to "<<DP<<endl; cout<<"Speed improved 2 points to "<<speed<<endl;
system("pause"); cout<<"AP improved 4 points to "<<AP<<endl;
isLevelUp(); // recursively call this function, so the character can level up multiple times if got enough exp cout<<"DP improved 5 points to "<<DP<<endl;
} system("pause");
isLevelUp(); // recursively call this function, so the character can level up multiple times if got enough exp
}
} }
bool swordsman::attack(player &p) bool swordsman::attack(player &p)
{ {
double HPtemp=0; // opponent's HP decrement double HPtemp=0; // opponent's HP decrement
double EXPtemp=0; // player obtained exp double EXPtemp=0; // player obtained exp
double hit=1; // attach factor, probably give critical attack double hit=1; // attach factor, probably give critical attack
srand((unsigned)time(NULL)); // generating random seed based on system time srand((unsigned)time(NULL)); // generating random seed based on system time
int attack = AP/p.DP; //depand on player's speed and p.DP
// If speed greater than opponent, you have some possibility to do double attack // If speed greater than opponent, you have some possibility to do double attack
if ((speed>p.speed) && (rand()%100<(speed-p.speed))) // rand()%100 means generates a number no greater than 100 if ((speed>p.speed) && (rand()%100<(speed-p.speed))) // rand()%100 means generates a number no greater than 100
{ {
HPtemp=(int)((1.0*AP/p.DP)*AP*5/(rand()%4+10)); // opponent's HP decrement calculated based their AP/DP, and uncertain chance HPtemp=(int)((attack)*AP*5/(rand()%4+10)); // opponent's HP decrement calculated based their AP/DP, and uncertain chance
cout<<name<<"'s quick strike hit "<<p.name<<", "<<p.name<<"'s HP decreased "<<HPtemp<<endl; cout<<name<<"'s quick strike hit "<<p.name<<", "<<p.name<<"'s HP decreased "<<HPtemp<<endl;
p.HP=int(p.HP-HPtemp); p.HP=int(p.HP-HPtemp);
EXPtemp=(int)(HPtemp*1.2); EXPtemp=(int)(HPtemp*1.2);
} }
// If speed smaller than opponent, the opponent has possibility to evade // If speed smaller than opponent, the opponent has possibility to evade
if ((speed<p.speed) && (rand()%50<1)) else if ((speed<p.speed) && (rand()%50<1))
{ {
cout<<name<<"'s attack has been evaded by "<<p.name<<endl; cout<<name<<"'s attack has been evaded by "<<p.name<<endl;
system("pause"); system("pause");
return 1; return 1;
} }
// 10% chance give critical attack // 10% chance give critical attack
if (rand()%100<=10) else
{ {
hit=1.5; if(rand()%100<=10) {
cout<<"Critical attack: "; hit=1.5;
} cout<<"Critical attack: ";
}
// Normal attack
//<!-- change
HPtemp=(int)(((attack)*AP*5/(rand()%4+10)) * hit);
//-->
cout<<name<<" uses chop, "<<p.name<<"'s HP decreases "<<HPtemp<<endl;
EXPtemp=(int)(EXPtemp+HPtemp*1.2);
//<!-- luck
p.HP=(int)(p.HP-HPtemp*((double)(rand() % 100 + 50) / (double)100));
//-->
// Normal attack }
HPtemp=(int)((1.0*AP/p.DP)*AP*5/(rand()%4+10));
cout<<name<<" uses bash, "<<p.name<<"'s HP decreases "<<HPtemp<<endl;
EXPtemp=(int)(EXPtemp+HPtemp*1.2); cout<<name<<" obtained "<<EXPtemp<<" experience."<<endl;
//<!-- luck
p.HP=(int)(p.HP-HPtemp*((double)(rand() % 100 + 50) / (double)100));
//-->
cout<<name<<" obtained "<<EXPtemp<<" experience."<<endl;
//<!-- luck //<!-- luck
EXP=(int)(EXP+EXPtemp*((double)(rand() % 100 + 50) / (double)100)); EXP=(int)(EXP+EXPtemp*((double)(rand() % 100 + 50) / (double)100));
//--> //-->
system("pause"); system("pause");
return 1; // Attack success return 1; // Attack success
} }
bool swordsman::specialatt(player &p) bool swordsman::specialatt(player &p)
{ {
if(MP<40) if(MP<40)
{ {
cout<<"You don't have enough magic points!"<<endl; cout<<"You don't have enough magic points!"<<endl;
system("pause"); system("pause");
return 0; // Attack failed return 0; // Attack failed
} }
else else
{ {
MP-=40; // consume 40 MP to do special attack MP-=40; // consume 40 MP to do special attack
//10% chance opponent evades //10% chance opponent evades
if(rand()%100<=10) if(rand()%100<=10)
{ {
cout<<name<<"'s leap attack has been evaded by "<<p.name<<endl; cout<<name<<"'s chooooooooooooooop attack has been evaded by "<<p.name<<endl;
system("pause"); system("pause");
return 1; return 1;
} }
double HPtemp=0; double HPtemp=0;
double EXPtemp=0; double EXPtemp=0;
//double hit=1; //double hit=1;
//srand(time(NULL)); //srand(time(NULL));
HPtemp=(int)(AP*1.2+20); // not related to opponent's DP //<!-- // Luck
EXPtemp=(int)(HPtemp*1.5); // special attack provides more experience HPtemp=(int)(AP*1.2*((double)(rand() % 100 + 50) / (double)100)+20); // not related to opponent's DP
cout<<name<<" uses leap attack, "<<p.name<<"'s HP decreases "<<HPtemp<<endl; //-->
cout<<name<<" obtained "<<EXPtemp<<" experience."<<endl; EXPtemp=(int)(HPtemp*1.5); // special attack provides more experience
p.HP=(int)(p.HP-HPtemp); cout<<name<<" uses chooooooooooooooop attack, "<<p.name<<"'s HP decreases "<<HPtemp<<endl;
//<!-- luck cout<<name<<" obtained "<<EXPtemp<<" experience."<<endl;
EXP=(int)(EXP+EXPtemp*((double)(rand() % 100 + 50) / (double)100)); p.HP=(int)(p.HP-HPtemp);
//--> EXP=(int)(EXP+EXPtemp);
system("pause"); system("pause");
} }
return 1; // special attack succeed return 1; // special attack succeed
} }
// Computer opponent // Computer opponent

Loading…
Cancel
Save