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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1060 ASP .<strong>NET</strong> and Web Services Chapter 21<br />

110 ' if dealer and player have not exceeded 21,<br />

111 ' higher score wins; equal scores is a push<br />

112 If dealersTotal > playersTotal Then<br />

113 GameOver(GameStatus.LOSE)<br />

114 ElseIf playersTotal > dealersTotal Then<br />

115 GameOver(GameStatus.WIN)<br />

116 Else<br />

117 GameOver(GameStatus.PUSH)<br />

118 End If<br />

119<br />

120 End Sub 'DealerPlay<br />

121<br />

122 ' deal another card <strong>to</strong> player<br />

123 Private Sub cmdHit_Click(ByVal sender As System.Object, _<br />

124 ByVal e As System.EventArgs) Handles cmdHit.Click<br />

125<br />

126 ' get player another card<br />

127 Dim card As String = dealer.DealCard()<br />

128 playersCards &= vbTab & card<br />

129 DisplayCard(playerCard, card)<br />

130 playerCard += 1<br />

131<br />

132 Dim <strong>to</strong>tal As Integer = _<br />

133 dealer.CountCards(playersCards)<br />

134<br />

135 ' if player exceeds 21, house wins<br />

136 If <strong>to</strong>tal > 21 Then<br />

137 GameOver(GameStatus.LOSE)<br />

138<br />

139 ' if player has 21, they cannot take more cards<br />

140 ' the dealer plays<br />

141 If <strong>to</strong>tal = 21 Then<br />

142 cmdHit.Enabled = False<br />

143 DealerPlay()<br />

144 End If<br />

145 End If<br />

146<br />

147 End Sub ' cmdHit_Click<br />

148<br />

149 ' deal two cards each <strong>to</strong> dealer and player<br />

150 Private Sub cmdDeal_Click(ByVal sender As System.Object, _<br />

151 ByVal e As System.EventArgs) Handles cmdDeal.Click<br />

152<br />

153 Dim card As String<br />

154 Dim cardImage As PictureBox<br />

155<br />

156 ' clear card images<br />

157 For Each cardImage In cardBoxes<br />

158 cardImage.Image = Nothing<br />

159 Next<br />

160<br />

161 pbStatus.Image = Nothing<br />

162<br />

Fig. 21.15 Blackjack game that uses the Blackjack Web service (part 4 of 9).

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

Saved successfully!

Ooh no, something went wrong!