Assignment - Red Yellow Green Game

Game Description

A simple guessing game is the red-yellow-green game. It is a two person game where one person picks a number between 100 and 999 and the other person tries to guess it. Every time a guess is made, the picker responds to the guesser by telling them the number of red digits, yellow digits and green digits in the guess.

A guess digit is a green digit if the guess digit and the corresponding answer digit are the same and in the same position. A guess digit is a yellow digit if the digit is in the secret number, but it is not in the right position. A guess digit is a red digit if it is not any of the digits in the secret number. Suppose the secret number is 123 and the guess is 422. The reply would be one red, one yellow and one green. The initial guess digit, 4, is a red digit because it is not 1, 2, or 3. The middle guess digit is green because it matches the corresponding answer digit. The final guess digit, 2, is a yellow digit because 2 is in the number, but it is not in the final position.

When supplying the red-yellow-green information in response to a guess, the reply gives the number of red digits first, the number of yellow digits next and then the number of green digits. By giving totals only, the game is made harder. Suppose the answer is 492 and the guess is 249; the picker would reply zero red, three yellow and zero green.

Requirements

·         The goal of the game is to guess the secret number in the lowest number of guesses possible, therefore, your game should display the number of guesses that the guesser has already used in the status bar.

·         When your user wins the status bar should tell them they have won.

·         There should be a button that allows the guesser to get a hint. The hint should display the secret number in the status bar. This is for marking and testing purposes only and wouldn’t be included in a real game.

·         There should be a button that allows the guesser to play again. (New Secret Number)

·         Comments should appear before ifs and loops and other major sections of code.

·         Code should be properly tabbed in and have white space throughout it.

·         The only textbox should be the one that allows the user to enter a guess.

·         You must use fonts and panels.

·         You need the following functions:

·         public int red (int guess)

·         public int green (int guess)

·         public int yellow (int guess)

·         public int win (int guess)

·         public void hint ()

The red method would be coded as follows:

public int red (long guess)
{ //divide guess into digits
long g1 = guess / 100;
long g2 = guess / 10 % 10;
long g3 = guess % 10;

//divide the secret num into digits
long s1 = secretnum / 100;
long s2 = secretnum / 10 % 10;
long s3 = scretnum % 10;

//make a counter to count the red digits
int r = 0;
if (g1 != s1 && g1 != s2 && g1 != s3)
r++;
if (g2 != s1 && g2 != s2 && g2 != s3)
r++;
if (g3 != s1 && g3 != s2 && g3 != s3)
r++;

//return the number of red digits
return r;
}

Planning

·         Before you start coding your program, you should decide what each of the buttons is going to do.

·         Write out the things each function will do on a piece of paper before you get started.

·         Because this will be used to mark your communication skills, pay attention to spelling and grammar. You do not need to write in complete sentences.

·         Plan your user interface on paper too.

  

Random Numbers

This code generates a secret number between 100 and 999 and puts it in the variable secretnum. You will need to import java.lang.Math

long secretnum = Math.round(Math.random()*1000);

        while (secretnum < 100)

        {secretnum = Math.round(Math.random()*1000);}

Red Yellow Green Game (Rubric)                                                  Name: ________________

Content (Application)                                                                                                            /35

RYG

            /10

Red, Yellow and Green values are correct.

Red and Green are correct.

One of red or green is correct.

No RYG values are correct.

GUI

           /10

All labels are changed colour. Background colour is changed. Font is changed. Nested Panels.

All labels are changed colour. Nice instructions. Panels.

Some labels are changed colour. Order of widgets is odd.

No labels are changed colour. Little effort to explain game to user.

Status Bar

           /3

Whenever a button is clicked, status bar changes.

When most buttons are clicked, the bar changes.

Status bar changes sometimes.

Status bar never changes.

Guesses

          /5

User gets a winning condition. Counting guesses.

Counts guesses or winning condition.

Problems.

No evidence of counting or winning conditions.

Methods

         /7

One item per method. Returns values as instructed.

Sometimes more than one function per method.

Return values not used correctly.

Major problems or not used.

Style (Communication)                                                                                                        /10

Comments

             /8

3 title comments. Excellent spelling and grammar. Comments before sections.

3 title comments. Comments before most sections of code.

3 title comments. Some comments.

None.

Space,Tab

             /2

White space before major sections of code. Code is tabbed well.

Some white space/tabbing errors.

Many white space/tabbing errors.

Code is extremely difficult to read because of lack of white space and tabbing.

Planning (Inquiry)                                                                                                                 /5

Paper

             /5

Each button is clearly described. It is ready to be implemented.

The 3 buttons are described. More detail is necessary

Vague. Not ready to be implemented.

None.