Advertisement

05.07.2008 at 03:00PM PDT, ID: 23384451 | Points: 500
[x]
Attachment Details
Help with minesweeper game
Tags: C++
Hi

I have a array containing 100 numbers (0-99). I have made a function that randomly puts in a number of bombs, marked with a "B" in the array and calculate the numbers around the bombs. The array is then shown to the user by using a for-loop that breaks the line after every 10th number.

What I need is a function that handle the input from the user. If the user inputs 40 the function should control that number 40 is not a mine and if not a mine then show the surrounding numbers. How should I do that?
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: gnukki
Question Asked On: 05.07.2008
Participating Experts: 3
Points: 500
Views: 0
Translate:
Loading Advertisement...
05.07.2008 at 03:02PM PDT, ID: 21520730

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.07.2008 at 03:03PM PDT, ID: 21520745

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.07.2008 at 03:06PM PDT, ID: 21520760

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.07.2008 at 04:45PM PDT, ID: 21521302

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.07.2008 at 10:45PM PDT, ID: 21522548

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.07.2008 at 11:38PM PDT, ID: 21522713

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.07.2008 at 11:57PM PDT, ID: 21522786

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.07.2008 at 11:58PM PDT, ID: 21522793

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 02:05AM PDT, ID: 21523274

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 02:06AM PDT, ID: 21523277

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 02:23AM PDT, ID: 21523320

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 02:26AM PDT, ID: 21523334

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 02:49AM PDT, ID: 21523407

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 02:50AM PDT, ID: 21523409

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 05:56AM PDT, ID: 21524175

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 07:27AM PDT, ID: 21525013

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 02:09AM PDT, ID: 21531230

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 02:16AM PDT, ID: 21531262

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 02:19AM PDT, ID: 21531274

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 02:39AM PDT, ID: 21531342

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 05:45AM PDT, ID: 21532168

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 05:55AM PDT, ID: 21532262

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 06:39AM PDT, ID: 21532628

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 06:44AM PDT, ID: 21532683

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 06:51AM PDT, ID: 21532760

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 07:06AM PDT, ID: 21532929

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 07:16AM PDT, ID: 21533041

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 07:26AM PDT, ID: 21533144

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 07:38AM PDT, ID: 21533262

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 08:01AM PDT, ID: 21533536

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 08:04AM PDT, ID: 21533569

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 08:10AM PDT, ID: 21533639

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 08:18AM PDT, ID: 21533731

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
05.07.2008 at 03:02PM PDT, ID: 21520730
And by the way, I'm not using the flag option know from minesweeper from windows
 
05.07.2008 at 03:03PM PDT, ID: 21520745
Sounds like you need a multidimensional array to store all the associated values needed to keep track of whats goign on

One value in the array would be placement possibly an xy coordinate, another would be response...booleon value of bomb or safety/true or false/ 1 or 0,
 
05.07.2008 at 03:06PM PDT, ID: 21520760
Then depending on the value of the response in the array...you would have a function that would from that x/y coordinate, change the picture/image of each adjacent x/y coordinate to its value.
 
05.07.2008 at 04:45PM PDT, ID: 21521302
Please tell us whether you're using a Windows GUI or just having them input text in the Command Window.  This will help determine what type of function best suits your purpose for getting the input from the user.

Luke
 
05.07.2008 at 10:45PM PDT, ID: 21522548
Okay. Should I use a 3-dimensional array, so I also can keep track of wheter the field is exposed, or is there a better way?

I'm only working in a command window :)
 
05.07.2008 at 11:38PM PDT, ID: 21522713

Rank: Genius

>> Okay. Should I use a 3-dimensional array, so I also can keep track of wheter the field is exposed, or is there a better way?

A 2D array should be sufficient. Each field in the 2D array would have a state flag that signifies its current state. If you need more than one information per field, then you can use a struct to group them :

        typedef struct Field {
            /* all information you need for a field */
        } Field;

        Field board[10][10];          /* <--- this is the board : 10x10 fields */
 
05.07.2008 at 11:57PM PDT, ID: 21522786
how could I store the numbers around the bombs?
 
05.07.2008 at 11:58PM PDT, ID: 21522793

Rank: Genius

>> how could I store the numbers around the bombs?

That could be relatively easy. When you place a bomb, just increment the surrounding fields by 1.
 
05.08.2008 at 02:05AM PDT, ID: 21523274
Okay if I have a 2D array that holds either B for bomb or the number. The rest is zero. How do I make the function to check for bombs in a specific coordinate?
 
