#include 0; i < 20000; i++) {

#include using std::cout;using std::cin;using std::endl;;#include using std::rand;using std::srand;#include using std::time;const int arraySize = 4;char elements arraySize arraySize = {{‘1′,’2′,’3′,’4’}, {‘5′,’6′,’7′,’8’}, {‘9′,’A’,’B’,’C’}, {‘D’,’E’,’ ‘,’F’}}; char chack arraySize arraySize = {{‘1′,’2′,’3′,’4’}, {‘5′,’6′,’7′,’8’}, {‘9′,’A’,’B’,’C’}, {‘D’,’E’,’F’,’ ‘}};int vSP = 3; // vertical space Positionint hSP = 2; // h space Positionvoid moveUp();void moveDown();void moveRight();void moveLeft();void randomise(); // randomize the array int winer(); // chacks if player have solved the puzzelint main(){ srand(time(0)); randomise(); bool quite(false); do { for(int i = 0; i < arraySize; i++){ for(int j = 0; j < arraySize; j++) cout << " " << elementsij; cout << endl << endl; } char a; cout << "w - Up, z - Down, a - Left, s - Right" << endl; cin >> a; switch(a) { case ‘W’: case ‘w’: moveUp(); break; case ‘Z’: case ‘z’: moveDown(); break; case ‘s’: case ‘S’: moveRight(); break; case ‘a’: case ‘A’: moveLeft(); break; default: cout << "Wrong character, pleas type again!" << endl; break; } int c = winer(); if(c == 1){ cout << "Bravo! You solved the puzle!" << endl; quite = true; } system("cls"); }while(quite == false); return 0;}void moveUp(){ int vP = vSP; if(vP + 1 < 4 && vP >= 0){ elementsvSPhSP = elementsvSP + 1hSP; elementsvSP + 1hSP = ‘ ‘; vSP += 1; }}void moveDown(){ int vP = vSP; if(vP + 1 <= 4 && vP > 0){ elementsvSPhSP = elementsvSP – 1hSP; elementsvSP – 1hSP = ‘ ‘; vSP -= 1; }}void moveRight(){ int hP = hSP; if(hP + 1 <= 4 && hP > 0){ elementsvSPhSP = elementsvSPhSP – 1; elementsvSPhSP – 1 = ‘ ‘; hSP -= 1; }}void moveLeft(){ int hP = hSP; if(hP + 1 < 4 && hP >= 0){ elementsvSPhSP = elementsvSPhSP + 1; elementsvSPhSP + 1 = ‘ ‘; hSP += 1; }}void randomise(){ for(int i = 0; i < 20000; i++) { int a = 1 + rand() % 4; switch(a) { case 1: moveUp(); break; case 2: moveDown(); break; case 3: moveRight(); break; case 4: moveLeft(); break; }}}int winer(){int ans;for(int i = 0; i < arraySize; i++){ for(int j = 0; j < arraySize; j++){if(elementsij == chackij)ans = 1;else return -1; }}return 1;}

Go Top
x

Hi!
I'm Rita!

Would you like to get a custom essay? How about receiving a customized one?

Check it out