Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- //new version 22.11 ~mika
- using namespace std;
- void print(int *** a, int num)
- {
- for (int y=0; y<num; y++)
- {
- for (int z=0; z<num; z++)
- if (a[y][z][1]==0)
- cout<<"#";
- else
- cout<<a[y][z][0];
- cout<<endl;
- }
- }
- int main()
- {
- int num;
- cout<<"enter number";
- cin>>num;
- int *** arr = new int ** [num]; //יצירת המערכים
- for (int k=0; k<num; k++)
- {
- arr[k]= new int *[num];
- for (int s=0; s<num; s++)
- {
- arr[k][s]=new int [2];
- }
- }
- int countT=num*num; //מספר הקופסאות שיש עוד לפתוח
- for( int m=0; m<num*num/5; m++) //הצבת פצצות
- arr[rand()% num][rand() % num ][0]=10;
- int countB=0;
- for (int p=0; p<num; p++) //הצבה של מספרים
- {
- for (int y=0; y<num; y++)
- {
- arr[p][y][1]=0; // סימון כל התאים כנצפו, 0 משמעו לא נפו, אחד משמעו נצפו
- if (arr[p][y][0]!=10)
- {
- countB=0;
- if ( y!=0 && arr[p][y-1][0]==10)
- countB++;
- if (y!=num - 1 && arr[p][y+1][0]==10) // changed y != num -> y != num - 1
- countB++;
- if (p!=0 && arr[p-1][y][0]==10)
- countB++;
- if (p!=num - 1 && arr[p+1][y][0]==10)
- countB++;
- if (p!=0 && y!=0 && arr[p-1][y-1][0]==10)
- countB++;
- if (p!=num - 1 && y!=num -1 && arr[p+1][y+1][0]==10)
- countB++;
- if (p!=0 && y!=num - 1 && arr[p-1][y+1][0]==10)
- countB++;
- if (p!=num - 1 && y!=0 && arr[p+1][y-1][0]==10)
- countB++;
- arr[p][y][0]=countB;
- }
- else
- countT--;
- }
- }
- //תחילת המשחק עצמו
- cout<<countT;
- print(arr,num);
- int row;
- int col;
- cout<<"Enter index of row and col";
- cin>>row;
- cin>>col;
- row--;
- col--;
- while( arr[row][col][0]!=10 && countT>0 )
- {
- if (arr[row][col][1]==1)
- cout << "You already opened this box";
- else
- {
- countT--;
- arr[row][col][1]=1;
- print(arr, num);
- }
- cout<<countT;
- cout<<"Enter index of row and col";
- cin>>row;
- cin>>col;
- row--;
- col--;
- }
- if (arr[row][col][0]==10)
- cout << "You clicked a bomb! loser ";
- if (countT==0)
- cout << "You won! you are OK after all!";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement