// class_eg3.cpp - an implementation of simple_game using classes.
// Shows how multiple objects can be created with ease... and
// the power of coupling Player data and methods. Also shows
// using a pointer to a class.
#include <iostream>
using namespace std;

class Player {
public:
	int xp;
	int yp;
	char name;
	Player(int x, int y, char n);
	~Player(); 
	void move(char dir);
	void print();
};

Player::Player(int x, int y, char n) {
	xp = x;
	yp = y;
	name = n;
}

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;
  char whichPlayer; // variable to hold user input for player to move

  Player myGuy = Player(2,3,'a');  // creating one player @ 2,3 represented by character 'a'
  Player myGuy2 = Player(3,2,'b');  // creating one player @ 3,2 represented by character 'b'
  Player *whichGuy; // creating a pointer to a Player. To be used later.

  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 if (myGuy2.xp == x && myGuy2.yp == y)
          myGuy2.print();
        else
          cout << '(' << x << "," << y << ") ";
      }
      cout << endl;
    }

	cout << "\nEnter in a player (a or b): ";  // getting which player to move from user
    cin >> whichPlayer;
    cout << "Enter in a direction (q to quit): ";
    cin >> direction;

	// Here we set the pointer to the correct myGuy object, dependent on what the user entered.
	if (whichPlayer == 'a') whichGuy = &myGuy;
	if (whichPlayer == 'b') whichGuy = &myGuy2;
	(*whichGuy).move(direction); // Now that we have the appropriate object, we will call the appropriate move function.

  }

}
