Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Welcome to GDB Online.
- GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
- C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
- Code, Compile, Run and Debug online from anywhere in world.
- *******************************************************************************/
- #include <iostream>
- #include <vector>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- typedef vector<int> VecteurI;
- typedef vector<VecteurI> MatriceI;
- int sizeH = 10;
- int sizeW = 10;
- int nb_mine = 10;
- int hit_x = 5;
- int hit_y = 5;
- int cases_remaining = sizeH * sizeW - nb_mine;
- MatriceI bo_sup(sizeH, VecteurI(sizeW));
- MatriceI bo_inf(sizeH, VecteurI(sizeW));
- bool init = false; //global if using class
- /////
- void loose {
- cout << "Vous avez malheuresement perdu." << endl << endl;
- for (int i = 0 ; i < sizeH ; i++) {
- for (int k = 0 ; k < sizeW ; k++) {
- if (bo_inf[i][k] == 9) {
- cout << "+ ";
- }
- else if (bo_sup[i][k] == 1) {
- cout << " ";
- }
- else
- cout << "# ";
- }
- cout << endl;
- }
- cout << endl;
- }
- void limites_tab(int& mX, int& MX, int& mY, int& MY, int posX, int posY)
- {
- mX = 0;
- MX = 0;
- mY = 0;
- MY = 0;
- if (posX == 0) {
- mX = 1;
- }
- else if (posX == sizeH) {
- MX = 1;
- }
- if (posY == 0) {
- mY = 1;
- }
- if (posY == sizeW) {
- MY = 1;
- }
- //ternaires ?
- }
- int adjacentes(int posX, int posY)
- {
- int minX, maxX, minY, maxY;
- limites_tab(minX, maxX, minY, maxY, posX, posY);
- int adja = 0;
- for (int x = posX - 1 + minX; x <= posX + 1 - maxX; x++) {
- for (int y = posY - 1 + minY; y <= posY + 1 - maxY; y++) {
- if (not(x == posX && y == posY)) {
- if (bo_inf[x][y] == 9) {
- adja++;
- }
- }
- }
- }
- return adja;
- }
- void init_bo_inf()
- {
- for (int i = 0; i < bo_inf.size(); i++) {
- for (int j = 0; j < bo_inf[i].size(); j++) {
- tab_inf[i][j] = 0;
- }
- }
- srand(time(NULL));
- while (nb_mine != 0) {
- int x = 0;
- int y = 0;
- do {
- x = rand() % (bp_inf.size() - 0) + 0;
- y = rand() % (bo_inf[0].size() - 0) + 0;
- } while (bo_inf[x][y] == 9 || bos_sup == 1); ///
- bo_inf[x][y] = 9;
- nb_mine--;
- }
- for (int X = 0; X < bo_inf.size(); X++) {
- for (int Y = 0; Y < bo_inf[X].size(); Y++) {
- if (bo_inf[X][Y] == 0) {
- bo_inf[X][Y] = adjacentes(X,Y);
- }
- }
- }
- }
- bool play_hit(vecteurI hit)
- {
- bo_sup[hit[0]][hit[1]] = 1;
- if (!init) {
- init = true;
- init_bo_inf();
- }
- if (bo_sup[hit[0]][hit[1]] == 9) {
- return true;
- }
- return false;
- }
- vecteurI ask_hit()
- {
- int x,y;
- do {
- do {
- std::cout << "Entrez votre coup sur l axe X (haut-bas) [1-" << sizeH << "] : ";
- cin >> x;
- x--;
- } while (x < 0 || x > bo_inf.size() -1);
- do {
- std::cout << "Entrez votre coup sur l axe Y (gauche-droite [1-" << sizeW <<"] : ";
- cin >> y;
- y--;
- } while (y < 0 || y > bo_inf[x].size() -1);
- if (bo_sup[x][y] == 1) {
- cout << "erreur, vous avez déjà joué sur cette case." << endl;
- }
- } while (bo_sup[x][y] == 1);
- VecteurI hit{x,y};
- return hit;
- }
- MatriceI init_bo_sup(int sizeH, int sizeW)
- {
- for (int i = 0; i < bo_sup.size(); i++) {
- for (int j = 0; j < bo_sup[i].size(); j++) {
- tab_sup[i][j] = 0;
- }
- }
- return bo_sup;
- }
- int main()
- {
- if (!init) {
- VecteurI hit = ask_hit();
- play_hit(hit);
- if (play_hit) {
- loose;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement