Step 13

Creating a reset button


Great work making it this far, we’re almost done! There’s just one more bit of code to do, we’re going to create a reset button in case we ever want to essentially restart the game.

Open up the “ControlPanel” file and start with creating a new class variable for this new button.

Next, add the code for what happens when the button gets clicked, just like with the other buttons. Here we call the “resetPlayer” function we made earlier, which will set our “Player” back to how it originally was.


Testing the reset button


With that code completed, let’s test it out! If done correctly, you should be able to click the button and reset the state of the “Player,” if not go back and check your code for errors. You may also need to resize the window to get the new button to appear.

Congratulations! The game is now complete! Amazing work getting to this point, this project was definitely not easy and you should be very proud to have made it this far. You are well on your way to becoming a Java master!

With this done, challenge yourself and see if you can come up with anything to add to this game! Modify and add onto it to really make it something unique and awesome!