Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5. using namespace System;
  6.  
  7. typedef struct {
  8.     int X, Y;
  9. }coord;
  10. void generarMatriz(int **matriz, int &lim)
  11. {
  12.     int num;
  13.     Random r;
  14.     Random s;
  15.  
  16.     lim = r.Next(4, 7);
  17.  
  18.     //genera los numeros
  19.     for (int f = 0; f < lim; f++) {
  20.         for (int c = 0; c < lim; c++)
  21.         {
  22.             num = r.Next(1, 21);
  23.             matriz[f][c] = num;
  24.         }
  25.     }
  26.  
  27.     //asigna a dos posiciones aleatorias un 0 (mina)
  28.     matriz[r.Next(0, lim)][s.Next(0, lim)] = 0;
  29.     matriz[r.Next(0, lim)][s.Next(0, lim)] = 0;
  30. }
  31.  
  32. void mostrarNuevaMatriz(int **matriz, int lim)
  33. {
  34.     for (int f = 0; f < lim; f++) {
  35.         for (int c = 0; c < lim; c++)
  36.         {
  37.             cout << " *  ";
  38.         }
  39.         cout << endl << endl;
  40.     }
  41.  
  42. }
  43.  
  44. void mostrarMatriz(int **matriz, int lim,int X, int Y, coord *Vcoord)
  45. {
  46.     for (int f = 0; f < lim*lim; f++)
  47.     {
  48.         for (int c = 0; c < lim; c++)
  49.         {
  50.             if (f == Vcoord[f].Y && c == Vcoord[f].X)
  51.             {
  52.                 cout << " " << matriz[f][c] << "  ";
  53.             }
  54.             else
  55.                 cout << " *  ";
  56.         }
  57.         cout << endl << endl;
  58.     }
  59.  
  60. }
  61.  
  62. void controlador(int **matriz, int &jugador, int &X, int &Y, int lim, char reinicio,int &puntaje1,int &puntaje2, coord *Vcoord)
  63. {
  64.     while (reinicio == 'S') {
  65.         int contador = 0;
  66.  
  67.         generarMatriz(matriz, lim);
  68.         while (jugador < 3) {
  69.             Console::Clear();
  70.                 mostrarMatriz(matriz, lim, X, Y, Vcoord );
  71.  
  72.             do {
  73.                 cout << "Jugador " << jugador << endl;
  74.                 do {
  75.                     cout << "coordenada X: ";
  76.                     cin >> X;
  77.    
  78.                     cout << "coordenada Y: ";
  79.                     cin >> Y;
  80.                 } while (Y > lim ||X > lim);
  81.  
  82.                 Console::Clear();
  83.                 mostrarMatriz(matriz, lim, X, Y,Vcoord);
  84.  
  85.                 if (matriz[Y - 1][X - 1] == 0)
  86.                     break;
  87.  
  88.                 Vcoord[0 + contador].X = X-1;
  89.                 Vcoord[0 + contador].Y = Y-1;
  90.  
  91.                 contador++;
  92.  
  93.                 if (jugador == 1)
  94.                 {
  95.                     puntaje1 += matriz[Y][X];
  96.                 }
  97.                 else
  98.                     puntaje2 += matriz[Y][X];
  99.  
  100.             } while (matriz[Y - 1][X - 1] != 0);
  101.  
  102.             jugador++;
  103.             if (jugador < 3) {
  104.                 cout << "Siguiente Jugador!\n";
  105.                 getch();
  106.             }
  107.         }
  108.  
  109.         cout << "\n--RESULTADOS--";
  110.         cout << "\nJugador 1: " << puntaje1;
  111.         cout << "\nJugador 2: " << puntaje2;
  112.         do {
  113.             cout << "\nDesea seguir jugando? (S/N): ";
  114.             cin >> reinicio;
  115.             reinicio = toupper(reinicio);
  116.         } while (reinicio != 'S'&&reinicio != 'N');
  117.         jugador = 1;
  118.         X = 100;
  119.         Y = 100;
  120.     }
  121. }
  122.  
  123. void main() {
  124.     int **matriz,**matriz2,lim,jugador,X,Y;
  125.     int puntaje1 = 0;
  126.     int puntaje2 = 0;
  127.     char reinicio='S';
  128.  
  129.     jugador = 1;
  130.     lim = 1;
  131.  
  132.     Random r;
  133.     lim = r.Next(4, 7);
  134.  
  135.     matriz = new int *[lim];
  136.     for (int i = 0; i < lim; i++)
  137.     {
  138.         matriz[i] = new int[lim];
  139.     }
  140.  
  141.     coord *Vcoord;
  142.     Vcoord = new coord[lim*lim];
  143.  
  144.     controlador(matriz, jugador, X, Y, lim,reinicio,puntaje1,puntaje2,Vcoord);
  145.  
  146.     getch();
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement