I'm currently a student in college and to get right to the point - I'm having a problem with figuring out the logic of making the program.
This is how I want my interface to look
TOP - MasterMind : Probably JLabel
CENTER - Where you set each guess to a color you want (Do I make a Panel for each spot? What should I make the spots out of? Buttons? JRadioButtons or just regular JButtons?)
WEST - Start, Retry, Solve buttons - I'll make this out of JButtons
EAST - Tells you what you did right or wrong. (I'm not sure what to use to show whats in the right spot or bad spot.)
SOUTH - Your color Choices (Make this out of JButtons? and change the background to its responding color?)
I'm working on the interface now.
Next problem I have is figuring out the logic of letting the user choose this color, place it over here.. and how the things check if you're right or wrong.
I've been thinking about this for a few days and can't seem to get my hands on what to do. Even the GUI placement confuses me. I'll update with code later on today if I get something going.
For now, I just ask for any direction to what I should do (not asking for code) My main goal here is to understand what I'm doing and not ask for handouts.
My education consist of: Tony Gaddis and GodFrey Muganda - Starting Out With Java Chapters: 1 - 11.
EDIT: Here's a handout by the teacher.
Due December 14, 2010
For your final project, you will program the game “MasterMind” game.
The game is played using:
•a decoding board, with a shield at one end covering a row of four large holes, and ten additional rows containing four large holes next to a set of four small holes;
•code pegs of six different colors, which will be placed in the large holes on the board; and
•key pegs, some black and some white, which are flat-headed and smaller than the code pegs; they will be placed in the small holes on the board.
One player becomes the codemaker (the program), the other the codebreaker (the player). The codemaker randomly chooses a pattern of four code pegs. Duplicates are allowed, so the codemaker could even choose four code pegs of the same color. The chosen pattern is placed in the four holes covered by the shield, visible to the codemaker but not to the codebreaker.
The codebreaker tries to guess the pattern, in both order and color, within ten turns. Each guess is made by placing a row of code pegs on the decoding board. Once placed, the codemaker provides feedback by placing from zero to four key pegs in the small holes of the row with the guess. A black key peg is placed for each code peg from the guess which is correct in both color and position. A white peg indicates the existence of a correct color peg placed in the wrong position.
If there are duplicate colors in the guess, they cannot all be awarded a key peg unless they correspond to the same number of duplicate colors in the hidden code. For example, if the hidden code is red-red-blue-blue and the player guesses red-red-red-blue, the codemaker will award two black pegs for the two correct reds, nothing for the third red as there is not a third red in the code, and a black peg for the blue. No indication is given of the fact that the code also includes a second black.
Once feedback is provided, another guess is made; guesses and feedback continue to alternate until either the codebreaker guesses correctly, or ten incorrect guesses are made.
You are to write a program to play the game with the computer acting as the codemaker. The color pattern should be randomly generated. You may choose which 6 colors you want to use from the color class. Use them throughout. You may also design your own screen and playing board but the same basic rules should be followed.
Your program should include:
• more than two class that you create (possible structure below)
• your own design for the layout
• a new Class not discussed in the classroom (suggestions below)
• proper use of the various classes and structures discussed throughout the semester
• features a player would expect such as rules, the ability to play again, etc. – You come up with the rest.
• Code to the dropbox including all necessary supporting files. Failure to put your code in the dropbox will result in a failing grade.
• Printouts of all classes created.
• A snapshot of your game.
• Your UML diagrams
• Standard report.
Color Management Class -- The first class I created was a class that would manage the colors chosen. This class had a field which was a Color array to keep track of the 4 colors the codemaker randomly selected. It had a constructor, a method to select 4 new colors, a method to map a number to a color, a method to compare a given color array passed in as an argument to the class’ field containing the colors and returned the number correct, a method given a color array that matched colors in the arrays that were not in the correct location and a toString method.
Color Choice Panel Class– This is the class used to create the panels for the user to select the color from. Four of these objects will be used in the main GUI class. I used fields for the radio buttons and the button group. Methods included a constructor, a method to set the backgrounds to a neutral color, a method to set all 6 radio button backgrounds to a color that is passed in as a parameter and finally an ActionListener class was implemented to set background colors depending on the radio button selected.
MasterMind Class -- This class is where the game is played. It has all of the GUI objects required to create an interface. I suggest methods to build the different panels to make the code readable. To access what colors that were selected on the Color Choice Panels you can use the getBackground method. You will need to implement action listeners. I had 6 methods to build panels and two different ActionListeners implemented. These will vary greatly depending on your design.
The main class – Creates an instance of your GUI window. A single line of code. You may use an embedded main if you prefer.
New class possibilities (note the Color class is not considered new):
• Add an image when the player wins
• Add sound
• Use a dropdown menu to have players select colors
• Use a new layout manager not discussed in the book
• NOT sure if your idea is a “new” class. Just ask.