Hi, I'm trying to make a set of monsters that have values that can be loaded. Like a Goblin having enemyhealth = 50, enemydamage = 15, etc. Here's what I kinda have an idea of doing... But I really have no idea how to use it.
(File containing values for enemies)
Monsterreader:
#include <iosteam>
using namespace std;
struct Archer {
char enemyname[25] = "Archer";
int enemyhealth = 55;
int enemydamage = 15;
int enemydefense = 5;
} ;
struct Goblin {
char enemyname[25] = "Goblin";
int enemyhealth = 30;
int enemydamage = 13;
int enemydefense = 10;
} ;
And the actual battle function:
// <strong class="highlight">include</strong> the declaration
#include "battle.h"
#include <iostream>
#include <windows.h>
char battlechoice[10];
char enemyname[25];
char name[50];
int enemyhealth;
int enemydamage;
int enemydefense;
int strength;
int intelligence;
int dexterity;
int health;
int mana;
int damage;
int defense;
int hitchance;
int roll;
int rollcalc;
int rollcalchit;
int hitroll;
int rand_0toN1(int rollcalc);
int randd_0toN1(int rollcalchit);
using namespace std;
// Function definition
void battleFunction() {
system("Color 05");
srand(time(NULL));
system("Cls");
std::cout << "Battle Initiated";
Sleep(2500);
system("Cls");
// 17
std::cout << " _________________ _________________ " << endl;
std::cout << "| Battle | " << enemyname << endl;
std::cout << "|-----------------| _________________ " << endl;
std::cout << "| Attack | " <<endl;
std::cout << "| Skill | Health " << enemyhealth <<endl;
std::cout << "| Defend | Defense " << enemydefense << endl;
std::cout << "| Item | Attack " << enemydamage << endl;
std::cout << "| Run | " << endl;
std::cout << "|_________________| " << endl <<endl <<"Health: "
<< health <<endl <<"Mana: " << mana << endl <<endl;
battlecommand:
std::cout << "Command: ";
cin.getline(battlechoice, 10);
if (battlechoice == "Attack" || "attack" || "atk" || "1" || "A")
{
roll = rand_0toN1(5) + 1;
hitroll = randd_0toN1(10) + 1;
damage = strength*roll*1.5-enemydefense*1.8;
hitchance = dexterity*hitroll*0.5;
if (hitchance >= 14)
{
enemyhealth = enemyhealth-damage;
cout << name <<" did " << damage << " damage!" <<endl;
}
else
{
cout << name <<" Missed!" <<endl;
Sleep(1500);
goto battlecommand;
}
}
Sleep(3000);
}
int rand_0toN1(int rollcalc) {
return rand() % rollcalc;
}
int randd_0toN1(int rollcalchit) {
return rand() % rollcalchit;
}
Thanks ahead of time - Valestrom