Created
March 5, 2016 15:01
-
-
Save SparedRay/ac6e544599a973971f00 to your computer and use it in GitHub Desktop.
Simulador rapido de partidos de futbol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Bayern|Barcelona|Chelsea|Atletico|Benfica|Juventus|Arsenal|Dortmund|Paris|Zenit|Porto|Valencia|Napoli|Basel|Bayer|Manchester|Olympiacos|Milan|Dynamo|Lazio|Fiorentina|Rubin|Lara|Aragua|Carabobo|Caracas|Llaneros|Mineros|Petare|Urena|Zamora|Trujillanos|Monagas|JBL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hernandez|Romo|Perozo|Tunez|Fuenmayor|Sanchez|Arango|Signorelli|Orozco|Guerra|Gonzalez|Miku|Rivas|Aristeguieta|Farias|Gomez|Lugo|Ocanto|Vargas|Contreras|Angel|Carabali|Melean|Peraza|Villanueva|Acosta|Soteldo|Moreno|Cermeno|Suarez|Ponce|Maldonado|Rey |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <strings.h> | |
#include "misc.h" | |
#define MAX_J 6 | |
#define MAX_T 6 | |
_jugador crearJugador(); | |
_equipo crearEquipo(); | |
int golEquipo(const _equipo t1, const _equipo t2); | |
void golJornada(_tabla tabla[], _equipo equipos[], int dia, int maximo, int cronograma[][maximo]); | |
char *getNombre(char *fileNombre); | |
void actualizarTabla(_tabla* tabla, int goles[]); | |
void moverTabla(_tabla tabla[], int sube, int baja); | |
int randomN(int max); | |
void menu(); | |
void juego(); | |
/** | |
* Funcion principal de inicio | |
* @return Integer | |
*/ | |
int main() | |
{ | |
int opcion; | |
do { | |
initScreen(); | |
printf("\n Opcion: "); | |
scanf("%d", &opcion); | |
switch(opcion) { | |
case 1: | |
juego(); | |
break; | |
case 2: | |
instrucciones(); | |
break; | |
case 9: | |
break; | |
default: | |
printf("Esa no es una opcion valida\n"); | |
system("pause"); | |
break; | |
} | |
} while(opcion != 9); | |
return 0; | |
} | |
/** | |
* Logica general del menu del juego | |
* @return NULL | |
*/ | |
void juego() | |
{ | |
srand(time(NULL)); | |
int i, t, x, dia = 0, maximo, decision, flag, mng = 0; | |
_equipo team[MAX_T]; | |
_tabla posiciones[MAX_T]; | |
team[0] = crearEquipo(1); | |
for(i = 1; i < MAX_T; i++) | |
team[i] = crearEquipo(0); | |
for(i = 0; i < MAX_T; i++) { | |
posiciones[i].teamId = (MAX_T - 1) - i; | |
posiciones[i].pts = 0; | |
posiciones[i].golesF = 0; | |
posiciones[i].golesC = 0; | |
} | |
printf("Cuantos dias quiere que dure la temporada? "); | |
scanf("%d", &maximo); | |
int cronograma[MAX_T][maximo]; | |
for(i = 0; i < MAX_T; i++) { | |
for(x = 0; x < maximo; x++) { | |
do { | |
t = randomN(MAX_T); | |
} while(t == i); | |
cronograma[i][x] = t; | |
} | |
} | |
do { | |
int opcion; | |
system("cls"); | |
//Mostrar 'imagen' de campo con las opciones a tomar | |
campoScreen(dia+1, team[mng].nombre, team[mng].jugador); | |
printf("Decision: "); | |
scanf("%d", &decision); | |
//Si se decide 'Entrenar' | |
if(decision == 1 && flag != 1) { | |
system("cls"); | |
printf("Seleccione el numero del jugador a entrenar (9 para cancelar):\n"); | |
for(i = 0; i < 6; i++) | |
printf("%d. %-7s\n", i+1, team[mng].jugador[i].nombre); | |
printf("Decision: "); | |
scanf("%d", &opcion); | |
if(opcion != 9) { | |
int plus; | |
flag = 1; | |
plus = randomN(2); | |
printf("Ataque: %s %d+%d puntos\n", team[mng].jugador[opcion-1].nombre, team[mng].jugador[opcion-1].atk, plus); | |
team[mng].jugador[opcion-1].atk += plus; | |
plus = randomN(2); | |
printf("Defensa: %s %d+%d puntos\n", team[mng].jugador[opcion-1].nombre, team[mng].jugador[opcion-1].def, plus); | |
team[mng].jugador[opcion-1].def += plus; | |
} | |
} else if(decision == 1) { | |
printf("Ya entrenaste a un jugador esta jornada\n"); | |
} | |
//Si se decide 'Ver la lista de jugadores' | |
if(decision == 2) { | |
printf("\n\tJugadores en la plantilla\n\n"); | |
printf("| Nombre | atk | def |\n"); | |
for(i = 0; i < MAX_J; i++) { | |
tablaJug(team[mng].jugador[i]); | |
} | |
} | |
//Si se decide 'Mover' | |
if(decision == 3) { | |
system("cls"); | |
int movimiento; | |
_jugador transicion; | |
printf("Seleccione el numero del jugador a mover\n"); | |
for(i = 0; i < MAX_J; i++) | |
printf("%d. %s\n", i, team[mng].jugador[i].nombre); | |
scanf("%d", &opcion); | |
transicion = team[mng].jugador[opcion]; | |
printf("Seleccione al jugador con el que intercambiara posicion %s\n", transicion.nombre); | |
for(i = 0; i < 6; i++) | |
printf("%d. %s\n", i, team[mng].jugador[i].nombre); | |
scanf("%d", &movimiento); | |
team[mng].jugador[opcion] = team[mng].jugador[movimiento]; | |
team[mng].jugador[movimiento] = transicion; | |
printf("Jugador movido!\n"); | |
} | |
//SI decide 'ver al prox equipo a enfrentar' | |
if(decision == 4) { | |
system("cls"); | |
printf("\n\tEquipo a enfrentar: %-12s\n", team[cronograma[mng][dia]].nombre); | |
printf("Plantilla:\n"); | |
printf("| Nombre | atk | def |\n"); | |
for(i = 0; i < MAX_J; i++) { | |
tablaJug(team[cronograma[mng][dia]].jugador[i]); | |
} | |
} | |
//Si se decide 'Terminar' | |
if(decision == 9) { | |
flag = 0; | |
system("cls"); | |
printf("Resumen de jornada:\n\n"); | |
golJornada(posiciones, team, dia, maximo, cronograma); | |
dia++; | |
} | |
system("pause"); | |
} while(dia < maximo); | |
for(i = 0; i < MAX_T; i++) { | |
if(posiciones[i].teamId == mng) { | |
char *mensaje = i == 0 ? "Felicidades haz ganado la temporada" : "Es una lastima que no hayas obtenido el primer puesto"; | |
finDeTemp(mensaje, i+1); | |
break; | |
} | |
} | |
} | |
/** | |
* Obtiene un numero al azar en el rango 0 - maz | |
* @params int | |
* @returns int | |
*/ | |
int randomN(int max) | |
{ | |
int r = rand() % max; | |
return r; | |
} | |
/** | |
* Actualiza la tabla al final de la jornada | |
* @params _tabla, _equipo, int, int | |
* @return NULL | |
*/ | |
void golJornada(_tabla tabla[], _equipo equipos[], int dia, int maximo, int cronograma[][maximo]) | |
{ | |
int i, x, goles[MAX_T][2]; | |
for(i = 0; i < MAX_T; i++) { | |
goles[i][0] = golEquipo(equipos[i], equipos[cronograma[i][dia]]); | |
goles[i][1] = golEquipo(equipos[cronograma[i][dia]], equipos[i]); | |
for(x = 0; x < MAX_T; x++) { | |
if(tabla[x].teamId == i) | |
actualizarTabla(&tabla[x], goles[i]); | |
} | |
} | |
for(i = MAX_T - 1; i >= 1; i--) { | |
if(tabla[i].pts > tabla[i-1].pts) { | |
moverTabla(tabla, i, i-1); | |
} else if(tabla[i].pts == tabla[i-1].pts) { | |
if(tabla[i].golesF > tabla[i-1].golesF) { | |
moverTabla(tabla, i, i-1); | |
} else if(tabla[i].golesF == tabla[i-1].golesF && tabla[i].golesC < tabla[i-1].golesC) { | |
moverTabla(tabla, i, i-1); | |
} | |
} | |
} | |
tablaPos(goles[0], equipos[0].nombre, equipos[cronograma[i][dia]].nombre, tabla, equipos); | |
} | |
void moverTabla(_tabla tabla[], int sube, int baja) | |
{ | |
_tabla transicion; | |
transicion = tabla[sube]; | |
tabla[sube] = tabla[baja]; | |
tabla[baja] = transicion; | |
} | |
/** | |
* Define cuantos goles obtene cada equipo en funcion de su defensa y ataque | |
* @params {_equipo} t1, {_equipo} t2 | |
* @return Integer | |
*/ | |
int golEquipo(const _equipo t1, const _equipo t2) | |
{ | |
int x, goles = 0; | |
for(x = 0; x < MAX_J; x++) { | |
if(t1.jugador[x].atk > t2.jugador[x].def) { | |
goles++; | |
} | |
} | |
return goles; | |
} | |
/** | |
* Actualiza las posiciones de los jugadores en la tabla | |
* @params _tabla | |
* @returns NULL | |
*/ | |
void actualizarTabla(_tabla* tabla, int goles[]) | |
{ | |
tabla->golesF += goles[0]; | |
tabla->golesC += goles[1]; | |
tabla->pts += goles[0] > goles[1] ? 3 : goles[0] < goles[1] ? 1 : 0; | |
} | |
/** | |
* Crea un equipo basado en el input del usuario | |
* @params int | |
* @returns _equipo | |
*/ | |
_equipo crearEquipo(int preguntar) | |
{ | |
_equipo equipo; | |
int x; | |
if(preguntar) { | |
printf("Ingrese el nombre del equipo: "); | |
scanf("%s", equipo.nombre); | |
printf("Llenando equipo\n"); | |
for(x = 0; x < MAX_J; x++) { | |
equipo.jugador[x] = crearJugador(); | |
} | |
printf("Listo!\n"); | |
} else { | |
char *nombre = getNombre("equipos.txt.txt"); | |
strcpy(equipo.nombre, nombre); | |
for(x = 0; x < MAX_J; x++) { | |
equipo.jugador[x] = crearJugador(); | |
} | |
} | |
return equipo; | |
} | |
/** | |
* Crea a un jugador, asignandoles valores y nombre aleatorio | |
* @returns _jugador | |
*/ | |
_jugador crearJugador() | |
{ | |
_jugador jugador; | |
char *nombre = getNombre("jugadores.txt.txt"); | |
strcpy(jugador.nombre, nombre); | |
jugador.atk = randomN(10); | |
jugador.def = randomN(10); | |
return jugador; | |
} | |
/** | |
* Obtiene un nombre desde el archivo de texto seleccionado | |
* @params char | |
* @returns char | |
*/ | |
char *getNombre(char *fileNombre) | |
{ | |
char archivo[50000]; | |
int n, c, indexN; | |
FILE *file; | |
file = fopen(fileNombre, "r"); | |
if(file == NULL) { | |
printf("No se pudo localizar el archivo de nombres\n"); | |
} | |
//Leyendo el archivo completo | |
n = fread(archivo, 1, 50000, file); | |
archivo[n] = '\0'; | |
//Separando las palabras por los | | |
char *t = strtok(archivo, "|"); | |
char *nombres[200] = {0}; | |
int f = 0; | |
while(t != NULL) { | |
nombres[f] = malloc(strlen(t)+1); | |
strcpy(nombres[f], t); | |
t = strtok(NULL, "|"); | |
f++; | |
} | |
fclose(file); | |
indexN = randomN(f); | |
//Borrando de la memoria nombres innecesarios | |
for(c = 0; c < 200; c++) { | |
if(c != indexN) | |
free(nombres[c]); | |
} | |
return nombres[indexN]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct _jugador { | |
char nombre[100]; | |
int atk; | |
int def; | |
} _jugador; | |
typedef struct _equipo { | |
char nombre[100]; | |
_jugador jugador[6]; | |
} _equipo; | |
typedef struct _tabla { | |
int teamId; | |
int golesF; | |
int golesC; | |
int pts; | |
} _tabla; | |
void initScreen() | |
{ | |
printf("\n _______ ___ \n"); | |
printf("| || |\n"); | |
printf("| ___|| |\n"); | |
printf("| |___ | |\n"); | |
printf("| ___|| |___\n"); | |
printf("| |___ | |\n"); | |
printf("|_______||_______|\n"); | |
printf(" __ __ _______ __ _ _______ _______ _______ ______ \n"); | |
printf(" | |_| || _ || | | || _ || || || _ |\n"); | |
printf(" | || |_| || |_| || |_| || ___|| ___|| | ||\n"); | |
printf(" | || || || || | __ | |___ | |_||_ \n"); | |
printf(" | || || _ || || || || ___|| __ |\n"); | |
printf(" | ||_|| || _ || | | || _ || |_| || |___ | | | |\n"); | |
printf(" |_| |_||__| |__||_| |__||__| |__||_______||_______||___| |_|\n"); | |
printf("\n\n"); | |
printf("\t\t 1. Iniciar Juego\n"); | |
printf("\t\t 2. Instrucciones\n"); | |
printf("\t\t 9. Salir\n"); | |
} | |
void instrucciones() | |
{ | |
system("cls"); | |
printf("\t\t -- Bienvenido a EL MANAGER --\n\n"); | |
printf("Instrucciones de juego:\n"); | |
printf("Lo primero al iniciar sera escribir el nombre de tu equipo, luego podras seleccionar cuantos dias deseas que dure la temporada\n"); | |
printf("Una vez en el menu de juego podras:\n"); | |
printf("\t 1. Entrenar a tus jugadores (Solo puedes entrenar a 1 jugador por jornada, asi que selecciona bien)\n"); | |
printf("\t 2. Mover a tus jugadores (Esto tiene gran inpacto en la forma en la que se calculan los partidos, ya se explicara luego)\n"); | |
printf("\t 3. Ver tu lista de jugadores, asi como sus estadisticas\n"); | |
printf("\t 4. Ver la lista de jugadores de tu proximo rival\n\n"); | |
printf("\t En la cancha:\n"); | |
printf("\t Dado tu estado de manager no jugaras los partidos, lo unico que te interesa a final de jornada es como resulto todo"); | |
printf(" por eso los calculos del partido son simples. tus jugadores se enfrentan 1 vs 1 con los jugadores del equipo rival en"); | |
printf(" el mismo orden en el que se encuentran en tu tabla (por eso la importancia de moverlos y entrenarlos), el jugador con"); | |
printf(" cuyo ataque sea mayor a la defensa del contrario otorgara un gol a su equipo es asi de facil!\n"); | |
printf("Finalmente para ganar la temporada, deberas acabar de nr 1 en la tabla de posiciones mostrada al final de cada dia. recuerda"); | |
printf(" que tu equipo no es el unico jugando, y los otros equipos haran los posible por ganar sus partidos y sumar puntos para la tabla.\n\n"); | |
system("pause"); | |
} | |
void campoScreen(int dia, char *equipo, _jugador jugador[]) | |
{ | |
printf("\t\t DIA %0d \n", dia); | |
printf(" _______________________________________________ \n"); | |
printf(" | %-12s | |______| | \n", equipo); | |
printf(" | %15s | | \n", " "); | |
printf(" | 01 %-12s | | Opciones \n", jugador[0].nombre); | |
printf(" | 02 %-12s | 09 | \n", jugador[1].nombre); | |
printf(" | 03 %-12s | | 1. Entrenar \n", jugador[2].nombre); | |
printf(" | 11 %-12s | 03 02 | 2. Ver jugadores \n", jugador[3].nombre); | |
printf(" | 15 %-12s | | 3. Mover \n", jugador[4].nombre); | |
printf(" | 09 %-12s | 15 11 | 4. Ver prox. \n", jugador[5].nombre); | |
printf(" | %15s | | 9. Terminar \n", " "); | |
printf(" | %15s | ______ | \n", " "); | |
printf(" | %15s | | 01 | | \n", " "); | |
printf(" |------------------------------------------------\n"); | |
} | |
void tablaPos(int golE[], char *e, char *c, _tabla tabla[], _equipo equipos[]) | |
{ | |
int i; | |
printf(" %-12s - %0d | %0d - %-12s \n\n", e, golE[0], golE[1], c); | |
printf(" TABLA DE POSICIONES \n"); | |
printf(" _________________________________________\n"); | |
printf("|pos| Nombre | pts | goles | contra |\n"); | |
for(i = 0; i < 6; i++) { | |
printf("|%03d| %-12s | %03d | %03d | %03d |\n", i+1, equipos[tabla[i].teamId].nombre, tabla[i].pts, tabla[i].golesF, tabla[i].golesC); | |
} | |
} | |
void tablaJug(_jugador jugador) | |
{ | |
printf("| %-12s | %03d | %03d |\n", jugador.nombre, jugador.atk, jugador.def); | |
} | |
void finDeTemp(char *m, int pos) | |
{ | |
system("cls"); | |
printf("\t\t ____________________\n"); | |
printf("\t\t| FIN DE TEMPORADA |\n"); | |
printf("\t\t --------------------\n\n"); | |
printf("\t %s\n", m); | |
printf("\t\t Posicion final: %d\n", pos); | |
system("pause"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment