1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include <cstdlib>
#include <iostream>
using namespace std;
class Arrays {
public:
int Display[10][10] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
int Actulal[10][10] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 4, 4, 4, 4, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{2, 0, 0, 0, 0, 0, 5, 0, 0, 0},
{2, 0, 0, 0, 0, 0, 5, 0, 0, 0},
{2, 0, 1, 1, 0, 0, 5, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 5, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 5, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{3, 3, 3, 0, 0, 0, 0, 0, 0, 0}};
} P;
class Status {
public:
int x;
int y;
int hits;
int Hits = 0;
} A;
int main() {
cout << "Game begins: \n";
cout << "4 means miss, 8 means hit \n";
do {
for (int x = 0; x < 10; x++) {
for (int y = 0; y < 10; y++) {
cout << P.Display[y][x] << " , ";
}
cout << endl;
}
cout << "Enter the collum number" << endl;
cin >> A.x;
cout << "Enter the row number" << endl;
cin >> A.y;
switch (P.Actulal[A.y][A.x]) {
case 1:
cout << "You hit a Destroyer!" << endl;
P.Display[A.x][A.y] = 8;
P.Actulal[A.x][A.y] = 6;
A.Hits = A.Hits + 1;
break;
case 2:
cout << "You hit a Submarine!" << endl;
P.Display[A.x][A.y] = 8;
P.Actulal[A.x][A.y] = 6;
A.Hits = A.Hits + 1;
break;
case 3:
cout << "You hit a Cruiser!" << endl;
P.Display[A.x][A.y] = 8;
P.Actulal[A.x][A.y] = 6;
A.Hits = A.Hits + 1;
break;
case 4:
cout << "You hit a Battleship!" << endl;
P.Display[A.x][A.y] = 8;
P.Actulal[A.x][A.y] = 6;
A.Hits = A.Hits + 1;
break;
case 5:
cout << "You hit a Carrier!" << endl;
P.Display[A.x][A.y] = 8;
P.Actulal[A.x][A.y] = 6;
A.Hits = A.Hits + 1;
break;
case 6:
cout << "You already hit there \n";
break;
default:
cout << "You missed \n";
P.Display[A.x][A.y] = 4;
P.Actulal[A.x][A.y] = 6;
};
} while (A.Hits != 17);
cout << "Game Over!";
}
|