Hi. I'm trying to make a two-dimensional array full of descriptions. As if they were map tiles for a text-based RPG. There's a point class that holds your coordinates and I use the Get_X and Get_Y functions to put into the map so it can read them. I'm just starting it and I've tried to fix this problem for at least an hour or two now. Could someone please help? Whenever I run the code like this the prompt just flies through a bunch of symbols and the cpu beeps a few times.

#include <iostream>
#include <string>
using namespace std;

class Coordinate
{
private:
	int m_x, m_y;
public:
	Coordinate() : m_x(0), m_y(0) {}
	Coordinate(int x, int y): m_x(x), m_y(y) {}
	void Setpoint(int x, int y) 
	{
		m_x = x;
		m_y = y;
	}
	int Get_X() { return m_x; }
	int Get_Y() { return m_y; }

	void Move_Up() { m_y++; }
	void Move_Down() { m_y--; }
	void Move_Right() { m_x++; }
	void Move_Left() { m_x--; }

	friend ostream& operator<<(ostream &out, Coordinate &point);
};

ostream& operator<< (ostream &out, Coordinate &point)
{
	out << "(" << point.Get_X() << "," << point.Get_Y() << ")";
	return out;
}

int main()
{
	string map[4][4] = 
	{
		{"nothing", "nothing", "nothing", "nothing"}, 
		{"nothing", "nothing", "nothing", "nothing"}, 
		{"nothing", "nothing", "nothing", "nothing"}, 
		{"nothing", "You walk on a bridge", "nothing", "nothing"}
	};
	
	Coordinate Point(3, 0);
	cout << map[(Point.Get_X())][(Point.Get_Y())];
	Point.Move_Right();
	cout << map[(Point.Get_X())][(Point.Get_Y())];

	cin.get();
}

Recommended Answers

All 2 Replies

What did you expect to happen?
There is no point to the right of (3|0).

You're right. I made a stupid post because I didn't bother to draw the diagram down and think a little bit more. I'm sorry and thanks you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.