Ciao a tutti, ho un problemino con un gioco stupidissimo che ho pensato. In pratica ci sono due player che in modalità 1vs1 si attaccano a vicenda, il problema è che man mano che aumentano i turni, la vita dei player non scende come dovrebbe, ma sembra ci siano "sessioni" diverse ogni due turni. Mi aiutereste?
codice:#include <stdio.h> typedef struct pl{ int vita; int danno; int frecce; }Player; void attacca(Player * firstPlayer, Player * secondPlayer); int main(){ int dec; do{ printf("Scegli modalita': \n\n 1) - 1vs1 \n\n"); scanf("%d", &dec); printf("\n"); }while(dec < 0 || dec > 10); if(dec == 1){ int turno = -1; Player giocatore1; Player giocatore2; giocatore1.vita = 45; giocatore2.vita = 60; giocatore1.danno = 5; giocatore2.danno = 2; giocatore1.frecce = 34; giocatore2.frecce = 40; while(giocatore1.vita > 0 && giocatore2.vita > 0){ turno+=1; if (turno%2 == 0){ printf("Turno %d giocatore 1, INVIO per attacco\n\n", turno); attacca(&giocatore1, &giocatore2); getch();} else{ printf("Turno %d giocatore 2, INVIO per attacco\n\n", turno); attacca(&giocatore2, &giocatore1); getch();} } } } void attacca(Player * firstPlayer, Player * secondPlayer){ firstPlayer->frecce -=1; secondPlayer->vita = secondPlayer->vita - firstPlayer->danno; printf("vita P1: %d, frecce P1: %d\n", firstPlayer->vita,firstPlayer->frecce); printf("vita P2: %d, frecce P2: %d\n\n", secondPlayer->vita,secondPlayer->frecce); }

Rispondi quotando
, ti dico la mia opignone.
