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.

Chapter 16 Graphics and Multimedia 723<br />

132 ' account for new row tile color switch<br />

133 light = Not light<br />

134 Next ' next row<br />

135<br />

136 End Sub ' ResetBoard<br />

137<br />

138 ' display board in form OnPaint event<br />

139 Protected Overrides Sub OnPaint(ByVal paintEvent _<br />

140 As PaintEventArgs)<br />

141<br />

142 ' obtain graphics object<br />

143 Dim graphicsObject As Graphics = paintEvent.Graphics<br />

144 Dim row, column As Integer<br />

145<br />

146 For row = 0 To mBoard.GetUpperBound(0)<br />

147<br />

148 For column = 0 To mBoard.GetUpperBound(1)<br />

149<br />

150 ' draw image specified in board array<br />

151 graphicsObject.DrawImage( _<br />

152 CType(mChessTile(mBoard(row, column)), _<br />

153 Image), New Point(TILESIZE * column, _<br />

154 TILESIZE * row))<br />

155 Next<br />

156<br />

157 Next<br />

158<br />

159 End Sub ' OnPaint<br />

160<br />

161 ' return index of piece that intersects point<br />

162 ' optionally exclude a value<br />

163 Private Function CheckBounds(ByVal point As Point, _<br />

164 Optional ByVal exclude As Integer = -1) As Integer<br />

165<br />

166 Dim rectangle As Rectangle ' current bounding rectangle<br />

167 Dim i As Integer<br />

168<br />

169 For i = 0 To mChessPieces.Count - 1<br />

170<br />

171 ' get piece rectangle<br />

172 rectangle = Getpiece(i).LocationRectangle()<br />

173<br />

174 ' check if rectangle contains point<br />

175 If (rectangle.Contains(point) AndAlso i exclude) Then<br />

176 Return i<br />

177 End If<br />

178<br />

179 Next<br />

180<br />

181 Return -1<br />

182 End Function ' CheckBounds<br />

183<br />

Fig. 16.26 Chess-game code (part 4 of 9).

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

Saved successfully!

Ooh no, something went wrong!