Hey im writing a program and i have countless errors. Im following tuturiols and i have no clue what has happened.
Thats the list. Im screwed. can anyone spot anything to get me kick started into a functional game.
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\weapon.h(21): error C2590: 'load' : only a constructor can have a base/member initializer list
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\weapon.h(21): error C2533: 'Weapon' : constructors not allowed a return type
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\weapon.h(23): error C2969: syntax error : ';' : expected member function definition to end with '}'
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\weapon.h(25): error C3769: 'Weapon' : a nested class cannot have the same name as the immediately enclosing class
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\monster.h(32): error C2079: 'Weapon::Monster::weapon' uses undefined class 'Weapon'
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.h(29): error C2079: 'Weapon::Player::weapon' uses undefined class 'Weapon'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\time.h(35): error C2059: syntax error : 'string'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\time.h(35): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\ctime(17): error C2059: syntax error : 'namespace'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\ctime(17): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(7): error C2059: syntax error : 'namespace'
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(7): error C2238: unexpected token(s) preceding ';'
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(10): error C3254: 'Weapon' : class contains explicit override '{ctor}' but does not derive from an interface that contains the function declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(10): error C2838: '{ctor}' : illegal qualified name in member declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(10): error C2535: 'Weapon::Weapon(void)' : member function already defined or declared
1> c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\weapon.h(13) : see declaration of 'Weapon::Weapon'
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(17): error C3254: 'Weapon' : class contains explicit override 'Death' but does not derive from an interface that contains the function declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(17): error C2838: 'Death' : illegal qualified name in member declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(22): error C3254: 'Weapon' : class contains explicit override 'takeDamage' but does not derive from an interface that contains the function declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(22): error C2838: 'takeDamage' : illegal qualified name in member declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(31): error C3254: 'Weapon' : class contains explicit override 'attack' but does not derive from an interface that contains the function declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(31): error C2838: 'attack' : illegal qualified name in member declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(68): error C3254: 'Weapon' : class contains explicit override 'rest' but does not derive from an interface that contains the function declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(68): error C2838: 'rest' : illegal qualified name in member declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(73): error C3254: 'Weapon' : class contains explicit override 'viewStats' but does not derive from an interface that contains the function declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(73): error C2838: 'viewStats' : illegal qualified name in member declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(89): error C3254: 'Weapon' : class contains explicit override 'victory' but does not derive from an interface that contains the function declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(89): error C2838: 'victory' : illegal qualified name in member declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(94): error C3254: 'Weapon' : class contains explicit override 'gameover' but does not derive from an interface that contains the function declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(94): error C2838: 'gameover' : illegal qualified name in member declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(107): error C3254: 'Weapon' : class contains explicit override 'displayHitPoints' but does not derive from an interface that contains the function declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(107): error C2838: 'displayHitPoints' : illegal qualified name in member declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.cpp(112): fatal error C1004: unexpected end-of-file found
1> Monster.cpp
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\weapon.h(21): error C2590: 'load' : only a constructor can have a base/member initializer list
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\weapon.h(21): error C2533: 'Weapon' : constructors not allowed a return type
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\weapon.h(23): error C2969: syntax error : ';' : expected member function definition to end with '}'
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\weapon.h(25): error C3769: 'Weapon' : a nested class cannot have the same name as the immediately enclosing class
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\monster.h(32): error C2079: 'Weapon::Monster::weapon' uses undefined class 'Weapon'
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\player.h(29): error C2079: 'Weapon::Player::weapon' uses undefined class 'Weapon'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\time.h(35): error C2059: syntax error : 'string'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\time.h(35): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\ctime(17): error C2059: syntax error : 'namespace'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\ctime(17): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\monster.cpp(6): error C2059: syntax error : 'namespace'
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\monster.cpp(6): error C2238: unexpected token(s) preceding ';'
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\monster.cpp(12): error C3254: 'Weapon' : class contains explicit override '{ctor}' but does not derive from an interface that contains the function declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\monster.cpp(12): error C2838: '{ctor}' : illegal qualified name in member declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\monster.cpp(26): error C3254: 'Weapon' : class contains explicit override 'Death' but does not derive from an interface that contains the function declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\monster.cpp(26): error C2838: 'Death' : illegal qualified name in member declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\monster.cpp(30): error C3254: 'Weapon' : class contains explicit override 'getName' but does not derive from an interface that contains the function declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\monster.cpp(30): error C2838: 'getName' : illegal qualified name in member declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\monster.cpp(36): error C3254: 'Weapon' : class contains explicit override 'attack' but does not derive from an interface that contains the function declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\monster.cpp(36): error C2838: 'attack' : illegal qualified name in member declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\monster.cpp(64): error C3254: 'Weapon' : class contains explicit override 'takeDamage' but does not derive from an interface that contains the function declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\monster.cpp(64): error C2838: 'takeDamage' : illegal qualified name in member declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\monster.cpp(69): error C3254: 'Weapon' : class contains explicit override 'displayHitPoints' but does not derive from an interface that contains the function declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\monster.cpp(69): error C2838: 'displayHitPoints' : illegal qualified name in member declaration
1>c:\users\conor\documents\visual studio 2010\projects\ca2\ca2\monster.cpp(73): fatal error C1004: unexpected end-of-file found
//Main.
#include "iostream"
using namespace std;
int main()
{
}
#include "Room.h"
#include <iostream>
using namespace std;
Room::Room()
{
name= "Default";
description= "Default";
exit = 0;
}
Room::Room(string name, string description, int exit)
{
name= "Default";
description = "Default";
exit = 0;
}
void Room::print()
{
cout<< "Name= " << name<< endl;
cout<< "Description= " << description<< endl;
cout<< "Exits= " << exit<< endl;
cout<< endl;
}
void Room::save(ofstream& outFile)
{
outFile<< "Name= " << name<< endl;
outFile<< "Description= " << description<< endl;
outFile<< "Exits= " << exit<< endl;
outFile<< endl;
}
void Room::load(ifstream& inFile)
{
string garbage;
inFile>> garbage >> name;
inFile>> garbage >> description;
inFile>> garbage >> exit;
}
//Room.
#ifndef ROOM_H
#define ROOM_H
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class Room
{
public:
Room();//Default Contructor.
//set functions.
Room(std::string name, string description, int exit);
void print();
void save(std::ofstream& outFile);
void load(std::ifstream& inFile);
private:
string name;
string description;
int exit;
};
//Weapon.h
#ifndef WEAPON_H
#define WEAPON_H
//For use of the String Variable.
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
class Weapon
{
public:
Weapon();//Default Contructor.
//set functions.
Weapon(std::string name, int weaponHitPoints);
void print();
void save(std::ofstream& outFile);
void load(ifstream& inFile);
};
struct Weapon
{
std::string Name;
int weaponHitPoints;
};
//Player.h
#ifndef PLAYER_H
#define PLAYER_H
#include "Weapon.h"
#include "Monster.h"
#include <string>
class Player
{
public:
//Constructor
Player();
//Methods
bool Death();
std::string getName();
void takeDamage(int damage);
void attack(Monster& monster);
void rest();
void viewStats();
void victory();
void gameover();
void displayHitPoints();
private:
//Data members
std::string Name;
int HitPoints;
Weapon weapon;
};
#endif //PLAYER_H
#include "Player.h"
#include "Monster.h"
#include "Weapon.h"
#include <ctime>
#include <iostream>
using namespace std;
Player::Player()
{
Name = "Default";
HitPoints = 0;
weapon.Name = "Default Weapon Name";
}
bool Player::Death()
{
return HitPoints <= 0;
}
void Player::takeDamage(int damage)
{
HitPoints -= damage;
}
void Player::attack(Monster& monster)
{
int selection = 1;
cout << "1) Attack, 2) Run Away ";
cin >> selection;
cout << endl;
switch(selection)
{
case 1:
cout << "You attack an " << monster.getName()
<< " with a " << weapon.Name << endl;
int damage = weapon.weaponHitPoints;
srand((unsigned)time(0));
int random_integer;
for(int index=0; index<1; index++){
random_integer = (rand()%2)+1;
cout << random_integer << endl;
if(random_integer = 1)
{
Monster.takeDamage;
cout << "Your Health is minus: " << damage;
}
else if( random_integer = 2)
{
cout<< "You missed";
}
break;
case 2:
//Run Away
cout << "You run away" << endl;
break;
}
}
}
void Player::rest()
{
cout << "Resting..." << endl;
}
void Player::viewStats()
{
cout << "PLAYER STATS" << endl;
cout << "============" << endl;
cout << endl;
cout << "Name = " << Name << endl;
cout << "HitPoints = " << HitPoints << endl;
cout << "Weapon Name = " << weapon.Name << endl;
cout << "Weapon Damage = " << weapon.weaponHitPoints;
cout << endl;
cout << "END PLAYER STATS" << endl;
cout << "================" << endl;
cout << endl;
}
void Player::victory()
{
cout << "You won the battle" << endl;
}
void Player::gameover()
{
cout << "You died in battle...." << endl;
cout << endl;
cout << "===============================" << endl;
cout << "GAME OVER" << endl;
cout << "===============================" << endl;
cout << "Press 'q' to quit: ";
char q = 'q';
cin >> q;
cout << endl;
}
void Player::displayHitPoints()
{
cout << Name << "'s hitpoints = " << HitPoints << endl;
}
#ifndef MONSTER_H
#define MONSTER_H
#include "Weapon.h"
#include <string>
class Player;
class Monster
{
public:
Monster(std::string name, int health, int hitPoints,
int miss, int damage,const std::string& weaponName);
bool Death();
int getXPReward();
std::string getName();
int getArmour();
void attack(Player& player);
void takeDamage(int damage);
void displayHitPoints();
void print();
void save(std::ofstream& outFile);
void load(std::ifstream& inFile);
private:
std::string Name;
int health;
int hitPoints;
int miss;
int damage;
Weapon weapon;
};
#endif //MONSTER_H
#include "Monster.h"
#include "Player.h"
#include "Weapon.h"
#include <iostream>
#include <ctime>
using namespace std;
//Constructor
Monster::Monster(std::string Name, int health, int hitPoints,
int miss, int damage,const std::string& weaponName){
Name = Name;
hitPoints = hitPoints;
Weapon weapon;
miss = miss;
damage = damage;
weapon.Name = weaponName;
}
//Methods
bool Monster::Death()
{
return hitPoints <= 0;
}
std::string Monster::getName()
{
return Name;
}
void Monster::attack(Player& player)
{
{
srand((unsigned)time(0));
int random_integer;
for(int index=0; index<1; index++){
random_integer = (rand()%2)+1;
cout << random_integer << endl;
}
cout << "A " << Name << " attacks you "
<<"with a " << weapon.Name << endl;
int damage = weapon.weaponHitPoints;
if(random_integer = 1)
{
Player.takeDamage;
cout << "Your Health is minus: " << damage;
}
else if( random_integer = 2)
{
cout<< "You missed";
}
}
}
void Monster::takeDamage(int damage)
{
hitPoints -= damage;
}
void Monster::displayHitPoints()
{
cout << Name << "'s hitpoints = " << hitPoints << endl;
}