Exemplo n.º 1
0
 /// <summary>
 /// Остановить игру (часы и т.д)
 /// </summary>
 public static void StopGame()
 {
     TimerStop();
     TimeWhite.Stop();
     TimeBlack.Stop();
     EventGameEnd?.Invoke(new object(), new EventArgs());
 }
Exemplo n.º 2
0
 /// <summary>
 /// Проверяет не иссякло ли время у одной из сторон
 /// </summary>
 public static void CheckTime(object obj)
 {
     if (TimeBlack.Elapsed > MaxTimeBlack)
     {
         WhiteWin = true;
         TimeBlack.Stop();
         TimeWhite.Stop();
         StopGame();
         EventTimeEnded?.Invoke(TimeBlack, TimeEndedArgs);
     }
     else if (TimeWhite.Elapsed > MaxTimeWhite)
     {
         BlackWin = true;
         TimeBlack.Stop();
         TimeWhite.Stop();
         StopGame();
         EventTimeEnded?.Invoke(TimeWhite, TimeEndedArgs);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Сделать ход в позиции (возвращает - возможен ли он)
 /// </summary>
 public static bool TryMoved(MoveCoord move)
 {
     if (GamePosition.Board[move.xStart, move.yStart].Figure.Type == TypeFigur.king)
     {
         if (move.yStart == 4)
         {
             if ((move.xStart == 0 && GamePosition.IsWhiteMove) || (move.xStart == 7 && GamePosition.IsWhiteMove == false))
             {
                 if (move.yEnd == 2 || move.yEnd == 6)
                 {
                     move.IsCastling = true;
                 }
             }
         }
     }
     if (GamePosition.Board[move.xStart, move.yStart].Figure.CheckMove(GamePosition, move))
     {
         Positions.Add((Position)GamePosition.DeepCopy());
         MoveCoord mc = new MoveCoord();
         mc.xStart      = move.xStart;
         mc.yStart      = move.yStart;
         mc.yEnd        = move.yEnd;
         mc.xEnd        = move.xEnd;
         mc.StartFigure = move.StartFigure;
         Moves.Add(mc);
         int coll = 0;
         GamePosition.MoveChess(move);
         if (move.EndFigure == new NotFigur() && !move.IsEnPassant)
         {
             MovesWithoutEating++;
         }
         else
         {
             MovesWithoutEating = 0;
         }
         foreach (Position p in Positions)
         {
             if (p.Equals(GamePosition))
             {
                 coll++;
             }
         }
         if (GamePosition.IsWhiteMove)
         {
             TimeBlack.Stop();
             TimeWhite.Start();
             int?i = CheckPosition(GamePosition);
             if (i < 0)
             {
                 BlackWin = true;
                 StopGame();
             }
             else if (i == 0)
             {
                 StopGame();
             }
             else if (coll > 2)
             {
                 MessageBox.Show("Троекратное повторение ходов. Ничья!");
                 MovesWithoutEating = 50;
                 StopGame();
             }
             else if (MovesWithoutEating > 49)
             {
                 MessageBox.Show("50 ходов без взятий. Ничья!");
                 StopGame();
             }
             return(true);
         }
         else
         {
             TimeWhite.Stop();
             TimeBlack.Start();
             int?i = CheckPosition(GamePosition);
             if (i > 0)
             {
                 WhiteWin = true;
                 StopGame();
             }
             if (i == 0)
             {
                 StopGame();
             }
             if (coll > 2 || MovesWithoutEating > 49)
             {
                 StopGame();
             }
             return(true);
         }
     }
     move = new MoveCoord();
     return(false);
 }