Está en la página 1de 10

#include <conio.

h> // getche();
#include <ctime> // time();
#include <iostream>

#define FALSE 0
#define TRUE 1

#define NADA 0
#define LIBRE 1
#define FICHA_AMARILLA 2
#define FICHA_VERDE 3
#define FICHA_AZUL 4
#define FICHA_NEGRA 5
#define FICHA_MARRON 6
#define FICHA_ROJA 7
#define NINGUNO -1

#define MODOS 9
#define COLORES 6
#define FICHAS 10

#define PASO_CORTO 1
#define PASO_LARGO 2

#define DameIndice(x) (x-2)

#define filas 17
#define columnas 13

struct scolor
{
unsigned char r;
unsigned char g;
unsigned char b;
};

void inicio(int state, int x, int y);


void control();
int MovidaValida(int m0, int n0, int m1, int n1,int mirar);
void InicializarTablero();
void SiguienteTurno();
int SigueJugando(int m, int n);
int FinJuego();
int FichaEnTurno(int ficha);
int FichasEnBase(int ficha);
int PuntajeMayorTurnos();
int TotalFichasTurno(int turno);
int TurnoSobreviviente();
int TurnoGanador();

using namespace std;

int modo = 0;
int turno = 0;
int comer = 0;

int mov = 0;
int seli, selj; //posicion seleccionada
int gi, gj; //guarda la posicion del tablero a la cual se movio la
ficha animada
int fichaanim; //valor de la ficha animada
int anim = 0; //se esta animando o no alguna ficha
int fin = 0; //termino la partida?

int ct;

int turnos[MODOS][COLORES + 1] = {
{FICHA_VERDE, FICHA_AMARILLA, NADA, NADA, NADA, NADA, NADA},
{FICHA_VERDE, FICHA_AZUL, FICHA_ROJA, NADA, NADA, NADA, NADA},
{FICHA_VERDE, FICHA_AZUL, FICHA_AMARILLA, FICHA_NEGRA, NADA, NADA, NADA},
{FICHA_VERDE, FICHA_MARRON, FICHA_AZUL, FICHA_ROJA, FICHA_NEGRA, NADA, NADA},
{FICHA_VERDE, FICHA_MARRON, FICHA_AZUL, FICHA_AMARILLA, FICHA_ROJA,
FICHA_NEGRA, NADA},
{FICHA_VERDE, FICHA_AMARILLA, FICHA_MARRON, FICHA_ROJA, FICHA_AZUL,
FICHA_NEGRA, NADA},
{FICHA_VERDE, FICHA_AZUL, FICHA_AMARILLA, FICHA_NEGRA, NADA, NADA, NADA},
{FICHA_VERDE, FICHA_MARRON, FICHA_AZUL, FICHA_AMARILLA, FICHA_ROJA,
FICHA_NEGRA, NADA},
{FICHA_VERDE, FICHA_AMARILLA, FICHA_MARRON, FICHA_ROJA, NADA, NADA, NADA}
};

int fichasxturno[MODOS] = {1, 1, 1, 1, 1, 2, 2, 3, 2};


int puntajes[COLORES] = {0, 0, 0, 0, 0, 0};
int fichas_comidas[COLORES] = {0, 0, 0, 0, 0, 0};

int iniciales[COLORES][FICHAS * 2] = {
{0, 6, 1, 6, 1, 7, 2, 5, 2, 6, 2, 7, 3, 5, 3, 6, 3, 7, 3, 8},
{13, 5, 13, 6, 13, 7, 13, 8, 14, 5, 14, 6, 14, 7, 15, 6, 15, 7, 16, 6},
{4, 0, 4, 1, 4, 2, 4, 3, 5, 1, 5, 2, 5, 3, 6, 1, 6, 2, 7, 2},
{9, 11, 10, 10, 10, 11, 11, 10, 11, 11, 11, 12, 12, 12, 12, 11, 12, 10, 12, 9},
{9, 2, 10, 1, 10, 2, 11, 1, 11, 2, 11, 3, 12, 0, 12, 1, 12, 2, 12, 3},
{4, 12, 4, 11, 4, 10, 4, 9, 5, 12, 5, 11, 5, 10, 6, 11, 6, 10, 7, 11}
};

int tablerobase[17][13] = {
{0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0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 0}
};

/* Esta funcion indica si la ficha consultada pertenece o no al turno actual. */


int FichaEnTurno(int ficha)
{
int i;
for (i = 0; i < fichasxturno[modo]; i++)
{
if (ficha == turnos[modo][turno + i]){
cout << "test: " << turnos[modo][turno + i] <<
endl; //////////////////////////////////////////
return TRUE;
}

}
return FALSE;
}

/* Retorna el color de la ficha cuya base corresponde como objetivo al color de la


ficha consultada.*/
int DameContrario(int ficha)
{
return 0;
}

