/******************************/
#include /************OffM@n************/
#include /******************************/
#include /**********1306050033**********/
#include /******************************/
#include
#include
#define BOYUT 16
int menu(char); //MEnuyu cizdirirken kullanılan func.
int giris(void); //Kullanicidan apsis ve ordinat alan fun.
void oyunBasi(void); //İlk olarak ekranaa oyunun seklini cizen func.(Bir kez kullaniliyor)
void cizim(void); //Gemileri yerlestiren func.
int oyunOynama(void); //Girilen degerlere karsı gelen deger varmı yok mu kontrol edip sekli yeniden cizen func.
void read(void); // Highskor dosyadan okuyan func.
void write(void); //HighSkor gecilirse dosyaya yazdiran func.
void ekran(void); //Eger kullanici gemileri nasıl yerlestirildini ornek gormek isterse kullanilan func.
void gemiVurma(void); //Bir gemi vurulunca cagirilan func.
double gercek[BOYUT][BOYUT],atis[BOYUT][BOYUT]; //Her func. iicden cagırabilmek icin global ve double olan diziler tanımladim.
int apsis ,ordinat,cikis=0 ,choice ,highScore, u ,k ,f ,m ,vurma[11]={0};
char ad[10] ,soyad[15];
int main()
{
srand(time(NULL));
printf("This game powered by Gokhan Abatay!\ne-mail:gokhanabatay@hotmail.com\n(My friends calling me like OffM@n)\n\n");
printf("Menuyu gormek icin bir tusa basiniz.\n>");
getch();
system("cls");
do{
menu(choice);
cikis=0; //Kullanici bir kere xx or XX bastiginda menuye donderdikden sonra cikisi sifilariz.
switch(choice)
{
case '1':
read();
oyunBasi();
cizim();
oyunOynama();
break;
case '2':
read();
printf("%15s%15s%15s\n\n","AD" ,"Soyad" ,"HighScore");
printf("%15s%15s%15d\n\n",ad ,soyad ,highScore);
printf("Press any key to continue...\n");
getch();
system("cls");
break;
case '3':
read();
oyunBasi();
printf("%29s%s%s%s%s%s%s%s%","***Amiral Batti***\n" ,
"The ships shall be randomly allocated in each game.\n"
"The positioning of ships shall be different in each game.\n",
"There shall be no overlapping squares among the ships.\n",
"Ships shall not be placed diagonally.\n"
"The game has eleven ships!Those are 4 Mayin tarama gemisi which\n",
"occupy 2 (neighbor) squares,4 Firkateyn which occupy 3 squares,\n",
"2 Kruvazor which occupy 4 squares,1 Ucak gemisi which occupies\n",
"5 squares.The game form is like that...\n");
printf("Press any key to continue...\n");
getch();
system("cls");
break;
case '4':
read();
cizim();
ekran();
printf("Press any key to continue...\n>");
getch();
system("cls");
break;
case '5':
read();
printf("%4s%11s%12s\n\n","AD" ,"Soyad" ,"HighScore");
printf("%4s%10s%10d\n\n",ad ,soyad ,highScore);
printf("Thanks a lot for playing the game!\n");
printf("Press any key to exit...\n>");
getch();
exit(0);
break;
default:
if((choice<'1')||(choice>'5')) //Kullanici menude sadece 1-5 arasinda bir sey girmeli.
{
printf("Your choice has to be between 1-5\n");
printf("Press any key to continue...\n\n>");
getch();
system("cls");
choice=0;
}
break;
} //Switch case bitis
}while(choice!='5');
return 0;
} //Main fonksiyonu bitis
int menu(char) //MEnuyu cizdirirken kullanılan func.
{
printf(" MENU\n\n 1.New Game\n\n 2.High Score\n\n"
" 3.Users Guide\n\n 4.How to give place to ships exp.\n\n 5.Stop\n");
printf("Please enter your choice...\n>");
scanf("%s" ,&choice);
system("cls");
return choice;
}
void oyunBasi(void) //İlk olarak ekranaa oyunun seklini cizen func.(Bir kez kullaniliyor)
{
int i,j;
for(i=0;i {
for(j=0;j gercek[i][j]=' ';
}
ekran();
}
int oyunOynama() //Girilen degerlere karsı gelen deger varmı yok mu kontrol edip sekli yeniden cizen func.
{
int i,j ,x ,score;
score=0;
u=1;
k=2;
f=4;
m=4;
read();
while(score>=0&&score<=BOYUT*BOYUT)
{
if(cikis==11)
{
system("cls");
return 0;
}
score++;
giris();
if(gercek[apsis][ordinat]<=1)
atis[apsis][ordinat]=6;
else if(gercek[apsis][ordinat]>=2&&gercek[apsis][ordinat]<=5)
{
atis[apsis][ordinat]=gercek[apsis][ordinat];
gemiVurma();
}
system("cls");
i=1;
printf("%4d " ,i);
for(i=2;i<=BOYUT;i++)
printf("%2d " ,i);
printf("\n ");
for(j=0;j<=4*BOYUT-2;j++)
printf("=");
printf("\n");
for(i=0;i { printf("%c" ,i+65);
for(j=0;j {
if(atis[i][j]<=5)
printf("| %d ",(int)atis[i][j]);
else if(atis[i][j]==6)
printf("| %c " ,88);
else
printf("| ");
}
printf("|\n ");
for(x=0;x<=4*BOYUT-2;x++)
printf("=");
printf("\n");
}
printf("Score=%d%10s%d%10s%d%10s%d%10s%d%15s%d\n" ,score,"U=",u ,"K=",k ,"F=",f ,"M=",m ,"Rekor=" ,highScore);
printf("Please enter your hit exp. A13 ,b5(Go to Menu xx or XX )\n\n>");
if((u+k+f+m)==0)
{
if(score<=highScore)
{ system("cls");
highScore=score;
write();
printf("Play it more times for well scores!(Click xx or XX go to main menu...)\n\n>");
}
else
printf("%s%s" ,"You didn'n made high score play it more time for well scores.\n" ,
"(Click xx or XX go to main menu...)\n\n>");
}
if(score==BOYUT*BOYUT)
printf("||**********|||Game Over|||**********||\n\n");
} //While (Oyunun en fazla oynanabilecegi dongu bitis)
return 0;
} //Oyun Oynama fonksiyonununn bitisi
int giris(void) //Kullanicidan apsis ve ordinat alan fun.
{
char string[4];
while(1)
{
int sayici ,j=0;
scanf("%s" ,string);
if(string[0]>=97)
string[0]-=32;
for(sayici=1;sayici<(int)strlen(string);sayici++)
{
string[sayici]=string[sayici]-48;
j = j*10 + string[sayici];
}
apsis=string[0]-65;
ordinat=j-1;
if(apsis==23&&(ordinat==39||ordinat==71))
{
cikis=11; //Oyun oynarken xx girince donguyu kırmak icin rastgele bir deger cikis...
return 0;
}
if(apsis>=0&&apsis<=BOYUT-1)
{
if(ordinat>=0&&ordinat<=BOYUT-1)
{
if(atis[apsis][ordinat]!=7)
printf("The entry has been entered.Try another hit...\n\n>");
else if(atis[apsis][ordinat]==7)
return 0;
}
}
if(apsis<0||apsis>(BOYUT-1)||ordinat<0||ordinat>(BOYUT-1))
printf("Wrong input please enter your hit exp. A13, B8\n\n>");
}
return 0;
} // giris fonksiyonu bitti. // giris fonksiyonu bitti.
void cizim(void) //Gemileri yerlestiren func.
{
int i,j,counter,sayici,sayac=0 ,kosul,kontrol1=0 ,kontrol2=0;
double gemi[12]={5 ,4 ,4.1 ,3 ,3.1 ,3.2 ,3.3 ,2 ,2.1 ,2.2 ,2.3,'\0'};
for(i=0;i {
for(j=0;j {
gercek[i][j]=0;
atis[i][j]=7;
} //Kullanici atis yaptıgı zaman karsılastirmak icin atis[i][j] dizime
} // atama yapıyorum rast gele ama gemilerin almayacagı bir degerdir 7.
while(gemi[sayac]!='\0')
{
kontrol1=0;
kontrol2=0;
i=rand()%BOYUT;
j=rand()%BOYUT;
if((BOYUT-i>=(int)gemi[sayac])&&(BOYUT-j>=(int)gemi[sayac])) //Eger gemi usunlugu kontrolu saglamıyorsa yeni bir
{ // i,j uretiyorum.
sayici=j;
for(counter=i;counter {
if(gercek[counter][sayici]!=0)
kontrol2=1;
}
counter=i;
for(sayici=j;sayici {
if(gercek[counter][sayici]!=0)
kontrol1=1;
}
if(kontrol1==0&&kontrol2==0)
{
kosul=rand()%2;
if(kosul==0)
{
sayici=j;
for(counter=i;counter gercek[counter][sayici]=gemi[sayac];
}
else if(kosul==1)
{
counter=i;
for(sayici=j;sayici gercek[counter][sayici]=gemi[sayac];
}
++sayac;
}
}
}
}
void ekran(void) //Eger kullanici gemileri nasıl yerlestirildini ornek gormek isterse kullanilan func.
{
int i=1 ,j ,x;
printf("%5d " ,i);
for(i=2;i<=BOYUT;i++)
printf("%2d " ,i);
printf("\n ");
for(j=0;j<=4*BOYUT-2;j++)
printf("=");
printf("\n");
for(i=0;i {
printf("%c" ,i+65);
for(j=0;j {
if(gercek[i][j]>=2&&gercek[i][j]<=5)
printf("| %d ",(int)gercek[i][j]);
else
printf("| ");
}
printf("|\n ");
for(x=0;x<=4*BOYUT-2;x++)
printf("=");
printf("\n");
}
printf("Score=0%10s%10s%10s%10s%10s%d\n" ,"U=1" ,"K=2" ,"F=4" ,"M=4" ,"Rekor=" ,highScore);
printf("Please enter your hit exp. A13 ,b5\n\n>");
}
void read(void) // Highskor dosyadan okuyan func.
{
FILE*cfPtr;
if((cfPtr=fopen("C:\\High.txt" ,"r+"))==NULL)
printf("Dosya açılamadi...\n");
else
fscanf(cfPtr,"%15s%16s%12d" ,ad ,soyad ,&highScore);
fclose(cfPtr);
}
void write(void) //HighSkor gecilirse dosyaya yazdiran func.
{
FILE *fptr;
fptr = fopen("C:\\High.txt","w");
if (!fptr)
{
printf("C:\\High.txt bulunamadi\n");
exit(0);
}
printf("**********You Are The WINNER**********\n");
printf("You are my number one in the game!\n");
printf("So that you can give me your name and surname...\n");
printf("Name:");
scanf("%s",ad);
printf("\n");
printf("%s","Surname:");
scanf("%s" ,soyad);
fprintf(fptr,"%15s%15s%15d\n",ad,soyad,highScore);
fclose(fptr);
}
void gemiVurma(void) //Gemi vurulursa calısacak func.
{
if(atis[apsis][ordinat]==5)
{
printf("You hit an Ucak Gemisi..\n");
++vurma[0];
printf("Press any key to continue.\n>");
getch();
if(vurma[0]==5)
{
u-=1;
printf("Ucak gemisi has sunk...\n");
printf("Press any key to continue.\n>");
getch();
vurma[0]=0;
}
}
if((int)atis[apsis][ordinat]==4)
{
printf("You hit a Kruvazor...\n");
printf("Press any key to continue.\n>");
getch();
if(atis[apsis][ordinat]==4)
++vurma[1];
else if(atis[apsis][ordinat]==4.1)
++vurma[2];
if(vurma[1]==4||vurma[2]==4)
{
printf("Kruvazor has sunk...\n>");
k-=1;
printf("Press any key to continue.\n>");
getch();
if(vurma[1]==4)
vurma[1]=0;
else if(vurma[2]==4)
vurma[2]=0;
}
}
if((int)atis[apsis][ordinat]==3)
{
printf("You hit a firkateyn...\n");
printf("Press any key to continue.\n>");
getch();
if(atis[apsis][ordinat]==3)
++vurma[3];
else if(atis[apsis][ordinat]==3.1)
++vurma[4];
else if(atis[apsis][ordinat]==3.2)
++vurma[5];
else if(atis[apsis][ordinat]==3.3)
++vurma[6];
if(vurma[3]==3||vurma[4]==3||vurma[5]==3||vurma[6]==3)
{
printf("Firkateyn has sunk...\n>");
f-=1;
printf("Press any key to continue.\n>");
getch();
if(vurma[3]==3)
vurma[3]=0;
else if(vurma[4]==3)
vurma[4]=0;
else if(vurma[5]==3)
vurma[5]=0;
else if(vurma[6]==3)
vurma[6]=0;
}
}
if((int)atis[apsis][ordinat]==2)
{
printf("You hit a Mayin tarama gemisi...\n");
printf("Press any key to continue.\n>");
getch();
if(atis[apsis][ordinat]==2)
++vurma[7];
else if(atis[apsis][ordinat]==2.1)
++vurma[8];
else if(atis[apsis][ordinat]==2.2)
++vurma[9];
else if(atis[apsis][ordinat]==2.3)
++vurma[10];
if(vurma[7]==2||vurma[8]==2||vurma[9]==2||vurma[10]==2)
{
printf("Mayin tarama gemisi has sunk...\n>");
m-=1;
printf("Press any key to continue.\n>");
getch();
if(vurma[7]==2)
vurma[7]=0;
else if(vurma[8]==2)
vurma[8]=0;
else if(vurma[9]==2)
vurma[9]=0;
else if(vurma[10]==2)
vurma[10]=0;
}
}
}