﻿ CS0004: Programming Project 2

# CS0004: Programming Project 2

Assigned: Final Project Due: February 8, 2007 February 21, 2007

# Overview

In this assignment, you will be implementing the game of black-jack but instead of playing with cards you will be playing the game with dice.

The game is played by two players, in your application one player will be the user and the other will be the computer (just like the paper, rock, scissors game). The game can be played with 1 or more dice but this project will focus on the use of a single die. Each player has two options during play, one they can roll the die and the other is they can stay (not roll the die). To play the game, the player rolls the die and adds the outcome of each roll to their total score. The goal is to reach a total score of 21 points. If the players total exceeds 21 the player loses (called bust). After each roll the player can chose to not roll again, once this happens its the other players turn (the computer). The computer playes the same way, with the same choices and the same constraints. Once the computer decides to no longer roll the totals of the two players are compared, and the player with the highest value that doesn't exceed 21 wins. Look at the example play for more details.

# Example #1

• Player #1 rolls, outcome is 5, total is now 5
• Player #1 rolls again, outcome is 3, total is now 8
• Player #1 rolls again, outcome is 1, total is now 9
• Player #1 rolls again, outcome is 6, total is now 15
• Player #1 rolls again, outcome is 4, total is now 19
• Player #1 decides to stay, player #2's turn
• Computer rolls, outcome is 6, total for computer is 6
• Computer rolls, outcome is 5, total for computer is 11
• Computer rolls, outcome is 3, total for computer is 14
• Computer rolls, outcome is 6, total for computer is 20
• Computer wins, because computer has 20 and player #1 only had 19!

# Example #2

• Player #1 rolls, outcome is 5, total is now 5
• Player #1 rolls again, outcome is 3, total is now 8
• Player #1 rolls again, outcome is 2, total is now 10
• Player #1 rolls again, outcome is 6, total is now 15
• Player #1 rolls again, outcome is 6, total is now 22
• Player #1 loses because he exceeds the goal of 21

# All the little Parts

Seem difficult, just remember what modular design teaches us - break difficult problems into smaller easier problems. Lets think about all the pieces you need to implement and I think it will be much easier. This is a list of some of the things you need to think about.

• You need a sub-procedure to display the die roll (We'll use use labels that have a lower-case 'l' using the windings font (which is a dot)
• You need a function to return the value of a given roll (pick a random number between 1 and 6)
• Keep the running total score for the user and computer in a variable in the class scope, so all function can access it
• Roll as the user and add the outcome to the total, determine if the user loses or not
• Reset the game (this will be a button)
• Play as the computer (this has multiple parts)
• Determine the computers next move (see computer details)

Note: this is not a complete list.

# Play like a Computer

Playing as the computer is the hard part, but we are going to keep it simple. The computer will _always_ choose to roll again if the computers total is less than 18. So the computer will play until its total exceeds 18 (did some one say a loop?)

# The Interface

The interface has two list boxes, one for the user and one for the computer. These list boxes will display the die outcome for each roll. The text boxes below the list boxes will display the total score, which is the sum of the numbers in the list boxes. The buttons will be used by the user, roll is to roll the die and add the outcome to the users list box and add it to the total. The stay button will be used when the user is happy with their total, this will trigger the computer to play. The computer will then play its turns, as described in the Play like a computer section. The stay button should also disable the buttons so the user can't click them again. The reset button will reset the entire application and the user can play again, this button should only be enabled after the computer has played. There should be a big text box at the bottom that displays the winner once a winner is known.

The grading sheet for this assignment is posted. The entire project is worth 100 points. Various items will be graded including functionality, design, proper use of form elements, code style, documentation, etc. Please note that documentation is graded, you must document your code!

# Submission

Again, there are two parts to turn in for the final project. First, you need to bring a printout of the code window to class on February 21. Second, create a zipped folder containing the entire project. Name this file Lastname_Firstname_Assignmentnumber.zip. Example: Mills_Bryan_2.zip

Don't use spaces in your filename thats just bad, not cool, and always wrong.

You then need to upload this zip file to the following location, http://www.cs.pitt.edu/~bmills/upload/ . This web page will allow you to upload your zip file only once. If you need to upload your file again add a revision number to the end of the file (ie Mills_Bryan_1_2.zip, Mills_Bryan_1_3.zip). I will grade the file with highest revision number.

Let me know if you have any problems uploading files by emailing me. I will not accept submissions turned in late some don't even try it, I have millions of little monkeys in the computer watching for late submissions.

# Extra Credit

I will offer a 10 point extra credit opportunity. If you have an idea for extra credit, email me or stop by during office hours and we can discuss it. Extra credit is added based upon the level and scope of the extra credit attempted. NO EXTRA CREDIT WILL BE AWARDED FOR ADDITIONS NOT DISCUSSED AND APPROVED!