Help with VC++ 6.0 (or my code) error
*I'm not exactly sure if this is the right place for this*
Hello, I'm new here. I'm teaching myself c++ and I decided to make a simple text RPG. I'm coding a "battle engine" first and I created two instances of the class cTheo to test it. It compiles with no problems, but when I run it, this is what I get:
Code:
Linking...
Cpp1.obj : error LNK2005: "void __cdecl Choice(class cTheo)" (?Choice@@YAXVcTheo@@@Z) already defined in Battle.obj
Cpp1.obj : error LNK2005: "void __cdecl Action(class cTheo,class cTheo)" (?Action@@YAXVcTheo@@0@Z) already defined in Battle.obj
Cpp1.obj : error LNK2005: "char choice" (?choice@@3DA) already defined in Battle.obj
Cpp1.obj : error LNK2005: "class cTheo theo" (?theo@@3VcTheo@@A) already defined in Battle.obj
Cpp1.obj : error LNK2005: "class cTheo allah" (?allah@@3VcTheo@@A) already defined in Battle.obj
Debug/Cpp1.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
This is the code. If it helps, I'm using VStudio 6.0 on WinXP Pro on a 533 Celeron.
Code:
<main>
#include "Battle.cpp"
int main() {
bool partyIsAlive = true;
Battle(partyIsAlive);
if (partyIsAlive == true)
cout << victory;
else
cout << defeat;
return 0;
}
<Battle.cpp>
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
using namespace std;
class cTheo {
public:
int hitPoints, strength;
string name;
cTheo::cTheo(int h, int s, string n)
{
cTheo::hitPoints = h;
cTheo::strength = s;
cTheo::name = n;
}
};
//Function Prototypes
void Choice(cTheo);
void Action(cTheo, cTheo);
//Globals and Constants
const string victory = "Party has Survived!\n";
const string defeat = "Party has been Defeated!\n";
char choice;
//Syntax cTheo -name- (hitPoints, strength, name)
cTheo theo(19, 10, "Theo");
cTheo allah(20, 15, "Allah");
bool Battle(bool& survived) {
survived = true;
//I would like to implement some mechanism that takes speed into account
while (theo.hitPoints > 0 && allah.hitPoints > 0) {
//Theo goes first
Choice(theo);
Action(theo, allah);
//Followed by Allah
Choice(allah);
Action(allah, theo);
//If I lose in my epic and blasphemous battle...
if (theo.hitPoints = 0)
survived = false;
}
return (survived);
}
//X is the attacker
void Choice(cTheo x) {
cout << x.name << "'s turn" << endl;
do{
cout << "Attack (A) Defend (D) ";
cin >> choice;
}while((choice != 'A') && (choice != 'D') && (choice != 'a') && (choice != 'd'));
//I need to fix this do-while statement.
}
//X is the attacker, Y is the receiver
void Action(cTheo x, cTheo y) {
srand(time(NULL));
int i = rand();
//Switch used b/c I want to a more options eventually
switch (choice) {
case ('A'):
case ('a'):
cout << x.name << " is attacking. \n";
y.hitPoints -= i + 3;
break;
case ('D'):
case ('d'):
cout << x.name << " is defending. \n";
cout << "On a later date, this will actually do something!\n";
break;
}
}
Any help would be greatly appreciated.
P.S. Please don't be offended by my use of Allah. It's not malicious -- I would just as quickly use Jesus/Bob/Jebus/Buddha/etc.