Tro

000
Last edited on
In your GameWorld.cpp file on line 67 you define a function void player(Player*player) inside void GameWorld::Move() and this is not allowed. Try adding and } on line 65 should solve this problem.
Thanks for your feedback, I did as you said. I now have the errors that my x and y have a undeclared identifier, along with my getMonsterx (and y) and all my moveUp, moveDown etc are undefined. I tried to define them myself but i cant seem to get it to work. Would i have to put the definitions in my .h files? if so please help me get them in the right place. Thanks.
Last edited on
Katie111 wrote:
Trouble with Identifier not Found 'moveUp' and Intellisense expected ';' errors.

Hi all,
I'm currently working on a project and i have found myself stuck. I am aware that I need to make an identifier to fix one of those errors but I can seem to make it in the right place (or make it right at all. Also i have checked my ';'s and i cant seem to find where they need to be. I'm sorry if you find my code confusing as i'm still a beginner. I hope you are able to guide me in the right direction.

My GameWorld.cpp file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <iostream>
#include "GameWorld.h"
#include <windows.h>
#include "Vector2.h"
#include "Monster.h"



using namespace std;


int option;		//allowing the user to exit the menu and begin the game


//-----GAME MENU-------

void GameWorld::menu(){

	Vector2 vec;	//calling the Vector2 func
	vec.SetX(1);	// Setting the X Values of the player
	vec.SetY(1);	// Setting the Y Values of the player

	system("cls");

	cout << "Computer Games Development AS1" << endl;	//Title
	cout << "" << endl;

	cout << "Your Starting X,Y Coordinates Are:" << endl;	//Starting Coordinates Displayed To Player 
	cout << "" << endl;
	cout << "X = " << vec.GetX() << endl;	//vector get function to display the X,Y coordanites
	cout << "" << endl;
	cout << "Y = " << vec.GetY() << endl;
	cout << "" << endl;

	cout << "Press 1 and Enter to Start The Game" << endl;	//Option funtion to exit the menu and begin the game
	cout << "" << endl;

	cin >> option;

	system("PAUSE");

}

void GameWorld::Move(){

	///----------------------------ADD IF OPTION -------------------------


	cout << "Your current X and Y Coordinates are:" << endl;
	cout << "" << endl;
	cout << "" << endl;

	char map[10][11] = {
		"##########",
		"#        #",
		"#---     #",
		"#        #",
		"#     ---#",
		"#        #",
		"#---     #",
		"#        #",
		"#        #",
		"##########"
	};


	void player(Player*player){
		char direction;                  //Stores user input
		cin >> direction;                //Get's user input
		switch (direction) {
		case 'a': moveLeft(player);
		case 'A':
			break;

		case 'd': moveRight(player);
		case 'D':
			break;

		case 'w': moveUp(player);
		case 'W':
			break;
		
		case 's': moveDown(player);
		case 'S':
			break;
		
		}
	}

}



//----MONSTER-------
void Monster::monster(){


	if (x == 0) { x++; } //Monster will spawned within x - 0 to 11
	if (x == 11){ x--; }


int getMonsterX(){ return x; }

if (x == 0) { y++; } //Monster will spawned within y - 0 to 11
if (x == 11){ y--; }


int getMonsterX(){ return y; }

//Monster(int playX, int playY){ x = playX; y = playY; } --------FIX

};


//----CLEAN UP-------
void GameWorld::cleanup(){

	std::cout << "Game Is Now Closing" << std::endl;	//cout statement for game closing
}

my Monster.h file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "Vector2.h"

class Monster{
private:
	int x, y; //Monster Location Storage

public:
	///----MONSTER X COORDINATES----

	void monster();

	void setX(int newX){ //set monster X coordinate
		x = newX;
		if (x == 0) { x++; } //set monsters X coordanite between 0-11
		if (x == 11){ x--; }
	}

	int getMonsterX(){ return x; }


	///----MONSTER Y COORDINATES----

	void setY(int newY){  //set monster Y coordinate
		y = newY;
		if (y == 0) { y++; }//set monsters Y coordanite between 0-11
		if (y == 11){ y--; }
	}

	int getMonsterY(){ return y; }

	Monster(int startX, int startY){ x = startX; y = startY; }


	};

class Player{
private:
	int x, y; //Monster Location Storage

public:

	void player();

	void setX(int newX){ x = newX; } // setting Players X coordinate
	int getPlayerX(){ return x; }

	void setY(int newy){ y = newy; }// setting Players Y coordinate
	int getPlayerY(){ return y; }


//Player Functions that allow them to move
	void moveLeft(Player *player)

	{
		player->setY(player->getPlayerY() - 1);
	}

	void moveRight(Player *player)
	{
		player->setY(player->getPlayerY() + 1);
	}

	void moveUp(Player *player)
	{
		player->setX(player->getPlayerX() - 1);

	}

	void moveDown(Player *player)
	{
		player->setX(player->getPlayerX() + 1);

	}

};

my GameWorld.h file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once

class GameWorld{
private:
	
	

public:
	GameWorld(int x, int y);
	~GameWorld();

	bool active = true;
	int x = 1;
	int y = 1;

	void Move();
	void init();
	void menu();
	void gameLoop();
	void cleanup();

};


You have defined the functions as member functions of the Player class so you need to specify which Player object you want to call the function on.

 
player->moveUp(player);


You probably should decide if you want it to be a member function or if you want to pass the player as argument. Doing both seems a bit redundant.

member function
1
2
3
4
5
6
7
8
// Inside the Player class.
void moveUp()
{
	setX(getPlayerX() - 1);
}

// When calling the function.
player->moveUp();


non-member function
1
2
3
4
5
6
7
8
// Outside the Player class.
void moveUp(Player* player)
{
	player->setX(player->getPlayerX() - 1);
}

// When calling the function.
moveUp(player);


By the way, haven't you mixed up X and Y? Normally the Y-coordinate is the one that should be changed when moving up and down.
Last edited on
Topic archived. No new replies allowed.