Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- using namespace System;
- typedef struct {
- int X, Y;
- }coord;
- void generarMatriz(int **matriz, int &lim)
- {
- int num;
- Random r;
- Random s;
- lim = r.Next(4, 7);
- //genera los numeros
- for (int f = 0; f < lim; f++) {
- for (int c = 0; c < lim; c++)
- {
- num = r.Next(1, 21);
- matriz[f][c] = num;
- }
- }
- //asigna a dos posiciones aleatorias un 0 (mina)
- matriz[r.Next(0, lim)][s.Next(0, lim)] = 0;
- matriz[r.Next(0, lim)][s.Next(0, lim)] = 0;
- }
- void mostrarNuevaMatriz(int **matriz, int lim)
- {
- for (int f = 0; f < lim; f++) {
- for (int c = 0; c < lim; c++)
- {
- cout << " * ";
- }
- cout << endl << endl;
- }
- }
- void mostrarMatriz(int **matriz, int lim,int X, int Y, coord *Vcoord)
- {
- for (int f = 0; f < lim*lim; f++)
- {
- for (int c = 0; c < lim; c++)
- {
- if (f == Vcoord[f].Y && c == Vcoord[f].X)
- {
- cout << " " << matriz[f][c] << " ";
- }
- else
- cout << " * ";
- }
- cout << endl << endl;
- }
- }
- void controlador(int **matriz, int &jugador, int &X, int &Y, int lim, char reinicio,int &puntaje1,int &puntaje2, coord *Vcoord)
- {
- while (reinicio == 'S') {
- int contador = 0;
- generarMatriz(matriz, lim);
- while (jugador < 3) {
- Console::Clear();
- mostrarMatriz(matriz, lim, X, Y, Vcoord );
- do {
- cout << "Jugador " << jugador << endl;
- do {
- cout << "coordenada X: ";
- cin >> X;
- cout << "coordenada Y: ";
- cin >> Y;
- } while (Y > lim ||X > lim);
- Console::Clear();
- mostrarMatriz(matriz, lim, X, Y,Vcoord);
- if (matriz[Y - 1][X - 1] == 0)
- break;
- Vcoord[0 + contador].X = X-1;
- Vcoord[0 + contador].Y = Y-1;
- contador++;
- if (jugador == 1)
- {
- puntaje1 += matriz[Y][X];
- }
- else
- puntaje2 += matriz[Y][X];
- } while (matriz[Y - 1][X - 1] != 0);
- jugador++;
- if (jugador < 3) {
- cout << "Siguiente Jugador!\n";
- getch();
- }
- }
- cout << "\n--RESULTADOS--";
- cout << "\nJugador 1: " << puntaje1;
- cout << "\nJugador 2: " << puntaje2;
- do {
- cout << "\nDesea seguir jugando? (S/N): ";
- cin >> reinicio;
- reinicio = toupper(reinicio);
- } while (reinicio != 'S'&&reinicio != 'N');
- jugador = 1;
- X = 100;
- Y = 100;
- }
- }
- void main() {
- int **matriz,**matriz2,lim,jugador,X,Y;
- int puntaje1 = 0;
- int puntaje2 = 0;
- char reinicio='S';
- jugador = 1;
- lim = 1;
- Random r;
- lim = r.Next(4, 7);
- matriz = new int *[lim];
- for (int i = 0; i < lim; i++)
- {
- matriz[i] = new int[lim];
- }
- coord *Vcoord;
- Vcoord = new coord[lim*lim];
- controlador(matriz, jugador, X, Y, lim,reinicio,puntaje1,puntaje2,Vcoord);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement