info

#include<stdio.h>
#include<stdlib.h>
#include<g2.h>
#include<g2_X11.h>
#include<math.h>
#include<time.h>
void grille(int d)
{
int i,j;
g2_pen(d,1);
g2_set_line_width(d,1);
for(i=50;i<=457;i=i+37)
{
g2_line(d,i,50,i,457);
}

for(j=50;j<=457;j=j+37)
{
g2_line(d,50,j,457,j);
}
}

int fenetre()
{int d,i;
char text[2];

d=g2_open_X11(500,750);
g2_pen(d,1);g2_rectangle(d,240,590,440,690);
g2_pen(d,1);g2_rectangle(d,40,590,240,690);
g2_set_font_size(d,30);
g2_string(d,100,550," <--Bataille Navale--> ");
g2_pen(d,15);
g2_filled_rectangle(d,50,50,457,457);
g2_pen(d,1);


for(i=1;i<=11;i++)
{
sprintf(text,"%d",i);
g2_string(d,63+37*(i-1),460,text);
sprintf(text,"%c",64+i);
g2_string(d,25,425-37*(i-1),text);
}


return d;
}


void Bateaux (int m[22][22])
{
srand((int)time(NULL));
int k,a,b,i,j,sens;



/*cmise à zero de la matrice*/
for(i=1;i<=11;i++)
{
for(j=1;j<=11;j++)
{
m[j]=0;
}
}


/*mise en place des Bateaux*/

/*bateau de 2*/

k=1;
do
{
a=rand();
sens=a=1+2*((1.0*a)/RAND_MAX);

if (sens==1) // horizontal
{
a=rand();
a=2+10*((1.0*a)/RAND_MAX);
b=rand();
b=2+11*((1.0*b)/RAND_MAX);
if((a!=11)&&(b!=12)&&(m[a]<100)&&(m[a+1]<100))
{
m[a]=102;
m[a+1]=102;
k++;
}
}

if (sens==2) // vertical
{
a=rand();
a=2+11*((1.0*a)/RAND_MAX);
b=rand();
b=2+10*((1.0*b)/RAND_MAX);
if((a!=12)&&(b!=11)&&(m[a]<100)&&(m[a][b+1]<100))
{
m[a]=102;
m[a][b+1]=102;
k++;
}
}

}
while(k<=1);

/*bateaux de 3*/

k=1;
do
{
a=rand();
sens=a=1+2*((1.0*a)/RAND_MAX);

if (sens==1) // horizontal
{
a=rand();
a=2+9*((1.0*a)/RAND_MAX);
b=rand();
b=2+11*((1.0*b)/RAND_MAX);
if((a!=11)&&(b!=12)&&(m[a]<100)&&(m[a+1]<100)&&(m[a+2]<100))
{
m[a]=103;
m[a+1]=103;
m[a+2]=103;
k++;
}
}

if (sens==2) // vertical
{
a=rand();
a=1+11*((1.0*a)/RAND_MAX);
b=rand();
b=2+9*((1.0*b)/RAND_MAX);
if((a!=12)&&(b!=11)&&(m[a]<100)&&(m[a][b+1]<100)&&(m[a][b+2]<100))
{
m[a]=103;
m[a][b+1]=103;
m[a][b+2]=103;
k++;
}
}
}
while(k<=2);

/*bateau de 4*/

k=1;
do
{
a=rand();
sens=a=1+2*((1.0*a)/RAND_MAX);

if (sens==1) // horizontal
{
a=rand();
a=1+8*((1.0*a)/RAND_MAX);
b=rand();
b=1+11*((1.0*b)/RAND_MAX);
if((a!=11)&&(b!=12)&&(m[a]<100)&&(m[a+1]<100)&&(m[a+2]<100)&&(m[a+3]<100))
{
m[a]=104;
m[a+1]=104;
m[a+2]=104;
m[a+3]=104;
k++;
}
}

if (sens==2) // vertical
{
a=rand();
a=1+11*((1.0*a)/RAND_MAX);
b=rand();
b=1+8*((1.0*b)/RAND_MAX);
if((a!=12)&&(b!=11)&&(m[a]<100)&&(m[a][b+1]<100)&&(m[a][b+2]<100)&&(m[a][b+3]<100))
{
m[a]=104;
m[a][b+1]=104;
m[a][b+2]=104;
m[a][b+3]=104;
k++;
}
}
}
while(k<=1);



/*remplacement des 0 par 99*/
for(a=1;a<=11;a++)
{
for(b=1;b<=11;b++)
{
if(m[a]==0)
m[a]=99;
}
}
}


void TirPC (int m[22][22])
{
srand((int)time(NULL));
int i,j,k;

k=1;
do
{
i=rand();
i=1+11*((1.0*i)/RAND_MAX);
j=rand();
j=1+11*((1.0*j)/RAND_MAX);
if((i!=12)&&(j!=12))
{
m[j]=-m[j];
k++;
}


}

while(k<=1);
}

