我正在製作C#國際象棋遊戲,所以我可以練習使用該語言編碼。我使用Windows窗體,並使用45x45.png圖標。我已經制作了我的圖片盒,以便電路板上的每個位置都是50x50像素,使picturebox/board成爲一個400x400的正方形。我想知道的是,如何初始化棋盤,以便使用矩形類型的二維數組移動棋子。這樣,電路板上的每個位置都是一個定義爲50x50平方的矩形。到目前爲止我的代碼,如果我失去了一些重要的東西,讓我知道:使用圖片框和矩形制作棋盤,如何初始化?
class Board//this class represents the board
{
private Rectangle[,] chessBoard = new Rectangle[8, 8]; //a 2d array of rectangles
public void initBoard()//this method will initialize the picturebox/board
{
for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 8; y++)
{
chessBoard[x, y] = new Rectangle(x * 50, y * 50, 50, 50);
}
}
}
}
好的...你的問題是什麼? – Servy
你在尋找肯定嗎?如果是這樣,那是一些極好的代碼 – Jonesopolis
移動到更多空間的答案... –