Mastermind Applet in Java by Gilliss Dyer January, 1997 BUG NOTE: A BLANK APPLET RECTANGLE CAN BE REMEDIED BY CLICKING SOMEWHERE IN THE RIGHT SIDE OF THE APPLET RECTANGLE. WHEN I WROTE THE APPLET, THIS PROBLEM DID NOT SHOW UP IN ANY JAVA VIRTUAL MACHINES . THE CODE WOULD PROBABLY BE FIXED BY OVERWRITING START SO THAT IT DRAWS THE BOARD. IN THIS VERSION, I ONLY OVERWROTE UPDATE AND PAINT This game is a version of the classic peg game "Mastermind." When you start the game, your computer generates a random arrangement of four colored pegs. Your object is to guess this random arrangement in eight tries, with a little help from your computer. The first thing you should do is select your difficulty. This effects the number of peg colors that the computer can choose from. In Easy level, there are 5 peg colors to choose from (and 625 possible arrangements of these colors): red, blue, green, yellow, and magenta. "Regular" adds the color cyan (giving 1296 possibilities), and "Difficult" makes blanks an option (for 2401 possibilities). When you click on [BEGIN!] to start, the answer area at the top of the board is covered. You start your guessing from the bottom row. The colored rectangles are used to select colors. You can drag pegs from the color regions to the space you want, or you can click on the color to select it, and click in the guess regions to put down pegs. You can also use the keyboard: use the first letter in the color name (space for blank) to place a peg and use numbers 1-4 or the arrow keys to select position for placement (indicated by a red dot below the board) NOTE: THE IE VIRTUAL MACHINE DOES NOT SEEM TO CAPTURE CHARACTERS IN THE ALPHABET, SO THIS DOESN'T WORK. Then, submit your guess by hitting [Return] or by clicking in the hint region. The computer puts a coded hint in the hint region to the right of your guess, and you start trying on the next row up. Assuming you're done, you can also submit your guess by placing pegs on the next row. The computer codes its hints in black and white pins. For each peg space, you get a pin in the answer region rating your answer. You get a black pin for a right color in the right place, a white pin for a color that is in the answer but that is not in the right place, and nothing for a color that isn't in the answer. These pins are not arranged in the same order as your guess; black pins come first, then come whites. Each peg is represented exactly once. If the right peg is in the right place, one black pin is added, and no whites. If you placed the same right color in the wrong place, a white pin will be added for that peg. Getting four black pins wins the game. For example, if the hidden answer is [red, green, green, green] and you guessed [cyan, cyan, green, red], the hint would be one black pin (for your guess of green in the right place) and one white pin (for your guess of red in the wrong place). If you guessed [red, red, red, red], you'd get one black pin (for the correctly placed red) and three white pins (for the other reds). Sometimes, if you are using a slow modem, the peg images may not have downloaded when you want them, even though they are tiny image files (the images are only 2k apiece). You'll know this is happening if, instead of nicely rendered pegs, you get colored dots where you place the pegs. My code instructs the compiler to load the images while you play, but some compilers still try to get it done before starting the applet. Please let me know if you have any
problems, or if you encounter any errors when you're playing this game.
Although it's not certified, I think my applet would qualify as
"pure" Java. I've tested and repaired this applet several times
under several different compilers on various computers. Every glitch I've
encountered in this final version of the game appeared to be anomalous and
mostly the fault of the compiler or the operating system. I'm always able
to resolve these problems by reloading the page. Still, I can't expose
every problem by myself. Java Links (definitely outdated)
| |