返回首页

Quote:

Quote:

High-Low Game

In the High-Low game, a player begins with a score of 1000 which can be used to wager on the results of a random number selection. The computer generates a random number between 1 and 13, and the player is asked to guess if the number is low (1-6) or high (8-13). Seven is considered neither high nor low, and is an automatic loss for the player. If the player guesses correctly, then the number of points wagered is doubled and added to the persons original amount. The player is then asked if they want to play again. The game continues until either the player decides to quit, in which case a farewell message is printed with the players final points, or until the player has no points left. Your task is to create a HighLow Console application which implements this game. Output should reflect the following:

High Low Game!

Welcome to the Game!

 

RULES:

Numbers 1 through 6 are low.

Numbers 8 through 13 are high.

Number 7 is neither high nor low.

 

You have 1000 points.

 

Enter points to risk: 500

 

Predict (1=High, 0=Low): 0

The computer generated a 4.

You win!

Play again? (y/n) y

 

You have 2000 points.

 

The first step you need to take is to open HighLowTemplate.cs from the shared drive (s:\CSharp) and resave it into your directory with the name HighLow.cs. It has all of the methods that you will need to define. Here is a paste from the file:

 

/* Precondition: None

* This method prints out the welcome message and rules of the game.

* Postcondition: The message has been printed to the screen.

*/

static void printRules()

{

//Type code.

}

 

/* Precondition: numPoints is a valid integer

* getWager asks the player to enter their wager. It checks the validity of

* the wager (a valid wager cannot be less than zero nor can it be more 

* points than the player currently has). The method then returns the valid 

* wager.

* Postcondition: A valid wager is returned.

*/

static int getWager(int numPoints) {

//Type code

} 

 

/* Precondition: None.

* getPrediction gets the player's prediction for high or low. The 

* prediction must be either high (1) or low (0). Validity checks are done 

* to ensure the prediction is within that range. Hence, a 0 or 1 is 

* returned from the method.

* Postcondition: 0 or 1 is returned.

*/

static int getPrediction() {

//Type code

}

 

/* Precondition: thePrediction and num are valid integers

* isWin will return a boolean as to whether or not the player has won their 

* bet. A win is defined as the following:

 

* if the player bet on low (0) and the number is less than 7, win is true

* if the player bet on high (1) and the number is greater than 7, win is 

* true

* otherwise, win is false

* 

* Postcondition: True is returned if the player has won; false is returned 

* otherwise.

*/

static Boolean isWin(int thePrediction, int num) {

//Type code

}

 

/* Precondition: The game is over.

* finalMessage prints out 1 of two messages. One is if the player has no 

* points left. A message indicating so is printed. Otherwise, the amount 

* of points is printed to the screen, with a farewell message.

* Postcondition: A message indicating no points OR points remaining is 

* printed to the screen.

*/

static void finalMessage(int thePoints)

{

//Type code

}

 

The game logic behind this game is not too complicated, and this is more an exercise for you to separate your programs into smaller methods that each executes a specific task. Code written in this way is much more manageable.

:8349150 |会员

回答

评论会员:游客 时间:2012/02/07
很抱歉,但答案是否定的。不会长久糖衣,我不关心,为他们做其他人的工作。也许别人会给你一个讲义。这可能有助于imgsrc=*虽然我应该指出,"问题"是通常的回答,但无一它几乎完全无用的,甚至尝试提供了一个答案
LanFanNinja
评论会员:游客 时间:2012/02/07
查看我在你的其他问题的解决方案,这里{A}]