30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

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.

664 Strings, Characters and Regular Expressions Chapter 15<br />

8 Public Sub New(ByVal faceValue As String, _<br />

9 ByVal suitValue As String)<br />

10<br />

11 face = faceValue<br />

12 suit = suitValue<br />

13 End Sub ' New<br />

14<br />

15 Public Overrides Function ToString() As String<br />

16 Return face & " of " & suit<br />

17 End Function ' ToString<br />

18<br />

19 End Class ' CCard<br />

Fig. 15.17 CCard class (part 2 of 2).<br />

1 ' Fig. 15.18: DeckOfCards.vb<br />

2 ' Simulating card dealing and shuffling.<br />

3<br />

4 Public Class FrmDeck<br />

5 Inherits Form<br />

6<br />

7 Friend WithEvents lblDisplay As Label ' displays dealt card<br />

8 Friend WithEvents lblStatus As Label ' number of cards dealt<br />

9<br />

10 Friend WithEvents cmdDeal As But<strong>to</strong>n ' deal one card<br />

11 Friend WithEvents cmdShuffle As But<strong>to</strong>n ' shuffle cards<br />

12<br />

13 ' <strong>Visual</strong> Studio .<strong>NET</strong> generated code<br />

14<br />

15 Private currentCard As Integer<br />

16 Private randomObject As Random = New Random()<br />

17 Private deck As CCard() = New CCard(51) {}<br />

18<br />

19 ' handles form at load time<br />

20 Public Sub FrmDeck_Load(ByVal sender As System.Object, _<br />

21 ByVal e As System.EventArgs) Handles MyBase.Load<br />

22<br />

23 Dim faces As String() = {"Ace", "Deuce", "Three", _<br />

24 "Four", "Five", "Six", "Seven", "Eight", "Nine", _<br />

25 "Ten", "Jack", "Queen", "King"}<br />

26<br />

27 Dim suits As String() = {"Hearts", "Diamonds", "Clubs", _<br />

28 "Spades"}<br />

29<br />

30 Dim i As Integer<br />

31<br />

32 ' no cards have been drawn<br />

33 currentCard = -1<br />

34<br />

Fig. 15.18 Card dealing and shuffling simulation (part 1 of 4).

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

Saved successfully!

Ooh no, something went wrong!