Jak działa saper w c++???#include<stdlib.h>#include<iostream>#include<stdio.h>#include<sstream>#include<time.h>using namespace std;char konwersja(int ilosc){ int ile=ilosc; stringstream ss; string wokol; ss << ile; ss >> wokol; std::string str(wokol); char znak = str[0]; return znak;}void wyswietl2(int x, int y, char zakryj[11][11]){ for (int i=1;i<=10;i++){ cout<<endl; for(int j=1;j<=10;j++){ zakryj[y][x]='B'; cout<<zakryj[i][j]<<" "; } }}void wyswietl(int x, int y, char zakryj[11][11], int ilosc){ cout<<endl; for (int i=1;i<=10;i++){ cout<<endl; for(int j=1;j<=10;j++){ zakryj[y][x]=konwersja(ilosc); cout<<zakryj[i][j]<<" "; } }}void gra(){ int n,x,y,s,d,puste; while(1){ cout<<"Podaj ilosc bomb max[99]: "; cin>>n; if (n>=100)continue; else break; }srand(time(0)); int tab[11][11]; for (int i=1;i<=10;i++){ for(int j=1;j<=10;j++){ tab[i][j]=0; } } for(int k=0;k<n;k++){ s=1+rand()%10; d=1+rand()%10; tab[s][d]=1; }puste=100-n; cout<<"Ilosc bomb na planszy: "<<n<<endl; char zakryj[11][11]; for (int i=1;i<=10;i++){ cout<<endl; for(int j=1;j<=10;j++){ zakryj[i][j]='-'; cout<<zakryj[i][j]<<" "; } } while(1){ cout<<endl<<endl; int ilosc=0; cout<<"Podaj wspolrzedne punktu: "<<endl; cout<<"x= "; cin>>x; cout<<"y= "; cin>>y; if(zakryj[y][x]!='-')continue; if(tab[y][x]==1){ wyswietl2(x,y,zakryj); cout<<endl<<endl; cout<<"Bomba!!! Przegrales! (Buhahahaha, kolejne zwyciestwo na moim koncie!!! Hahahaha)"<<endl<<endl; break; } if (x<=10 && y<=10){ if(tab[y][x]==0){ if(tab[y][x-1]==1)ilosc++; if(tab[y-1][x]==1)ilosc++; if(tab[y-1][x-1]==1)ilosc++; if(tab[y+1][x-1]==1)ilosc++; if(tab[y+1][x]==1)ilosc++; if(tab[y-1][x+1]==1)ilosc++; if(tab[y][x+1]==1)ilosc++; if(tab[y+1][x+1]==1)ilosc++; wyswietl(x,y,zakryj,ilosc); puste--; if(puste==0){cout<<endl<<"Jaka szkoda. WYGRALES!!!"<<endl<<endl;break;} cout<<endl<<endl; cout<<"Pozostalo "<<puste<<" pol do odkrycia"; continue; } } }}int main(){ char kont;cout<<" ****** * ******* ******* *******"<<endl;cout<<" * * * * * * * *"<<endl;cout<<" ****** * * ******* ****** *******"<<endl;cout<<" * ******* * * * *"<<endl;cout<<" ****** * * * ******* * *"<<endl<<endl<<endl; while(1){ gra(); cout<<"Grasz jeszcze raz?"<<endl<<"t - aby grac dalej..."<<endl<<"n - aby zakonczyc..."<<endl; cin>>kont; if (kont=='t' || kont=='T'){system("cls");continue;} else break; } cout<<endl; system("pause"); return 0;}
Answer

Life Enjoy

" Life is not a problem to be solved but a reality to be experienced! "

Get in touch

Social

© Copyright 2013 - 2024 KUDO.TIPS - All rights reserved.