Professional Documents
Culture Documents
Myfile
Myfile
Myfile
#include <iostream>
#include<iomanip>
#include<ctime>
#include<cstdlib>
using namespace std;
int board[4] [4];
int dirLine[] = {1, 0,-1,0};
int dirColumn[]={0,1,0,-1};
void printUI()
{ system("cls");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
if (board[i][j]==0)
cout<<setw(4)<<".";
else cout<<setw(4)<< board[i][j];
cout<<"\n";
}
cout<<"n: new game, w:up, s: down, d:right ,a:left, q:quit\n";
}
int main()
{
srand(time(0));
char commandToDir[128];
commandToDir['s']=0;
commandToDir['d']=1;
commandToDir['w']=2;
commandToDir['a']=3;
newGame();
while (true) {
printUI();
char command;
cin>>command;
if(command == 'n')
newGame();
else if(command == 'q')
break;
else{
int currentDirection = commandToDir[command];
applyMove(currentDirection);
}
}
return 0;
}