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.


Thursday 28 November 2013

placeMines()

I made a placeMines method which will randomly place the mines somewhere in the mineField by using Math.Random and a do while loop which will randomly place those mines as long as mineNum isn't equal to 9 since the 9s are where there are mines and a mine shouldn't be placed over a mine. This placeMines() is then put into the game() so that it would be called whenever the user decides to play the game.

Wednesday 20 November 2013

Button2

I forgot that you can't use the same button twice in two different places... so that was the problem. I just made a second menu button and it works fine now that I've added a MouseListener to it, and added it to the mouseClicked method.
I'm also finished with the instructions frame. It includes how to play it and what the left and right mouse clicks will do when clicking on the minefield.

Tuesday 19 November 2013

Instructions

I found a problem with the gameFrame last time but it's fixed now. I've decided to just make the different frames visible or invisible, which is actually easier than what I was doing before.
My menu button isn't showing up for some reason.

Thursday 14 November 2013

Minefield

Didn't do much but set up the minefield for minesweeper.
Oh, and I also changed the JButtons to Buttons which extends JButtons. I can put info for each button in that class. It includes private variables for mineNum and revealed, which will tell me whether or not a button has been revealed yet.