// class_eg.cpp - an implementation of simple_game using classes.
#include <iostream>
using namespace std;

// Declaration of our Player class. You are defining your own type here. Think of
// a class as a blueprint for something to be made later (Player objects).
class Player {
// You can have public and private variables and methods in your classes. Public
// variables and methods can be used anywhere in your program. Private variables
// can only be seen inside your class.
public:
	int xp;
	int yp;
	char name;
	void move(char dir);
	void print();
};

// Here is a Player method / member function, move which affects data specific to 
// our Player class: xp and yp.
void Player::move(char dir) {
	if (dir == 'n') yp--;
	else if (dir == 's') yp++;
	else if (dir == 'e') xp++;
	else if (dir == 'w') xp--;
}

// This Player method just prints out the character that represents the player.
void Player::print() {
  cout << "  " << name << "  ";
}

int main() {

  char direction;

  // Here we are creating a class object called myGuy. It is using
  // a 'default constructor.'
  Player myGuy = Player();
  // Here we are refering to class variables xp, xy and name by using dot notation. We
  // can refer to them in main() since we definied them as public in our class declaration.
  myGuy.xp = 2;
  myGuy.yp = 3;
  myGuy.name = '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();  // calling a method defined in our class to print out the object's (myGuy's) character.
        else
          cout << '(' << x << "," << y << ") ";
      }
      cout << endl;
    }

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

	// Here we are calling a method defined in our Player class. Note we use
	// the same dot notation we used when refering to the class variables.
	myGuy.move(direction);

  }

}
