LESSON 13 Visual Basic Culminating Assessment II

advertisement
LESSON 13
Visual Basic
Culminating Assessment II
1. Create Visual Basic Black Jack game. You are given the BlackJack Form, the list of Picture files, and
the program code. You need to be able to read the code and match it up with each object on the
form. Hint: Beconsistant with the naming of the picture files. The form doesn’t show that you can
have more than two cards for both your hand and the Computer’s hand.
Program Code
'Sets variables that will be constant throughout the game
Dim DealerScore, Card1Value, Card2Value, Score As Integer
Private Sub cmdDeal_Click()
'Sets command buttons variables
Dim Response, Card1, Card2 As Integer
Dim i As String
'Makes all the values below random
Randomize
'Starts the game with a card value of 0 then generates the random cards
Card1Value = 0
Card2Value = 0
Card1 = Int(Rnd * 12) + 1
Card2 = Int(Rnd * 12) + 1
DealerScore = Int(Rnd * 20) + 2
DPCDSB
Computer Science TIK2O1
Page - 1 -
LESSON 13
Visual Basic
Culminating Assessment II
'First card
'Makes ace = one or 11
'Generates the picture of the Ace cards and gives the score of 1 or 11
If DealerScore > 21 Then
MsgBox "You Win. The Dealer Had" + " " + DealerScore
End If
If Card1 = 1 Then
i = Int(Rnd * 3) + 1
ImgCardYou1.Picture = LoadPicture("a:\BlackJack\Ace" + i + ".bmp")
Response = MsgBox("You Have an Ace, Would You Like To Make it 11?", vbYesNo, "You Have An
Ace")
If Response = 6 Then
Card1Value = 11
ElseIf Response = 7 Then
Card1Value = 1
End If
End If
'Generates the picture of the 2 cards
'and gives the score of 2
If Card1 = 2 Then
i = Int(Rnd * 3) + 1
ImgCardYou1.Picture = LoadPicture("a:\BlackJack\Two" + i + ".bmp")
Card1Value = 2
'Generates the picture of the 3 cards and gives the score of 3
ElseIf Card1 = 3 Then
i = Int(Rnd * 3) + 1
ImgCardYou1.Picture = LoadPicture("a:\BlackJack\Three" + i + ".bmp")
Card1Value = 3
'Generates the picture of the 4 cards and gives the score of 4
ElseIf Card1 = 4 Then
i = Int(Rnd * 3) + 1
ImgCardYou1.Picture = LoadPicture("a:\BlackJack\Four" + i + ".bmp")
Card1Value = 4
'Generates the picture of the 5 cards and gives the score of 5
ElseIf Card1 = 5 Then
i = Int(Rnd * 3) + 1
ImgCardYou1.Picture = LoadPicture("a:\BlackJack\Five" + i + ".bmp")
Card1Value = 5
'Generates the picture of the 6 cards and gives the score of 6
ElseIf Card1 = 6 Then
i = Int(Rnd * 3) + 1
ImgCardYou1.Picture = LoadPicture("a:\BlackJack\Six" + i + ".bmp")
Card1Value = 6
'Generates the picture of the 7 cards and gives the score of 7
ElseIf Card1 = 7 Then
i = Int(Rnd * 3) + 1
DPCDSB
Computer Science TIK2O1
Page - 2 -
LESSON 13
Visual Basic
Culminating Assessment II
ImgCardYou1.Picture = LoadPicture("a:\BlackJack\Seven" + i + ".bmp")
Card1Value = 7
'Generates the picture of the 8 cards and gives the score of 8
ElseIf Card1 = 8 Then
i = Int(Rnd * 3) + 1
ImgCardYou1.Picture = LoadPicture("a:\BlackJack\Eight" + i + ".bmp")
Card1Value = 8
'Generates the picture of the 8 cards and gives the score of 9
ElseIf Card1 = 9 Then
i = Int(Rnd * 3) + 1
ImgCardYou1.Picture = LoadPicture("a:\BlackJack\Nine" + i + ".bmp")
Card1Value = 9
'Generates the picture of the 10 cards and gives the score of 10
ElseIf Card1 = 10 Then
i = Int(Rnd * 3) + 1
ImgCardYou1.Picture = LoadPicture("a:\BlackJack\Ten" + i + ".bmp")
Card1Value = 10
'Generates the picture of the Jack cards and gives the score of 10
ElseIf Card1 = 11 Then
i = Int(Rnd * 3) + 1
ImgCardYou1.Picture = LoadPicture("a:\BlackJack\Jack" + i + ".bmp")
Card1Value = 10
'Generates the picture of the Queen cards and gives the score of 10
ElseIf Card1 = 12 Then
i = Int(Rnd * 3) + 1
ImgCardYou1.Picture = LoadPicture("a:\BlackJack\Queen" + i + ".bmp")
Card1Value = 10
'Generates the picture of the King cards and gives the score of 10
ElseIf Card1 = 13 Then
i = Int(Rnd * 3) + 1
ImgCardYou1.Picture = LoadPicture("a:\BlackJack\King" + i + ".bmp")
Card1Value = 10
End If
'Second Card
'This code does the same as the code for card one But for card 2
If Card2 = 1 Then
i = Int(Rnd * 3) + 1
ImgCardYou2.Picture = LoadPicture("a:\BlackJack\Ace" + i + ".bmp")
Response = MsgBox("You Have an Ace, Would You Like To Make it 11?", vbYesNo, "You Have An
Ace")
If Response = 6 Then
Card1Value = 11
ElseIf Response = 7 Then
Card1Value = 1
End If
DPCDSB
Computer Science TIK2O1
Page - 3 -
LESSON 13
Visual Basic
Culminating Assessment II
End If
If Card2 = 2 Then
i = Int(Rnd * 3) + 1
ImgCardYou2.Picture = LoadPicture("a:\BlackJack\Two" + i + ".bmp")
Card2Value = 2
ElseIf Card2 = 3 Then
i = Int(Rnd * 3) + 1
ImgCardYou2.Picture = LoadPicture("a:\BlackJack\Three" + i + ".bmp")
Card2Value = 3
ElseIf Card2 = 4 Then
i = Int(Rnd * 3) + 1
ImgCardYou2.Picture = LoadPicture("a:\BlackJack\Four" + i + ".bmp")
Card2Value = 4
ElseIf Card2 = 5 Then
i = Int(Rnd * 3) + 1
ImgCardYou2.Picture = LoadPicture("a:\BlackJack\Five" + i + ".bmp")
Card2Value = 5
ElseIf Card2 = 6 Then
i = Int(Rnd * 3) + 1
ImgCardYou2.Picture = LoadPicture("a:\BlackJack\Six" + i + ".bmp")
Card2Value = 6
ElseIf Card2 = 7 Then
i = Int(Rnd * 3) + 1
ImgCardYou2.Picture = LoadPicture("a:\BlackJack\Seven" + i + ".bmp")
Card2Value = 7
ElseIf Card2 = 8 Then
i = Int(Rnd * 3) + 1
ImgCardYou2.Picture = LoadPicture("a:\BlackJack\Eight" + i + ".bmp")
Card2Value = 8
ElseIf Card2 = 9 Then
i = Int(Rnd * 3) + 1
ImgCardYou2.Picture = LoadPicture("a:\BlackJack\Nine" + i + ".bmp")
Card2Value = 9
ElseIf Card2 = 10 Then
i = Int(Rnd * 3) + 1
ImgCardYou2.Picture = LoadPicture("a:\BlackJack\Ten" + i + ".bmp")
Card2Value = 10
ElseIf Card2 = 11 Then
i = Int(Rnd * 3) + 1
ImgCardYou2.Picture = LoadPicture("a:\BlackJack\Jack" + i + ".bmp")
Card2Value = 10
ElseIf Card2 = 12 Then
i = Int(Rnd * 3) + 1
ImgCardYou2.Picture = LoadPicture("a:\BlackJack\Queen" + i + ".bmp")
Card2Value = 10
ElseIf Card2 = 13 Then
DPCDSB
Computer Science TIK2O1
Page - 4 -
LESSON 13
Visual Basic
Culminating Assessment II
i = Int(Rnd * 3) + 1
ImgCardYou2.Picture = LoadPicture("a:\BlackJack\King" + i + ".bmp")
Card2Value = 10
End If
lblCardValue = Card1Value + Card2Value
End Sub
Private Sub cmdExit_Click()
'End Program
MsgBox "Thank You For Playing", vbOKOnly, BlackJack
End
End Sub
Private Sub cmdNewGame_Click()
'This code lets you reset the game.
lblCardValue = ""
ImgCardYou1.Picture = LoadPicture("a:\BlackJack\CardBack.bmp")
ImgCardYou2.Picture = LoadPicture("a:\BlackJack\CardBack.bmp")
End Sub
Private Sub cmdStay_Click()
'This Code finalizes the score and see if you win or not & tells you what the dealer had.
If Score < DealerScore Then
MsgBox "You Lose. The Dealer Had" & " " & DealerScore
elseIf Score > DealerScore Then
MsgBox "You Win. The Dealer Had" & " " & DealerScore
elseIf
MsgBox "You Lose. The Dealer Had" & " " & DealerScore
End If
End Sub
Private Sub Form_Load()
'This code starts the form with the pictures of the back of the card.
ImgCardYou1.Picture = LoadPicture("A:\BlackJack\CardBack.bmp")
ImgCardYou2.Picture = LoadPicture("a:\BlackJack\CardBack.bmp")
ImgCardComp1.Picture = LoadPicture("a:\BlackJack\CardBack.bmp")
ImgCardComp2.Picture = LoadPicture("a:\BlackJack\CardBack.bmp")
End Sub
Private Sub Form_Unload(Cancel As Integer)
MsgBox "Thank You For Playing", vbOKOnly, BlackJack
End Sub
DPCDSB
Computer Science TIK2O1
Page - 5 -
LESSON 13
Visual Basic
Culminating Assessment II
Final Projects Suggestions
1. Cafeteria Selections Program. This program would permit students to choose their lunch purchases
from a menu in the cafeteria. It would calculate the tax on taxable items (candy, pop), and present the
user with a total. The program would accept a tendered amount and compute and output change
down to the actual coins and bills involved. An added inventory component could keep a running total
of individual items purchased.
2. Nutrition or Not Nutrition - That is the question! Our nutrition program again deals with some of the
food choices served at a regular school cafeteria. This program would analyse the nutritional value
of what students are buying for lunch by way of a cafeteria menu selection system. Important
nutritional values could be kept track of such as amount of fat, caloric count, protein, etc. and
reported to the student after the purchase. The program could track on a weekly or monthly basis
these nutritional totals for the student and print out reports regarding trends it finds that are both
healthy or suspicious.
3. Mathematical Quiz Show. A program is required for the Mathematics department. It will simulate
quiz shows seen on television to deliver short answer questions on a range of topics as determined
by the category selections. Student teams would participate in playing the game much as it is played
on TV. At the end, one of the teams is declared the winner.
4. Tic-tac-toe. The children's game of Tic-Tac-Toe can be played between either a player and the
computer or between two players. This will likely involve the use of arrays and therefore should be
considered somewhat challenging for the average grade 10 student.
5. Trivia Game. Students enjoy programming board games. A trivia type game can be adapted to a
computer screen with some modification for the grade 10 level. Banks of questions can be replaced
by randomly chosen mathematical questions if desired. Otherwise, a bank of questions can be stored
in a disk file. Pieces can be moved on a game board rather easily if programming in Visual Basic but
will require some ingenuity in text based languages.
6. Game of Life. The well-known Game of Life board game has been in existence for decades now.
Living objects on the screen either survive to the next cycle and reproduce or perish according to a
set of rules based upon where neighboring objects are located. The full set of rules is available on
the Internet. Go and get it. It makes for an interesting program.
7. Edit your Black Jack game to include another aspect of the game. Players normally have a chance
to say “Hit Me” if they want a third card to add to their score. The player would typically stay with any
score 16 or more. A score of less than 16, the player tries their luck for another card hoping to get
close to 21 without going over. A second item that should be changed is the way that the computer
gets it’s hand (score). Presently the method does not truly reflect the odds for the house (computer’s
hand). Making these two changes to the Black Jack game must follow the rules of the game.
Research the rules of the games, if you need to.
DPCDSB
Computer Science TIK2O1
Page - 6 -
LESSON 13
Visual Basic
Culminating Assessment II
Final Programming Project Guide
Define the Problem
Prepare a statement, written in his/her own words, explaining what the problem involves and briefly
describing how he/she intends to solve this problem, that is to say, what algorithm will be used. This brief
prospectus will be presented to the teacher for approval before moving on to the next step.
Plan the Solution
Prepare an IPO chart or similar planning device according to the input-processing-output model. The
teacher may want other flowcharts for certain parts of the algorithm. This planning stage again must be
presented to the teacher for approval. To save class time for computer coding work, most of this
planning should be carried out at home. The teacher may require more specific detail in the form of
pseudo-code or a top down flowchart showing the various procedures and their relationships. Again, the
student does not move to the computer until this planning stage has been completed to the teacher's
satisfaction.
Code the Solution
Begin coding the solution into the computer, one procedure at a time, testing, debugging syntax and logic
errors, and validating each component. The student must supply generous comments throughout
including an identification header block. You will use the standards that have been given, Commenting,
Naming and Usage The student must ensure that all inputs/outputs are clear, unambiguous and conform
to the original program design. All names for variables, constants, and procedures must be descriptive in
nature. All decisions and loops must conform to the original algorithm and show proper indentation and
use of white space to improve readability.
Test the Solution
Fully test the entire program once most of the coding has been completed. Students will ensure that
sufficient and diverse test data is used to provide for a comprehensive checking of all components,
especially how they relate to one another. In addition, while testing, students must ensure that output
results are valid for all inputs. Checking results with calculators or pencil/paper calculations is a vital step
at this point. Students should complete a data test worksheet, documenting all test data used and results
obtained. Finally, students must bullet-proof all user inputs against the infamous "garbage-in-garbageout" problem. Challenge other students to crash the program and note the necessary code must be
included to render the program crash resistant.
Student should document the testing procedure.
Document the Solution
Complete the documentation phase of the project, now that it appears to operate successfully. Students
will ensure that all internal comments have been clearly worded and provide the necessary information.
Students may wish to critique the documentation of other programs in the class for clarity and usefulness.
Teachers may require that students prepare a word processed document critiquing the shortcomings of
the solution in terms of limited functionality and crash resistance or suggesting possible enhancements in
design to make the product more user friendly. The intent is to generalize the solution as much as
possible. Having the student critique his own work in this manner should be a useful exercise.
DPCDSB
Computer Science TIK2O1
Page - 7 -
LESSON 13
Proposal Rubric
Level
Expectations
Defines the
problem in terms of
required outputs,
necessary inputs
and steps required
to produce the
result
TFV.01K
TF1.01K
TF1.03K
Able to state a
problem clearly
SPV.01K
SP1.01K
Identifies and
provides all
information required
SP1.02K
Visual Basic
1
2
3
4
Two components
of the input,
process and
output model is
not complete
One component of
the input, process,
output model is
not complete
Expresses the
proposal in terms
of required results,
the process
required to reach
these results and
the necessary
inputs
Clearly expresses
the proposal in
terms of required
results(output), the
process required
to reach these
results and the
necessary inputs
Problem is not
stated clearly,
major
improvement
required
Information is
missing and or
ambiguous
States problem,
some
improvement in
wording required
States problem
clearly, minor
points need
clarification
States problem or
situation clearly
Some information
is missing
All relevant
information has
been identified
and provided
All information is
identified and
provided
2
Some modification
needed to design
of method of
obtaining
information from
the user
3
Has designed a
method of
obtaining
information from
the user
4
Has designed a
clear and concise
method of
obtaining
information from
the user
Has specified and
classified most of
the information
that must be
stored in the
program
Has specified and
classified correctly
information that
must be stored in
the program
Has specified and
classified correctly
information that
must be stored in
the program. Only
necessary info has
been chosen
Progress Report Rubric
Level
1
Easy to understand Significant
user interface
modification
needed to design
SP1.03K
of method of
obtaining
information from
the user
Has identified the
Has specified and
required information classified little of
to be stored as
the information
variables
that must be
stored in the
SP3.02P
program
DPCDSB
Culminating Assessment II
Computer Science TIK2O1
Page - 8 -
LESSON 13
Visual Basic
Culminating Assessment II
Final Program Rubric
Level
Uses input and
output statements
correctly
SP3.04K
Uses programs
structures as
required by
program design
SP 3.08K
Uses selection
structures correctly
SPV.04K
SP3.05K
SP3.06K
Uses repetition
structures corrrectly
SPV.04K
SP3.07K
SP3.08K
Completes internal
comments & follows
defined standards
SPV.03K,SP3.09
Finds program
errors
SPV.03K
SP3.10K
Validates program
results
SPV.03K,SP3.11K
Follows descriptive
naming conventions
SP3.03K
DPCDSB
1
2
Major
improvement
needed in use of
input and output
statements
Program
structures are not
complete and/or
improvement
needed in use
Major
improvement
needed in
construction and
use of selection
structures
Major
improvement
needed in
construction and
use of selection
structures
Little use of
documentation
and following of
local standards
Program has
many errors, little
or no evidence of
testing
The program
produces few
correct results
Rarely uses
descriptive naming
conventions
Some
improvement
needed in use of
input and output
statements
Most program
structures are
complete, some
improvement
needed in use
Some
improvement
needed in
construction and
use of selection
structures
Some
improvement
needed in
construction & use
of selection
structures
Some use of
documentation
and following of
local standards
Program runs with
some errors, some
evidence of testing
The program
produces some
correct results
Some variable
names are not
descriptive
3
4
Minor
improvement
needed in use of
input and output
statements
All program
structures are
complete, minor
improvement in
use required
Constructs and
uses selection
structures
correctly
Uses correct input
and output
statements
correctly
Consistently
constructs and
uses repetition
structures
correctly
Consistently
constructs and
uses repetition
structures
correctly
Most program
components are
documented to
local standards
Program runs with
minor errors, a
testing log is
provided
Most run
situations provide
correct results
One or two
variables names
are not descriptive
All program
components
documented to
local standards
Program runs
error free and a
record of testing is
provided
All test runs of the
program produce
correct results
Always uses
descriptive
variable names
Computer Science TIK2O1
All program
structures are
complete and
make sense
Consistently
constructs and
uses selection
structures
correctly
Page - 9 -
Download