Monday 23 December 2013

Documentation and Reading in a File

I've added a lot more documentation into my program and I've started to read in a file, in this case, it's instructions.txt.

At first it wasn't working because I wasn't using try/catch but now that I've put my code into one, it builds. Now, the word "null" shows up on the screen instead of the actual instructions, which do show up in the tracing statement.

If I use an if statement that runs when null is reached, I could use break; which would stop null from being printed.

For the rest of the text, it apparently only prints the last line of it after I use if(instructionsText==null) break;

So I have to have another string variable that will store each of the lines that it prints so that it would all show up in the end when it's finished running. I put \n as well so each line is actualy showing up under the previous one instead of an ongoing line of words.

Thursday 19 December 2013

reset() continued

It works now. It actually resets when I press playButton and resetButton but it hasn't managed to reset the number of flags yet.

Wednesday 18 December 2013

reset()

I've created the reset method that sets all related variables back to their original state so the game can start all over again with mines in different places etc.

I've also created a resetButton that I put in gameNorthPane but I plan to change that to a smilie face if I have enough time. If I don't, it's just going to be reset.

The game's also supposed to reset when the user presses the playButton.

Tuesday 17 December 2013

winFlag

Now when the squares with  mines beneath them are flagged, a JOptionPane will pop up telling the user that they won! There's also a variable that's keeping track of how many flags they have left. But I didn't put an actual limit to it, since minesweeperonline.com didn't either. All that minesweeper does is continue into the negative. But by then the user would know that they've gon too far. I'm keepin git at 20, giving them a hint of how many mines there are, though there's actually less than 20.

Monday 16 December 2013

Number of Mines Surrounding Square

Now my program shows the numbers that tell us how many mines are surrounding that certain square (I have a feeling I was getting an error previously because I didn't do this part yet).

The code is very similar to the code I used to make the recursion (to reaveal the squares surrounding the square if they are not equal to 9) except that now the only thing inside the if statements is n++; to increase the total number of mines surrounding that square.

Friday 13 December 2013

Flowchart and Recursion

I started working on the flow chart today as one of my documentations. It's on paper, with a lot of arrows flying all over the place but I'm going to redo it on Smart Ideas.

Previously, my program gave me an error saying that I was going outside of the loop (when I was making the if statements for the recursion part of my program), which I tried to fix. Now when I run the program, it doesn't give me that error but there's obviously something still wrong since all the squares become revealed when I click on one of them. Which isn't supposed to happen since there are supposed to be mines randomly placed all over the 15 x 15 field.

I also made a JOptionPane that says "You hit a mine" appear whenever the user clicks on a square whose mineNum is equal to 9. Though now it simply continues to pop up even after the OK button has been pressed. Which is another error. I also need to make a reset method that I can call to reset all the mines and make all the buttons revealed=false again.