Use of Objects and Classes and GUI components
Instructions
For this lab you will need to recreate the game of NIM from lab2 using classes and a graphical user interface. A player class should be created that will encapsulate the properties and behaviors of a player in the game. The Player class should be able to be used for both computer and human players and should include the pile (number of stones remaining) as a data member as well as methods for executing a human player's move and the computer player's move (call them move( int s ) and automove( )).
The interface for the game should consist of:
- Three dialog boxes - one to allow the user to enter the number of stones to start with, one to allow the user to select who goes first in the game, and the last to announce the winner of the game.
- Two JButtons - one for taking one stone, the other for taking two stones.
- Two JTextAreas - one for displaying the moves of the game and the other for showing a representation of the stone pile.
- Any additional components (JScrollPanes, JLabels, etc.) that are needed can be added at your discretion.
Example:
Your version of this program, because it is an application, not an applet like the example given above, does not require a 'Start Game' button. I included this in the applet version because without it, you would have been required to play a game every time you visited this page.