Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 26th, 2007, 11:40 PM   #1
physicist
Hobbyist Programmer
 
Join Date: Oct 2006
Posts: 146
Rep Power: 2 physicist is on a distinguished road
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...
physicist is offline   Reply With Quote
Old May 27th, 2007, 3:00 AM   #2
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 309
Rep Power: 3 andro is on a distinguished road
Send a message via AIM to andro
Your if and else are using assignment ( = vs == ).
andro is online now   Reply With Quote
Old May 27th, 2007, 11:20 AM   #3
physicist
Hobbyist Programmer
 
Join Date: Oct 2006
Posts: 146
Rep Power: 2 physicist is on a distinguished road
thank you
physicist is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:51 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC