Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- int main()
- {
- string outLettersUp = "ABCDEFGHIJKLMNOPQRSTUVWXY", outLettersLow = "abcdefghijklmnopqrstuvwxy";
- string BoutLettersUp = "ABCDEFGHIJKLMNOPQRSTUVWXY", BoutLettersLow = "abcdefghijklmnopqrstuvwxy";
- string intLettersUp = outLettersUp;
- string guess;
- int loop = 1;
- char guessChar;
- int bombCount[25] = {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};
- srand(time(0));
- cout<<"MINESWEEPER"<<endl;
- for (int a = 0; a < 5; a++)
- {
- int b = rand()% 25;
- intLettersUp.replace(b, 1, "Z");
- intLettersLow.replace(b, 1, "Z");
- }
- //special case 1: position 0
- for (int i = 0; i < 3; i++)
- {
- if (i == 0)
- {
- if (intLettersUp.substr(1, 1) == "Z")
- {
- bombCount[0] += 1;
- }
- }
- if (i == 1)
- {
- if (intLettersUp.substr(5, 1) == "Z")
- {
- bombCount[0] += 1;
- }
- }
- if (i == 2)
- {
- if (intLettersUp.substr(6, 1) == "Z")
- {
- bombCount[0] += 1;
- }
- }
- }
- //special case 2: position 20
- for (int j = 0; j < 3; j++)
- {
- if (j == 0)
- {
- if (intLettersUp.substr(15, 1) == "Z")
- {
- bombCount[20] += 1;
- }
- }
- if (j == 1)
- {
- if (intLettersUp.substr(16, 1) == "Z")
- {
- bombCount[20] += 1;
- }
- }
- if (j == 2)
- {
- if (intLettersUp.substr(21, 1) == "Z")
- {
- bombCount[20] += 1;
- }
- }
- }
- // special case: position 4
- for (int k = 0; k < 3; k++)
- {
- if (k == 0)
- {
- if (intLettersUp.substr(3, 1) == "Z")
- {
- bombCount[4] += 1;
- }
- }
- if (k == 1)
- {
- if (intLettersUp.substr(9, 1) == "Z")
- {
- bombCount[4] += 1;
- }
- }
- if (k == 2)
- {
- if (intLettersUp.substr(8, 1) == "Z")
- {
- bombCount[4] += 1;
- }
- }
- }
- // special case: position 24
- for (int l = 0; l < 3; l++)
- {
- if (l == 0)
- {
- if (intLettersUp.substr(23, 1) == "Z")
- {
- bombCount[24] += 1;
- }
- }
- if (l == 1)
- {
- if (intLettersUp.substr(19, 1) == "Z")
- {
- bombCount[24] += 1;
- }
- }
- if (l == 2)
- {
- if (intLettersUp.substr(18, 1) == "Z")
- {
- bombCount[24] += 1;
- }
- }
- }
- // case left; positions 5, 10, 15
- for (int m = 5; m < 16; m += 5)
- {
- for (int n = 0; n < 5; n++)
- {
- if (n == 0)
- {
- if (intLettersUp.substr(m-5, 1) == "Z")
- {
- bombCount[m] += 1;
- }
- }
- if (n == 1)
- {
- if (intLettersUp.substr((m-4), 1) == "Z")
- {
- bombCount[m] += 1;
- }
- }
- if (n == 2)
- {
- if (intLettersUp.substr((m+1), 1) == "Z")
- {
- bombCount[m] += 1;
- }
- }
- if (n == 3)
- {
- if (intLettersUp.substr((m+5), 1) == "Z")
- {
- bombCount[m] += 1;
- }
- }
- if (n == 4)
- {
- if (intLettersUp.substr((m+6), 1) == "Z")
- {
- bombCount[m] += 1;
- }
- }
- }
- }
- // case right; positions 9, 14, 19
- for (int o = 9; o < 20; o = o + 5)
- {
- for (int p = 0; p < 5; p++)
- {
- if (p == 0)
- {
- if (intLettersUp.substr(o-6, 1) == "Z")
- {
- bombCount[o] += 1;
- }
- }
- if (p == 1)
- {
- if (intLettersUp.substr(o-5, 1) == "Z")
- {
- bombCount[o] += 1;
- }
- }
- if (p == 2)
- {
- if (intLettersUp.substr(o-1, 1) == "Z")
- {
- bombCount[o] += 1;
- }
- }
- if (p == 3)
- {
- if (intLettersUp.substr(o+4, 1) == "Z")
- {
- bombCount[o] += 1;
- }
- }
- if (p == 4)
- {
- if (intLettersUp.substr(o+5, 1) == "Z")
- {
- bombCount[o] += 1;
- }
- }
- }
- }
- // case up; positions 9, 14, 19
- for (int q = 1; q < 4; q++)
- {
- for (int r = 0; r < 5; r++)
- {
- if (r == 0)
- {
- if (intLettersUp.substr(q-1, 1) == "Z")
- {
- bombCount[q] += 1;
- }
- }
- if (r == 1)
- {
- if (intLettersUp.substr(q+1, 1) == "Z")
- {
- bombCount[q] += 1;
- }
- }
- if (r == 2)
- {
- if (intLettersUp.substr(q+4, 1) == "Z")
- {
- bombCount[q] += 1;
- }
- }
- if (r == 3)
- {
- if (intLettersUp.substr(q+5, 1) == "Z")
- {
- bombCount[q] += 1;
- }
- }
- if (r == 4)
- {
- if (intLettersUp.substr(q+6, 1) == "Z")
- {
- bombCount[q] += 1;
- }
- }
- }
- }
- // case down; positions 21, 22, 23
- for (int s = 21; s < 24; s++)
- {
- for (int t = 0; t < 5; t++)
- {
- if (t == 0)
- {
- if (intLettersUp.substr(s-6, 1) == "Z")
- {
- bombCount[s] += 1;
- }
- }
- if (t == 1)
- {
- if (intLettersUp.substr(s-5, 1) == "Z")
- {
- bombCount[s] += 1;
- }
- }
- if (t == 2)
- {
- if (intLettersUp.substr(s-4, 1) == "Z")
- {
- bombCount[s] += 1;
- }
- }
- if (t == 3)
- {
- if (intLettersUp.substr(s-1, 1) == "Z")
- {
- bombCount[s] += 1;
- }
- }
- if (t == 4)
- {
- if (intLettersUp.substr(s+1, 1) == "Z")
- {
- bombCount[s] += 1;
- }
- }
- }
- }
- // case middle; positions 6, 7, 8, 11, 12, 13, 16, 17, 18
- for (int u = 6; u < 19; u++)
- {
- if (u == 9)
- {
- u = 11;
- }
- if (u == 14)
- {
- u = 16;
- }
- for (int v = 0; v < 9; v++)
- {
- if (v == 0)
- {
- if (intLettersUp.substr(u-6, 1) == "Z")
- {
- bombCount[u] += 1;
- }
- }
- if (v == 1)
- {
- if (intLettersUp.substr(u-5, 1) == "Z")
- {
- bombCount[u] += 1;
- }
- }
- if (v == 2)
- {
- if (intLettersUp.substr(u-4, 1) == "Z")
- {
- bombCount[u] += 1;
- }
- }
- if (v == 3)
- {
- if (intLettersUp.substr(u-1, 1) == "Z")
- {
- bombCount[u] += 1;
- }
- }
- if (v == 4)
- {
- if (intLettersUp.substr(u+1, 1) == "Z")
- {
- bombCount[u] += 1;
- }
- }
- if (v == 5)
- {
- if (intLettersUp.substr(u+4, 1) == "Z")
- {
- bombCount[u] += 1;
- }
- }
- if (v == 6)
- {
- if (intLettersUp.substr(u+5, 1) == "Z")
- {
- bombCount[u] += 1;
- }
- }
- if (v == 7)
- {
- if (intLettersUp.substr(u+6, 1) == "Z")
- {
- bombCount[u] += 1;
- }
- }
- }
- }
- for (int w = 0; w < 25; w++)
- {
- if (bombCount[w] == 0)
- {
- if (intLettersUp.substr(w, 1) != "Z")
- {
- intLettersUp.replace(w, 1, "0");
- }
- }
- if (bombCount[w] == 1)
- {
- if (intLettersUp.substr(w, 1) != "Z")
- {
- intLettersUp.replace(w, 1, "1");
- }
- }
- if (bombCount[w] == 2)
- {
- if (intLettersUp.substr(w, 1) != "Z")
- {
- intLettersUp.replace(w, 1, "2");
- }
- }
- if (bombCount[w] == 3)
- {
- if (intLettersUp.substr(w, 1) != "Z")
- {
- intLettersUp.replace(w, 1, "3");
- }
- }
- if (bombCount[w] == 4)
- {
- if (intLettersUp.substr(w, 1) != "Z")
- {
- intLettersUp.replace(w, 1, "4");
- }
- }
- if (bombCount[w] == 5)
- {
- if (intLettersUp.substr(w, 1) != "Z")
- {
- intLettersUp.replace(w, 1, "5");
- }
- }
- }
- // for checking
- for (int d=0; d<5; d++)
- {
- cout<<intLettersUp.substr(d, 1)<<" ";
- }
- cout<<endl;
- for (int e=5; e<10; e++)
- {
- cout<<intLettersUp.substr(e, 1)<<" ";
- }
- cout<<endl;
- for (int f=10; f<15; f++)
- {
- cout<<intLettersUp.substr(f, 1)<<" ";
- }
- cout<<endl;
- for (int g=15; g<20; g++)
- {
- cout<<intLettersUp.substr(g, 1)<<" ";
- }
- cout<<endl;
- for (int h=20; h<25; h++)
- {
- cout<<intLettersUp.substr(h, 1)<<" ";
- }
- cout<<endl;
- Start:
- while (loop == 1)
- {
- for (int d=0; d<5; d++)
- {
- cout<<outLettersUp.substr(d, 1)<<" ";
- }
- cout<<endl;
- for (int e=5; e<10; e++)
- {
- cout<<outLettersUp.substr(e, 1)<<" ";
- }
- cout<<endl;
- for (int f=10; f<15; f++)
- {
- cout<<outLettersUp.substr(f, 1)<<" ";
- }
- cout<<endl;
- for (int g=15; g<20; g++)
- {
- cout<<outLettersUp.substr(g, 1)<<" ";
- }
- cout<<endl;
- for (int h=20; h<25; h++)
- {
- cout<<outLettersUp.substr(h, 1)<<" ";
- }
- cout<<endl;
- cout<<endl<<"Choose a letter."<<endl;
- guessChar = getch();
- guess += guessChar;
- for (int x = 0; x < 25; x++)
- {
- if ((guess.substr(0, 1) == BoutLettersUp.substr(x, 1)) || (guess.substr(0,1) == BoutLettersLow.substr(x, 1))
- {
- goto GuessMark;
- }
- else {
- cout<<"The character you pressed should be within the grid only.";
- guess.clear();
- guessChar = '';
- goto Start;
- }
- }
- GuessMark:
- cout<<endl<<"Your guess is: "<<guess<<endl;
- system("pause");
- for
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement