示例#1
0
void test_fichier(jeu_s * j,sauvegarde *s){
    *j = (jeu_s)malloc(sizeof(t_jeu));

    init_plateau(&((*j)->p));
    init_partie(&((*j)->g));

    init_tigres(*j);
    init_sauvegarde(s);

    (*j)->participant = (joueur)malloc(sizeof(t_joueur)*2);

    (*j)->participant[CHEVRE].score = 0;
    (*j)->participant[TIGRE].score = 10;

    (*j)->p->grille[0][0].pion = TIGRE;

    (*j)->p->grille[1][1].pion = CHEVRE;
    (*j)->p->grille[2][2].pion = CHEVRE;

    (*j)->p->grille[0][1].pion = CHEVRE;
    (*j)->p->grille[0][2].pion = CHEVRE;

    (*j)->p->grille[1][0].pion = CHEVRE;
    (*j)->p->grille[2][0].pion = CHEVRE;

    maj_score(*j);

    sauvegarde_fichier(*j,*s);

    printf("Sauvegarde effectuee !\n");

    printf("Reset du jeu\n");

    free(*j);

    *j = (jeu_s)malloc(sizeof(t_jeu));

    init_sauvegarde(*s);
    init_plateau(&((*j)->p));

    (*j)->participant = (joueur)malloc(sizeof(t_joueur)*2);

    if( chargement_fichier(*j,*s) == -1 ){
        printf("Erreur pendant le chargement, il se peut que la sauvegarde soit corrompu!\n");
        return;
    }else
        printf("Chargement effectuee !\n");

    printf("Affichage de la case 0 0 :\n");
    printf("%d\n",(*j)->p->grille[0][0]);

    printf("Affichage de la case 1 1 :\n");
    printf("%d\n",(*j)->p->grille[1][1]);

    printf("Affichage du score de tigre:\n");
    printf("%d\n",(*j)->participant[TIGRE].score);
}
示例#2
0
文件: jeu.c 项目: hahahafr/ziege
void init_jeu(jeu_s * j){
    *j = (jeu_s)malloc(sizeof(t_jeu));

    init_plateau(&((*j)->p));
    init_partie(&((*j)->g));
    init_tigres(*j);
    init_chevres(*j);

    init_sauvegarde(&((*j)->s));

}
示例#3
0
void test_historique(jeu_s *j,sauvegarde * s){

    *j = (jeu_s)malloc(sizeof(t_jeu));

    init_plateau(&((*j)->p));
    init_partie(&((*j)->g));

    init_tigres(*j);
    init_sauvegarde(*s);

    (*j)->participant = (joueur)malloc(sizeof(t_joueur)*2);

    (*j)->participant[CHEVRE].score = 0;
    (*j)->participant[TIGRE].score = 10;

    (*j)->p->grille[0][0].pion = TIGRE;

    (*j)->p->grille[1][1].pion = CHEVRE;
    (*j)->p->grille[2][2].pion = CHEVRE;

    (*j)->p->grille[0][1].pion = CHEVRE;
    (*j)->p->grille[0][2].pion = CHEVRE;

    (*j)->p->grille[1][0].pion = CHEVRE;
    (*j)->p->grille[2][0].pion = CHEVRE;

    maj_score(*j);

    ajout_historique(*j,*s);

    printf("Destruction du jeu (par un free sur le pointeur du jeu)\n");

    free(*j);

    *j = revenir_arriere(*j,*s);

    printf("case 0 0 : %d\n",(*j)->p->grille[0][0].pion);
    printf("case 1 1 : %d\n",(*j)->p->grille[1][1].pion);

    printf("score des tigres : %d\n",(*j)->participant[TIGRE].score);

}
示例#4
0
int main(int argc, char** argv){
	char* outPl[NB_PLAYER] = {NULL, NULL}; // Les sorties pour chaque joueur
	linkedlist_t listResp = NULL;
	int pipeW;
	int J1 = 0;
	int J2 = 1;
	int i;
	int jGagne = -1;
	int jPerdu;
	int plein = 0;
	int choix;
	char caract[NB_PLAYER];
	caract[0] = 'X';
	caract[1] = 'O';
	
	char plateau[HAUTEUR][LARGEUR];
	
	if(argc >= 1){
		pipeW = atoi(argv[0]);
	}
	else{
		perror("Erreur, arguments incorrects.\n");
		exit(EXIT_FAILURE);
	}
	
	init_plateau(plateau);


	
	
	while(jGagne == -1 && !plein){
		for(i=0; i < NB_PLAYER; i++){
			systemc(&outPl[J1], "clear");
			outc(&outPl[J1], "%s", "======= Morpion =======\n\n");
			dessinerPlateau(&outPl[J1], plateau);
			outc(&outPl[J1], "%s", "Entrez un numero de case (1, 2, ...) : ");
			inc(&outPl[J1], "%d");
			
			systemc(&outPl[J2], "clear");
			outc(&outPl[J2], "%s", "======= Morpion =======\n\n");
			dessinerPlateau(&outPl[J2], plateau);
			outc(&outPl[J2], "%s", "C'est a votre adversaire de jouer.\n");
			
			flushc(pipeW, outPl, NB_PLAYER);
			choix = (int)getResp(&listResp, INT);
			if(jouer(plateau, choix, caract[J1])){
				if(gagner(plateau, caract[J1])){
					jGagne = J1;
					break;
				}
				if(estPlein(plateau)){
					plein = 1;
					break;
				}
			}
			reversePlayer(&J1, &J2);
		}
	}
	
	systemc(&outPl[J1], "clear");
	systemc(&outPl[J2], "clear");
	if(!plein && jGagne != -1){
		jPerdu = nextPlayer(jGagne);
		outc(&outPl[jGagne], "%s", "======= Morpion =======\n\n");
		outc(&outPl[jGagne], "%s", "Vous avez gagne, felicitation !!\n");
		
		outc(&outPl[jPerdu], "%s", "=======  Morpion =======\n\n");
		outc(&outPl[jPerdu], "%s", "Vous avez perdu, votre adversaire etait peut etre plus intelligent...\n");
	}
	else{
		outc(&outPl[J1], "%s", "=======  Morpion =======\n\n");
		outc(&outPl[J1], "%s", "Vous etes aussi fort (ou mauvais) que votre adversaire...\n");
		outc(&outPl[J2], "%s", "=======  Morpion =======\n\n");
		outc(&outPl[J2], "%s", "Vous etes aussi fort (ou mauvais) que votre adversaire...\n");
	}
	flushc(pipeW, outPl, NB_PLAYER);
	
	// On attend un peut avant de quitter
	waitc(&outPl[J1], 3);
	waitc(&outPl[J2], 3);
	quitc(&outPl[J1]); // Fermera le jeu pour le client
	quitc(&outPl[J2]);
	flushc(pipeW, outPl, NB_PLAYER);
	quit(pipeW);
	close(pipeW);
	close_out_players(outPl, NB_PLAYER);
	return EXIT_SUCCESS;
}
示例#5
0
文件: ihm.c 项目: naaf/Master
void gest_ihm(int signum, siginfo_t * info, void * vide) {
	SigMsg *sigMsg = (SigMsg*) info->si_value.sival_ptr;
	fprintf(stderr, "gest_ihm %d \n", sigMsg->val);

	attenteTraitement |= sigMsg->val;

	if ( PHASE_SESSION & sigMsg->val) {
		printf("pl %s \n", sigMsg->data);
		init_plateau(initPl);
		parse_plateau(sigMsg->data, initPl);
		cpyPlateau(initPl, pl);
		display_plateau(pl);
	}

	if ( PHASE_REFLEX & sigMsg->val) {

		printf("phase reflexion %s , %s\n", sigMsg->data, sigMsg->data2);

		parse_enigme(sigMsg->data, &initEnigme);
		parse_bilan(sigMsg->data2, &bilan);
		cpyEnigme(&initEnigme, &enigme);
		cpyPlateau(initPl, pl);
		bind_enigme_plateau(pl, &enigme);

		currentPhase = PHASE_REFLEX;

		onclickReset(pl, &enigme, coups, moves);
		display_bilan(&bilan);
		displayMsg("REFLEXION", TRUE);
		timeStart = SDL_GetTicks();
		free(sigMsg->data);
		free(sigMsg->data2);

	}
	if ( PHASE_ENCHERE & sigMsg->val) {
		currentPhase = PHASE_ENCHERE;
		displayMsg("ENCHERE", TRUE);
		timeStart = SDL_GetTicks();
	}
	if ( PHASE_RESO & sigMsg->val) {
		currentPhase = PHASE_RESO;
		displayMsg("SOLUTION", TRUE);
		timeStart = SDL_GetTicks();
	}

	if ( UPDATE_L & sigMsg->val) {
		if (sigMsg->data != NULL && sigMsg->u == NULL) {
			adduser(sigMsg->data, 0, &bilan.list_users);
			free(sigMsg->data);
		}
		if (sigMsg->data2 != NULL && sigMsg->u == NULL) {
			removeuser(sigMsg->data2, &bilan.list_users);
			free(sigMsg->data2);
		}
		display_bilan(&bilan);
	}
	if ( UPDATE_U & sigMsg->val) {
		if (sigMsg->data != NULL && sigMsg->data2 != NULL) {
			user_t *u = getuser(sigMsg->data, &bilan.list_users);
			if (u == NULL) {
				printf(stderr, "erreur user not exist %s", sigMsg->data);
			} else {
				u->nb_coups = atoi(sigMsg->data2);
			}
		}
		display_bilan(&bilan);
	}
	if ( SIGALEMENT & sigMsg->val) {
		displayMsg(msg_signal, FALSE);
	}
	free(sigMsg);
}