CS 230 Spring 2007 Assignment 8 & 9 –
More Sub Procedures and Function Procedures and Files–
(Paparazzi
Invasion II – Celebrity Revenge Silly Simulation Game) 200
points
Assigned: 03/21/2007
Due: 04/04/2007 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. Plan out tasks, objects, and events
needed for program. Write pseudocode for the main buttons and for
functions / independent sub procedures. There’s a lot here, take it on bit by
bit, as recommended in class.
.
Main Assignment:
You are
creating a simplified but improved simulation “game”. You are now more
powerful, and so are the celebrities subject to the paparazzi invasion!
·
Write a program that
simulates the invasion by paparazzi with the player allowed to choose a defense
against them.
·
Upon loading the form
(Form Load Event), randomly generate the effectiveness of each of 5 possible
defenses against the paparazzi (do this using a independent sub procedure
called from the Form Load Event Handling Procedure for reasons that will become
clear below).
·
For the Simulate
button - Get from the user the starting number of paparazzi, difficulty level
(1-10, combo box recommended), defense of choice (combobox recommended), and
the number of months to simulate. Make sure that input values are all validated
as described below (do this using an independent function procedure called from
the button handling procedure).
·
Display in a
RichTextBox (see below) for each month elapsed, the number of months elapsed to
that point, the number of new paparazzi, the number of paparazzi eliminated and
the resulting number of invading paparazzi.
·
After the given
number of months, display in labels or read-only textboxes the final number of
paparazzi. Also, update the textbox for starting number of paparazzi (so the
player can continue the game if they like), and make it read-only. NOTE – this
task MUST be done with a loop – I need to see the month by month results in the
text box – and in order to see that, you cannot do a single one-time
calculation.
·
Provide capabilities
to:
o
simulate,
o
clear (the inputs and
outputs) to start again, and set the difficulty level to default (5), set the
current month back to the beginning, and make the starting number of paparazzi
text box no longer read only.
o
restart (clearing inputs and
outputs etc, as above, AND redo the random number generation for defense
effectiveness)
o
exit.
·
A sample interface is
provided on page 3. Don’t let that constrain your creativity. Use it to help
understand what I see as the inputs and outputs.
·
A surprise
“twist” to the project related to files will be added to the requirements on
3/28. Stay tuned! (Hence the Assignment 8 AND 9)
Hand in:
- Floppy disk or CD-R with an entire folder containing all files
related to the project (or e-mail with zipped attachment containing all
files related to the project).
- 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 8).
- Use Windows to copy the whole folder, instead of trying
to “Save As”.
- Print out of your code.
Task Details:
·
In this task, we will get
several of the benefits of procedures and functions (some will be called from
more than one place, saving code; dividing a task up into manageable sub-tasks,
making the whole easier than the sum of the tasks, and hopefully being able to
re-use existing code). You must write procedures and functions
for this assignment (and use them!):
·
Random generation of
effectiveness of defenses must be handled by a function
(hopefully called 5 times instead of once) (for details on the effectiveness,
see below)
·
Determining how many new
paparazzi will invade each month could be handled by a function (recommended).
(for details on the invasion, see below)
·
Determining effectiveness of
currently chosen defense could be handled by a function (recommended) . Use of module
scope variables is ok, since effectiveness will be determined by another button
and/or form load.
·
Validating inputs must
be handled by a function(s) (preferably one function, called more than one
time)
·
You must use an
independent sub procedure to clear textboxes etc for clear and restart capabilities
- After the user plays
the first time, set the textbox for the starting number of paparazzi to be
read only. Keep the total number of months elapsed in a module scope
variable so that it can be kept track of from button click to button
click.
- Defense Effectiveness: - provide the user 5 defenses they could
use (e.g. restraining order, body guard, …).
- I recommend letting
the user chose a defense using a combo box. Choices for a combo box can
be set using the Items property of the combo box.
- Each defense has a
different random effectiveness, so a player can change defenses in order
to try to fend off the paparazzi.
- However, these
effectivenesses do not change frequently – they are set only during form
load and when “restart” button is selected (hence the user can learn
through repeated play what defense is effective).
- The effectiveness of
a defense (number of paparazzi eliminated) is determined via calling a
function. The calculation is purposely somewhat complicated so that the
advantage of dividing up a task will be illustrated. Randomly generate
one of 100, 200, 300, 400, 500, or 600, then randomly add a value between
-10 and 10. (Think about how to do this!)
- New Paparazzi: The pace of paparazzi invasion is
different than in assignment 5.
- The number of newly invading
paparazzi is 100 times the difficulty level plus 10% of the current
paparazzi (they must reproduce some how)
- a months new
paparazzi is calculated before any elimination (or addition either). E.g.
if at the end of month 1, the number of paparazzi is 100 and the
difficulty level is 3, then the number of new paparazzi arriving during
month 2 is 310 regardless of how many are eliminated.
- The number of new
paparazzi invading must always be a whole number; you might be interested
in Math.round built in function and/ or Convert.toInt32 built in
function.
- Validation: We’re no longer going to assume that the
clerk enters valid and reasonable values.
- Ensure that the
starting number of paparazzi, difficulty level, and number of months are
numeric (and whole numbers for that matter), and
- that the starting
number of paparazzi is between 1 and 10000,
- the difficulty level
is 1-10, and
- the number of months
is between 2 and 100.
- Don’t try to
calculate anything if bad data has been entered (display a message).
- For simplification,
don’t worry about the reason that starting number of paparazzi is out of
range (if because of user error or because the paparazzi have been
eliminated or have overrun the place completely); the same message can be
used.
- Hint: If a combo box is used, a DropDownStyle
property value of DropDownList makes it impossible for the user to type
in values of their own – thus making validation unnecessary if the
choices given the user are all valid. The value selected by the user is
in the Text property of a combo box, as with other controls.
- MAKE SURE YOUR PROGRAM
WORKS! (i.e. gets the correct answers). It doesn’t have to just run, it
needs to run correctly! It should run on any inputs (We are
now branching – so the program must be tested on more inputs to ensure
that all paths through the program code work!). For instance, does your
program still do the right thing no matter how many of the inputs are
invalid? Think up some different
examples to test the program on.
Miscellaneous
- You must turn on
Option Explicit and Option Strict.
- 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. Comments are indicated with a single quote (everything
after the single quote is only for humans)
- You MUST include
comments that explain your program in order to get full credit.
- Define numbers
(especially those that appear more than once and/or could change sometime
in the futures) as named constants
- Remember to use
meaningful variable names
- Remember to indent to
show the structure of the program (VB usually does this correctly).
- Name all textboxes,
rich text boxes, comboboxes, and buttons meaningfully, and use conventions
for starting their names.
- Make textboxes that
user should never enter a value in (results / outputs) “Read Only”.
- 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. Make error messages as clear and helpful as possible!