05.08.2008 at 02:06AM PDT, ID: 21523277

Rank: Genius

>> How do I make the function to check for bombs in a specific coordinate?

Just check if the flag is set to B at those coordinates ...
 
05.08.2008 at 02:23AM PDT, ID: 21523320
I dont understand how to use "typedef struct Field " ??
 
05.08.2008 at 02:26AM PDT, ID: 21523334

Rank: Genius

>> I dont understand how to use "typedef struct Field " ??

If you don't need to store more than one data for each field, then you don't have to use it :)


For more information about structs, let me refer you to this tutorial :

        http://www.cplusplus.com/doc/tutorial/structures.html
 
05.08.2008 at 02:49AM PDT, ID: 21523407
I should use 2 data for each field. But I can't get any sense of the tutorial :(
 
05.08.2008 at 02:50AM PDT, ID: 21523409

Rank: Genius

>> But I can't get any sense of the tutorial :(

Which part confuses you ?
 
05.08.2008 at 05:56AM PDT, ID: 21524175
Just as Infinity08 said, it seems you could just use a 2D array with one value per location: either B or a number 1-8 to signify that it is a bomb or that there are 1-8 bombs touching that square.  To get the input from the user, you can use your preferred input method, cin >>, or cin.get(.....).  Ask the user for the coordinates, i.e. for 2 numbers, horizontal coordinate first, followed by the enter key, then vertical coordinate, followed by the enter key, or something like that.  Once you have those numbers, say ChoiceX and ChoiceY, you can use them to check your array.  Something like the attached code.

Luke
1:
2:
3:
4:
5:
6:
7:
8:
9:
//Let's say "map" is the name of your array, and it's a char[][]
if(map[ChoiceX][ChoiceY] == 'B')
{
     cout << "Location " << ChoiceX << ", " << ChoiceY << " has a Bomb!" << "\n";
}
else
{
     cout << "There are " << map[ChoiceX][ChoiceY] << " Bombs surrounding location " << ChoiceX << ", " << ChoiceY << "\n";
}
Open in New Window
 
05.08.2008 at 07:27AM PDT, ID: 21525013
Like I said  before....a 2 D array is what you need..but your logic is going to have to iterate and call several functions to achieve your objective.

Essentially you have your first array which stores the information about the game board.
But you have to have the other 2d array that essentially is the players movement on the board.

You would iterate through each 2d array based on the users input as a starting point in the array.
When a user selection is made you would use input as a starting point...iterate through the a arrary from that point to
show the numbers and or bombs from that location...storing in session where the user is at all times.  Essentially your array is plotting the course
and at certain distinct times you will need to store values in memory to use in the functions that will display the adjacent cells.  Very similar to a TIC TAC TOE game I made in C++ back in my college days.
 
05.09.2008 at 02:09AM PDT, ID: 21531230
Infinity08: I have now sorted out my problems about struct :)

Okay, I have now moved over to a 2D array. I'm using struct to store information for the field, such as if the field is opened og closed, if the field is a mine or how many mines that are located around the field, this is represented by numbers.

Now I would like to if the user hits a zero that all zeros that are connected are beeing opened. How do I do that?
 
05.09.2008 at 02:16AM PDT, ID: 21531262

Rank: Genius

>> Now I would like to if the user hits a zero that all zeros that are connected are beeing opened. How do I do that?

For a zero field, you open all its surrounding fields (all 8 of them). If one or more of those 8 are 0 fields too, then you do the same for them (open all 8 of their surrounding fields), etc.
 
05.09.2008 at 02:19AM PDT, ID: 21531274
Yes. But I can't seme to find a easy way for this, do you have a hint? :)
 
05.09.2008 at 02:39AM PDT, ID: 21531342

Rank: Genius

You can do it :

1) recursively

2) iteratively (store zero nodes in some temporary vector that needs to be processed, and iterate over that vector, until you reach the end, adding new zero nodes at the end obviously)
 
05.09.2008 at 05:45AM PDT, ID: 21532168
okay, how do I do it recursively?
 
05.09.2008 at 05:55AM PDT, ID: 21532262

Rank: Genius

>> okay, how do I do it recursively?

Have a function that determines the surrounding 8 fields, and call the function recursively for all 8. That's it.
 
05.09.2008 at 06:39AM PDT, ID: 21532628
Okay, I'v tried but every time the function gets to a zero it closes without any warning. Here is a part of my code, hopefull you can spot the error :)
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:
5