![]() The simple way to do this is to have a "been expanded" flag that you set when you have called Expand neighbours on a square, and clear the flag from all squares on the board after the ExpandNeighbours recursion has finished. You need to mark a square as having been expanded this turn though, and not call the function for a square you have already expanded. ![]() Then, if you find a 0 neighbours square during the call to this function, call it again FROM WITHIN THAT FUNCTION for all of the neighbours of that square too. ![]() Put this in a function called ExpandNeighbours or something. First, get it working so it just expands all the neighbours correctly. The "expand all blank squares" if you click on a "0" neighbouring bombs square involves recursion. You have to use a special flag on the borders so the program doesn't think it's a blank or a bomb or a flagged square. The other way is to have a board with a border around it that isn't drawn, so the board will be (num rows + 2) by (num columns + 2) big. you can used a signed value for the row and column check and do nothing if it is less than zero or greater than or equal to the number of rows (or columns, depending on whether you are checking x or y coordinates) - assuming 0,0 is one of the corners and (num rows-1),(num columns-1) is the opposite corner. There are 2 ways to avoid going off the board. It looks like find_mines could accidentally access outside the bounds of the board.Īs for times, you will need to use functions from time.Good choice for a first game, my first C game was a minesweeper for Unix when I was on a programming course. Maybe make a function, clear_board, that does this for whichever board it is passed. The first part of setup_mines and the whole of build_user_board are both setting an entire board to dashes. You're placing one mine randomly in each row. ![]() ![]() Make a single function and pass in the board you want to print. You don't need separate print_board, print_user_board functions. Maybe get rid of the separate win and loss functions and make a single function called play_again (as this is almost the entire content of both). Void getInfo()Actually, I would've expected the board(s) to be defined in main and passed into the funcions instead of being a global. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |