From f290b8cd7e40ed8688175fba312697f7da96a34e Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 26 Oct 2014 18:15:21 +0000 Subject: game: Add a buildable version of the agme Signed-off-by: Olivier Gayot --- ia.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 ia.c (limited to 'ia.c') diff --git a/ia.c b/ia.c new file mode 100644 index 0000000..cfd0bce --- /dev/null +++ b/ia.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include "constantes.h" +#include "structures.h" +#include "prototypes.h" +#include + +void Factionennemi(int* Vtourennemi,SURFACES* surfaces,POSITIONS* positions, ENNEMIS ennemis[], PERSONNAGES persos[],int Vnbennemis,int*Vtour,int Vtourallie) +{ + int target,degats; + + target=Fchoosetargetallie(persos); + degats=Fgeneratedegats(persos, ennemis,*Vtourennemi,target); + persos[target].pv=persos[target].pv-degats; + do + { + if(*VtourennemiVpositionmort.x=positions->Vpositionpersos[target].x+surfaces->Tperso[target]->w/2-surfaces->Pmort->w/2; + positions->Vpositionmort.y=positions->Vpositionpersos[target].y+surfaces->Tperso[target]->h/2-surfaces->Pmort->h/2; + SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort); + } + Fafficherdegats(surfaces,positions,degats,ALLIE,target,persos); + SDL_Delay(1000); + SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); + if(*Vtour==ALLIE) + Fblitcoloredselection(surfaces,positions,Vtourallie,persos); + SDL_Flip(surfaces->Pecran); +} + +int Fchoosetargetallie(PERSONNAGES persos[]) +{ + int min=0,max=2,target; + + do + { + target=(rand()%(max-min+1)+min); + }while(persos[target].etat==MORT); + return target; +} + +int Fgeneratedegats(PERSONNAGES persos[],ENNEMIS ennemis[],int Vtourennemi,int target) +{ + int degats,taux,min,max; + + degats=ennemis[Vtourennemi].force*60-persos[target].defense*50; + taux=degats/4; + min=degats-taux; + max=degats+taux; + degats=(rand()%(max-min+1)+min); + if(degats<0) + degats=0; + + return degats; +} -- cgit v1.2.3