public static bool CheckFreeFinishCell(int X, int Y, bool[,] chessmanPresenceSign, ControlCollection Controls, object sender) { var result = false; foreach (var control in Controls) { if (control is Chessman) { var chessFinishLocation = new Point(X * 50 + 27, Y * 50 + 27); if (((Chessman)control).Location == chessFinishLocation) { if (((Chessman)control).ChessColor == ((Chessman)sender).ChessColor && control != sender) { result = true; } else { if (control != sender && !((Chessman)sender).FakeCheck) { TemporaryChassman = ((Chessman)control); Controls.Remove((Chessman)control); ((Chessman)sender).RemoveChessman = true; } } } } } return(result); }
private void Chessman_MouseUp(object sender, MouseEventArgs e) { chessmanCanMove = false; chess = (Chessman)sender; //Выравнивание положения шахматы в ячейке for (var j = 0; j < CellsCountInRow; j++) { if (chess.Location.X >= CellsPositions[0, j].X - 25 && chess.Location.X < CellsPositions[0, j].X + 25) { chessmansCellIndexColumn = j; } } for (var i = 0; i < CellsCountInRow; i++) { if (chess.Location.Y >= CellsPositions[i, 0].Y - 25 && chess.Location.Y < CellsPositions[i, 0].Y + 25) { chessmansCellIndexRow = i; } } chess.Location = CellsPositions[chessmansCellIndexRow, chessmansCellIndexColumn]; //Проверка очередности хода if (moveOrder[((Chessman)sender).ChessColor] == moveOrder.Values.Max()) { //Проверка логики хода CheckChessMove(chess); } else { MessageBox.Show(Resources.moveOrderMessageError); ((Chessman)sender).Location = initialChessmanLocation; } }
public Chessman GetCharacter(string key) { // Uses "lazy initialization" Chessman chessman = null; if (_chessmans.ContainsKey(key)) { chessman = _chessmans[key]; } else { switch (key) { case "King": chessman = new ChessmanKing(); break; case "Queen": chessman = new ChessmanQueen(); break; case "Rook": chessman = new ChessmanRook(); break; case "Bishop": chessman = new ChessmanBishop(); break; case "Knight": chessman = new ChessmanKnight(); break; case "Pawn": chessman = new ChessmanPawn(); break; } _chessmans.Add(key, chessman); } return(chessman); }
private void Chessman_MouseDown(object sender, MouseEventArgs e) { chessmanCanMove = true; initialMouseLocation = e.Location; chess = (Chessman)sender; initialChessmanLocation = chess.Location; }
private void Chessman_MouseMove(object sender, MouseEventArgs e) { if (chessmanCanMove) { chess = (Chessman)sender; chess.Top += e.Y - initialMouseLocation.Y; chess.Left += e.X - initialMouseLocation.X; } }
void HandleFailedDrop() { MainCanvas.Children.Remove(_draggedFeagure); _draggedFeagureParent.Background = Brushes.Transparent; _draggedFeagureParent.Opacity = 1; _draggedFeagureParent.Child = _draggedFeagure; _draggedFeagureParent = null; _draggedFeagure = null; }
// Überprüft, ob der aktuelle Spieler Matt gesetzt wurde public bool IsKingCheckmate(string color) { //Chessboard analysisBoard = this.Clone(); // foreach (Chessman ownMan in chessman) for (int i = 0; i < chessman.Count; i++) { Chessman ownMan = chessman[i]; if (ownMan.Color == color) { Square source = GetSquare(ownMan.Current_position); string ownMan_last_pos = ownMan.Current_position; foreach (Square dest in squares) { Chessman opponent = null; Chessman chessmanAtDest = GetChessmanAtSquare(dest); if (chessmanAtDest != null && chessmanAtDest.Color != ownMan.Color) { opponent = chessmanAtDest; } try { ownMan.Move(source, dest, true); if (!IsKingInCheck(ownMan.Color)) { ownMan.Current_position = ownMan_last_pos; if (opponent != null) { chessman.Add(opponent); } Clear(); DisplayChessman(); return(false); } else { ownMan.Current_position = ownMan_last_pos; if (opponent != null) { chessman.Add(opponent); } } } catch (InvalidMoveException) { } catch (BlockedMoveException) { } catch (PlacedInCheckException) { } } } } Clear(); DisplayChessman(); return(true); }
void RectangleOnDrop(object sender, DragEventArgs e) { try { var border = ((Border)sender); border.BorderBrush = Brushes.Transparent; border.BorderThickness = new Thickness(0); var point = new System.Drawing.Point(Grid.GetColumn(border), Grid.GetRow(border)); if (!_draggedFeagure.CanGo(point, true)) { HandleFailedDrop(); return; } MainCanvas.Children.Remove(_draggedFeagure); _draggedFeagureParent.Background = Brushes.Transparent; _draggedFeagureParent.Opacity = 1; try { _draggedFeagure.Go(point); } catch (RequireExchangeException) { var chooseFeagureDialog = new ChooseFeagure(); chooseFeagureDialog.Owner = this; chooseFeagureDialog.ShowDialog(); _draggedFeagure.Mutate(chooseFeagureDialog.SelectedFeagure); } catch (FatalityException ex) { MessageBox.Show(String.Format("{0} win.", ex.WinColor)); Trace.TraceInformation("{0} win. Game over.", ex.WinColor); _gameOver = true; } border.Child = _draggedFeagure; _draggedFeagure = null; Game.Current.ChangeTurn(); } catch (Exception ex) { Trace.TraceError(ex.ToString()); _gameOver = true; } }
public override bool IsMoveValid(Square dest) { Square source = this.game.board.GetSquare(this.Current_position); int source_col = GetColumnCoordinate(source); int source_row = GetRowCoordinate(source); int dest_col = GetColumnCoordinate(dest); int dest_row = GetRowCoordinate(dest); Chessman opponent = null; Chessman chessman = this.game.board.GetChessmanAtSquare(dest); if (chessman != null && chessman.Color != this.Color) { opponent = chessman; } if (!this.isMoved) { return // Der Bauer darf ein oder zwei Felder VERTIKAL vorrücken ((source_col == dest_col && source_row - dest_row >= 1 && source_row - dest_row <= 2) || ( // oder ein Feld DIAGONAL den Gegner schlagen ((source_col - 1 == dest_col) || (source_col + 1 == dest_col)) && (source_row - dest_row == 1) && (opponent != null) )); } else { return // Der Bauer darf ein Feld VERTIKAL vorrücken ((source_col == dest_col && source_row - dest_row == 1) || // oder ein Feld DIAGONAL den Gegner angreifen ( ((source_col - 1 == dest_col) || (source_col + 1 == dest_col)) && (source_row - dest_row == 1) && (opponent != null) ) || // oder einen gegnerischen Bauer en passant schlagen ( ((source_col - 1 == dest_col) || (source_col + 1 == dest_col)) && (dest_row - source_row == -1) && (source_row == 4) && (this.game.GetWaitingPlayer().DoubleStepMovedPawn != null) && (Convert.ToInt16(this.game.GetWaitingPlayer().DoubleStepMovedPawn.Current_position.Substring(1, 1)) == 4) && (Convert.ToInt16(Convert.ToChar(this.game.GetWaitingPlayer().DoubleStepMovedPawn.Current_position.Substring(0, 1))) == dest_col) )); } }
public void InitBoard() { rook = new Rook(toPromote.IsWhite, "A1", game) { Current_position = toPromote.Current_position, IsMoved = true }; knight = new Knight(toPromote.IsWhite, "A2", game) { Current_position = toPromote.Current_position }; bishop = new Bishop(toPromote.IsWhite, "A3", game) { Current_position = toPromote.Current_position }; queen = new Queen(toPromote.IsWhite, "A4", game) { Current_position = toPromote.Current_position }; Chessman[] promMan = new Chessman[4] { rook, knight, bishop, queen }; for (int i = 1; i <= 4; i++) { Square square = new Square(); square.Content = promMan[i - 1].View; square.Click += SetSelectedChessman; square.Width = 50; square.Height = 50; square.Name = "A" + i; if (i % 2 == 0) { square.Color = Brushes.White; square.Background = square.Color; } else { square.Color = Brushes.RosyBrown; square.Background = square.Color; } this.panel.Children.Add(square); } }
void image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { try { if (_gameOver) { return; } var chessman = (Chessman)sender; if (!chessman.IsTurn) { return; } var data = new DataObject(); data.SetData("data", 13); //data.SetData("image", (Image)sender); _draggedFeagure = chessman; _draggedFeagureParent = (Border)_draggedFeagure.Parent; _draggedFeagureParent.Child = null; Panel.SetZIndex(_draggedFeagure, 2); MainCanvas.Children.Add(_draggedFeagure); _draggedFeagureParent.Background = Brushes.SlateGray; _draggedFeagureParent.Opacity = 0.3; var result = DragDrop.DoDragDrop((Image)sender, data, DragDropEffects.Move); if (result == DragDropEffects.None) { HandleFailedDrop(); } } catch (Exception ex) { Trace.TraceError(ex.ToString()); _gameOver = true; } }
static void Main() { string[] main_chessmans = { "Rook", "Knight", "Bishop", "Queen", "King", "Bishop", "Knight", "Rook" }; string[] pawn_chessmans = { "Pawn", "Pawn", "Pawn", "Pawn", "Pawn", "Pawn", "Pawn", "Pawn" }; ChessmanFactory factory = new ChessmanFactory(); //white_player bool state = true; foreach (string chman in main_chessmans) { Chessman character = factory.GetCharacter(chman); character.Display(state); } Console.WriteLine(""); foreach (string chman in pawn_chessmans) { Chessman character = factory.GetCharacter(chman); character.Display(state); } Console.WriteLine("\n\n\n\n"); //black_player state = false; foreach (string chman in pawn_chessmans) { Chessman character = factory.GetCharacter(chman); character.Display(state); } Console.WriteLine(""); foreach (string chman in main_chessmans) { Chessman character = factory.GetCharacter(chman); character.Display(state); } Console.WriteLine(""); Console.ReadKey(); }
//public abstract void Move(Square source, Square dest); public virtual void Move(Square source, Square dest, bool silentMode = false) { int source_col = GetColumnCoordinate(source); int source_row = GetRowCoordinate(source); int dest_col = GetColumnCoordinate(dest); int dest_row = GetRowCoordinate(dest); // Prüft auf gültigen Zug: VERTIKAL oder HORIZONTAL oder DIAGONAL if (IsMoveValid(dest)) { if (!IsMoveBlocked(dest)) { // Gewoehnlicher Zug ohne Angriff if (this.game.board.GetChessmanAtSquare(dest) == null) { string last_pos = this.Current_position; this.Current_position = GetSquarenameFromCoordinates(dest_col, dest_row); if (!this.game.board.IsKingInCheck(this.Color)) { if (!silentMode) { source.Content = ""; this.game.board.lastAction = "BEWEGE " + this.Desc + " VON " + source.Name + " AUF " + dest.Name; this.IsMoved = true; // Neuer Logeintrag LogEntry log = new LogEntry(this, last_pos, this.Current_position); log.PlacedInCheck = this.game.board.IsKingInCheck(this.game.GetWaitingPlayer().Color); this.game.logger.Add(log); this.game.View.movesList.Items.Add(log); } } // Zug Rückgängig machen, wenn sich nach dem Zug // der König im Schach befinden würde else { this.Current_position = last_pos; throw new PlacedInCheckException(); } } else { Chessman chessmanAtDest = this.game.board.GetChessmanAtSquare(dest); // Angriffszug if (chessmanAtDest.Color != this.Color) { string last_pos = this.Current_position; this.Current_position = GetSquarenameFromCoordinates(dest_col, dest_row); this.game.board.chessman.Remove(chessmanAtDest); if (!this.game.board.IsKingInCheck(this.Color)) { if (!silentMode) { source.Content = ""; //this.Current_position = GetSquarenameFromCoordinates(dest_col, dest_row); this.game.board.lastAction = this.Desc + " SCHLÄGT " + chessmanAtDest.Desc + " AUF " + dest.Name; this.IsMoved = true; // Neuer Logeintrag LogEntry log = new LogEntry(this, last_pos, this.Current_position); log.OpponentMan = chessmanAtDest; log.PlacedInCheck = this.game.board.IsKingInCheck(this.game.GetWaitingPlayer().Color); this.game.logger.Add(log); this.game.View.movesList.Items.Add(log); } } // Zug Rückgängig machen, wenn sich nach dem Zug // der König im Schach befinden würde else { this.Current_position = last_pos; this.game.board.chessman.Add(chessmanAtDest); throw new PlacedInCheckException(); } } else { throw new BlockedMoveException(); } } } else { throw new BlockedMoveException(); } } else { throw new InvalidMoveException(); } }
public override void Move(Square source, Square dest, bool silentMode = false) { int source_col = Convert.ToInt16(Convert.ToChar(source.Name.Substring(0, 1))); int source_row = Convert.ToInt16(source.Name.Substring(1, 1)); int dest_col = Convert.ToInt16(Convert.ToChar(dest.Name.Substring(0, 1))); int dest_row = Convert.ToInt16(dest.Name.Substring(1, 1)); if (IsMoveValid(dest)) { // Gewoehnlicher Zug ohne Angriff if (source_col == dest_col) { if (!IsMoveBlocked(dest)) { string last_pos = this.Current_position; this.Current_position = GetSquarenameFromCoordinates(dest_col, dest_row); if (!this.game.board.IsKingInCheck(this.Color)) { if (!silentMode) { source.Content = ""; this.game.board.lastAction = "BEWEGE " + this.Desc + " VON " + source.Name + " AUF " + dest.Name; isMoved = true; // Neuer Logeintrag wird initialisiert LogEntry log = new LogEntry(this, last_pos, this.Current_position); // Zieht ein Bauer im Doppelschritt, // kann dieser unmittelbar danach 'en passant' geschlagen werden if (Math.Abs(source_row - dest_row) == 2) { this.game.GetActivePlayer().DoubleStepMovedPawn = this; } // Zieht ein Bauer auf die letzte Linie, // kann er gewandelt werden if (dest_row == 1) { // Ein modales Fenster zur Auswahl der neuen Figur wird geöffnet PromotePawn(); // Der Logeintrag wird um die umgewandelte Figur ergänzt log.PromotedIn = this.promotedIn; } log.PlacedInCheck = this.game.board.IsKingInCheck(this.game.GetWaitingPlayer().Color); this.game.logger.Add(log); this.game.View.movesList.Items.Add(log); } } // Zug Rückgängig machen, wenn sich nach dem Zug // der König im Schach befinden würde else { this.Current_position = last_pos; throw new PlacedInCheckException(); } } else { throw new BlockedMoveException(); } } // Angriffszug else { Chessman opponent = this.game.board.GetChessmanAtSquare(dest); string last_pos = this.Current_position; // Standardangriff if (opponent != null) { this.Current_position = GetSquarenameFromCoordinates(dest_col, dest_row); this.game.board.chessman.Remove(opponent); if (!this.game.board.IsKingInCheck(this.Color)) { if (!silentMode) { source.Content = ""; isMoved = true; this.game.board.lastAction = this.Desc + " SCHLÄGT " + opponent.Desc + " AUF " + dest.Name; // Neuer Logeintrag wird initialisiert LogEntry log = new LogEntry(this, last_pos, this.Current_position); log.OpponentMan = opponent; // Zieht ein Bauer auf die letzte Linie, kann er gewandelt werden if (dest_row == 1) { PromotePawn(); log.PromotedIn = this.promotedIn; } log.PlacedInCheck = this.game.board.IsKingInCheck(this.game.GetWaitingPlayer().Color); this.game.logger.Add(log); this.game.View.movesList.Items.Add(log); } } // Zug Rückgängig machen, wenn sich nach dem Zug // der König im Schach befinden würde else { this.Current_position = last_pos; this.game.board.chessman.Add(opponent); throw new PlacedInCheckException(); } } // En Passant Angriff else { string opponent_curr_pos = GetSquarenameFromCoordinates(dest_col, 4); Square opponent_pos_square = this.game.board.GetSquare(opponent_curr_pos); opponent = this.game.board.GetChessmanAtSquare(opponent_pos_square); this.Current_position = GetSquarenameFromCoordinates(dest_col, dest_row); this.game.board.chessman.Remove(opponent); if (!this.game.board.IsKingInCheck(this.Color)) { if (!silentMode) { source.Content = ""; opponent_pos_square.Content = ""; isMoved = true; this.game.board.lastAction = this.Desc + " SCHLÄGT " + opponent.Desc + " AUF " + dest.Name + " IM VORBEIGEHEN (EN PASSANT)"; // Neuer Logeintrag LogEntry log = new LogEntry(this, last_pos, this.Current_position); log.OpponentMan = opponent; log.TookEnPassant = true; log.PlacedInCheck = this.game.board.IsKingInCheck(this.game.GetWaitingPlayer().Color); this.game.logger.Add(log); this.game.View.movesList.Items.Add(log); } } // Zug Rückgängig machen, wenn sich nach dem Zug // der König im Schach befinden würde else { this.Current_position = last_pos; this.game.board.chessman.Add(opponent); throw new PlacedInCheckException(); } } } } else { throw new InvalidMoveException(); } }
public override void Move(Square source, Square dest, bool silentMode = false) { int source_col = GetColumnCoordinate(source); int source_row = GetRowCoordinate(source); int dest_col = GetColumnCoordinate(dest); int dest_row = GetRowCoordinate(dest); // Prüft auf gültigen Zug: VERTIKAL oder HORIZONTAL oder DIAGONAL // bei einer Reichweite von einem Feld if (IsMoveValid(dest)) { if (!IsMoveBlocked(dest)) { if (this.game.board.GetChessmanAtSquare(dest) == null) { // Kleine Rochade if (source_col - dest_col == -2 && source_row == dest_row) { Rook rook = this.game.board.GetRook("H" + this.Orig_position.Substring(1, 1)); Square rook_source = this.game.board.GetSquare(rook.Orig_position); string last_pos = this.Current_position; string rook_last_pos = rook.Current_position; this.Current_position = GetSquarenameFromCoordinates(dest_col, dest_row); rook.Current_position = GetSquarenameFromCoordinates(dest_col - 1, dest_row); if (!this.game.board.IsKingInCheck(this.Color)) { if (!silentMode) { source.Content = ""; rook_source.Content = ""; this.isMoved = true; this.HasPerformedCastling = true; rook.IsMoved = true; this.game.board.lastAction = this.Desc + " FÜHRT DIE KLEINE ROCHADE" + " VON " + source.Name + " AUF " + dest.Name + " AUS"; // Neuer Logeintrag LogEntry log = new LogEntry(this, last_pos, this.Current_position); log.PerformedCastlingKingsSide = true; log.PlacedInCheck = this.game.board.IsKingInCheck(this.game.GetWaitingPlayer().Color); this.game.logger.Add(log); this.game.View.movesList.Items.Add(log); } } // Zug Rückgängig machen, wenn sich nach dem Zug // der König im Schach befinden würde else { this.Current_position = last_pos; rook.Current_position = rook_last_pos; throw new PlacedInCheckException(); } } // Große Rochade else if (source_col - dest_col == 2 && source_row == dest_row) { Rook rook = this.game.board.GetRook("A" + this.Orig_position.Substring(1, 1)); Square rook_source = this.game.board.GetSquare(rook.Orig_position); string last_pos = this.Current_position; string rook_last_pos = rook.Current_position; this.Current_position = GetSquarenameFromCoordinates(dest_col, dest_row); rook.Current_position = GetSquarenameFromCoordinates(dest_col + 1, dest_row); if (!this.game.board.IsKingInCheck(this.Color)) { if (!silentMode) { source.Content = ""; rook_source.Content = ""; this.isMoved = true; this.HasPerformedCastling = true; rook.IsMoved = true; this.game.board.lastAction = this.Desc + " FÜHRT DIE GROßE ROCHADE" + " VON " + source.Name + " AUF " + dest.Name + " AUS"; // Neuer Logeintrag LogEntry log = new LogEntry(this, last_pos, this.Current_position); log.PerfomedCastlingQueensSide = true; log.PlacedInCheck = this.game.board.IsKingInCheck(this.game.GetWaitingPlayer().Color); this.game.logger.Add(log); this.game.View.movesList.Items.Add(log); } } // Zug Rückgängig machen, wenn sich nach dem Zug // der König im Schach befinden würde else { this.Current_position = last_pos; rook.Current_position = rook_last_pos; throw new PlacedInCheckException(); } } // Einfacher Zug else { string last_pos = this.Current_position; this.Current_position = GetSquarenameFromCoordinates(dest_col, dest_row); if (!this.game.board.IsKingInCheck(this.Color)) { if (!silentMode) { source.Content = ""; this.isMoved = true; this.game.board.lastAction = "BEWEGE " + this.Desc + " VON " + source.Name + " AUF " + dest.Name; // Neuer Logeintrag LogEntry log = new LogEntry(this, last_pos, this.Current_position); log.PlacedInCheck = this.game.board.IsKingInCheck(this.game.GetWaitingPlayer().Color); this.game.logger.Add(log); this.game.View.movesList.Items.Add(log); } } // Zug Rückgängig machen, wenn sich nach dem Zug // der König im Schach befinden würde else { this.Current_position = last_pos; throw new PlacedInCheckException(); } } } else { Chessman chessmanAtDest = this.game.board.GetChessmanAtSquare(dest); // Angriffszug if (chessmanAtDest.Color != this.Color) { string last_pos = this.Current_position; this.Current_position = GetSquarenameFromCoordinates(dest_col, dest_row); this.game.board.chessman.Remove(chessmanAtDest); if (!this.game.board.IsKingInCheck(this.Color)) { if (!silentMode) { source.Content = ""; this.isMoved = true; this.game.board.lastAction = this.Desc + " SCHLÄGT " + chessmanAtDest.Desc + " AUF " + dest.Name; // Neuer Logeintrag LogEntry log = new LogEntry(this, last_pos, this.Current_position); log.OpponentMan = chessmanAtDest; log.PlacedInCheck = this.game.board.IsKingInCheck(this.game.GetWaitingPlayer().Color); this.game.logger.Add(log); this.game.View.movesList.Items.Add(log); } } // Zug Rückgängig machen, wenn sich nach dem Zug // der König im Schach befinden würde else { this.Current_position = last_pos; this.game.board.chessman.Add(chessmanAtDest); throw new PlacedInCheckException(); } } else { throw new BlockedMoveException(); } } } else { throw new BlockedMoveException(); } } else { throw new InvalidMoveException(); } }
public void Select_Field(Square selected) { // SCHACHFIGUR SELEKTIEREN if (selectedField == null) { selectedChessman = GetChessmanAtSquare(selected); if (selectedChessman != null) { if (game.GetActivePlayer().Color == selectedChessman.Color) { selectedField = selected; selectedField.Background = Brushes.MediumAquamarine; lastAction = selectedChessman.Desc + " AUF " + selectedField.Name + " AUSGEWÄHLT"; game.ShowInfo(lastAction); } else { game.ShowInfo("BITTE EINE EIGENE SCHACHFIGUR AUSWÄHLEN"); } } else { game.ShowInfo("BITTE EINE SCHACHFIGUR AUSWÄHLEN"); } } // SCHACHFIGUR DE-SELEKTIEREN else if (selectedField == selected) { selectedField.Background = selectedField.Color; selectedField = null; selectedChessman = null; game.ShowInfo("NICHTS AUSGEWÄHLT"); } // SCHACHFIGUR BEWEGEN else { fieldToMove = selected; if (selectedChessman != null) { Square currentField = GetSquare(selectedChessman.Current_position); try { selectedChessman.Move(currentField, fieldToMove); DisplayChessman(); game.RotatePlayer(); game.ShowInfo(lastAction, true); } catch (InvalidMoveException) { game.ShowInfo("UNGÜLTIGER ZUG"); } catch (BlockedMoveException) { game.ShowInfo("DIESER ZUG IST BLOCKIERT"); } catch (PlacedInCheckException) { if (game.GetActivePlayer().IsKingInCheck) { game.ShowInfo("DIESER ZUG IST NICHT MÖGLICH (KÖNIG WIRD BEDROHT)"); } else { game.ShowInfo("DIESER ZUG SETZT DEN KÖNIG IN SCHACH"); } } } else { game.ShowInfo("KEINE FIGUR ZUM BEWEGEN AUSGEWÄHLT! - NICHTS AUSGEWÄHLT"); } selectedField.Background = selectedField.Color; selectedField = null; selectedChessman = null; } }
public LogEntry(Chessman OwnMan, string OwnManSource, string OwnManDest) { this.OwnMan = OwnMan; this.OwnManSource = OwnManSource; this.OwnManDest = OwnManDest; }
private void CheckChessMove(object sender) { var startX = (initialChessmanLocation.X - 27) / 50; var startY = (initialChessmanLocation.Y - 27) / 50; var finishX = (CellsPositions[chessmansCellIndexRow, chessmansCellIndexColumn].X - 27) / 50; var finishY = (CellsPositions[chessmansCellIndexRow, chessmansCellIndexColumn].Y - 27) / 50; var impossibleMove = sender is Queen ? Queen.CheckQueenMove(startX, startY, finishX, finishY, ChessmanPresenceSign, Controls, sender, moveOrder) : sender is Castle ? Castle.CheckCastleMove(startX, startY, finishX, finishY, ChessmanPresenceSign, Controls, sender, moveOrder) : sender is Elephant ? Elephant.CheckElephantMove(startX, startY, finishX, finishY, ChessmanPresenceSign, Controls, sender, moveOrder) : sender is Horse ? Horse.CheckHorseMove(startX, startY, finishX, finishY, ChessmanPresenceSign, Controls, sender, moveOrder) : sender is King ? King.CheckKingMove(startX, startY, finishX, finishY, ChessmanPresenceSign, Controls, sender, sender) : Pawn.CheckPawnMove(startX, startY, finishX, finishY, ChessmanPresenceSign, Controls, sender, moveOrder); if (impossibleMove) { MessageBox.Show(Resources.ImpossibleMoveMessage); chess = (Chessman)sender; chess.Location = initialChessmanLocation; } else { //Проверка возможности превращения if (sender is Pawn) { if (((Pawn)sender).CanTransform) { var dialogWindow = new PawnTransfomDialog(); dialogWindow.Owner = this; DialogResult dialogResult = dialogWindow.ShowDialog(); if (dialogResult == DialogResult.OK && !dialogWindow.RBPawn.Checked) { var color = ((Pawn)sender).ChessColor; var finishPoint = new Point(finishX * 50 + 27, finishY * 50 + 27); ((Pawn)sender).Dispose(); if (dialogWindow.RBCastle.Checked) { var index = Castles.Count + 1; Castles.Add(color + "Castel" + index, new Castle(color)); Controls.Add(Castles[color + "Castel" + index]); Castles[color + "Castel" + index].Location = finishPoint; Castles[color + "Castel" + index].MouseLeave += Chessman_MouseLeave; Castles[color + "Castel" + index].MouseDown += Chessman_MouseDown; Castles[color + "Castel" + index].MouseUp += Chessman_MouseUp; Castles[color + "Castel" + index].MouseMove += Chessman_MouseMove; sender = Castles[color + "Castel" + index]; Chessman.CheckEnemyKingBeAttaced(startX, startY, finishX, finishY, ChessmanPresenceSign, Controls, sender, moveOrder); } if (dialogWindow.RBElephant.Checked) { var index = Elephants.Count + 1; Elephants.Add(color + "Elephant" + index, new Elephant(color)); Controls.Add(Elephants[color + "Elephant" + index]); Elephants[color + "Elephant" + index].Location = finishPoint; Elephants[color + "Elephant" + index].MouseLeave += Chessman_MouseLeave; Elephants[color + "Elephant" + index].MouseDown += Chessman_MouseDown; Elephants[color + "Elephant" + index].MouseUp += Chessman_MouseUp; Elephants[color + "Elephant" + index].MouseMove += Chessman_MouseMove; sender = Elephants[color + "Elephant" + index]; Chessman.CheckEnemyKingBeAttaced(startX, startY, finishX, finishY, ChessmanPresenceSign, Controls, sender, moveOrder); } if (dialogWindow.RBHorse.Checked) { var index = Horses.Count + 1; Horses.Add(color + "Horse" + index, new Horse(color)); Controls.Add(Horses[color + "Horse" + index]); Horses[color + "Horse" + index].Location = finishPoint; Horses[color + "Horse" + index].MouseLeave += Chessman_MouseLeave; Horses[color + "Horse" + index].MouseDown += Chessman_MouseDown; Horses[color + "Horse" + index].MouseUp += Chessman_MouseUp; Horses[color + "Horse" + index].MouseMove += Chessman_MouseMove; sender = Horses[color + "Horse" + index]; Chessman.CheckEnemyKingBeAttaced(startX, startY, finishX, finishY, ChessmanPresenceSign, Controls, sender, moveOrder); } if (dialogWindow.RBQueen.Checked) { var index = Queens.Count + 1; Queens.Add(color + "Queen" + index, new Queen(color)); Controls.Add(Queens[color + "Queen" + index]); Queens[color + "Queen" + index].Location = finishPoint; Queens[color + "Queen" + index].MouseLeave += Chessman_MouseLeave; Queens[color + "Queen" + index].MouseDown += Chessman_MouseDown; Queens[color + "Queen" + index].MouseUp += Chessman_MouseUp; Queens[color + "Queen" + index].MouseMove += Chessman_MouseMove; sender = Queens[color + "Queen" + index]; Chessman.CheckEnemyKingBeAttaced(startX, startY, finishX, finishY, ChessmanPresenceSign, Controls, sender, moveOrder); } } } } //Проверка мата или шаха ChessmanPresenceSign[startY, startX] = false; ChessmanPresenceSign[finishY, finishX] = true; moveOrder[((Chessman)sender).ChessColor] += -2; if (((Chessman)sender).ShahSigne && !((Chessman)sender).MateSigne) { MessageBox.Show(Resources.ShahMessage); ((Chessman)sender).ShahSigne = false; } if (((Chessman)sender).MateSigne) { DialogResult result = MessageBox.Show(Resources.MateMessage + Environment.NewLine + Resources.restartQuestion, Resources.GameEndMessage, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { Application.Restart(); } else { Application.Exit(); } } } }