Kategorier: Alle - gaming - methods - choice - results

av Gary Sibbitts 10 år siden

571

RPS class

A gaming program is designed to simulate a Rock-Paper-Scissors (RPS) game, where the user plays against the computer. The program starts by displaying a welcome message and prompts the user to enter the number of games they want to play.

RPS class

Gaming Program

Play it again Sam!

Subtopic

escape key

utilize a sentinel value that when entered exits the loop

ie: using 1,2,3 or r,p,s for throw, use 0 or x as a sentinel to exit

?what do we do with any other keys?
?data validation?

RPSChoice userChoice;
while ( (userChoice = GetUserChoice()) != RPSChoice.exit )

OR

// priming "read"
RPSChoice userChoice = GetUserChoice();
while ( userChoice != RPSChoice.exit )
{
// do stuff
userChoice = GetUserChoice();
}


or

specific continue or not prompt

user enters number of games to play

RPS class

Toolbox

get user's choice
enumerator for choices
random number generator

Members

Properties
computerChoice
userChoice
Methods
throw
play again
play game

* input - player's choice
* return the result(win,lose,tie)
* need to know the computer's choice?
* option 1 - use a property
* option 2 - out/ref parameter

RPSChoice computerChoice;
RPSResult rpsResult = rpsGame.Play(playerChoice, out computerChoice);
string txtComputerChoice = computerChoice.ToString();

constructor

Use Cases

Describe what the user does and sees from the computer

0) computer displays welcome message

1) play game

1) computer prompts user for a choice

2) user makes choice

3) computer displays the computer's choice

4) display the result

user input/throw
scissors
paper
rock
bad input
results
user loses
User wins
draw