Пример #1
0
//Fonction qui fait le combat entre 2 pokemons, renvoie si le joueur à gagner (1) ou non (0)
int combat (Pokemon pok1, Pokemon pok2, int diff)
{
  Attaque attselect;
  Attaque attAI;
  int dommage;
  //Affiche les deux pokemons selon l'affichage qui leur correspond (1 pour le joueur, 0 l'adversaire)
  get_Pokemon(0, pok2);
  get_Pokemon(1, pok1);
  //Demande au joueur de choisir une attaque
  attselect = choix_attaque(pok1);
  //Netoie l'écran
  nettoie();
  //Calcule et inflige les dommages au pokemon adverse
  dommage = hit(attselect, pok1, pok2);
  pok2.HP = pok2.HP - dommage;
  //Si le pokemon adverse est en vie, sinon nettoie l'écran et fini le combat
  if (en_vie(pok2))
    {
      //Choisi une attaque selon l'AI et inflige les dommages
      if (diff == 1) attAI = att_AI_min(pok2, pok1);
      if (diff == 2) attAI = att_AI_rand(pok2);
      if (diff == 3) attAI = att_AI_max(pok2, pok1);
      dommage = hit(attAI, pok2, pok1);
      pok1.HP = pok1.HP - dommage;
      //Si le pokemon du joueur est en vie, on recommence toute la séquence, sinon on affiche le message de défaite
      if (en_vie(pok1)) return(combat(pok1, pok2, diff));
      nettoie();
      printf("Dommage ! Vous avez perdu le combat contre %s.\n\n", pok2.Nom);
      return(0);
    }
  nettoie();
  printf("Bravo ! Vous avez gagne le combat contre %s.\n\n", pok2.Nom);
  return(1);
}
Пример #2
0
//Fonction qui demande l'attaque à effectuer au joueur, et renvoie l'attaque
Attaque choix_attaque (Pokemon pok)
{
  int attselect;
  char nombre[1];
  printf("Selectionner une attaque entre 1 et 4.\n");
  scanf("%s", nombre);
  attselect = atoi(nombre);
  //Teste si l'input est bien entre 1 et 4
  if (attselect < 1 || attselect > 4)
    {
      printf("Veuillez selectionner une attaque entre 1 et 4, votre entree est invalide.\n\n");
      return(choix_attaque(pok));
    }
  return(pok.Attaques[attselect - 1]);
 }
Пример #3
0
int ordiAttaque(Context* C, navire* nav, int** tab) {
    int i = 0;
    int j = 0;
    int k = 0;
    int l = 0;
    int m = 0;
    int x = 0;
    int y = 0;
    int o = 0;
    int xg = 0; 
    int yg = 0;
    int attacked = 0;
    
    /*D'abord on analyse le tableau de la grille*/
    for(i = 0; i < 10; i++) {
	for(j = 0; j < 10; j++) {
	    if(tab[j][i] == 1) {
		/*On en déduit une case à attaquer (si possible)*/
		if(choix_attaque(j, i, tab, &x, &y)) {
		    attacked = 1;
		    break;
		}
	    }
	}
	if(attacked) break;
    }
    if(attacked) {
	/*On a attaqué donc on regarde si un navire a été touché*/
	for(l = 0; l < NB_BOATS; l++) {
	    for(k = nav[l].x[0]; k <= nav[l].x[1]; k++) {
		for(m = nav[l].y[0]; m <= nav[l].y[1]; m++) {
		    if(k == x && m == y) {
			/*On a touché un navire...*/
			if(!nav[l].r)
			    nav[l].etat[x-nav[l].x[0]] = 1;
			else
			    nav[l].etat[y-nav[l].y[0]] = 1;
			tab[y-1][x-1] = 1;
			/*On calcule les coordonnees*/
			xg = OFFSET_L+(CELL_W*(x-1))+(x-1);
			yg = OFFSET_T+(CELL_W*(y-1))+(y-1);
			
			for(o = 0; o < 34; o++) {
			    if(C->cTouche[o].x == -1 && C->cTouche[o].y == -1) {
				C->cTouche[o].x = xg;
				C->cTouche[o].y = yg;
				break;
			    }
			}
			return 1;
		    }
		}
	    }
	}

	/*Pas touché ?*/
	tab[y-1][x-1] = 2;
	/*On calcule les coordonnees*/
	xg = OFFSET_L+(CELL_W*(x-1))+(x-1);
	yg = OFFSET_T+(CELL_W*(y-1))+(y-1);
	
	for(o = 0; o < 166; o++) {
	    if(C->cRate[o].x == -1 && C->cRate[o].y == -1) {
		C->cRate[o].x = xg;
		C->cRate[o].y = yg;
		break;
	    }
	}
    }

    /*Si l'on a pas attaqué jusqu'à ici c'est parce qu'il n'y a pas encore eu d'attaque depuis le début ou qu'il n'y a
    plus de possibilité d'attaque sur un navire déjà touché...*/
    else if(!attacked) {
	do {
	    x = rand() % 10;
	    y = rand() % 10;
	} while(tab[y][x] == 2 || tab[y][x] == 1);
	
	/*On regarde si un navire a été touché...*/
	for(l = 0; l < NB_BOATS; l++) {
	    for(k = nav[l].x[0]; k <= nav[l].x[1]; k++) {
		for(m = nav[l].y[0]; m <= nav[l].y[1]; m++) {
		    if((k-1) == x && (m-1) == y) {
			/*On a touché un navire...*/
			tab[y][x] = 1;
			if(!nav[l].r)
			    nav[l].etat[x+1-nav[l].x[0]] = 1;
			else
			    nav[l].etat[y+1-nav[l].y[0]] = 1;
			/*On calcule les coordonnees*/
			xg = OFFSET_L+(CELL_W*x)+x;
			yg = OFFSET_T+(CELL_W*y)+y;
			
			for(o = 0; o < 34; o++) {
			    if(C->cTouche[o].x == -1 && C->cTouche[o].y == -1) {
				C->cTouche[o].x = xg;
				C->cTouche[o].y = yg;
				break;
			    }
			}
			return 1;
		    }
		}
	    }
	}

	tab[y][x] = 2;
	/*On calcule les coordonnees*/
	xg = OFFSET_L+(CELL_W*x)+x;
	yg = OFFSET_T+(CELL_W*y)+y;
				
	for(o = 0; o < 166; o++) {
	    if(C->cRate[o].x == -1 && C->cRate[o].y == -1) {
		C->cRate[o].x = xg;
		C->cRate[o].y = yg;
		break;
	    }
	}
    }
    return 0;
}