Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-24-2004, 02:23 AM   PM User | #1
Serex
Regular Coder

 
Join Date: Mar 2004
Location: Australia
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
Serex is an unknown quantity at this point
c++: Minesweeper Game

Hai, I have recently begun working on my own version of minesweeper. I have pretty much got it all figured. The only thing i need now are the actual mines.

Just after a few examples on what would be the best way to store the random locations. or would it be better to have a boolean attribute to the current block thats there?

few suggestions would be great.

thanks
Serex is offline   Reply With Quote
Old 11-24-2004, 03:13 PM   PM User | #2
Dr. Evil
New Coder

 
Join Date: Nov 2004
Location: Netherlands
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Dr. Evil is an unknown quantity at this point
I'd create a point array as long as there are mines and the location for each one in their element. Like this, kind of.
Code:
//mine_num = number of mines

POINT mines[mine_num]
srand(time(NULL));

for(i=0; i<mine_num; i++)
{
mines[i].x = rand() % /*size of horizontal side*/;
mines[i].y = rand() % /*size of vertical side*/;
for(j=0; j<mine_num; j++)
{
if(mines[i].x == mines[j].x) i--;
else if(mines[i].y == mines[j].y) i--;
}
}

//...
EDIT: Oops, I messed up that part to see if it was in the same place. Here's what the code should look like.
Code:
//mine_num = number of mines

POINT mines[mine_num]
srand(time(NULL));

for(i=0; i<mine_num; i++)
{
mines[i].x = rand() % /*size of horizontal side*/;
mines[i].y = rand() % /*size of vertical side*/;
for(j=0; j<mine_num; j++)
{
if((mines[i].x == mines[j].x) && (mines[i].y == mines[j].y) && (j != i)) i--;
}
}

//...

Last edited by Dr. Evil; 11-25-2004 at 09:57 AM..
Dr. Evil is offline   Reply With Quote
Old 03-02-2012, 11:40 AM   PM User | #3
str8acer
New to the CF scene

 
Join Date: Mar 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
str8acer is an unknown quantity at this point
minesweeper

Hi, im new in c++ designing and i wanted to design minesweeper but i needed a little bit of help. i created a structure code so that i can follow but i'm would actually like to see if i have it correct or if someone can help me with breaking it down into sections? Thanks
str8acer is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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


All times are GMT +1. The time now is 08:15 AM.


Advertisement
Log in to turn off these ads.