/* Puzzle Game Project. * Written By : Ahmad Siavashi, * Summer 1391 - 2012. */ #include #include #include void gotoxy(int x,int y); void DrawTable(void); void StartGame(void); void GeneratingNums(int **board); void HashTheNums(int **board); void PuttingNumsInTable(int **board); void GameControl(int **board); int BoardSize,Hardness; int main() { printf("Enter the dimension of the table : "); scanf("%d",&BoardSize); printf("\nEnter level of hardness : "); scanf("%d",&Hardness); system("cls"); DrawTable(); StartGame(); return EXIT_SUCCESS; } // The Game Begins. void StartGame(void) { int i; int **board = (int **)malloc(BoardSize * sizeof(int)); for(i=0;i=0) { temp = board[EmptyPos.Y-1][EmptyPos.X]; board[EmptyPos.Y-1][EmptyPos.X] = board[EmptyPos.Y][EmptyPos.X]; board[EmptyPos.Y][EmptyPos.X] = temp; } else goto SET_DIRECTION; break; case LEFT: if(EmptyPos.X+1=0) { temp = board[EmptyPos.Y][EmptyPos.X-1]; board[EmptyPos.Y][EmptyPos.X-1] = board[EmptyPos.Y][EmptyPos.X]; board[EmptyPos.Y][EmptyPos.X] = temp; } else goto SET_DIRECTION; break; } } } // Generating Numbers of the board. void GeneratingNums(int **board) { int i,j,n=1; for(j=0;j0 && i>0) board[--j][--i]=0; } void gotoxy(int x, int y) { // Initialize the coordinates COORD coord = {x, y}; // Set the position SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); } // Draws the table of the game. void DrawTable() { int i,j; int x,y; for(j=0,x=y=0;j<=BoardSize;++j) { for(i=0;i=0) { gotoxy(x+EmptyPos.X*MOVE_RL,y+EmptyPos.Y*MOVE_UD); printf("%d",board[EmptyPos.Y-1][EmptyPos.X]); gotoxy(x+(EmptyPos.X)*MOVE_RL,y+(EmptyPos.Y-1)*MOVE_UD); printf(" \b\b\b"); temp = board[EmptyPos.Y-1][EmptyPos.X]; board[EmptyPos.Y-1][EmptyPos.X] = board[EmptyPos.Y][EmptyPos.X]; board[EmptyPos.Y][EmptyPos.X] = temp; } break; case LEFT: if(EmptyPos.X+1=0) { gotoxy(x+EmptyPos.X*MOVE_RL,y+EmptyPos.Y*MOVE_UD); printf("%d",board[EmptyPos.Y][EmptyPos.X-1]); gotoxy(x+(EmptyPos.X-1)*MOVE_RL,y+(EmptyPos.Y)*MOVE_UD); printf(" \b\b\b"); temp = board[EmptyPos.Y][EmptyPos.X-1]; board[EmptyPos.Y][EmptyPos.X-1] = board[EmptyPos.Y][EmptyPos.X]; board[EmptyPos.Y][EmptyPos.X] = temp; } break; } } } }