I'm working on a programming exercise (very little practical programming experience) to create a chess game. Though I shudder at the logic required to verify a King's Move is legal, luckily I'm not at that point yet.
Currently I am trying to give life to the chess-board that only exists in memory. As designed, each 'Game' object creates an array of 'Square' objects with properties like color, piece, rank, file, etc. As far as I can tell, everything works like clockwork. Whenever I create a new 'Game' I also create a new Form to run the game (the visual component to the logical board).
While I could dynamically create an 8x8 series of buttons, each of which call appropriate methods in the 'Game' or 'Square' classes, I'd like to somehow give my own custom 'Square' class a visual component that can be clicked on. I may have the terminology wrong, but essentially I'd like to create 'image' or 'color/height/width/xpos/ypos' properties for the 'Square's.
I've tried to lookup the carious properties of pre-built controls in the MSDN knowledgebase, and various tutorials on creating classes and assigning properties. I know I can add controls dynamically (I could create a button for each 'Square') and I've come to the (true|false) conclusion that a control is nothing more than a pre-built class. If that's true, I should be able to do this. All of the tutorials, sadly, assume that all I am doing with my classes is behind-the-scenes logic.
In short (which I rarely do), how would I give a custom 'Square' class a 100x100 black image on a form?
I'm certainly not asking for the code (Eliminates half of the fun!), but a reference or keyword would be greatly appreciated.
For reference, the famed 'Square' class!
Public Class Square
'Permanent properties cannot be changed after the game is created.
Property White As Boolean = True 'True is White, False is Black
Property Rank As Byte = 0
Property File As Byte = 0
'Other Properties can be changed after the game is created.
Property Height As Byte = 100 'Considering it is a SQUARE, the value of WIDTH can be inferred.
Property ThreatenedByWhite As Boolean = False
Property ThreatenedByBlack As Boolean = False
Property Piece As SByte = 0 'Negative values indicate black pieces, positive values indicate white pieces
'0 - Empty
'1 - Pawn
'2 - Knight
'3 - Bishop
'4 - Rook
'5 - Queen
'6 - King
Public Sub New(ByVal Rank As Byte, ByVal File As Byte, ByVal White As Boolean)
Me.White = White
Me.Rank = Rank
Me.File = File
End Sub
End Class

New Topic/Question
Reply




MultiQuote





|