Create an applet Nim that will allow two players to play the game of nim. Initially, there are three rows of coins. During his or her turn, a player can take as many coins as desired from a single row. The rows have 3, 5, and 7 coins each. The last person to take a coin loses. Use buttons with icons for the coins. As a player clicks the button, it will become invisible. There should be a Turn over button that is visible only when a player has taken at least one coin. Use a label to let the players know whose turn it is and who has won the game.
This application makes use of icons and visibility. One interesting feature of the solution is that it uses a non-regular two-dimensional array of buttons. Each row in the array corresponds to a row of coins in the game. You will need to have a state variable that records the row that the first coin in a turn was removed from. Subsequent removals must be checked against the row. Determining which coin button was pressed is an interesting challenge. One way to accomplish this is to set the label for each of the coin buttons with its location in the array; Example: “Coin 1,3”. You will then need to parse the action command to determine what to do. This solution takes a slightly different and less efficient approach. It scans the array of buttons and checks to see if any of them is the source (uses the getSource method). This gives it the location of the button. Other than that, it is pretty straightforward.
See the code in Nim.java. The associated image is coin.jpg
You might also like to view...
When using __________ access, access to the data starts at the beginning of the file and proceeds through all the records to the end of the file.
a. direct b. sequential c. reading d. writing
If you use Remote Assistance with someone who does not have Windows 7, an invitation file is sent. the invitation file includes a ________ that is used to connect the two computers
A) help file and password B) Website address C) login and password D) password
The Adobe ____ Center is Adobe’s community forum for designers.
a. Talent b. Technology c. Photoshop d. Design
Which of the following is resistant to crosstalk?
A. 100BaseFX B. 10GBaseCX C. STP D. 1000BaseT