// class_eg2.cpp - an implementation of simple_game using classes. 
// Introducing constructors + destructors.
#include <iostream>
using namespace std;

class Player {
public:
	int xp;
	int yp;
	char name;
	Player(int x, int y, char n); 
	// Including a constructor. Constructors are called whenever you create an object.
	// It never has a return value so no need to have a return type (leave out the void)
	// and is always named the same as the class name.
	~Player(); 
    // This is our destructor. Only need to be used when using allocated vars in your obj (new + delete)
	void move(char dir);
	void print();
};

// Here is our contructor function. It sets the variables of our class. 
Player::Player(int x, int y, char n) {
	xp = x;
	yp = y;
	name = n;
}

// This is our destructor.
Player::~Player() {
}

void Player::move(char dir) {
	if (dir == 'n') yp--;
	else if (dir == 's') yp++;
	else if (dir == 'e') xp++; 
	else if (dir == 'w') xp--;
}

void Player::print() {
  cout << "  " << name << "  ";
}

int main() {

  char direction;

  // Here we are calling our Player constructor when creating our Player
  // object. 
  Player myGuy = Player(2,3,'a');

  while(direction != 'q') {

    for(int y=0;y<5;y++) {
      for(int x=0;x<5;x++) {
        if (myGuy.xp == x && myGuy.yp == y)
          myGuy.print(); 
        else
          cout << '(' << x << "," << y << ") ";
      }
      cout << endl;
    }

    cout << "\nEnter in a direction (q to quit): ";
    cin >> direction;

	myGuy.move(direction);

  }

}

