![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Oct 2006
Posts: 146
Rep Power: 2
![]() |
DOS Minesweeper
Printing the grid works, and in general the array structures and everything updates as it should, random mines are generated; but no matter which square you choose, it CHANGES that square to a mine then says you lose cause you selected a mine; even if it wasnt originally a mine
i have narrowed it down to the bolded function; again, initially about 30% of the squares are mines, and when you click on a mine it works properly, when you select a mineless square it changes it to a mine and says you lose, when it should just continue the game (ill implement neighbor function later once this works) #include<iostream>
#include<cstdlib>
#include<ctime>
#include<string>
using namespace std;
void initialize();
void paint();
string matrix[100];
int mine[100];
void updatematrix(int r, int c);
int main()
{
initialize();
int rguess;
int cguess;
paint();
while(1)
{
cout <<"Enter row of square to open (0-9)";
cin >> rguess;
cout <<"Enter column of square to open (0-9)";
cin >> cguess;
updatematrix(rguess,cguess);
}
system("PAUSE");
return 0;
}
void paint()
{
int i=0;
for (int row=10; row>0; row--)
{
for (int column=10; column>0; column--)
{
cout <<matrix[i];
cout <<mine[i];
i++;
}
cout<<"\n";
}
}
void initialize()
{
bool a;
int b;
srand( (unsigned int) time( NULL ) );
int c=0;
while (c<100)
{
matrix[c]="|_|";
b= rand()%10+1;
if (b<3){a=1;}
else {a=0;}
mine[c]=a;
c++;
}
}
void updatematrix(int r, int c)
{
int square =r*10 + c;
if (mine[square]=1)
{cout <<"You lose";}
else if (mine[square]=0)
{matrix[square]="|X|";}
paint();
}edit: the only reason the paint() function prints the mine value of each square was for testing to see which squares were mines... |
|
|
|
|
|
#2 |
|
Professional Programmer
|
Your if and else are using assignment ( = vs == ).
|
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Oct 2006
Posts: 146
Rep Power: 2
![]() |
thank you
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Algorithm for Mineless Areas in Minesweeper? | UnKnown X | Python | 8 | Jun 11th, 2006 7:47 PM |
| Python/pygame minesweeper (And multiplayer) | Writlaus | Show Off Your Open Source Projects | 4 | Apr 12th, 2006 11:49 AM |