I’ve made a small application for class that works like this:
- you click any button on the chessboard to start the knight’s tour from that button.
- my program solves the knight’s tour and prints out 1-64 on the chessboard for how the knight traversed the board.
Now I’m trying to implement a New Game feature. I have a menu bar, File, that has New Game in it.
I have absolutely no idea how to implement a new game where upon clicking new game, a “fresh” new board is displayed for the user to click.
Is there any built in function in java that can do this?
Thanks
It’s a bit hard without knowing how you implemented your initial game when loaded, but you call all of your initializing when the applet starts into a method, and then just call it from your action listener.
Initialize your board in empty mode (again, hard to know since I don’t know how your board is even represented, and clear all data (either create a new objects, and let GC dispose of the old ones, or give them initial value, depends on your implementation.)
Alternatively, You could just create sort of ‘reset’ method for each object (the board, the knight, etc) and just call all the resets, and redraw everything on the action listener of the menu item.
But it would help a lot to see a bit of code, or at least know how you implemented everything.
Goodluck