public void TransClicked(object sender, EventArgs e) { MyPictureBox clicked = sender as MyPictureBox; chessboard[clicked.coordinate_x, clicked.coordinate_y].id = clicked.trans_id; Redraw(); foreach (MyPictureBox trans_box in trans_list) { trans_box.Dispose(); } UpdatePossibleMoves(clicked.coordinate_x, clicked.coordinate_y); if (FindCheck(6 * turn) == true) { const string message = "You are in check"; MessageBox.Show(message, "Check", MessageBoxButtons.OK); } }
/*public void DrawRectangle(EventArgs e) * { * Pen pen = new Pen(Brushes.Black, 5); * pen.Width = 10; * * e.Graphics.DrawRectangle(pen, 0, 0, 600, 600); * }*/ public void CreatePBoxes() { int black = 180; int white = 0; Pen pen = new Pen(Brushes.Black, 5); pen.Width = 10; //nakresli obdlznik okolo //System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing) //System.Drawing.Graphics form_graphics; //form_graphics.FillRectangle() //DrawRectangle(pen, 0, 0, 600, 600); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { MyPictureBox pbox = new MyPictureBox(); picture_boxes.Add(pbox); if (((i % 2 == 0) && (j % 2 == 1)) || ((i % 2 == 1) && (j % 2 == 0))) { pbox.BackColor = Color.FromArgb(black, 0, 0, 0); } else { pbox.BackColor = Color.FromArgb(white, 0, 0, 0); } pbox.Parent = this; pbox.Height = 75; pbox.Width = 75; pbox.Visible = true; pbox.coordinate_x = i; pbox.coordinate_y = j; pbox.Top = i * 75; pbox.Left = j * 75; pbox.SizeMode = PictureBoxSizeMode.StretchImage; pbox.BorderStyle = BorderStyle.FixedSingle; pbox.Click += PicClicked; } } }
public void TransformPawn(int x, int y) { for (int i = 0; i < 4; i++) { MyPictureBox pawn_transform_opt = new MyPictureBox(); int transform_id = (i + 2) * turn; pawn_transform_opt.trans_id = transform_id; pawn_transform_opt.coordinate_x = x; pawn_transform_opt.coordinate_y = y; pawn_transform_opt.Parent = this; pawn_transform_opt.Height = 100; pawn_transform_opt.Width = 100; pawn_transform_opt.Visible = true; pawn_transform_opt.Top = 300; pawn_transform_opt.Left = i * 100 + 700; pawn_transform_opt.SizeMode = PictureBoxSizeMode.StretchImage; pawn_transform_opt.BorderStyle = BorderStyle.FixedSingle; pawn_transform_opt.Click += TransClicked; pawn_transform_opt.Image = Image.FromFile(@"..\..\icons\" + Convert.ToString(transform_id) + ".png"); trans_list.Add(pawn_transform_opt); } }
public void PicClicked(object sender, EventArgs e) { //if turn == true tj je player na tahu - iba pri sigleplayer /*Color black = Color.FormArgb(180, 0, 0, 0); * Color white = new Color.FromArgb(0, 0, 0, 0); * Color blue = new Color.FromArgb(100, 0, 0, 255);*/ MyPictureBox pic_click = sender as MyPictureBox; if ((first_click == true) || (pic_click.BackColor != Color.FromArgb(100, 0, 0, 255))) { foreach (MyPictureBox pbox in picture_boxes) { if (((pbox.coordinate_x % 2 == 0) && (pbox.coordinate_y % 2 == 1)) || //restore backcolor po kliku ((pbox.coordinate_x % 2 == 1) && (pbox.coordinate_y % 2 == 0))) { pbox.BackColor = Color.FromArgb(180, 0, 0, 0); } else { pbox.BackColor = Color.FromArgb(0, 0, 0, 0); } } } UpdatePossibleMoves(pic_click.coordinate_x, pic_click.coordinate_y); DeleteCheckMoves(pic_click.coordinate_x, pic_click.coordinate_y); //chessboard je pole figurok, FIRST CLICK if ((chessboard[pic_click.coordinate_x, pic_click.coordinate_y].exist == true) && (first_click == true) && (chessboard[pic_click.coordinate_x, pic_click.coordinate_y].id * turn > 0)) { foreach (Coordinates coord in chessboard[pic_click.coordinate_x, pic_click.coordinate_y].possible_moves) { foreach (MyPictureBox pbox in picture_boxes) //zmen pozadie kam mozno tahat { if ((pbox.coordinate_x == coord.x) && (pbox.coordinate_y == coord.y)) { pbox.BackColor = Color.FromArgb(100, 0, 0, 255);; } } } from.x = pic_click.coordinate_x; from.y = pic_click.coordinate_y; first_click = false; } if (first_click == false) //SECOND CLICK { if (chessboard[pic_click.coordinate_x, pic_click.coordinate_y].id * turn > 0) //znovu klikol na svojho { { foreach (Coordinates coord in chessboard[pic_click.coordinate_x, pic_click.coordinate_y].possible_moves) { foreach (MyPictureBox pbox in picture_boxes) //zmen pozadie kam mozno tahat { if ((pbox.coordinate_x == coord.x) && (pbox.coordinate_y == coord.y)) { pbox.BackColor = Color.FromArgb(100, 0, 0, 255);; } } } from.x = pic_click.coordinate_x; from.y = pic_click.coordinate_y; first_click = false; } } if (pic_click.BackColor == Color.FromArgb(100, 0, 0, 255))//klikol na dostupne policko { MakeMove(from.x, from.y, pic_click.coordinate_x, pic_click.coordinate_y); foreach (MyPictureBox pbox in picture_boxes) { if (((pbox.coordinate_x % 2 == 0) && (pbox.coordinate_y % 2 == 1)) || //restore backcolor po kliku ((pbox.coordinate_x % 2 == 1) && (pbox.coordinate_y % 2 == 0))) { pbox.BackColor = Color.FromArgb(180, 0, 0, 0); } else { pbox.BackColor = Color.FromArgb(0, 0, 0, 0); } } if (IsPawnToTransform(pic_click.coordinate_x, pic_click.coordinate_y) == true) { TransformPawn(pic_click.coordinate_x, pic_click.coordinate_y); } for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if ((chessboard[i, j].id != 0) && (chessboard[i, j].exist == true)) { UpdatePossibleMoves(i, j); //DeleteCheckMoves(i, j); } } } //------------------koniec tahu-------------------------------------------- turn = -1 * turn; Redraw(); first_click = true; if (FindCheck(6 * turn) == true) { const string message = "You are in check"; MessageBox.Show(message, "Check", MessageBoxButtons.OK); } } } }