Skip to content
This repository was archived by the owner on Jun 12, 2025. It is now read-only.

Commit 174fdda

Browse files
GamerMan7799GamerMan7799
authored andcommitted
Merge pull request #22 from GamerMan7799/dev
Update master to V3.0b
2 parents dcee90b + 015a976 commit 174fdda

File tree

2 files changed

+137
-24
lines changed

2 files changed

+137
-24
lines changed

battle.h

Lines changed: 120 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
Made By: Patrick J. Rye
55
Purpose: A header to hold all the functions related to battling, levelling up and player stats.
6-
Current Revision: 2.3.1
6+
Current Revision: 3.0.1
77
Change Log---------------------------------------------------------------------------------------------------------------------------------------------------
88
Date Revision Changed By Changes
99
------ --------- ------------ ---------------------------------------------------------------------------------------------------------------------
@@ -65,6 +65,16 @@ Date Revision Changed By Changes
6565
2015/03/06 2.3.1 Patrick Rye -Changed system("pause") to getchar();
6666
-Added more pauses.
6767
=============================================================================================================================================================
68+
2015/03/06 3.0 Patrick Rye -Added chance for stun.
69+
-Redid monster levelling.
70+
-Redid health calculation.
71+
-Redid damage calculation.
72+
-Added some variability to attack damage.
73+
=============================================================================================================================================================
74+
2015/03/09 3.0.1 Patrick Rye -Changed some text to better reflect certain changes.
75+
-The less health something has the less damage it will do.
76+
-Nerffered attack damage a bit.
77+
=============================================================================================================================================================
6878
*/
6979

7080
/*
@@ -79,7 +89,7 @@ For Stat Arrays
7989
/*********************************************************************************************************/
8090
/*A quick note on the base stats, a stat cannot be lower than 6, as a modifier might reduce the value by 5 points.
8191
The base stat point should also add up to be 100. */
82-
int MonsterBaseStats[5] = {25,25,10,25,15}; //A base array for the monsters
92+
int MonsterBaseStats[5] = {20,20,20,20,20}; //A base array for the monsters
8393
const int ZombieBaseStats[5] = {25,25,10,25,15};
8494
const int SkeletonBaseStats[5] = {35,18,6,35,6};
8595
const int WitchBaseStats[5] = {15,15,20,20,30};
@@ -101,13 +111,53 @@ int PlayerStats[5] = {5,5,5,5,5};
101111
int intBattleLevel = 1;
102112
bool blBattleDebugMode = false;
103113
/*********************************************************************************************************/
114+
void SetBattleDebugMode(bool isDebug) {blBattleDebugMode = isDebug;}
115+
/*********************************************************************************************************/
116+
117+
118+
119+
bool StunCheck(int intAttackerLuck, int intDefenderLuck)
120+
{
121+
if (intDefenderLuck < intAttackerLuck) {if(rand()% 101 < (intAttackerLuck - intDefenderLuck) / 3) {return true;}}
122+
return false;
123+
}
124+
125+
float DamageHealthPercent(int CurrentHealth, int MaximumHealth)
126+
{
127+
/*Function that returns a percentage value that will be multiplied by the damage.
128+
The value will vary with health so that the less health something has
129+
The less damage it will do.
130+
The max value it return is about 1.01 or something similar, the min value
131+
is about 0.64 */
132+
133+
float HealthPercent = CurrentHealth / MaximumHealth;
134+
float TempValue = 0;
135+
TempValue -= 0.8981 * pow(HealthPercent, 3);
136+
TempValue += 1.297 * pow(HealthPercent, 2);
137+
TempValue -= 0.0358 * HealthPercent;
138+
TempValue += 0.64;
139+
return TempValue;
140+
}
141+
142+
string HitName()
143+
{
144+
/*Outputs a string that represents an attack,
145+
for example rather than just "hit" over and over,
146+
you could get "stabbed" "hit"*/
147+
const string HitStringArray[5] = {"hit","stabbed","cut","slashed","damaged"};
148+
string TempString;
149+
TempString = HitStringArray[rand() % 5];
150+
if (TempString != "") {return TempString;}
151+
return "hit";
152+
}
104153

