19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

End Sub<br />

Private Sub cmdDropBomb_Click()<br />

bomb.GoDown bomber, frmPlanes.Height<br />

End Sub<br />

Private Sub cmdQuit_Click()<br />

End<br />

End Sub<br />

[Run, press the Move button twice, <strong>and</strong> then press the Drop Bomb button.]<br />

EXAMPLE 2<br />

Write a program to deal a five-card poker h<strong>and</strong>. The program should have a deck-of-cards object containing<br />

an array of 52 card objects.<br />

SOLUTION:<br />

Our card object will have two properties, Denomination <strong>and</strong> Suit, <strong>and</strong> one method, IdentifyCard. The<br />

IdentifyCard method returns a string such as “Ace of Spades.” In the DeckOfCards object, the Initialize<br />

event procedure assigns denominations <strong>and</strong> suits to the 52 cards. The method ReadCard(n) returns the<br />

string identifying the nth card of the deck. The method ShuffleDeck uses Rnd to mix-up the cards while<br />

making 200 passes through the deck. The event Shuffling(n As Integer, nMax As Integer)<br />

is triggered during each shuffling pass through the deck <strong>and</strong> its parameters communicate the number<br />

of the pass <strong>and</strong> the total number of passes, so that the program that uses it can keep track of the<br />

progress.<br />

‘Class module for CCard<br />

Private m_Denomination As String<br />

Private m_Suit As String<br />

Object Property Setting<br />

frmPokerH<strong>and</strong> Caption Poker H<strong>and</strong><br />

picH<strong>and</strong><br />

cmdShuffle Caption &Shuffle<br />

cmdDeal Caption &Deal<br />

cmdQuit Caption &Quit<br />

Public Property Let Denomination(ByVal vDenom As String)<br />

m_Denomination = vDenom<br />

End Property<br />

Class Relationships 377

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!