Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. #include <cstdio>
  5. using namespace std;
  6. #define SIZE 12
  7. class maze{
  8.  
  9. private:
  10.  
  11. int t;
  12. char a[SIZE][SIZE];
  13.  
  14. public:
  15.  
  16. maze();
  17. void printMaze();
  18. void mazegen();
  19.  
  20.  
  21. };
  22.  
  23. maze::maze()
  24. {
  25.  
  26. int t=0;
  27. }
  28.  
  29. void maze::mazegen(){
  30.  
  31. srand (time(NULL));
  32.  
  33. // initialize '#' to all positions of left-hand wall
  34. for ( int i = 0; i < SIZE; ++i )
  35. {
  36. a[i][0] = '#';
  37. }
  38. // initialize '#' to all positions of left-hand wall
  39. for ( int i = 0; i < SIZE; ++i )
  40. {
  41. a[i][SIZE - 1] = '#';
  42. }
  43.  
  44. // initialize '.' to left-hand wall random positions from 1 -> 10
  45. t = rand() % 11 + 1;
  46. a[t][0] = '.';
  47.  
  48. // initialize '.' to right-hand wall random positions from 1 -> 10
  49. t = rand() % 11 + 1;
  50. a[t][SIZE - 1] = '.';
  51.  
  52. // intialize '#' to all positions of top maze
  53. for (int i = 1; i < SIZE - 1; ++i)
  54. {
  55. a[0][i] = '#';
  56. }
  57.  
  58. // intialize '#' to all positions of bottom maze
  59. for (int i = 1; i < SIZE - 1; ++i)
  60. {
  61. a[SIZE - 1][i] = '#';
  62. }
  63.  
  64.  
  65. }
  66.  
  67. void maze::printMaze(){
  68.  
  69. cout<<"";
  70. for (int i = 0; i < SIZE; ++i)
  71. {
  72. for (int j = 0; j< SIZE; ++j)
  73. {
  74. cout<<a[i][j];
  75. }
  76. cout<<"";
  77. }
  78. cout<<""<<endl;
  79.  
  80.  
  81.  
  82.  
  83. }
  84.  
  85. int main(void)
  86. {
  87. maze m;
  88. m.mazegen();
  89. m.printMaze();
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement