Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. //new version 22.11 ~mika
  5.  
  6. using namespace std;
  7.  
  8. void print(int *** a, int num)
  9. {
  10. for (int y=0; y<num; y++)
  11. {
  12. for (int z=0; z<num; z++)
  13. if (a[y][z][1]==0)
  14. cout<<"#";
  15. else
  16. cout<<a[y][z][0];
  17. cout<<endl;
  18. }
  19. }
  20.  
  21. int main()
  22. {
  23. int num;
  24. cout<<"enter number";
  25. cin>>num;
  26. int *** arr = new int ** [num]; //יצירת המערכים
  27. for (int k=0; k<num; k++)
  28. {
  29. arr[k]= new int *[num];
  30. for (int s=0; s<num; s++)
  31. {
  32. arr[k][s]=new int [2];
  33. }
  34. }
  35.  
  36. int countT=num*num; //מספר הקופסאות שיש עוד לפתוח
  37.  
  38. for( int m=0; m<num*num/5; m++) //הצבת פצצות
  39. arr[rand()% num][rand() % num ][0]=10;
  40.  
  41. int countB=0;
  42. for (int p=0; p<num; p++) //הצבה של מספרים
  43. {
  44. for (int y=0; y<num; y++)
  45. {
  46. arr[p][y][1]=0; // סימון כל התאים כנצפו, 0 משמעו לא נפו, אחד משמעו נצפו
  47. if (arr[p][y][0]!=10)
  48. {
  49. countB=0;
  50. if ( y!=0 && arr[p][y-1][0]==10)
  51. countB++;
  52. if (y!=num - 1 && arr[p][y+1][0]==10) // changed y != num -> y != num - 1
  53. countB++;
  54. if (p!=0 && arr[p-1][y][0]==10)
  55. countB++;
  56. if (p!=num - 1 && arr[p+1][y][0]==10)
  57. countB++;
  58. if (p!=0 && y!=0 && arr[p-1][y-1][0]==10)
  59. countB++;
  60. if (p!=num - 1 && y!=num -1 && arr[p+1][y+1][0]==10)
  61. countB++;
  62. if (p!=0 && y!=num - 1 && arr[p-1][y+1][0]==10)
  63. countB++;
  64. if (p!=num - 1 && y!=0 && arr[p+1][y-1][0]==10)
  65. countB++;
  66. arr[p][y][0]=countB;
  67. }
  68. else
  69. countT--;
  70. }
  71. }
  72. //תחילת המשחק עצמו
  73. cout<<countT;
  74.  
  75. print(arr,num);
  76.  
  77. int row;
  78. int col;
  79. cout<<"Enter index of row and col";
  80. cin>>row;
  81. cin>>col;
  82. row--;
  83. col--;
  84.  
  85. while( arr[row][col][0]!=10 && countT>0 )
  86. {
  87. if (arr[row][col][1]==1)
  88. cout << "You already opened this box";
  89. else
  90. {
  91. countT--;
  92. arr[row][col][1]=1;
  93. print(arr, num);
  94. }
  95. cout<<countT;
  96. cout<<"Enter index of row and col";
  97. cin>>row;
  98. cin>>col;
  99. row--;
  100. col--;
  101. }
  102.  
  103. if (arr[row][col][0]==10)
  104. cout << "You clicked a bomb! loser ";
  105. if (countT==0)
  106. cout << "You won! you are OK after all!";
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement