0

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();
}
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by ichigo_cool
0

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

Edited by Aranarth: n/a

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.