#include <iostream>
#include <ctime>
#include <cstdlib>
#include <stdlib.h>
usingnamespace std;
int main(){
char val;
do {
srand(unsigned(time(NULL)));
int p=10, q=15;
int inside[p][q];
char outside[p][q];
for (int i=0;i<p;i++)
{
for (int j=0;j<q;j++)
{
inside[i][j]=0;
}
}
for (int i=0;i<p;i++)
{
for (int j=0;j<q;j++)
{
if ((i==0) && (j==0)) {outside[i][j]=(char)201;}
elseif ((i==0) && (j==q-1)) {outside[i][j]=(char)187;}
elseif ((i==p-1) && (j==0)) {outside[i][j]=(char)200;}
elseif ((i==p-1) && (j==q-1)) {outside[i][j]=(char)188;}
elseif ((i==0) || (i==p-1)) {outside[i][j]=(char)205;}
elseif ((j==0) || (j==q-1)) {outside[i][j]=(char)186;}
else {outside[i][j]=(char)197;}
}
}
int a, b, c, d;
int e=0;
int flag=true;
int e1=5; int e1d=2;
int e2=3; int e2d=3;
int e3=2; int e3d=4;
while (e<e1d) {
int flag=true;
do {
flag=true;
c=rand()%2;
if (c==0) {
a=rand()%(p-2)+1;
b=rand()%(q-1-e1)+1;
for (int i=b;i<=b+(e1-1);i++) {if (inside[a][i]>0) {flag=false;}}
}
else {
a=rand()%(p-1-e1)+1;
b=rand()%(q-2)+1;
for (int i=a;i<=a+(e1-1);i++) {if (inside[i][b]>0) {flag=false;}}
}
} while (flag==false);
if (c==0) {
for (int i=b;i<=b+(e1-1);i++) {inside[a][i]=e+1;}
}
else {
for (int i=a;i<=a+(e1-1);i++) {inside[i][b]=e+1;}
}
e=e+1;
}
e=0;
while (e<e2d) {
do {
flag=true;
c=rand()%2;
if (c==0) {
a=rand()%(p-2)+1;
b=rand()%(q-1-e2)+1;
for (int i=b;i<=b+(e2-1);i++) {if (inside[a][i]>0) {flag=false;}}
}
else {
a=rand()%(p-1-e2)+1;
b=rand()%(q-2)+1;
for (int i=a;i<=a+(e2-1);i++) {if (inside[i][b]>0) {flag=false;}}
}
} while (flag==false);
if (c==0) {
for (int i=b;i<=b+(e2-1);i++) {inside[a][i]=e1d+e+1;}
}
else {
for (int i=a;i<=a+(e2-1);i++) {inside[i][b]=e1d+e+1;}
}
e=e+1;
}
e=0;
while (e<e3d) {
do {
flag=true;
c=rand()%2;
if (c==0) {
a=rand()%(p-2)+1;
b=rand()%(q-1-e3)+1;
for (int i=b;i<=b+(e3-1);i++) {if (inside[a][i]>0) {flag=false;}}
}
else {
a=rand()%(p-1-e3)+1;
b=rand()%(q-2)+1;
for (int i=a;i<=a+(e3-1);i++) {if (inside[i][b]>0) {flag=false;}}
}
} while (flag==false);
if (c==0) {
for (int i=b;i<=b+(e3-1);i++) {inside[a][i]=e1d+e2d+e+1;}
}
else {
for (int i=a;i<=a+(e3-1);i++) {inside[i][b]=e1d+e2d+e+1;}
}
e=e+1;
}
int talalat=0;
int probalkozas=0;
char x;
int y=0, z=0, index=1;
bool talalte=false;
int torpedo=60;
int elozoazon=0;
int damagedmaradek=0;
int hajokszama=e1d+e2d+e3d;
cout<<"\n\n\n ___ ____ ___ ___ _ ____ ____ _ _ _ ___ ____ \n |__] |__| | | | |___ [__ |__| | |__] [__ \n |__] | | | | |___ |___ ___] | | | | ___]"<<endl;
cout<<"\n T H E G A M E";
cout<<"\n\n by: coolbean";
cout<<"\n\n\n\n Nyomj ENTERT...";
cin.get();
system("cls");
while (talalat<e1*e1d+e2*e2d+e3*e3d && index<=torpedo) {
for (int k=0;k<p;k++)
{
for (int l=0;l<q;l++)
{
if (inside[k][l]==elozoazon) {damagedmaradek=damagedmaradek+1;}
}
}
if (damagedmaradek==0) {hajokszama=hajokszama-1;}
cout<<"\n ABCDEFGHIJKLM"<<endl;
for (int i=0;i<p;i++)
{
if (i>0 && i<p-1) {cout<<" "<<i;}
else {cout<<" ";}
for (int j=0;j<q;j++)
{
cout<<outside[i][j];
if (j==q-1 && i==0) {cout<<"\tLovesek szama: "<<index-1;}
if (j==q-1 && i==1) {cout<<"\tTalatok szama: "<<talalat;}
if (j==q-1 && i==2) {cout<<"\tHatralevo torpedok szama: "<<(torpedo+1)-index;}
if (j==q-1 && i==3) {cout<<"\tMaradek hajok szama: "<<hajokszama;}
if (j==q-1 && i==5 && index>1) {
if (talalte==true) {cout<<"\tElozo loves: "<<x<<y<<" - x";}
else {cout<<"\tElozo loves: "<<x<<y<<" - o";}}
if (j==q-1 && i==6 && index>1) {
if (talalte==true) {cout<<"\t\t Talalt!";}
else {cout<<"\t\t Nem talalt!";}}
if (damagedmaradek==0 && j==q-1 && i==8) {if (elozoazon<=e1d) {cout<<"\tMegsemmisitettel egy anyahajot!";}
elseif (elozoazon<=e2d) {cout<<"\tMegsemmisitettel egy rombolot!";}
else {cout<<"\tMegsemmisitettel egy jarorhajot!";}}
}
cout<<endl;
}
elozoazon=0;
damagedmaradek=0;
/* for (int k=0;k<10;k++)
{
for (int l=0;l<15;l++)
{
cout<<inside[k][l];
}
cout<<endl;
}
*/
do {
cout<<endl;
do {cout<<" Add meg az oszlop azonositojat: "; cin>>x;} while (x-'A'+1<1 || x-'A'+1>q-2);
do {cout<<" Add meg a sor azonositojat: "; cin>>y;} while (y<1 || y>p-2);
z=x-'A'+1;
if (outside[y][z]=='X' || outside[y][z]=='O') {cout<<"\n A megadott mezot mar tamadtad korabban! Adj meg uj koordinatakat!";}
} while (outside[y][z]=='X' || outside[y][z]=='O');
if (inside[y][z]>0) {elozoazon=inside[y][z];
inside[y][z]=0;
outside[y][z]='X';
talalat=talalat+1;
talalte=true;}
else {outside[y][z]='O';
talalte=false;}
system("cls");
index=index+1;
}
if (index==torpedo+1) {cout<<"\n\n\t G A M E O V E R\n\n Nincs tobb torpedod!\n\n";
for (int i=0;i<p;i++) {cout<<"\t ";
for (int j=0;j<q;j++) {
if (inside[i][j]>0) {cout<<(char)254;}
else {cout<<outside[i][j];}
}
cout<<endl;
}
cout<<"\n\n y - Uj jatek\n n - Kilepes\n\n ";}
else {cout<<"\n\n\tM I S S I O N C O M P L E T E D\n\n Teljes megsemmisites!\n\n";
for (int i=0;i<p;i++) { cout<<"\t ";
for (int j=0;j<q;j++) {
if (inside[i][j]>0) {cout<<(char)254;}
else {cout<<outside[i][j];}
}
cout<<endl;
}
cout<<"\n\n y - Uj jatek\n n - Kilepes\n\n ";}
do {
cin>>val;
} while(val!='n'&& val!='y'&& val!='N'&& val!='Y');
} while (val=='y'||val=='Y');
return 0;
}