If you saw my thread earlier, you know that I'm currently working on a text based minesweeper program in C++. I've got a lot of the base game down but I need assistance with a few bugs and mechanics that I don't really understand.
Things I need help on:
If anybody could throw in their input on what I'm missing, or would be willing to help guide me through over Skype, I'd greatly appreciate it. Really trying to get a better understanding of the language.
Here's my code so far:
Things I need help on:
- How to hide the mines (0 is a free space, 1 is a mine) behind a symbol, like a +, while keeping the value equivalant (1 or 0)
- What seems to be a bug where I enter the coordinates, it runs through the if statements, and then changes the number of a different coordinate (you will probably have to run the program to see what I mean)
If anybody could throw in their input on what I'm missing, or would be willing to help guide me through over Skype, I'd greatly appreciate it. Really trying to get a better understanding of the language.
Here's my code so far:
Code
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
int mines = 0, x, y, i, j, mark = 0, repeat;
int grid[10][10] = {0}; //This sets whole array to zeroes
//---------------------------------------- Random mine placement
cout<<"Placing Mines..."<<endl;
do{
do{
x = rand()%10; //get a random row
y = rand()%10; //get a random column
}while (grid[x][y] != 0); //do again if a mine is located there already
grid[x][y] = 1; //place a mine at location
mines++; //increases mine count
}while(mines<10); //keep going until we have 10 mines
for(x=0;x<10;x++){
for(y=0;y<10;y++){
cout<<grid[x][y]<<" "; //print out grid
}
cout<<endl; //After print a row, do a new line, and start a new row
}
cout<<"There are "<<mines<< " Mines\n\n";
//---------------------- This is where I need to begin the user input
do{
cout<<"Input (x, y) entered on separate lines"<<endl; //using variables i for x and j for y, just to make sure nothing gets messed up
cin>>i;
cin>>j;
i = i-1;
j = j-1;
cout<<"i is "<<i<<" and j is "<<j<<endl;
if(grid[i][j] != 1){
cout<<"mark is "<<mark<<endl;
//Test A
if(grid[i-1][j+1] == 1){
mark += 1;
cout<<"mark is "<<mark<<endl;
}
//Test B
if(grid[i][j+1] == 1){
mark += 1;
cout<<"mark is "<<mark<<endl;
}
//Test C
if(grid[i+1][j+1] == 1){
mark += 1;
cout<<"mark is "<<mark<<endl;
}
//Test D
if(grid[i-1][j] == 1){
mark += 1;
cout<<"mark is "<<mark<<endl;
}
//Test E
if(grid[i=1][j] == 1){
mark += 1;
cout<<"mark is "<<mark<<endl;
}
//Test F
if(grid[i-1][j-1] == 1){
mark += 1;
cout<<"mark is "<<mark<<endl;
}
//Test G
if(grid[i][j-1] == 1){
mark += 1;
cout<<"mark is "<<mark<<endl;
}
//Test H
if(grid[i+1][j-1] == 1){
mark += 1;
cout<<"mark is "<<mark<<endl;
}
cout<<"mark is "<<mark<<endl;
grid[i][j] = mark;
for(x=0;x<10;x++){
for(y=0;y<10;y++){
cout<<grid[x][y]<<" "; //print out grid
}
cout<<endl; //After print a row, do a new line, and start a new row
}
repeat = 1;
}
else{
cout<<"You hit a mine, GG"<<endl;
repeat = 0;
break;
}
}while(repeat = 1);
}