105154
bool MonsterAttack(int MonsterDamage, double MonsterMuli, bool ishealing)
106155
{
107156
//Holds stuff for when monster attacks.
108157
//Only returns true if player died.
109158
//Is in its own function so I can call it a couple of different places.
110159
cout<<endl;
160+
MonsterDamage = floor(MonsterDamage * DamageHealthPercent(MonsterHealth[0],MonsterHealth[1])); //Reduce damage based on health.
111161
if (ishealing) {floor(MonsterDamage /= 2);} //if player is healing reduce damage.
112162
if (MonsterDamage != 0)
113163
{
@@ -126,10 +176,11 @@ bool PlayerAttack(int PlayerDamage, double PlayerMuli)
126176
//Only returns true if monster died.
127177
//Is in its own function so I can call it a couple of different places.
128178
cout<<endl;
179+
PlayerDamage = floor(PlayerDamage * DamageHealthPercent(PlayerHealth[0],PlayerHealth[1])); //Reduce damage based on health.
129180
if (PlayerDamage != 0)
130181
{
131182
if (PlayerMuli > 1){cout<<"You got a crit on the "<<MonsterName<<"! ";}
132-
cout<<"You hit the "<<MonsterName<<" for "<<PlayerDamage<<".";
183+
cout<<"You "<<HitName()<<" the "<<MonsterName<<" for "<<PlayerDamage<<".";
133184
}
134185
else {cout<<"The "<<MonsterName<<" dodged your attack.";}
135186
MonsterHealth[0] -= PlayerDamage;
@@ -179,18 +230,33 @@ int CalculateHealth(int HealthLevel, int ConsStat)
179230
{
180231
//A simple function for calculating health.
181232
//In its own function so future changes will be changed everywhere.
182-
return floor((23*((5.25+0.5625*HealthLevel+0.00375*pow(HealthLevel,2))+(1+0.066*HealthLevel)*(ConsStat/16))));
233+
double HealthTemp = 0;
234+
HealthTemp = (0.9722 * pow(HealthLevel, 2) )+( 0.4167 * HealthLevel) + 48.611;
235+
HealthTemp += 23.979*exp(0.01414 * ConsStat);
236+
return floor(HealthTemp);
183237
}
184238

185239
int CalculateDamage(int DamageLevel, int StrStat, int DefStat)
186240
{
187-
//A simple function for calculating damage
241+
//A simple function for calculating damage.
188242
//In its own function so future changes will be changed everywhere.
189-
return floor(((((2 * (DamageLevel/5) + 2) * ((10*DamageLevel)/DefStat))*(StrStat))+5));
243+
int DamageTemp = 0;
244+
int intMinDamage = floor((MonsterHealth[1]+PlayerHealth[1])/20) + 1;
245+
StrStat += rand() % DamageLevel;
246+
DefStat += rand() % DamageLevel;
247+
if (DefStat > StrStat) {return intMinDamage;}
248+
else if (DefStat == StrStat) {return intMinDamage + rand() % (DamageLevel *2);}
249+
else
250+
{
251+
DamageTemp = floor((StrStat - DefStat)*1.75);
252+
DamageTemp += intMinDamage;
253+
DamageTemp += rand() % (DamageLevel *2);
254+
return DamageTemp;
255+
}
256+
257+
return intMinDamage;
190258
}
191259

192-
void SetBattleDebugMode(bool isDebug) {blBattleDebugMode = isDebug;}
193-
194260
void RandomMonster()
195261
{
196262
//Generates a number 0 - 4 representing the location of a monster in the monster name array
@@ -301,6 +367,31 @@ void RandomMonsterModifier()
301367
//End of random monster modifier.
302368
}
303369

370+
void LevelUpMonster()
371+
{
372+
//Function to level up the monster.
373+
int StatUpgradeChance[5] = {0,0,0,0,0};
374+
int intStatPoints = (intBattleLevel - 1) *5; //How many stat points the monster gets.
375+
int intRandomStatChoice = 0;
376+
377+
StatUpgradeChance[0] = MonsterBaseStats[0];
378+
for (int i = 0; i < 5; i++) {MonsterStats[i] = MonsterBaseStats[i];}
379+
for (int i = 1; i < 5; i++) {StatUpgradeChance[i] = StatUpgradeChance[i - 1] + MonsterBaseStats[i];}
380+
for (int i = 0; i < intStatPoints; i++) //Random place points in the different stats.
381+
{
382+
intRandomStatChoice = rand() % 101;
383+
if (intRandomStatChoice < StatUpgradeChance[0]) {MonsterStats[0] += 1;}
384+
else if (intRandomStatChoice < StatUpgradeChance[1]) {MonsterStats[1] += 1;}
385+
else if (intRandomStatChoice < StatUpgradeChance[2]) {MonsterStats[2] += 1;}
386+
else if (intRandomStatChoice < StatUpgradeChance[3]) {MonsterStats[3] += 1;}
387+
else {MonsterStats[4] += 1;}
388+
}
389+
if (blBattleDebugMode) {for(int i = 0; i < 5; i++ ) {cout<<endl<<MonsterStats[i];}}
390+
//Recalculate healths and re-heal them
391+
MonsterHealth[1] = floor(CalculateHealth(intBattleLevel,MonsterStats[1])/2);
392+
MonsterHealth[0] = MonsterHealth[1];
393+
}
394+
304395
void LevelUpFunction()
305396
{
306397
//Holds function for levelling up.
@@ -387,13 +478,8 @@ char BattleScene()
387478
double douPlayerHealAmount;
388479
char chrPlayerBattleChoice;
389480

390-
//Recalculate all of the stats needed.
391-
//Update monster stats to new level.
392-
for (int i=0; i<5; i++) {MonsterStats[i] = floor(((intBattleLevel-1)*4+MonsterBaseStats[i]));/*cout<<endl<<MonsterStats[i];*/ /*Debugging line*/}
481+
LevelUpMonster();
393482

394-
//Recalculate healths and re-heal them
395-
MonsterHealth[1] = floor(CalculateHealth(intBattleLevel,MonsterStats[1])/3);
396-
MonsterHealth[0] = MonsterHealth[1];
397483
//Recalculate amount player heals for.
398484
douPlayerHealAmount = floor(PlayerHealth[1]/10);
399485
BattleGoto:
@@ -447,16 +533,25 @@ char BattleScene()
447533
//Monster attacks first.
448534
blPlayerDead = MonsterAttack(intMonsterDamage,douMonsterDamageMuli,false);
449535
if (blPlayerDead) {return 'F';}
450-
blMonsterDead = PlayerAttack(intPlayerDamage,douPlayerDamageMuli);
451-
if (blMonsterDead) {return 'T';}
536+
if (!StunCheck(MonsterStats[4],PlayerStats[4]))
537+
{
538+
blMonsterDead = PlayerAttack(intPlayerDamage,douPlayerDamageMuli);
539+
if (blMonsterDead) {return 'T';}
540+
}
541+
else {cout<<endl<<"You were stunned and unable to attack.";}
452542
}
453543
else
454544
{
455545
//Player attacks first.
456546
blMonsterDead = PlayerAttack(intPlayerDamage,douPlayerDamageMuli);
457547
if (blMonsterDead) {return 'T';}
458-
blPlayerDead = MonsterAttack(intMonsterDamage,douMonsterDamageMuli,false);
459-
if (blPlayerDead) {return 'F';}
548+
if (!StunCheck(PlayerStats[4],MonsterStats[4]))
549+
{
550+
blPlayerDead = MonsterAttack(intMonsterDamage,douMonsterDamageMuli,false);
551+
if (blPlayerDead) {return 'F';}
552+
}
553+
else {cout<<endl<<"The "<<MonsterName<<" was stunned by your hit and unable to attack.";}
554+
460555
}
461556
cout<<endl;
462557
getchar();
@@ -471,8 +566,12 @@ char BattleScene()
471566
blPlayerDead = MonsterAttack(intMonsterDamage,douMonsterDamageMuli,true);
472567
if (blPlayerDead) {return 'F';}
473568

474-
if (PlayerHealth[0]+douPlayerHealAmount > PlayerHealth[1]) {PlayerHealth[0]=PlayerHealth[1];}
475-
else {PlayerHealth[0] += douPlayerHealAmount;}
569+
if (!StunCheck(MonsterStats[4],PlayerStats[4]))
570+
{
571+
if (PlayerHealth[0]+douPlayerHealAmount > PlayerHealth[1]) {PlayerHealth[0]=PlayerHealth[1];}
572+
else {PlayerHealth[0] += douPlayerHealAmount;}
573+
}
574+
else {cout<<endl<<"You were stunned and unable to heal.";}
476575
}
477576
else
478577
{
@@ -566,7 +665,7 @@ char PlayerInitialize()
566665
cout<<"In this game there are five stats that effect different elements of the game.";
567666
cout<<endl<<"Strength (STR) - Effects how much damage you do when you attack."<<endl;
568667
cout<<"Constitution (CONS) - Effects how much health you have."<<endl;
569-
cout<<"Dexterity (DEX) - Effects if your chance to dodge."<<endl;
668+
cout<<"Dexterity (DEX) - Effects if your chance to dodge, and if you attack first."<<endl;
570669
cout<<"Defence (DEF) - Effects how much damage you take."<<endl;
571670
cout<<"Luck (LUK) - The random chance things will go your way, with dodges, crits, and rare modifiers that appear on monsters."<<endl;
572671
int intSkillPointsLeft = 100;

main.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ For more information, please refer to <http://unlicense.org>
2929
/*
3030
Made By: Patrick J. Rye
3131
Purpose: A game I made as an attempt to teach myself c++, just super basic, but going to try to keep improving it as my knowledge increases.
32-
Current Revision: 2.5ß
32+
Current Revision: 3.0b
3333
Change Log---------------------------------------------------------------------------------------------------------------------------------------------------
3434
Date Revision Changed By Changes
3535
------ --------- ------------ ---------------------------------------------------------------------------------------------------------------------
@@ -89,6 +89,10 @@ Date Revision Changed By Changes
8989
-Changed change log date format from MM/DD/YY to YYYY/MM/DD because I like it better.
9090
-Added better opening message.
9191
-Replaced all system("pause") with getchar();
92+
=============================================================================================================================================================
93+
2015/03/06 3.0b Patrick Rye -Redid some calculations in battle.h
94+
-Added better winning message.
95+
-Added spells.h does nothing currently just for testing.
9296
=============================================================================================================================================================
9397
*/
9498

@@ -106,6 +110,7 @@ Date Revision Changed By Changes
106110
#include "basic.h" //Functions that are simple and won't need to be changed very often.
107111
#include "battle.h" //Functions that deal with battling, levelling up and making a player.
108112
#include "rooms.h" //Functions that deal with generating a dungeon.
113+
//#include "spells.h" //Functions that deal with spells and magic, a possible future addition.
109114
/*********************************************************************************************************/
110115
using namespace std;
111116
Dungeon d; //Define the dungeon class as 'd' so I can use functions in there anywhere later in the code.
@@ -114,8 +119,9 @@ Dungeon d; //Define the dungeon class as 'd' so I can use functions in there any
114119
int intMainLevel; //The level of the dungeon.
115120
int intLevelStart = 1; //The level that the game starts at. Will be 1 unless loading from a save.
116121
bool blDebugMode = false; //If game is in debug mode or not, effects if player has access to debug commands.
117-
const string CurrentVerison = "2.5ß"; //The current version of this program, stored in a save file later on.
122+
const string CurrentVerison = "3.0b"; //The current version of this program, stored in a save file later on.
118123
/*********************************************************************************************************/
124+
//Some constant string for different messages that appear as large ASCII text.
119125
const string OpeningMessage[16] = {" \n",
120126
",--. ,--. ,--. \n",
121127
"| | | | ,---. | | ,---. ,---. ,--,--,--. ,---. \n",
@@ -132,6 +138,14 @@ const string OpeningMessage[16] = {"
132138
"| .-. |'-. .-''-. .-'' ,-. || .--'| /| .-. :| .--' \n",
133139
"| | | | | | | | \\ '-' |\\ `--.| \\ \\\\ --.| | \n",
134140
"`--' `--' `--' `--' `--`--' `---'`--'`--'`----'`--' \n"};
141+
142+
const string WinningMessage[6] = {"__ __ _ _ _ _ _ \n",
143+
"\\ \\ / / | | | (_) | | |\n",
144+
" \\ V /___ _ _ | | | |_ _ __ | | |\n",
145+
" \\ // _ \\| | | | | |/\\| | | '_ \\| | |\n",
146+
" | | (_) | |_| | \\ /\\ / | | | |_|_|\n",
147+
" \\_/\\___/ \\__,_| \\/ \\/|_|_| |_(_|_)\n"};
148+
135149
/*********************************************************************************************************/
136150
//These functions have to be up here as functions in save.h use them.
137151
//These values are used to pass values to the save header so that they may be saved.
@@ -237,7 +251,7 @@ int main()
237251
//End of FOR levels.
238252
}
239253
cout << string(50, '\n');
240-
cout<<"You win!!";
254+
for (int i = 0; i < 6; i++) {cout<<WinningMessage[i];}
241255
getchar();
242256
return 0;
243257
//End of main

0 commit comments

Comments
 (0)