-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainGame.cpp
More file actions
150 lines (144 loc) · 4.04 KB
/
Copy pathMainGame.cpp
File metadata and controls
150 lines (144 loc) · 4.04 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <iostream>
#include <time.h>
using namespace std;
const int SIZE = 10;//can be changed to display any amount of arrays needed for bigger or smaller boards
void hiddenGameBoard();
void ruleBoard();
void gameBoard(char array[SIZE][SIZE]);//function to pass realGamboard array to follow non-functional requirements
int main() {
int bomb = 0;
char choice;
int x, y;
int points = 0;
do {
char realGameBoard[SIZE][SIZE] = {' '}; // space resets the gameboard
int guess = 5;
hiddenGameBoard();//call to function to display the a demo gameboard
ruleBoard();//displays the rules of the game
srand(time(NULL));
int goldCount = 0;
int bombCount = 0;
while (goldCount < 5) { //to get gold onto the gameboard
int gold1 = (rand() % (SIZE-2))+2;
int gold2 = (rand() % (SIZE-2))+2;
realGameBoard[gold1][gold2] = 'G';
goldCount++;
}
cout << endl;
while (bombCount < 1) { // to get bomb to display onto gameboard
int bomb1 = (rand() % (SIZE-2))+2;
int bomb2 = (rand() % (SIZE-2))+2;
realGameBoard[bomb1][bomb2] = 'B';
bombCount++;
}
do {
cout << "Enter x coordinate: " << endl;// user input
cin >> x;
cout << "Enter y coordinates: " << endl;// user input
cin >> y;
x++;
y++;
if (realGameBoard[x][y] == 'G') { //finding gold
cout << "You found GOLD!! Only " << ++guess << " guesses to go! You have " << ++points << " points!" << endl << endl;
realGameBoard[x][y] = 'F';
}
else if (realGameBoard[x][y] == 'B') {//finding bomb
cout << "BOMB! Game Over!" << endl << endl;
bomb++;
}
else {// when you miss gold or bomb or even guess the same space
cout << "Too bad... you have " << --guess << " guesses to go!" << endl << endl;
}
} while (bomb == 0 && guess != 0);
cout << "You earned " << points << " points" << endl;//displays points from this and previous games
cout << "Better Luck Next Time" << endl;
cout << "Here's your board" << endl;
gameBoard(realGameBoard);//function call to get gameboard and the results
cout << "Play again? Enter 'Y'" << endl;
cin >> choice;//user input to play again
//start--;
} while ((choice == 'y' || choice == 'Y'));//loop to keep going if y or Y
system("pause");
return 0;
}
void hiddenGameBoard() {
int countX = 1;//these are used to make sure they reset at end of each iteration of the game
int countY = 1;
char hiddenArray[SIZE][SIZE] = { };//creating game board
for (int y = 0; y < SIZE; y++) {
for (int x = 0; x < SIZE; x++) {
if (x == 1 && y == 1) {
cout << "_";
}
else if (x <= 1 && y <= 1) {
cout << " ";
}
else if (x <= SIZE && y == 1) {
cout << "_";
}
else if (y <= SIZE && x == 1) {
cout << "|";
}
else if (x <= SIZE && y == 0) {
cout << countX++;
}
else if (y <= SIZE && x == 0) {
cout << countY++;
}
else {
cout << "?";
}
cout << " ";
}
cout << endl;
}
}
void gameBoard(char array[SIZE][SIZE]) {
int countX = 1;//these are used to make sure they reset at end of each iteration of the game
int countY = 1;
for (int y = 0; y < SIZE; y++) {
for (int x = 0; x < SIZE; x++) {//statements to find out what value is in a certain array index
if (x == 1 && y == 1) {
cout << "_";
}
else if (x <= 1 && y <= 1) {
cout << " ";
}
else if (x <= SIZE && y == 1) {
cout << "_";
}
else if (y <= SIZE && x == 1) {
cout << "|";
}
else if (x <= SIZE && y == 0) {
cout << countX++;
}
else if (y <= SIZE && x == 0) {
cout << countY++;
}
else if (array[x][y] == 'F') {
cout << "F";
}
else if (array[x][y] == 'G') {
cout << "G";
}
else if (array[x][y] == 'B') {
cout << "B";
}
else {
cout << " ";
}
cout << " ";
}
cout << endl;
}
}
void ruleBoard() { // rules for the game
cout << " __________________" << endl;
cout << "** ****************** **" << endl;
cout << "** Find Gold! **" << endl;
cout << "** You have 5 guesses,**" << endl;
cout << "** 5 pieces of gold **" << endl;
cout << "** and 1 bomb **" << endl;
cout << "** Good Luck! **" << endl;
}