Sie sind auf Seite 1von 3

CS105 - Computer Programming in C# - Assignment #2 http://userweb.cs.utexas.edu/~kuhlmann/cs105/assignment2.

html

CS105 Assignment #2
Windows GUI Programming in C# Spring 2007

Assignment #2 - Windows GUI Programming in C#

Due: Wednesday, February 14 at 11:59pm

This assignment is intended to give you experience in event-driven programming and Windows GUI
applications in C#.

Yahtzee

Your task in this assignment is to create a Windows application for the game of Yahtzee. Yahtzee is a dice
game that can be played by any number of players. You will be implementing the single-player version of
the game.

You can find the rules for Yahtzee online here:


http://en.wikipedia.org/wiki/Yahtzee

These are the rules that should be used for scoring with the exception of the rules regarding multiple
Yahtzees. After the first Yahtzee has been scored, additional Yahtzee will only be given the points for the
category in which it is used. Yahtzees cannot be used as jokers and will not be awarded 100 point bonuses.

GUI Design

The game is to be implemented as a Windows GUI application. The interface should resemble the
following screen shot (click for demo):

You may create the application completely in code if you choose, but it is recommended that you use
Visual Studio's Form Designer to lay out the interface.

1 of 3 28-08-2010 17:34
CS105 - Computer Programming in C# - Assignment #2 http://userweb.cs.utexas.edu/~kuhlmann/cs105/assignment2.html

The form window must include a visual representation of the 5 dice that are rolled throughout the game.
The dice must use the dot representation as shown in the screen shot, however you may display them in
any color(s) you like. The dice should be displayed as bitmap images in PictureBox controls. When the
application begins, the dice should all display blank faces (no dots). To make your life a little easier, a zip
file containing 56x56 bitmap images for the six die faces and a blank face can be found here.

To make use of these images, you will first have to import them into your project as resources. To do this,
with your project open, click on the "application name Properties..." item from the "Project" menu. Select
the "Resources" tab. Change the resource type to "Images". Then "Add a Resource", "Add Existing
File...". You may add each bitmap image one by one, or you may add them all at once by highlighting
them all and clicking "Open". Close the resources menu. Now, for each of the five dice, create a
PictureBox control on your form. You can set the image to be displayed by setting the "Image" property
of the PictureBox control. A variable will be created for each die face image that is imported. To access
the sixth face image from you code, for example, you refer to it as "Properties.Resources.six". Hint: I
highly recommend creating an array or collection to store these resources, so that you can refer to them
by indexing into the collection with the integer matching their face value.

There should be a checkbox next to each die that when checked holds the die so it will not be re-rolled. If
you so desire, you may replace this hold mechanism with something more fancy like clicking the dice and
having them change state, as long as it clear to the user whether a die is being held or not. When the dice
are rolled, the hold checkboxes (or other visual hold representation) should be reset so that no dice are
held. The checkboxes (hold mechanism) should be disabled under the following three conditions:

1. the user has completed his third roll in that round and therefore may not re-roll anymore
2. the dice are in the middle of rolling
3. the current game has ended or has not yet begun

What is meant by "disabled" is that the Enabled property of the control is set to false.

The form must also include a button that when clicked rolls the dice. The button should be disabled under
the following three conditions:

1. the user has selected all 5 hold checkboxes


2. the user has completed his third roll in that round and therefore may not re-roll anymore
3. the dice are in the middle of rolling

Finally, the form must include three scoring sections: upper, lower, and grand total score. The upper
section should include read-only textboxes to display the scores for each of the six categories. The text in
the box should be blank at the beginning of a game and only filled in with the score after the category has
been selected to score that round. Next to each box, there should be a button with the name of the
category. When the user clicks on the button, the score for the corresponding category is calculated for
the current dice configuration, then the dice are rolled to begin the next round (with the exception of the
final category selected). If the user clicks on the button for a category that has already been scored, it has
no effect. The category buttons should be disabled under the following three conditions:

1. the application has just started


2. the dice are in the middle of rolling
3. the current game has ended or has not yet begun

They become enabled when the roll button is clicked to begin the next game.

The upper section should also include read-only textboxes and accompanying labels for the Total Score
(subtotal), 63+ bonus, and upper total. These textboxes should remain blank until all six categories in the
upper section are scored.

The lower section should behave in the same way as the upper section.

2 of 3 28-08-2010 17:34
CS105 - Computer Programming in C# - Assignment #2 http://userweb.cs.utexas.edu/~kuhlmann/cs105/assignment2.html

The grand total section should contain read-only textboxes and accompanying labels for the upper total,
lower total, and the sum of the two. Again, the textboxes should start off blank. The upper and lower
totals should each be filled out when the respective section is completed. At the end of the game, the
grand total appears in the grand total box, and the game simply waits for the roll dice button to be clicked
to start a new game.

When a dice roll is initiated by either the roll dice button or by one of the category buttons, the dice
should change to a new random configuration. The change should not happen immediately, however.
Instead, the dice should change through a series of random configurations before settling on the final
configuration, thereby simulating the look of a real dice roll. The roll should cause the dice to pass through
roughly 5-15 configurations in 0.5-1.5 seconds. Hint: Use Timer and Random. To reinforce what was
stated previously, all buttons and checkboxes should be disabled while the dice roll is taking place.

Extending the assignment

For those looking for a challenge, you may consider extending the game to allow for multiply players.
Another idea would be to keep track of high scores. And of course, there's plenty that could be done to
make the interface more attractive.

Grading

The main grading criteria for this assignment is that it meets the specification for both the rules of the
game and the behavior of the interface. As in the previous assignment, coding style is also important. To
receive full points for coding style, the code should be well-organized, algorithms should be implemented
in a reasonable way and C# naming conventions should be followed. To the best of your ability, you
should separate the rules and play of the game from the interface in your implementation.

Submission

Please submit a zip file called "Assign2.zip" containing the project directory as well as the .sln file. The
names of the internal files are up to you. The project directory should contain all of the source files and
resources necessary to compile the program. By extracting the zip file and double-clicking the .sln file, the
project should load into Visual Studio. You do not need to include any debug or release binaries. In fact,
including these files may make your zip file very large, so please avoid it. To clarify, the submission should
be laid out in the following way:

Assign2.zip
MySolution.sln
MyFolder
Program.cs
MyForm.cs
MyForm.Designer.cs
...resources, etc...

Last Modified Wed Jan 31 18:16:40 CST 2007

3 of 3 28-08-2010 17:34

Das könnte Ihnen auch gefallen