static void dopop(poffHandle_t poffHandle, poffProgHandle_t poffProgHandle) { int opcode; int arg16; int arg16a; int arg16b; /* We have found PUSHS. No search for the next occurrence * of either and instruction that increments the string * stack or for the matching POPS */ /* Skip over the PUSHS for now */ inch = poffGetProgByte(poffHandle); while (inch != EOF) { /* Did we encounter another PUSHS? */ if (inch == oPUSHS) { /* Yes... recurse to handle it */ current_level++; dopop(poffHandle, poffProgHandle); current_level--; } else if (inch == oPOPS) { /* Flush the buffered data without the PUSHS */ flushbuf(poffProgHandle); /* And discard the matching POPS */ inch = poffGetProgByte(poffHandle); break; } else if (inch == oLIB) { /* Get the 16-bit argument */ putbuf(inch, poffProgHandle); arg16a = poffGetProgByte(poffHandle); putbuf(arg16a, poffProgHandle); arg16b = poffGetProgByte(poffHandle); putbuf(arg16b, poffProgHandle); arg16 = (arg16a << 8) | arg16b; inch = poffGetProgByte(poffHandle); /* Is it LIB MKSTK? MKSTKSTR? or MKSTKC? */ if ((arg16 == lbMKSTK) || (arg16 == lbMKSTKSTR) || (arg16 == lbMKSTKC)) { /* Flush the buffered data with the PUSHS */ flushc(oPUSHS, poffProgHandle); flushbuf(poffProgHandle); /* And break out of the loop to search for * the next PUSHS */ break; } } else { /* Something else. Put it in the buffer */ putbuf(inch, poffProgHandle); /* Get the next byte from the input stream */ opcode = inch; inch = poffGetProgByte(poffHandle); /* Check for an 8-bit argument */ if ((opcode & o8) != 0) { /* Buffer the 8-bit argument */ putbuf(inch, poffProgHandle); inch = poffGetProgByte(poffHandle); } /* Check for a 16-bit argument */ if ((opcode & o16) != 0) { /* Buffer the 16-bit argument */ putbuf(inch, poffProgHandle); inch = poffGetProgByte(poffHandle); putbuf(inch, poffProgHandle); inch = poffGetProgByte(poffHandle); } } } }
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; }
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 nbTry = 0; int jGagne = -1; // Le numéro du joueur qui a gagné la partie int jPerdu; int nbLettre; char* word[NB_PLAYER]; char* hiddenWord[NB_PLAYER]; char* choice; // Le mot que le joueur a essayer if(argc >= 1){ pipeW = atoi(argv[0]); } else{ perror("Erreur, arguments incorrects.\n"); exit(EXIT_FAILURE); } for(i=0; i < NB_PLAYER; i++){ systemc(&outPl[J1], "clear"); systemc(&outPl[J2], "clear"); outc(&outPl[J1], "%s", "======= Jeu du pendu =======\n\n"); outc(&outPl[J1], "%s", "Entrez un mot(10 carct max): "); inc(&outPl[J1], "%s"); outc(&outPl[J2], "%s", "======= Jeu du pendu =======\n\n"); outc(&outPl[J2], "%s", "Attendez que l'autre joueur choisisse un mot...\n"); flushc(pipeW, outPl, NB_PLAYER); word[J1] = (char*)getResp(&listResp, STRING); upperWord(word[J1]); hiddenWord[J1] = initHiddenWord(word[J1]); //printf("Les mot choisi est : %s\n", word[J1]); reversePlayer(&J1, &J2); fflush(stdout); } systemc(&outPl[J2], "clear"); outc(&outPl[J2], "%s", "======= Jeu du pendu =======\n\n"); while(jGagne == -1){ for(i=0; i < NB_PLAYER && jGagne == -1; i++){ systemc(&outPl[J1], "clear"); outc(&outPl[J1], "%s", "======= Jeu du pendu =======\n\n"); outc(&outPl[J1], "%s %d %s", "Nombre d'essais : ", nbTry, "\n"); outc(&outPl[J1], "%s %s %s", "Le mot a trouver : ", hiddenWord[J2], "\n"); outc(&outPl[J1], "%s", "C'est a vous, entrez une lettre ou un mot : "); inc(&outPl[J1], "%s"); outc(&outPl[J2], "%s", "\nC'est a votre adversaire de jouer...\n"); flushc(pipeW, outPl, NB_PLAYER); choice = (char*)getResp(&listResp, STRING); if(strlen(choice) > 1){ upperWord(choice); if(strcmp(word[J2], choice) == 0){ outc(&outPl[J1], "%s", "Votre mot est le bon.\n"); jGagne = J1; } else{ outc(&outPl[J1], "%s", "Votre mot ne correspond pas.\n"); } } else{ // Si le joueur a entré un seul caractère nbLettre = searchInHidden(hiddenWord[J2], word[J2], choice[0]); if(nbLettre == 0){ outc(&outPl[J1], "%s", "Cette lettre n'est pas presente dans le mot.\n"); } else{ outc(&outPl[J1], "%s %d %s", "Cette lettre a ete trouve ", nbLettre, " fois dans le mot.\n"); } if(strcmp(word[J2], hiddenWord[J2]) == 0){ jGagne = J1; } } free(choice); reversePlayer(&J1, &J2); } nbTry++; } //printf("Pendu : Le joueur %d a gagne.\n", jGagne+1); jPerdu = nextPlayer(jGagne); systemc(&outPl[J1], "clear"); systemc(&outPl[J2], "clear"); outc(&outPl[jGagne], "%s", "======= Jeu du pendu =======\n\n"); outc(&outPl[jGagne], "%s %s %s", "Le mot etait bien : ", word[jPerdu], "\n"); outc(&outPl[jGagne], "%s %d %s", "Vous avez gagne en ", nbTry, " essais, felicitation !!\n"); outc(&outPl[jPerdu], "%s", "======= Jeu du pendu =======\n\n"); outc(&outPl[jPerdu], "%s", "Vous avez perdu, votre adversaire a ete plus rapide..\n"); outc(&outPl[jPerdu], "%s %s %s", "Le mot etait : ", word[jGagne],"\n"); flushc(pipeW, outPl, NB_PLAYER); for(i=0; i < NB_PLAYER; i++){ free(hiddenWord[i]); free(word[i]); } // On attend un peut avant de quitter waitc(&outPl[J1], 2); waitc(&outPl[J2], 2); 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; }