C# Corner - Mastermind
By Mike Gold
Source Code: Mastermind

Back when C# was in its infancy, and was still in beta, Mike Gold wrote a nice little
application to play Mastermind. His original article and
original code can still be found at http://www.c-sharpcorner.com/UploadFile/mgold/MastermindMG11142005065858AM/MastermindMG.aspx?ArticleID=56bf7bcc-e6cf-461b-8a3a-dfbd180fd8e7.
The code consisted of four classes:
| Class |
Description |
| Form1 |
The main form for the application. |
| Board |
Draws the colour pegboard and calls the ScoreBoard class to draw the score peg
column. |
| ColorPanel |
Draws directly onto the form and has a routine for determining which colour is chosen by
the user |
| ScoreBoard |
Draws the score pegs. |
The code available for download above is written using C# Express and incorporates many of the
features written by Mike. It also includes new features added by myself. The code consists of nine
classes. Four classes are the same or similar to the orginals:
| Class |
Description |
| Form1 |
The form upon which everything is drawn, determines the chosen pegs and controls
whether the guess is correct or not. |
| PegBoard |
Draws the colour pegboard. |
| ScoreBoard |
Draws the score pegs. |
| LoseForm |
Displays the pegs when the player loses. |
The other five classes add rules and high scores etc to the game:
| Class |
Description |
| EntryForm |
High Score Name Entry Form. |
| HighScoreForm |
Form to display the top ten highest scores. |
| HighScoreEntry |
Simple class to store name and associated score. |
| HighScoreTable |
Handles loading and saving of high score table. |
| RulesForm |
Form to display the rules from a rtf file. |
Enjoy the game.
© Publicjoe, 2008
|