0% encontró este documento útil (0 votos)
23 vistas4 páginas

Proyecto Jafet Caballero 62111424

Descargar como txt, pdf o txt
Descargar como txt, pdf o txt
Descargar como txt, pdf o txt
Está en la página 1/ 4

#include <iostream>

using namespace std;


#include <array>

void imprimirTablero(char **array)


{

cout << " 0";


for (int i = 1; i <= 7; i++)
{
cout << " " << i;
}
cout << " -----> Filas";
cout << endl;

for (int i = 0; i <= 7; i++)


{
cout << " " << i << " |";
for (int j = 0; j <= 7; j++)
{
if (array[i][j] == 'N' or array[i][j] == 'B')
{
cout << " " << array[i][j] << " |";
}
else
{
cout << " |";
}
}

cout << endl;


cout << " ---------------------------------" << endl;
}
}

char **iniciarTablero(char **array)


{

for (int i = 0; i <= 7; i++)


{
for (int j = 0; j <= 7; j++)
{
if (i == 0 && j % 2 != 0)
{
array[i][j] = 'N';
}
else if (i == 1 && j % 2 == 0)
{
array[i][j] = 'N';
}
else if (i == 2 && j % 2 != 0)
{
array[i][j] = 'N';
}
else if (i == 5 && j % 2 == 0)
{
array[i][j] = 'B';
}
else if (i == 6 && j % 2 != 0)
{
array[i][j] = 'B';
}
else if (i == 7 && j % 2 == 0)
{
array[i][j] = 'B';
}
else
{
array[i][j] = ' ';
}
}
}

return array;
}

void moverFicha(char **array)


{
int turno = 0, player, piezaX, piezaY, movimientoX, movimientoY, piezaMovida;

do
{
if (turno % 2 == 0)
{
player = 1;
}
else
{
player = 2;
}

if (player == 1)
{
cout << "Turno de jugador 1 (N): ";
}
else
{
cout << "Turno de jugador 2 (B): ";
}

cout << "\nIndique la pieza que moverá" << endl;


cout << "Fila : ";
cin >> piezaX;
cout << "Columna : ";
cin >> piezaY;

cout << "\nIndique donde la quiere mover" << endl;


cout << "Fila : ";
cin >> movimientoX;
cout << "Columna : ";
cin >> movimientoY;
cout << endl;

// Movimiento de la pieza
if (array[movimientoX][movimientoY] == ' ')
{
piezaMovida = array[piezaX][piezaY];
array[piezaX][piezaY] = ' ';
array[movimientoX][movimientoY] = piezaMovida;
turno++;
}

else
{
cout << "No puedes mover ahi" << endl;
}

if (player == 1)
{
if (array[movimientoX - 1][movimientoY - 1] == 'B') // Para setear el
espacio en blanco en el lugar donde se movio la ficha
{
array[movimientoX - 1][movimientoY - 1] = ' ';
cout << "TE COMISTE UNA FICHA!!!" << endl;
}
if (array[movimientoX - 1][movimientoY + 1] == 'B')
{
array[movimientoX - 1][movimientoY + 1] = ' ';
cout << "TE COMISTE UNA FICHA!!!" << endl;
}
}
if (player == 2)
{
if (array[movimientoX + 1][movimientoY + 1] == 'N')
{
array[movimientoX + 1][movimientoY + 1] = ' ';
cout << "TE COMISTE UNA FICHA!!!" << endl;
}
if (array[movimientoX + 1][movimientoY - 1] == 'N')
{
array[movimientoX + 1][movimientoY - 1] = ' ';
cout << "TE COMISTE UNA FICHA!!!" << endl;
}
}
imprimirTablero(array);
} while (true);
turno++;
}

void ganador(char **array)


{
int piezaN = 12, piezaB = 12;
for (int i = 0; i <= 8; i++)
{
for (int j = 0; j <= 8; j++)
{
if (array[i][j] == 'N')
{
piezaN--;
}
}
}
for (int i = 0; i <= 8; i++)
{
for (int j = 0; j <= 8; j++)
{
if (array[i][j] == 'B')
{
piezaB--;
}
}
}
if (piezaN == 0)
{
cout << "Ganó el jugador 2 (B)" << endl;
}
else if (piezaB == 0)
{
cout << "Ganó el jugador 1 (N)" << endl;
}
}

int main()
{

int width = 8;
int height = 8;

char **arr = new char *[width];

for (int i = 0; i < width; ++i)


{
arr[i] = new char[height];
}
cout << " ------EL JUEGO HA COMENZADO------\n"
<< endl;

iniciarTablero(arr);
imprimirTablero(arr);
moverFicha(arr);
ganador(arr);

delete[] arr;
return 0;
}

También podría gustarte