Click here to Skip to main content
15,917,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey I’m writing the code for a minesweeper game in c and i want to make a menu so that the user can select the difficulty of the game like 30 by 30 with 99 bombs 16 by 16 with 30 bombs and 9 by 9 with 10 bombs. Can someone tell me how can i achieve this? like the user has to enter 1 for easy 2 for medium and... .

What I have tried:

i know i can use switch case but the code is too large. is there anyway to run a certain project in code blocks from an another project? because that would totally solve my problem.
Posted
Updated 25-Dec-18 8:12am
v3

That's going to depend pretty much entirely on the environment in which you are both coding the game, and running the game: since nobody in their right mind is going to try and play "minesweeper - the console game" you are presumably using a GUI of some form.

And we have no idea what kind of GUI facilities you have available, and for C ... well, it could be anything in theory!

Go back to your development environment, and look at how you are displaying your game: that will be how you need to start with your menu code!
 
Share this answer
 
Comments
average_angela 23-Dec-18 12:25pm    
hey, thanks for the answer but can you take another look at the question because i updated it.
Why does there have to be a switch/case statement? If numbers are entered then they determine the size for everything in the game. The board area would either have to be allocated dynamically or you define a maximum size and make everything that big. For example, say you make 32 the maximum dimension size. Define a board variable type of int that is 32x32. You just make all your loops extended only as far as they need to for the current board size. Also - Mr. Griff's idea of the unused board boundary is a very good one and I would definitely use it. As previously mentioned, if you fix the board to 32x32 then you will have a usable board size of 30x30 so that would be the maximum size you allow the user to enter.

I just realized that I was assuming the user entered the actual size and not a level of difficulty. You could provide both if you wanted to. You could have easy, medium, hard, and user-defined as your possibilities. As for a switch/case statement - there are four cases and only two variables to assign in each case (board size and bomb count) and I think that's pretty easy.

If this is a console application, fgets( stdin, ... ) can be used to read lines of input from the user and atoi can convert the input into an integer. Both functions have tchar and wchar equivalents.
 
Share this answer
 
Quote:
i know i can use switch case but the code is too large. is there anyway to run a certain project in code blocks from an another project? because that would totally solve my problem.

Even if your project was 100 times larger, it wouldn't be too large.
The difference between each level of difficulty is the size of minefield and number of mines, there is no way you need a second project for this.
 
Share this answer
 
When you really want to write a minesweeper game the language C isnt the best, because some graphic element with an elegant GUI would be a better result. So C++ with some framework like MFC or Gt or C# would leed to nicer results, because the have big libraries like for string handling, painting beautiful graphics and UI elements.

If you really want to use C than you should structure and design your code. I have provided some of my experiences and knowledge in the article How to start the homework.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900