// Ü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); }
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; } }