a better way to do this is
Code:
#include <iostream>
#define M 4
#define N 10
using namespace std;
char map[M][N];
int x,y;
void welcome()
{
cout<<"Welcome to the simplest game by thapchi corporations limited";
cout<<"\n \t \t press enter to continue....(x=exit)";
getchar();
system("cls");
}
void print_game_board(){
system("cls");
for (int i=0;i<M;i++){
for(int j=0;j<N;j++){
if (x==i && y==j)
cout<<"j";
else
cout<<map[i][j];
}
printf("\n");
}
}
void create_map(){
for (int i=0;i<M;i++)
for(int j=0;j<N;j++)
map[i][j]='*';
}
void moveRight(){
y++;
if (y>N-1) y=N-1;
print_game_board();
}
void moveLeft(){
y--;
if (y<0) y=0;
print_game_board();
}
void moveDown(){
x++;
if (x>M-1) x=M-1;
print_game_board() ;
}
void moveUp(){
x--;
if (x<0) x=0;
print_game_board();
}
int main(){
welcome();
char move='0';
create_map();
x=1;y=4;//first position of our character
print_game_board();
while (move!='x'){
cout<<"your move:(w,a,s,d,x):";cin>>move;
switch(move){
case 'w':moveUp();
break;
case 'a':moveDown();
break;
case 's':moveLeft();
break;
case 'd':moveRight();
break;
}
}
cout<<"\nprogram exits!";
return 0;
}