Write a program to play the game of nim with the computer


Part A -

Write a program to play the game of Nim with the computer. To play Nim, start with 15 tokens. Each player takes from one up to a maximum of three tokens at each turn, and the player taking the last token loses. Randomly choose whether the user or the computer moves first. At start up, display all the tokens. When it is user's turn, display a prompt message to ask the user to select his/her tokens. Let the user select a token with a mouse click, which should cause the token to be erased. When finished selecting tokens, the user should press the D key. Make sure the user never selecting more than three tokens. The computer should print a message stating how many tokens it chooses, and these tokens should be erased. When the game is over, display a message announcing the winner. User may press the N key to start a new Game.

You may implement an easy version. Instead of playing against the computer, two players play each other.

Help:

Using an array of bool type called cleared to hold 15 bool value and all initialized to false. Using a bool variable called turn. If turn is true means, it is first player's turn otherwise it is second player's turn. Every time there is a mouse click, locate the index where he/she clicked. If it is a painted square and the user has not clicked more than 3 times, set the cleared array at the index to true, call invalidate to repaint then the square will be cleared. Every time, a D key is pressed, check for winner. If there is one token left, whoever has the turn loses. If there is no token left, whoever has the turn wins.  When the user pressed N key, reset all variables.

Part B -

Create a TipCalculator like

Amount

 

Tip (%)

 

Split

 

Total (per Person)

 

Left four are labels. The last one on the right is also a label. Other three are textboxes.

Initially set Tip as 15% while user can modify it.

Initally set Split as 1 while allow user to modify it.

You should catch click event in each one of them. Any time one of the boxes makes a change, adjust the total

For Example, it may look like

Amount

40

Tip (%)

15

Split

2

Total (per Person)

$23

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: Write a program to play the game of nim with the computer
Reference No:- TGS02267903

Expected delivery within 24 Hours