Ok, I made at least a test of the program, and my compiler seems to hate me, I don't see any problems with the code, but it does:
I know I'm not supposed to post all my code, but I'm still getting the same types of problems
Code:
#include <iostream>
#include <windows.h>
#include <cstring>
#include <time.h>
using namespace std;
void randomize () {
time_t seconds;
time(&seconds);
srand ((unsigned int) seconds);
}
void clrscrn ( void ){
DWORD n; /* Number of characters written */
DWORD size; /* number of visible characters */
COORD coord = {0}; /* Top left screen position */
CONSOLE_SCREEN_BUFFER_INFO csbi;
/* Get a handle to the console */
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
GetConsoleScreenBufferInfo ( h, &csbi );
/* Find the number of characters to overwrite */
size = csbi.dwSize.X * csbi.dwSize.Y;
/* Overwrite the screen buffer with whitespace */
FillConsoleOutputCharacter ( h, TEXT ( ' ' ), size, coord, &n );
GetConsoleScreenBufferInfo ( h, &csbi );
FillConsoleOutputAttribute ( h, csbi.wAttributes, size, coord, &n );
/* Reset the cursor to the top left position */
SetConsoleCursorPosition ( h, coord );
}
class zombie {
public:
zombie ( int hp ) {}
~zombie () {}
int life () {
if ( hp > 0 ) {
return 1;
}
if (hp <= 0 ) {
return 0;
}
}
void attack () {
attacktype = rand () % (2) + 1;
if (attacktype = 1) {
gnaw();
}
if (attacktype = 2) {
bite();
}
if (attacktype = 3) {
moan();
}
cin.get();
clrscrn();
}
void takedamage ( int dmg ) {
hp = hp - dmg;
cout << "The zombie took " << dmg << " damage.";
cout << "\n\nThe zombie's health is down to " << hp;
cin.get();
clrscrn();
}
private:
int hp, attacktype, attackpower, dmg;
void gnaw () {
attackpower = rand () % (5) + 1;
cout << "The zombie gnaws on your arm, trying to extract you life force";
cout << "You take " << attackpower << " damage";
user.takedamage (attackpower);//'user' undeclared (first use this function)
}
void bite () {
attackpower = rand () % (11) + 10;
cout << "The zombie bites your face, trying to extract you brains";
cout << "You take " << attackpower << " damage";
user.takedamage (attackpower);//'user' undeclared (first use this function)
}
void moan () {
cout << "The zombie moans loudly, waking the neighbors.\n, then a small music video begins with the lyrics to 'lets wake up the neighbors'";
}
}
class player {
public:
player ( int hp ) {}//invalid use of member (did you forget the '&' ?
~player () {}
int life () {
if ( hp > 0 ) {
return 1;
}
if (hp <= 0 ) {
return 0;
}
}
void attack () {
cout << "Please enter the weapon you would like to use:\n\n"
<< "1. Axe\n"
<< "2. Machete\n"
<< "3. Chainsaw\n";
cin >> attacktype;
switch (attacktype) {
case 1:
axe();
break;
case 2:
machete();
break;
case 3:
chainsaw();
break;
default:
cout<<"Your instincts have failed you, and you freeze up\n";
break;
}
cin.get();
clrscrn();
}
void takedamage ( int dmg ) {
hp = hp - dmg;
cout << "You took " << dmg << " damage.";
cout << "\n\nYour health is down to " << hp;
cin.get();
clrscrn();
}
private:
int hp, attacktype, attackpower, dmg;
void axe () {
attackpower = rand () % (25) + 1;
cout << "You swing the axe at the zombie's head, but it continues to move\n";
cout << "The zombie takes " << attackpower << " damage";
bob.takedamage (attackpower);//'bob' undeclared (first use this function)
}
void machete () {
attackpower = rand () % (25) + 25;
cout << "You hack down the zombie with the machete\n";
cout << "The zombie took " << attackpower << " damage";
bob.takedamage (attackpower);//'bob' undeclared (first use this function)
}
void chainsaw () {
attackpower = rand() % (26) + 50;
cout << "You zwing your chainsaw, annihilating the zombie's limbs";
cout << "The zombie took " << attackpower << " damage";
bob.takedamage (attackpower);//'bob' undeclared (first use this function)
}
}
void battle () {//new types may not be defined in a return type // two or more data types in declaration of 'battle' [it says that one twice]
zombie bob;//no matching function call for 'zombie::zombie()' //candidates are zombie::zombie (const zombie&), and 'zombie::zombie(int)'
player user;//same as above only 'player::player()'
while (bob.life() == 1 and user.life() == 1) {
if (user.life() == 1) {
user.attack();
}
if (bob.life() == 1) {
bob.attack();
}
}
if (user.life() == 0) {
cout << "You failed to defeat the zombie\n\n";
}
if (bob.life() == 0) {
cout << "You defeated the zombie\n\n";
}
}
int main() {
cout << "blablabla, battle the zombie\n";
cin.get();
clrscrn();
battle();
cin.get();
cout << "closing game, this is only a test";
}
I really wish all these little phrases had a little more description to them on the compiler's website
Sorry about all the code, I hope it's easy to read