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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
char array1[26] = {'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F'}; // a 5x5 array.
int array_mine[26];
int mine_number;
int input;
int a = 0;
int b = 0;
int c = 0;
int hint = 0;
bool endgame = false;
bool boom = false;
void check();
void random()
{
while(a < 26)
{
array_mine[a] = rand() % 2;
a++;
};
return;
}
void check()
{
while(b < 26)
{
if(b == input)
{
switch(array_mine[b])
{
case 0:
array1[b] = 'E';
if(10 > b > 6 || 20 > b > 16 || 15 > b > 11)
{
hint = array_mine [b-6] + array_mine [b-5] + array_mine [b-4] + array_mine [b-1] + array_mine [b+1] + array_mine [b+4] + array_mine [b+5] + array_mine [b+6];
}
if(b == 1)
{
hint = array_mine [b];
}
if(5 > b > 1)
{
hint = array_mine [b-1] + array_mine [b+1] + array_mine [b+4] + array_mine [b+5] + array_mine [b+6];
}
if(b == 5)
{
hint = array_mine [b-1] + array_mine [b+4] + array_mine [b+5];
}
if(b == 6 || b == 11 || b == 16)
{
hint = array_mine [b-5] + array_mine [b-4] + array_mine [b+1] + array_mine [b+5] + array_mine [b+6];
}
if(b == 10 || b == 15 || b == 20)
{
hint = array_mine [b-6] + array_mine [b-5] + array_mine [b-1] + array_mine [b+4] + array_mine [b+5];
}
if(21 < b < 25)
{
hint = array_mine [b-6] + array_mine [b-5] + array_mine [b-4] + array_mine [b-1] + array_mine [b+1];
}
if(b == 25)
{
hint = array_mine [b-6] + array_mine [b-6] + array_mine [b-1];
}
if(b == 21)
{
hint = array_mine [b-5] + array_mine [b-4] + array_mine [b+1];
}
break;
case 1:
array1[b] = 'M';
boom = true;
break;
default:
break;
}
}
b++;
}
b = 0;
return;
}
int main()
{
srand(time(NULL));
cout << "Welcome to Minesweeper.\n" ;
cout << "The minefield is 5 x 5\n";
cout << "F is a unknown field, E is cleared field.\n";
cout << "This minesweeper is diffrent though.\n Yes, it will display how many mines are around tile you just uncovered after each move.\n But once you make another move, that hint is gone, place for new one.\n You need to memorize hints this programm gives to you.";
cout << "Detect area by inserting number of field, counting left-right, top-down.\n";
cout << "Ammount of mines as well as their allocation is random. It means it is possible to have 0 mines or 25 (maximum) mines.\n In latter case im terribly sorry if it happens.\n";
cout << endl;
cout << endl;
random();
while(boom == false || endgame == false)
{
cout << array1[1] << array1[2] << array1[3] << array1[4] << array1[5] << endl;
cout << array1[6] << array1[7] << array1[8] << array1[9] << array1[10] << endl;
cout << array1[11] << array1[12] << array1[13] << array1[14] << array1[15] << endl;
cout << array1[16] << array1[17] << array1[18] << array1[19] << array1[20] << endl;
cout << array1[21] << array1[22] << array1[23] << array1[24] << array1[25] << endl;
cin >> input;
check();
if(boom == true)
{
cout << "BOOM! You blew yourself up! Better luck next time :)";
return 0;
}
if(array1[1] != 'F' && array1[2] != 'F' && array1[3] != 'F' && array1[4] != 'F' && array1[5] != 'F' && array1[6] != 'F' && array1[7] != 'F' && array1[8] != 'F' && array1[9] != 'F' && array1[10] != 'F' && array1[11] != 'F' && array1[12] != 'F' && array1[13] != 'F' && array1[14] != 'F' && array1[15] != 'F' && array1[16] != 'F' && array1[17] != 'F' && array1[18] != 'F' && array1[19] != 'F' && array1[20] != 'F' && array1[21] != 'F' && array1[22] != 'F' && array1[23] != 'F' && array1[24] != 'F' && array1[25] != 'F')
{
endgame = true;
}
cout << "There is " << hint << " mines around this tile!\n";
cin.ignore();
}
cout << "Congratulations! You cleared the minefield!";
return 0;
}
|