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

Assignment Help Programming Languages
Reference no: EM131472337

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

Reference no: EM131472337

Questions Cloud

Ephesians emphasizes god action in planning : In addition to the church and love, Ephesians emphasizes God's action in planning, decreeing, and providing salvation.
Effects of public debt on income distribution : What are some real or potential effects of public debt on income distribution, economic incentives, fiscal policy, and private investment?
Review the case study of jones : Jones (appellee) signed a printed contract form agreeing to purchase a house from Long. Long also signed the form. At the time of signing, Jones also made.
How does the hundreds and thousands of immigrants : How does the hundreds and thousands of immigrants, legal and illegal from around the world that come into the United States affect the country economically.
Write a program to play the game of nim with the computer : Write a program to play the game of Nim with the computer. To play Nim, start with 15 tokens
Reflect on your practicum experiences : Reflect on your Practicum Experiences.Analyze a problem, issue, or situation that you have observed during your Practicum Experience.
Can healy legally hold bratman liable for his oral promise : Bratman, an attorney, had a client who was injured in an automobile accident and was being treated by Dr. Healy. Bratman orally promised to pay Healy.
Consumption function upward or downward : What does the textbook say are the two factors that shift the consumption function upward or downward?
Examine the concept of the johari window : Explain the importance of self-awareness in leadership development. Examine concept of Johari Window and apply this concept to your own leadership development.

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd