Write a C# application that will play a simple game between two players.

The object of this program is to write this game using programmer-defined methods. You must use a minimum of 3 methods that you create and utilize.

The rules of the game are simple and are as follows:

  • Player 1 will begin the game.
  • The computer will generate a number between 1 and 10.
  • The player will input a number between 1 and 10. No unhandled exceptions should be thrown.
  • If the player's guess is within 1 number of the generated number, the player wins a point and gets another turn. For example, if the computer generates the number 3, the input values of 2, 3, or 4 will result in a win.
  • The computer will then generate another random number between 1 and 10.
  • If the player's guess is not within 1 number of the generated number, game shifts to the next player.
  • The computer will then generate another random number between 1 and 10.
  • The next player will input a number between 1 and 10. No unhandled exceptions should be thrown.
  • As long as the player continues to guess within 1 number of the generated number, the player will continue their turn.
  • After each guess is made, the computer will display the randomly generated number along with a message indicating a win or loss.
  • The score of each player is continually visible and updated as appropriate.
  • The first player to reach a score of three wins the game.
  • When the game first begins, be sure all appropriate controls are enabled and disabled as needed.
  • If it is player 1's turn, player 2 should be disabled.
  • If it is player 2's turn, player 1 should be disabled.
  • Be sure all input boxes and buttons are enabled when appropriate.
  • If it's player 1's turn, the focus should be on the input textbox for player 1. If it's player 2's turn, the focus should be on the input textbox for player 2.
  • Once the "Ready? Press to Begin" button is clicked, disable this button until the Clear button is pressed.
  • If the user clicks the Clear button, reset all scores to 0, enable the Ready button, and disable player 2.

Here's one example of the form layout:

When the game begins, both player 1 and player 2 are disabled: see image.

The user has clicked the "Ready? Press to Begin" button and Player 1 is up and made a guess of 4. Player 2 is disabled. The player now clicks the "Did I win?" button: see image.

The result: see image.

Player 1 loses. Player 2 begins (Player 1 is now disabled): see image.

When player 1's turn comes back around, the "Enter a guess" and "Computer" textboxes should be enabled and cleared. Player 2 will be disabled.

Remember, this chapter is all about using methods in your code. Any project not using at least three methods created on your own and used appropriately throughout the project will result in a project submission grade of 0.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.