#include #include #include #include // Created by D. Levi, Feb 2001 // Modified by I. Markov int main() { unsigned n=0; cout << "Enter size of map "<< endl; while(n<4) { cout << "Please choose a number more than 3 : "; cin >> n; } ofstream outFile("maze.txt"); if (!outFile) { cerr << "Cannot open file maze.txt" << endl; exit(1); } outFile << n << endl; srand(time(0)); // seed the RNG with Unix time // man -s 2 time for more info (on Linux: man s 2 time) outFile <<"OX" ; unsigned i,j; for (i=2; i < n; i++) outFile << 'X'; outFile << endl; for (i = 0; i < n; i++) outFile << ' '; outFile << endl; for (i = 0; i < n-4; i++) { for (j = 0; j < n; j++) { if ( (rand() % 9 + 1) > 4 ) outFile << ' '; else outFile << 'X'; } outFile << endl; } for (i = 0; i < n; i++) outFile << ' '; outFile << endl; for (i = 0; i < n-2; i++) outFile << 'X'; outFile<<"CX"<< endl; outFile.close(); cout << " A new maze is ready in maze.txt" << endl; }