i fail to refresh/reprint the winform
Basically, i made a chessboard. i have 2 classes. the partial class, that triggers the events, and the logic class where the chess game code is executed (i.e. MVC model).
basically, what i am working on now is to make a reply of the game. The game ,of course, has to restart (redraw) itself.
To start , i am going to explain to you how the pictures are loaded.
Here is the algorithm when the chess is loaded.
PictureBox[,] chessPics = new PictureBox[9, 9];// this is an array of pictureBox. each square is a picture box
private void Chess_Load(object sender, EventArgs e)
{
chessPics = Pattern();// pattern is a function that returns an array of
PrintPieces(codeFile.FirstTimeLoad());// this FirstTimeLoad method, goes to the chess code file an brings a new array of all the chess pieces (each chess piece is an object).
}
public PictureBox[ , ] Pattern()
{
chessPics[1, 1] = a1;// each letter and number is an event that triggers the picture.
chessPics[1, 2] = b1;
chessPics[1, 3] = c1;
chessPics[1, 4] = d1;
chessPics[1, 5] = e1;
chessPics[1, 6] = f1;
chessPics[1, 7] = g1;
chessPics[1, 8] = h1;
chessPics[2, 1] = a2;
chessPics[2, 2] = b2;
chessPics[2, 3] = c2;
chessPics[2, 4] = d2;
chessPics[2, 5] = e2;
chessPics[2, 6] = f2;
chessPics[2, 7] = g2;
chessPics[2, 8] = h2;
chessPics[3, 1] = a3;
chessPics[3, 2] = b3;
chessPics[3, 3] = c3;
chessPics[3, 4] = d3;
chessPics[3, 5] = e3;
chessPics[3, 6] = f3;
chessPics[3, 7] = g3;
chessPics[3, 8] = h3;
chessPics[4, 1] = a4;
chessPics[4, 2] = b4;
chessPics[4, 3] = c4;
chessPics[4, 4] = d4;
chessPics[4, 5] = e4;
chessPics[4, 6] = f4;
chessPics[4, 7] = g4;
chessPics[4, 8] = h44;
chessPics[5, 1] = a5;
chessPics[5, 2] = b5;
chessPics[5, 3] = c5;
chessPics[5, 4] = d5;
chessPics[5, 5] = e5;
chessPics[5, 6] = f5;
chessPics[5, 7] = g5;
chessPics[5, 8] = h5;
chessPics[6, 1] = a6;
chessPics[6, 2] = b6;
chessPics[6, 3] = c6;
chessPics[6, 4] = d6;
chessPics[6, 5] = e6;
chessPics[6, 6] = f6;
chessPics[6, 7] = g6;
chessPics[6, 8] = h6;
chessPics[7, 1] = a7;
chessPics[7, 2] = b7;
chessPics[7, 3] = c7;
chessPics[7, 4] = d7;
chessPics[7, 5] = e7;
chessPics[7, 6] = f7;
chessPics[7, 7] = g7;
chessPics[7, 8] = h7;
chessPics[8, 1] = a8;
chessPics[8, 2] = b8;
chessPics[8, 3] = c8;
chessPics[8, 4] = d8;
chessPics[8, 5] = e8;
chessPics[8, 6] = f8;
chessPics[8, 7] = g8;
chessPics[8, 8] = h8;
return chessPics;
}
The method that prints each picture on a picture box:
public void PrintPieces(Pieces [,] pieces)
{
for (int i = 1; i < 9; i++)
{
for (int j = 1; j < 9; j++)
{
if (pieces[i, j] is Object)
{
chessPics[i, j].Load(pieces[i, j].print()); // in the pieces object there are objects with a print method which specifies from which location to load the pictures
}
else
{
chessPics[i, j].Image = null;
}
}
}
}
what i fail to do , is in the middle or end of the game to reset everything to the begining. i tried to create new objects and new methods that will replicate the algorithm that i did when in the load function form, but nothing worked.
is there any solution?
here is my Class2:
public class Class2
{
public static bool MATE;
Pieces[,] pieces;
Pieces[,] piece;
i created a new object
Class2 codeFileReplay = new Class2();
and even assigned a method to reset and retreat a new array:
public void resetBoard()
{
piece = null;
pieces = null;
}
i activated that method , and did the whole process again, of sending a new array of the new object to the method that prints the board
public static Pieces[,] ChessBoardDisplay()
{
Pieces[,] piece2 = new Pieces[9, 9];
piece2[8, 1] = new Rook("WR");
piece2[8, 2] = new Knight("WKN");
piece2[8, 3] = new Bishop("WB");
piece2[8, 5] = new Queen("WQ");
piece2[8, 4] = new King("WK");
piece2[8, 6] = new Bishop("WB");
piece2[8, 7] = new Knight("WKN");
piece2[8, 8] = new Rook("WR");
piece2[7, 1] = new Pawn("WP");
piece2[7, 2] = new Pawn("WP");
piece2[7, 3] = new Pawn("WP");
piece2[7, 4] = new Pawn("WP");
piece2[7, 5] = new Pawn("WP");
piece2[7, 6] = new Pawn("WP");
piece2[7, 7] = new Pawn("WP");
piece2[7, 8] = new Pawn("WP");
piece2[1, 1] = new Rook("BR");
piece2[1, 2] = new Knight("BKN");
piece2[1, 3] = new Bishop("BB");
piece2[1, 5] = new Queen("BQ");
piece2[1, 4] = new King("BK");
piece2[1, 6] = new Bishop("BB");
piece2[1, 7] = new Knight("BKN");
piece2[1, 8] = new Rook("BR");
piece2[2, 1] = new Pawn("BP");
piece2[2, 2] = new Pawn("BP");
piece2[2, 3] = new Pawn("BP");
piece2[2, 4] = new Pawn("BP");
piece2[2, 5] = new Pawn("BP");
piece2[2, 6] = new Pawn("BP");
piece2[2, 7] = new Pawn("BP");
piece2[2, 8] = new Pawn("BP");
return piece2;
}
public Pieces[,] FirstTimeLoad()
{
pieces = ChessBoardDisplay();
piece = ChessBoardDisplay();
return pieces;
}
i activated teh FirstTimeLoad in the partial class:
PrintPiecesReplay(codeFileReplay.FirstTimeLoad());
PictureBox[,] chessPictures = new PictureBox[9, 9];
public void PrintPiecesReplay(Pieces[,] pieces)
{
for (int i = 1; i < 9; i++)
{
for (int j = 1; j < 9; j++)
{
if (pieces[i, j] is Object)
{
chessPictures[i, j].Load(pieces[i, j].print());
}
else
{
chessPictures[i, j].Im开发者_Python百科age = null;
}
}
}
}
Basically, i did the whole process from the beginning with a new object of the class code (Class2). wont redraw the board
According to PrintPieces
, it's the pieces
array you need to worry about resetting, not the chessPics
array.
精彩评论