Assuming all your function names match in your actual project and that Adventure::random() has been declared in your class header, you could try re-building all of your project as MSVC doesn't always recompile files when it should.
Assuming all your function names match in your actual project and that Adventure::random() has been declared in your class header, you could try re-building all of your project as MSVC doesn't always recompile files when it should.
I will print the files after another and see if the helps.
Adventure.h
---------------
#ifndef ADVENTURE_H
#define ADVENTURE_H
class Adventure
{
public:
void happenOnRoll();
void monsterMeeting();
void itemFind();
void goldFind();
int random(int RND_MAX);
}a;
#endif
Adventure.cpp
------------------
#include <iostream>
#include <ctime>
using namespace std;
#include "Adventure.h"
void Adventure::happenOnRoll()
{
int rndSeed = 4;
int randAction;
randAction = random(rndSeed);
switch (randAction)
{
case 1:
monsterMeeting();
break;
case 2:
itemFind();
break;
case 3:
goldFind();
break;
}
}
// Function that randomizes a number between 1 and RND_MAX
int Adventure::random(int RND_MAX)
{
unsigned int rndNum;
rndNum = 1 + rand() % RND_MAX;
return rndNum;
}
void Adventure::monsterMeeting()
{
// just putting out text for the moment
cout << "You see a horrid creature coming at you" << endl;
}
void Adventure::itemFind()
{
// just putting out text for the moment
cout << "You have found an item" << endl;
}
void Adventure::goldFind()
{
// just putting out text for the moment
cout << "You have found some gold" << endl;
}
Main.cpp
-----------
#include <iostream>
#include <ctime>
using namespace std;
#include "Character.h"
#include "Adventure.h"
//***********************************************
// Main.cpp´s function declarations
//***********************************************
void gameMenu(); // Game menu function
void printCoordinates();
const int rndSeed = 6; // number to randomize
int random(int RND_MAX); // random function
//************************************************** *
// Game starting menu
//************************************************** *
void gameMenu()
{
char menuChoice;
cout << "*******************" << endl;
cout << "=NIGHT OF VENGANCE=" << endl;
cout << "*******************" << endl << endl;
cout << "What do you want to do?" << endl;
cout << "1.Start a new game" << endl;
cout << "2.Load a saved game" << endl;
cout << "3.Quit" << endl;
cin >> menuChoice;
switch (menuChoice)
{
case '1':
cout << "Start the game" << endl;
break;
case '2':
cout << "Load a game" << endl;
break;
case '3':
cout << "Exiting the game" << endl;
break;
default:
break;
}
}
//************************************************** **************
// Characters walking function
//************************************************** **************
void Character::walking()
{
char menuChoice;
cout << "Move the character, and se how the coordinates change" << endl;
while (menuChoice != '5')
{
cout << "Where do you want to go?" << endl;
if (x > 50)
x = 50; // Highest value of x
if (x < 0)
x = 0; // Lowest value of x
if (y > 50)
y = 50; // highest value of y
if (y < 0)
y = 0; // Lowest value of y
printCoordinates();
if (y < 50)
cout << "1.North" << endl;
if (x > 0)
cout << "2.West" << endl;
if (x < 50)
cout << "3.East" << endl;
if (y > 0)
cout << "4.South" << endl;
cout << "5.Exit program" << endl;
cin >> menuChoice;
switch (menuChoice)
{
case '1':
y += random(rndSeed); // How far you get in a direction
//a.happenOnRoll(); // Calls the function happenOnRoll
break;
case '2':
x -= random(rndSeed);
//a.happenOnRoll();
break;
case '3':
x += random(rndSeed);
//a.happenOnRoll();
break;
case '4':
y -= random(rndSeed);
//a.happenOnRoll();
break;
default:
break;
}
system("cls");
}
}
// prints character coordinates
void printCoordinates() // For testing only
{
cout << "X = " << c.getXcoord() << endl;
cout << "Y = " << c.getYcoord() << endl << endl;
}
// Function take a int argument RND_MAX, and returns the randomized number
//*****************
// Random function
//*****************
int random(int RND_MAX)
{
unsigned int rndNum;
srand(time(0));
rndNum = 1 + rand() % RND_MAX;
return rndNum;
}
//****************
// Main function
//****************
int main()
{
a.happenOnRoll(); // Testing (fails when I try this)
gameMenu();
c.walking();
return 0;
}
Hope it shows as it should do!!
Some general things:
Drop the variables from your headers. No variable declaration in header files !
you header file should look like
#define XXX_H
#ifndef XXX_H
class XXX
{
//stuff here
};
#endif //XXX_H
Your error means the functions belonging to your class cannot be found. The compiler noticed it's syntactically fine, but your linker had no clue where it should get the code from. Make sure you have included your .cpp file in your project.
If you need variables, declare them in one .cpp file. If they are global, make an headerfile called globals.h and declare them as extern there.
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.