/* Verifica si el movimiento es valido o no, en caso positivo indica que tipo de


movimiento fue realizado.*/
int MovidaValida(int m0, int n0, int m1, int n1, int mirar)
{
return 0;
}

/* Indica el total de fichas en el tablero que posee el turno consultado. */


int TotalFichasTurno(int algunturno)
{
int i, total;
total = 0;
for (i = 0; i < fichasxturno[modo]; i++)
{
total += (FICHAS - fichas_comidas[DameIndice(turnos[modo][algunturno +
i])]);
}
return total;
}
/* Contabiliza la cantidad de fichas que estan en la base destino. */
int FichasEnBase(int ficha)
{
int i, j, cont;
cont = 0;
i = DameIndice(DameContrario(ficha));
for (j = 0; j < 20; j += 2)
{
if (tablero[iniciales[i][j]][iniciales[i][j + 1]] == ficha)
{
cont++;
}
}
return cont;
}

/* Indica el total de fichas del turno consultado las cuales se encuentran dentro
de la base objetivo. */
int TotalFichasEnBase(int algunturno)
{
int i, fichasenbase = NADA;
for (i = 0; i < fichasxturno[modo]; i++)
{
fichasenbase += FichasEnBase(turnos[modo][algunturno + i]);
}
return fichasenbase;
}

/* Condicion de fin del juego, mientras no todos los turnos hayan llegado. */
int FinJuego()
{
return 0;
}

/* Verifica si el turno actual todavia puede realizar movidas. */


int SigueJugando(int m, int n)
{
return 0;
}

/* Pasa el control al siguiente turno. */


