![]() |
|
[C] Update on Minesweeper project - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C] Update on Minesweeper project (/showthread.php?tid=4189591) |
Update on Minesweeper project - shaggy756 - Apr 23, 2014 If you saw my thread earlier, you know that I'm currently working on a text based minesweeper program in C++. I've got a lot of the base game down but I need assistance with a few bugs and mechanics that I don't really understand. Things I need help on:
If anybody could throw in their input on what I'm missing, or would be willing to help guide me through over Skype, I'd greatly appreciate it. Really trying to get a better understanding of the language. Here's my code so far: Code #include <iostream>* - Trisomy 21 - Apr 23, 2014 For your first question: you could opt to have 2 grids, one with filled with all of the correct numbers/mines, and one filled with 'X's or some other character. When the user chooses a coordinate on the grid with the 'X's, that coordinate location is compared with the real grid and the 'X' is overwritten with the correct data. * - shaggy756 - Apr 23, 2014 That's an interesting way to look at it. I'll try that out and see what I can make of it. * - Trisomy 21 - Apr 23, 2014 (Apr 23, 2014 12:36 PM)shaggy756 Wrote: That's an interesting way to look at it. I'll try that out and see what I can make of it. You could also use a 2d array of objects as your grid. And each object will hold variables specifying its number(if it is not a mine), whether it is a mine or not, and a boolean value that switches once it is uncovered by the user. This might be cleaner than using two separate arrays but im not sure. And obviously you can use Boost.Random or the old srand() to randomize the values in each object(excluding the boolean switch). * - shaggy756 - Apr 23, 2014 Ahh I like that idea a lot more. How would I go about doing that? Would I put the array inside of the class and use a for loop of some sort? * - Trisomy 21 - Apr 23, 2014 (Apr 23, 2014 12:50 PM)shaggy756 Wrote: Ahh I like that idea a lot more. How would I go about doing that? Would I put the array inside of the class and use a for loop of some sort? No, google "array of objects". You will literally be creating an array of instances of your class. * - shaggy756 - Apr 23, 2014 Ok awesome! I'll do that now. Thanks for your help! * - 0xDEAD10CC - Apr 23, 2014 C++11 has the <random> header btw... And why would you use arrays here? Have you looked into the STL? There's some valuable containers that could be useful here. Everything is in main() too... Why? * - Z5T1 - Apr 25, 2014 You could just use a third value for undiscovered mines, eg: 0 = no mine 1 = discovered mine 2 = undiscovered mine As for the second issue, you may find managing the board much easier if you use a console UI library like ncurses instead of repeatedly printing the entire gameboard all over. You can find a really great guide on ncurses here. * - 0xDEAD10CC - Apr 27, 2014 OP: Are you paying attention to what you're writing? Beginner mistake: Code ... }while(repeat = 1); |