CS 230 Fall 2009
Assignment 8 – Procedures/Functions and More Looping and
Branching – Craps!
100 Assignment Points
Assigned: 11/02/2009
Due: 11/09/2009 at the start of class
Pre-Lab (Do Before Lab): Bring materials – a way to
save a copy for you and a copy to turn in. Read through the whole assignment;
hints and details are spelled out throughout. Plan out tasks, objects, and
events needed for program. Think about the main function’s pseudocode / flow
chart.
Main Assignment Description:
We’re
going to implement a simplified “craps” game. We will only use one of the many
kinds of bets that can be made in craps – see below. Provide the capability to:
·
Play one game
·
Play a bunch
of games without user intervention
·
Reset –
clearing the results to start again
·
Exit
Show
how each game goes (details) in a rich text box. Keep a running tally of wins
and losses in text boxes (read-only of course) or labels.
Please
set the name of the project to something other than the default name (WindowsApplication1, …). It
is helpful if you use a name that identifies you as well as the assignment
(e.g. yourlastname assignment 7).
Background Knowledge:
·
The form of craps we are
playing goes by the following rules:
Roll
·
7 or 11 wins
·
2,3, or 12 loses
·
Anything else – becomes “point” – new target – keep rolling
After that
·
7 – loses (NOW, 7 is BAD)
·
“Point” – wins
·
Anything else – keep rolling (does NOT change “point”)
Any questions, please ask!!! Even if you’ve played different variations,
the above is what we’re playing here.
Task Details:
- Roll dice with a “pseudo” random number generation, as we have done
in class. If you make the random number generator have a “module scope” –
i.e. declared at the top of the module, then the one declaration will make
it available in all procedures/ functions. E.g.
Public Class Form1
Dim randGen As New Random
…
- As dice are rolled,
show results in the rich text box (what the individual dice were, and
the total)
- In this assignment,
when “keep rolling” don’t rely on the user doing anything – keep rolling
for them
- For “Play One Game” (don’t
do for “play a bunch of games”!!!):
- When there is a
winner or loser, notify the user and
- When the user plays
again, make sure to clear the rich text box so that previous dice rolls
are not in the way.
- For both “Play One
Game” AND “Play a Bunch of Games”
- update the tally of
wins/ losses
- The only user entered
value is how many games to play when the “play a bunch of games” button is
clicked
- The number of games
should be validated when “play a bunch” is selected to ensure that it is a
number, and is between 2 and 10,000 (inclusive). Don’t try to play if bad
data has been entered (display a message).
It
is recommended that the validation be done via calling a function!
·
This
assignment is intentionally designed to reward use of procedures/functions –
playing a game is basically the same in playing one game or in playing a bunch
of games. Write a function that can be called from each! This is
required as the #1 focus of this assignment is on functions. Doing
this will also avoid the need to use nested loops!
·
HINT # 1:
anything that needs to happen in one and not the other probably shouldn’t be in
the procedure/ function.
·
HINT #2:
return a Boolean indicating if the player won or not – this will allow the Play
one game caller to display a message while the play a bunch of games doesn’t
display a message (which would be very annoying if you played
1000 games)
·
HINT #3: you
might try writing the code for “Play One Game”, then when that works move it
into a function and make it work for both “Play One” and “Play Bunch”
- MAKE SURE YOUR PROGRAM
WORKS! (i.e. gets the correct answers) - it doesn’t have to just run, it
needs to run correctly! Now that our program is branching, we
need to try more examples to make sure that they work. We want all paths
through the program to work correctly. Think, “what different
possibilities need to be checked?”For instance, does your program do the
right thing no matter how long it takes to win or lose?
Miscellaneous:
- Play it safe - save
your work before running your program. It is possible that an “infinite
loop” could have to be terminated. Usually that will be ok, but if you
ever had to kill VB using the task manager it is possible that you could
lose unsaved work.
- You must turn on Option
Strict and Option Explicit
- Put YOUR NAME, e-mail
address, date, and purpose of the program in comments at the beginning of
the program. The purpose should be what the program is supposed to do, not
the learning goals.
- You MUST include
comments that explain your program in order to get full credit.
- Name all textboxes,
rich text boxes and buttons meaningfully, and use conventions for ending
their names. Also, any labels referred to in code should also be named
meaningfully.
- Any variables that you
declare should have meaningful names – descriptive of the data that they
hold.
- Make any textboxes and
rich text boxes that user should never enter a value in “Read Only” (or
use labels instead of textboxes!)
- Put your name on
the form as a Label or as part of the form title.
- Try to use good user
interface design. Make clear what user needs to do and what the answers
mean.
Hand in:
- Compressed (zipped) folder with your entire project containing
all files related to the project, submitted to Blackboard. Please
name the zip file something along the lines of yournameAssignment8
- Print out of your code.