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 103 104 105 106
|
#include<iostream.h> // This header is depreciated,
// meaning it's 10 years old, and has since been replaced)
#include<conio.h> // Not standard, but not big deal in this case.
/* You didn't declare a using directive, yet you are using members from the
* std namespace with no qualifiers, i.e "cout" instead of "std::cout" */
void main() /* Main should not be a void function,
* You need to return 0 or EXIT_SUCCESS on a successful exit, with no errors,
* and return an error status when an error occurs.
* GNU compiler won't even let you use a void main(),
* but some (IMO, inferior for this reason) compilers will, which is bad.
* ISO C++ Standard dictates that it has to be int main(), basically. */
{
clrscr();
/* clrscr() is very non-standard. It is specific to only a few compilers,
* not including GNU, which is what I use.
* Preferably, you should use a non-OS-specific, non-compiler-specific
* method to do this ... Actually not doing this at all is best ...
* But system("cls") is at least portable to different compilers,
* though is still Windows specific. */
{ // <-- What is this doing here? The start bracket for main() is already in here.
// This one is redundant and will cause a compile error.
int bomb[5][5] = { { 0, 1, 0, 0, 1 }, { 1, 1, 0, 1, 0 }, { 0, 0, 1, 1, 0 },
{ 1, 0, 0, 1, 0 }, { 0, 0, 1, 0, 0 } };
int bombscan[5][5] = { { -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1 }, {
-1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1 },
{ -1, -1, -1, -1, -1 } };
int vert, hor, r, c, mnRw, mnCl, mxRw, mxCl, bombc = 0, flag = 0, check = 0;
while (check <= 7) {
clrscr();
for (r = 0; r < 5; r++) {
for (c = 0; c < 5; c++) {
if (bombscan[r][c] == -1)
cout << "[ ]";
else if (bombscan[r][c] == -10)
cout << "[x]";
else
cout << "[" << bombscan[r][c] << "]";
}
cout << endl;
}
if (check == 19) {
cout << "finish!!";
goto exit;
/* Never, EVER, use a goto like this! This isn't a batch script!
* In this case, you can simply use a return statement. */
}
if (flag == 1) {
cout << "game over!";
goto exit;
}
/* You don't need endl to simply print a newline.
* Use '\n' whenever possible, endl is more resource intensive,
* and is unnecessary here */
cout << "Enter cell coordinates:" << endl;
cout << "\tVertical:"; cin >> vert;
cout << "\tHorizontal:"; cin >> hor;
vert = vert - 1;
hor = hor - 1;
if (bomb[vert][hor] == 1) {
bomb[vert][hor] = -10;
flag = 1;
} else {
check++;
if (vert == 0)
mnRw = 0;
else
mnRw = vert - 1;
if (hor == 0)
mnCl = 0;
else
mnCl = hor - 1;
if (hor == 2)
mxRw = 2;
else
mxRw = +1;
if (hor == 2)
mxCl = 2;
else
mxCl = hor + 1;
for (r = mnRw; r <= mxRw; r++) {
for (c = mnCl; c <= mxCl; c++) {
if (bomb[r][c] == 1) {
bombc++;
}
}
}
bombscan[vert][hor] = bombc;
bombc = 0;
}
}
exit:
}
getch();
} // <-- This will cause a compile error, as main() ends with the bracket above,
// and this one is useless.
/* There is also no return statement, i.e. "return 0;", and getch() is outside
* of main(), and is thus useless, and also will cause a compilation error.
*/
|