// moving on a grid

#include <iostream>
#include <cstdlib>
#include <conio.h>
using namespace std;

void drawGrid(int x, int y);

int main()
{
   char userLetter = 's';
   int x = 0;
   int y = 0;

   cout << "X";
   
   while (x != ' ')
   {
		userLetter = _getch();

		if (userLetter == 'w') 
		{	
			x--;
		}
		else if (userLetter == 's') 
		{
			x++;
		}
		else if (userLetter == 'a') 
		{
			y--;
		}
		else if (userLetter == 'd') 
		{
			y++;
		}

		drawGrid(x, y);
   }

   system("pause");
   return 0;
}// end of main

void drawGrid(int x, int y)
{
	system("CLS");

	for (int row = 0; row < 20; row++)
	{

		for (int col = 0; col < 20; col++)
		{
			if (row == x && col == y) 
			{
				cout << "X";
			}
			else 
			{
				cout << " ";
			}
		}

		cout << endl;
	}

}// end of drawGrid
