Is this bad?

Designing a game where a player can navigate a map, is this "bad form" and getting too complex?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include "board.h"
#include "player.h"

player hero;
board area("game-files/map.txt");


int main() 
{
	hero.getLimits(area.returnMaxLimit(), area.returnMinLimit());
	
	bool gameOver = false;
	while ( !gameOver )
	{
		hero.getMove();
		hero.updateLocation(area.returnCurrentLocation(hero.returnX(), hero.returnY()));
	}
	return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef BOARD_H
#define BOARD_H
#include <iostream>
class board
{
	public:
		
		board(std::string filename);
		
		int returnMaxLimit();
		int returnMinLimit();
		std::string returnCurrentLocation(int x, int y);
		
	private:
		
		static const int maxLimit = 5;
		static const int minLimit = -1;
		std::string area[maxLimit][maxLimit];
};

#endif 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef BOARD_H
#define BOARD_H
#include <iostream>
class board
{
	public:
		
		board(std::string filename);
		
		int returnMaxLimit();
		int returnMinLimit();
		std::string returnCurrentLocation(int x, int y);
		
	private:
		
		static const int maxLimit = 5;
		static const int minLimit = -1;
		std::string area[maxLimit][maxLimit];
};

#endif 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef PLAYER_H
#define PLAYER_H
#include <iostream>

class player 
{
	public:
		player();
		
		void updateLocation(std::string newLocation);
		void getMove();
		void searchLibrary(std::string command);
		void getLimits(int max, int min);
		int returnX();
		int returnY();
		
	private:
		int xCoord, yCoord;
		int minLimit, maxLimit;
		std::string currentLocation, lastLocation;
};

#endif 

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
#include "player.h"
#include <iostream>

player::player()
{
	xCoord = 0, yCoord = 0;
	lastLocation = "start";
	currentLocation = "home";
}
void player::updateLocation(std::string newLocation)
{
	lastLocation = currentLocation;
	currentLocation = newLocation;
	std::cout << "current:" << currentLocation << std::endl;
	std::cout << "last:" << lastLocation << std::endl;
}
void player::getMove()
{
	std::string commandInput;
	getline(std::cin, commandInput);
	for ( int x = 0; x < commandInput.size(); x++ )
	{
		commandInput[x] = tolower(commandInput[x]);
	}
	searchLibrary(commandInput);
}
void player::searchLibrary(std::string command)
{
	if ( command == "go north" || command == "north" )
	{
		if ( xCoord - 1 > minLimit )
		{
			xCoord--;
		}
		else
		{
			std::cout << "I can't go that way." << std::endl;
		}

	}	
	else if ( command == "go south" || command == "south" )
	{
		if ( xCoord + 1 < maxLimit )
		{
			xCoord++;
		}
		else
		{
			std::cout << "I can't go that way." << std::endl;
		}
		
	}
	else if ( command == "go east" || command == "east" )
	{
		if ( yCoord + 1 < maxLimit )
		{
			yCoord++;
		}
		else
		{
			std::cout << "I can't go that way." << std::endl;
		}
		
	}
	else if ( command == "go west" || command == "west" )
	{
		if ( yCoord - 1 > minLimit)
		{
			yCoord--;
		}
		else
		{
			std::cout << "I can't go that way." << std::endl;
		}
		
	}
}
void player::getLimits(int max, int min)
{
	maxLimit = max;
	minLimit = min;
}
int player::returnX()
{
	return xCoord;
}
int player::returnY()
{
	return yCoord;
}
and criticism is welcome :)
:)
Topic archived. No new replies allowed.