C# Corner - Yahtzee

By Mike Gold


Source Code: Yahtzee

Back when C# was in its infancy, and was still in beta, Mike Gold wrote a nice little application to play Yahtzee. His original article and original code can still be found at http://www.c-sharpcorner.com/UploadFile/mgold/yahtzee211142005051513AM/yahtzee2.aspx?ArticleID=0a2d8fcf-24d0-4e6e-9a91-914996b2ae50.

I could never get the code translated from the beta version to version 1. So I decided to write my own version based upon some of the concepts in Mike's code. The main concepts I used were to write a control to draw the dice, and break the code up in a similar manner.

The code available for download above is written using C# Express. The code consists of eight classes:

Class Description
Form1 The form upon which everything is drawn. Controls the main flow of play.
CalculateScore Calculates the score of the dice and checks that it is valid for the score bein assigned to.
Dice User control to display and control a single die.
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.


<< Mastermind Contents Snake >>

© Publicjoe, 2008