void click(int d, int u, int v, int m[22][22])
{int i,j,a,b,new,old;
char text[2];
if (m[v]==100) //perdu
{
g2_pen(d,19);
g2_set_line_width(d,3);
printf("perdu !\n");
for(i=1;i<=20;i++)
{
for(j=1;j<=20;j++)
{
if(abs(m[j])==100)
{
g2_circle(d,(i-1)*20+50+10,(j-1)*20+50+10,5);
}
}
}


}

if((m[v]>0)&&(m[v]<=8))//voisin
{
g2_pen(d,0); g2_set_font_size(d,15);
sprintf(text,"%d",m[v]);
g2_string(d,(u-1)*20+50+8,(v-1)*20+50+2,text);
}

if(m[v]==99)
{
m[v]=10;
g2_pen(d,5);
g2_filled_rectangle(d,(u-1)*20+50,(v-1)*20+50,u*20+50,v*20+50);
new=1;
}

do
{old=new;
for(i=1;i<=20;i++)
{
for(j=1;j<=20;j++)
{
if(m[j]==10)
{
for(a=-1;a<=1;a++)
{
for(b=-1;b<=1;b++)
{
if(m[i+a][j+b]==99)
{
m[i+a][j+b]=10;
g2_filled_rectangle(d,(i+a-1)*20+50,(j+b-1)*20+50,(i+a)*20+50,(j+b)*20+50);
new++;
}
}
}
}
}
}
}while(new-old!=0);

}



int main()
{
int d,u,v,m[22][22],i,j,score,on;
char text [4];
double x,y;
unsigned int but;
score= 200;

d=fenetre();
grille(d);
Bateaux(m);
TirPC(m);


/* affichage champ de bataille */
printf("\n");
for(i=1;i<=11;i++)
{
for(j=1;j<=11;j++)
{
printf("%4d ",m[j]);
}
printf("\n");
};

for(;;)
{
g2_query_pointer(d,&x,&y,&but);
u=1+((x-50)/37);
v=1+((y-50)/37);
if((u>=1)&&(u<=11)&&(v>=1)&&(v<=11))
{
// printf("u=%d v=%d m= %d\n",u,v,m[v]);
// printf("x=%f y=%f but=%d u=%d v=%d\n",x,y,but,u,v);
if ((but!=16)&&(but!=0)&&(on==0))
{
on=1;
// printf("dans if u=%d v=%d \n",u,v,m[v]);
g2_pen(d,7);


// Eau
if(m[v]<100)
{
score-=10;


printf ("score=%d Raté ! \n ",score);
sprintf (text,"%d",score);
g2_pen(d,0); g2_filled_rectangle(d,250,600,430,680);
g2_pen(d,1);g2_string(d,310,650,text);

g2_pen(d,7);
g2_set_font_size(d,30);
g2_string(d,100,630,"raté !");
g2_circle(d,50+18+(u-1)*37,50+18+(v-1)*37,10);
}

// Touché
if(m[v]>100)
{
g2_pen(d,19);
score+=50;
printf ("score=%d Touché ! \n",score);
sprintf (text,"%d",score);
g2_pen(d,0); g2_filled_rectangle(d,250,600,430,680);
g2_pen(d,1);g2_string(d,310,650,text);
g2_pen(d,0); g2_filled_rectangle(d,50,600,230,680);
g2_pen(d,19);
g2_set_font_size(d,30);
g2_string(d,100,630,"touché !");

g2_circle(d,50+18+(u-1)*37,50+18+(v-1)*37,10);
}
if(score<=0)
{
printf("vous avez perdu !!!");
g2_pen(d,0); g2_filled_rectangle(d,50,600,230,680);
g2_pen(d,1);g2_rectangle(d,50,600,230,680);
g2_pen(d,5);
g2_set_font_size(d,30);
g2_string(d,100,630,"perdu !");
}


/*if(score> 10)
{

g2_pen(d,0);g2_filled_rectangle(d,250,600,430,680);

}*/






/*affichage matrice*/
/* printf("\n");
for(i=1;i<=11;i++)
{
for(j=1;j<=11;j++)
{
printf("%4d ",m[j]);
}
printf("\n");
}; */
}
if ((but==16)||(but==0)) on=0;

}
}


getchar();
return 10;
}

[ Ajouter un commentaire ] [ Aucun commentaire ]

# Posté le mercredi 10 juin 2009 06:22

Sunset

Sunset

# Posté le dimanche 28 septembre 2008 10:05

Marathon

Marathon
Rox

# Posté le samedi 19 juillet 2008 05:11

Soirée baba #6

Soirée baba #6
[/xSuperbe soirée avec vous les gars que de classe aucune pudeur :) ]
nous sommes pas des bitches pour rien

kissouilles
<3<3<3 :D

# Posté le lundi 14 juillet 2008 07:06

Modifié le lundi 14 juillet 2008 14:28

#3

#3

# Posté le lundi 30 juin 2008 10:35