void SiguienteTurno()
{

void Imprimir()
{
cout << "\n\t\t\t ";
for (int j = 0; j < columnas - 1; j++){
if (j < 9)
cout << " " << j + 1;
else
cout << " " << j + 1;
}
cout << "\n\n";
for (int i = 0; i < filas; i++)
{
cout << "\t\t" << i << "\t";
for (int j = 0; j < columnas; j++)
{
if ((i % 2) == 0)
{
if (tablero[i][j] > 0){
switch (tablero[i][j])
{
case 1:
cout << " " << "*";
break;
case 2:
cout << " " << "R";
break;
case 3:
cout << " " << "P";
break;
}

}
else{
cout << " ";
}
}
else
{
if (tablero[i][j] > 0){
switch (tablero[i][j])
{
case 1:
cout << " " << "* ";
break;
case 2:
cout << " " << "R ";
break;
case 3:
cout << " " << "P ";
break;
}
}
else
cout << " ";
}
}
cout << endl;
}

cout << "\n\t\t\t";


for (int j = 0; j < columnas; j++){
if (j < 10)
cout << " " << j;
else
cout << " " << j;
}
cout << "\n\n";
}
/*
Coloca las fichas del color en cuestion en su posicion inicial.
*/
void PintarTablero(int ficha)
{
int i, j;
i = DameIndice(ficha);
for (j = 0; j < (FICHAS * 2); j += 2)
{
tablero[iniciales[i][j]][iniciales[i][j + 1]] = ficha;
}
}

/*
Inicializa todos los valores del tablero
*/
void InicializarTablero()
{
int i = 0;
while (turnos[modo][i] != NADA)
{
PintarTablero(turnos[modo][i]);
i++;
}
}

/*
Inicializa una partida
*/
void juegonuevo()
{
for (int i = 0; i < 17; i++)
{
for (int j = 0; j < 13; j++)
{
tablero[i][j] = tablerobase[i][j];
}
}
turno = 0;
}

void control()
{
int ficha;
do
{
system("cls");
Imprimir();

cout << "Digite FICHA: ";


cin >> seli >> selj;

inicio(1, 1, 1);

} while (2>1);

}
void inicio(int state, int x, int y)
{
struct scolor color;
int curi, curj;
static int ban = 0;
int movtipo;

cout << "Coordenada: ";


cin >> curi >> curj;
cout << "Comparacion: " << seli << "\t" << selj << "\t" << curi << "\t" <<
curj << endl;
if (!(curi == seli && curj == selj))
{
int gseli, gselj;
movtipo = MovidaValida(seli, selj, curi, curj, 0);
if ((ban && movtipo == PASO_LARGO) || (!ban && movtipo))
{
cout << "GENIAL ";
fichaanim = tablero[seli][selj];
tablero[curi][curj] = fichaanim;
tablero[seli][selj] = 1;
gi = curi;
gj = curj;
gseli = seli;
gselj = selj;
//inianim(seli, selj, curi, curj);
if (movtipo == PASO_LARGO && SigueJugando(curi, curj))
{
seli = curi;
selj = curj;
ban = 1;
}
else
{
ban = 0;
mov = 0;
seli = -1;
selj = -1;
ct = 1;
}
}
else
{
if (!ban)
{
cout << "Bam\n";
mov = 0;
seli = -1;
selj = -1;
}
}
}
else
{ /*
cout << "Casi de nuevo";
if (ban)
{
ban = 0;
if (FinJuego() || TurnoSobreviviente())
{
fin = 1;
}
else
{
SiguienteTurno();
}
}
mov = 0;
seli = -1;
selj = -1;
*/
}

//display();
}

void mensaje_salida()
{
cout << "\n\t\t............::::::::: FIN DE PROGRAMA :::::::::::............"
<< "\n\t\t============================================================="
<< "\n\t\tName : Damas Chinas"
<< "\n\t\tAuthor : @Eber"
<< "\n\t\tVersion : Hito 1"
<< "\n\t\tDescription : Programacion I"
<<
"\n\t\t=============================================================\n\n";
}

void reglas()
{
cout << "\n\t\t\t :::::::::::::::::::: MODO DE JUEGO ::::::::::::::::::::\n"
<< "\n\t\tCADA EQUIPO CONSTA DE DIES FICHAS O PIEZAS. AL EMPEZAR EL JUEGO,
ESTAS DIEZ"
<< "\n\t\tDE UN MISMO JUGADOR ESTAN JUNTAS, EN UNO DE LOS TRIANGULOS QUE
FORMAN LAS"
<< "\n\t\tPUNTAS DE LA ESTRELLA. EL OBJETIVO DEL JUEGO ES LLEVAR LAS 10
FICHAS O PIEZAS"
<< "\n\t\tDE UN EQUIPO DESDE UNA PUNTA HASTA LA OPUESTA."
<< "\n\t\tPUNTA HASTA LA OPUESTA"
<< "\n\t\tCADA JUGADOR SOLO MUEVE UNA FICHA POR TURNO"
<< "\n\t\tUN MOVIMIENTO VALIDO ES:"
<< "\n\t\t - A UNA CASILLA ADYACENTE LIBRE"
<< "\n\t\t - SALTANDO UNA CASILLA ADYACENTE OCUPADA POR OTRA FICHA (SEA
PROPIA O,"
<< "\n\t\t CONTRARIA) Y POSANDOLA EN LA CASILLA SIGUIENTE SI ESTA
LIBRE\n"
<< "\n\t\t\t :::::::::::::::::::: INSTRUCCIONES ::::::::::::::::::::\n"
<< "\n\t\tPARA JUGAR A DAMAS CHINAS LA PARTIDA COMENZARA CON EL JUGADOR DE
MAYOR PUNTAJE."
<< "\n\t\tPOSTERIORMENTE SE ALTERNARAN EL TURNO DE JUGAR DE ACUERDO A LAS
REGLAS"
<< "\n\t\tPARA HACER UN MOVIMIENTO DEBE SELECCIONAR PRIMERO LA COORDENADA
VERTICAL, Y "
<< "\n\t\tDESPUES LA COORDENADA HORIZONTAL, CASO DE NO HABER FICHA SE TE
VOLVERA A PEDIR"
<< "\n\t\tQUE VUELVAS A TIRAR PARA SELECCIONAR EL MOVIMIENTO DE LA FICHA
PERSIONA [1]"
<< "\n\t\tPARA MOVERLA DIAGONALMENTE IZQUIERDA O [2] PARA DIAGONAL
DERECHA"
<< "\n\t\tGANA EL JUGADOR QUE PUEDA COLOCAR PRIMERO SUS 10 FICHAS EN EL
EXTREMO OPUESTO."
<< "\n";
}

void presentacion()
{
system("color B");
cout << "\n\t\t .....::::: BIENVENIDO AL JUEGO DE DAMAS CHINAS EN C+
+ :::::.....\n\n"
<< "\n\t\t\t\t || PRESIONE ENTER PARA CONTINUAR ||\n\n";
Imprimir();
cout << "\n\t\t\t 2020 copyright \251Eber Todos los Derechos Reservados";
getche();
}

int menu()
{
system("cls");
int opcion;
cout << "\n\t\t\t\t=============================="
<< "\n\t\t\t\t....:::: DAMAS CHINAS ::::...."
<< "\n\t\t\t\t==============================\n"
<< "\n\t\t\t\t[1] JUGAR"
<< "\n\t\t\t\t[2] REGLAS"
<< "\n\t\t\t\t[3] SALIR\n";
do
{
cout << "\n\t\t\t\tDigite opcion [ ]\b\b";
cin >> opcion;
} while (opcion < 1 || opcion > 3);

return opcion;
}

void procesos()
{
int opcion;
do
{
opcion = menu(); // representa la seleccion del menu
system("cls");
switch (opcion)
{
case 1:
juegonuevo();
InicializarTablero();
control();
break;
case 2:
reglas();
break;
case 3:
mensaje_salida();
break;
}
getche();
} while (opcion != 3);
}

int main()
{
presentacion();
procesos();
}

También podría gustarte