private static bool checkCorrectWay(int x, int y, int x1, int y1, figure fig) { if (fig == figure.Knight) { return((Math.Abs(x1 - x) == 2 && Math.Abs(y1 - y) == 1) || (Math.Abs(x1 - x) == 1 && Math.Abs(y1 - y) == 2)); } if (fig == figure.Bishop) { return(Math.Abs(x1 - x) == Math.Abs(y1 - y)); } if (fig == figure.Rook) { return((Math.Abs(x1 - x) != 0 && Math.Abs(y1 - y) == 0) || (Math.Abs(x1 - x) == 0 && Math.Abs(y1 - y) != 0)); } if (figure == figure.Queen) { return((Math.Abs(x1 - x) == Math.Abs(y1 - y)) || ((y1 == y) && (x1 - x) != 0) || (x1 == x) && (y1 - y) != 0); } if (figure == figure.King) { return((Math.Abs(x1 - x) == 1) && (y1 == y) || (Math.Abs(y1 - y) == 1) && (x1 == x) || (Math.Abs(y1 - y) == Math.Abs(x1 - x))); } }
/// <summary> /// двигает 2 текущие активные фигуры /// </summary> public void MoveFigure() { moves++; //DebuggingStats(z, x); if (board[second_z, second_x].figure_name == "empty") // просто двигаем { buffer = board[z, x]; board[z, x] = board[second_z, second_x]; board[second_z, second_x] = buffer; // Debug.Log("moved"); } DeleteFigures(); UpdateFigures(); // Debug.Log(board[z, x].figure_name); // Debug.Log(board[second_z, second_x].figure_name); board[z, x].isSecondActive = false; board[z, x].active = false; board[second_z, second_x].isSecondActive = false; board[second_z, second_x].active = false; if (State == 0) { To_AI(); } }
/// <summary> /// рокировка /// </summary> public void RokirovkaMove() { if (board[z, x].figure_name == "king") { if (z == 0 & x == 4) { if (second_z == 0 & second_x == 2) { buffer = board[0, 0]; board[0, 0] = board[0, 3]; board[0, 3] = buffer; } } } if (board[z, x].figure_name == "king") { if (z == 0 & x == 4) { if (second_z == 0 & second_x == 6) { buffer = board[0, 7]; board[0, 7] = board[0, 5]; board[0, 5] = buffer; } } } if (board[z, x].figure_name == "king") { if (z == 7 & x == 4) { if (second_z == 7 & second_x == 2) { buffer = board[7, 7]; board[7, 7] = board[7, 3]; board[7, 3] = buffer; } } } if (board[z, x].figure_name == "king") { if (z == 7 & x == 4) { if (second_z == 7 & second_x == 6) { buffer = board[7, 7]; board[7, 7] = board[7, 5]; board[7, 5] = buffer; } } } }
static void Main(string[] args) { Console.WriteLine("введите x фигуры: "); int x = int.Parse(Console.ReadLine()); Console.WriteLine("введите y фигуры: "); int y = int.Parse(Console.ReadLine()); Console.WriteLine("введите x проверяемой точки: "); int x1 = int.Parse(Console.ReadLine()); Console.WriteLine("введите y проверяемой точки: "); int y1 = int.Parse(Console.ReadLine()); Console.WriteLine("введите название фигуры(King, Queen, Knight, Bishop,Rook),: "); figure fig = (figure)int.Parse(Console.ReadLine()); checkCorrectWay(x, y, x1, y1, figure); }
public void Drag(figure figure, int dx, int dy) { figure.Move(figure.X + dx, figure.Y + dy); figure.Resize(figure.width - dx, figure.height - dy); }
public void Drag(figure figure, int dx, int dy) { GraphicsEditor.figure.Move(GraphicsEditor.figure.X, GraphicsEditor.figure.Y + dy); GraphicsEditor.figure.Resize(GraphicsEditor.figure.width + dx, GraphicsEditor.figure.height - dy);; }
private void panelDrawing_MouseDown(object sender, MouseEventArgs e) { #region handle _redo int CurrentPage = int.Parse(textBoxNumberPage.Text); for (int i = 0; i < _redo.Count; i++) { ArrayList al = (ArrayList)_redo[i]; int page = (int)al[0]; if (page == CurrentPage) { _redo.RemoveAt(i); i--; } } #endregion handle _redo if (e.Button == MouseButtons.Right) { return; } Point p = new Point(e.X, e.Y); shape s = null; #region Selector Eraser if (radioButtonSelector.Checked || radioButtonEraser.Checked) { ArrayList shapes = getPage(); bool b; foreach (shape shp in shapes) { b = shp.selector(p); if (b) { #region if (radioButtonEraser.Checked) { shapes.Remove(shp); panelDrawing.Invalidate(); } #endregion #region selector if (radioButtonSelector.Checked) { _currentPoint = new Point(e.X, e.Y); SelectorShape = shp; panelCurrentColor.BackColor = SelectorShape._Color; _pen.Width = SelectorShape.Width; panelWidth1.Invalidate(); panelWidth2.Invalidate(); panelWidth3.Invalidate(); panelWidth4.Invalidate(); } #endregion selector return; } } b = false; SelectorShape = null; } #endregion Selector Eraser #region text if (radioButtonText.Checked) { if (textBoxContent.Visible) { s = handleText(); } textBoxContent.Visible = true; textBoxContent.Text = ""; textBoxContent.Location = p; if (s == null) { return; } } #endregion text #region FreeHand and Line if (radioButtonFreeHand.Checked) { s = new freeHand(_pen.Width, _pen.Color, p); } if (radioButtonLine.Checked) { s = new line(_pen.Width, _pen.Color, p); } #endregion FreeHand and Line #region Rectangle and Ellipse if (radioButtonRectangle.Checked) { bool isFill = panelFilled.BackColor == Color.Blue; s = new figure(figure.types.Rectangle, isFill, _pen.Width, _pen.Color, p); } if (radioButtonEllipse.Checked) { bool isFill = panelFilled.BackColor == Color.Blue; s = new figure(figure.types.Ellipse, isFill, _pen.Width, _pen.Color, p); } #endregion Rectangle and Ellipse if (s == null) { return; } addShape(s); }