Example #1
0
 public bool IsBlockedIfMove(Doska.Yacheika from, Doska.Yacheika to, Doska.Yacheika blocked)
 {
     if (possibleMoves.Contains(blocked) && !possibleMoves.Contains(to))
     {
         return(false);
     }
     else if (possibleMoves.Contains(from))
     {
         int toIndex = possibleMoves.IndexOf(to);
         if (0 <= toIndex && toIndex < possibleMoves.Count - 1)
         {
             return(true);
         }
         else
         {
             // Если мы двинулись дальше
             foreach (Doska.Yacheika move in from.OpenLineOfSight(X, Y, DesiredCount - possibleMoves.Count))
             {
                 if (move == to) //перешел на новый путь
                 {
                     return(true);
                 }
                 if (move == blocked) //заблокирован
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
Example #2
0
 private void turnOver()// Вызывается, когда ход передается другому игроку.
 {
     board.Move(holdedNode, moveTo, promoteOption);
     holdedNode    = null;
     moveTo        = null;
     playerState   = PlayerState.Idle;
     currentPlayer = currentPlayer == PlayerColor.White ? PlayerColor.Black : PlayerColor.White;
     turnStart();
 }
Example #3
0
 public void Draw(ConsoleGraphics g)//Рисует игру
 {
     g.FillArea(new CChar(' ', ConsoleColor.Black, ConsoleColor.DarkGray), 10, 5, 8, 8);
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             Doska.Yacheika yacheika = board.GetCell(i, j);
             if (yacheika.Piece != null)
             {
                 g.DrawTransparent(yacheika.Piece.Char, (yacheika.Piece.Color == PlayerColor.White) ? ConsoleColor.White : ConsoleColor.Black, 10 + i, 5 + (7 - j));
                 if (yacheika.Piece.LegalMoves.Count == 0)
                 {
                     g.SetBackground(ConsoleColor.DarkRed, 10 + i, 5 + (7 - j));
                 }
             }
             if (yacheika.HitBy.Contains(debugPiece))
             {
                 g.SetBackground(ConsoleColor.DarkMagenta, 10 + i, 5 + (7 - j));
             }
         }
     }
     if (holdedNode != null && playerState == PlayerState.Holding)
     {
         foreach (Doska.Yacheika move in holdedNode.Piece.LegalMoves)// Подсветка возможных ходов
         {
             g.SetBackground(ConsoleColor.DarkGreen, 10 + move.X, 5 + (7 - move.Y));
         }
     }
     g.SetBackground(ConsoleColor.DarkYellow, 10 + cursorX, 5 + (7 - cursorY));// курсор- желтый
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             if ((i + j) % 2 == 1)
             {
                 g.LightenBackground(10 + i, 5 + j);
             }
         }
     }
     if (playerState == PlayerState.AwaitPromote)// Меню параметров продвижения
     {
         g.DrawTextTrasparent("Dama", promoteOption == PromoteOptions.Queen ? ConsoleColor.Yellow : ConsoleColor.White, 22, 7);
         g.DrawTextTrasparent("LAdiya", promoteOption == PromoteOptions.Rook ? ConsoleColor.Yellow : ConsoleColor.White, 22, 9);
         g.DrawTextTrasparent("Slon", promoteOption == PromoteOptions.Bishop ? ConsoleColor.Yellow : ConsoleColor.White, 22, 11);
         g.DrawTextTrasparent("Kon", promoteOption == PromoteOptions.Knight ? ConsoleColor.Yellow : ConsoleColor.White, 22, 13);
     }
     else
     {
         g.ClearArea(22, 7, 6, 7);
     }
 }
Example #4
0
        // kогда пользователь нажимает клавишу ввода
        private void interact()
        {
            switch (playerState)
            {
            case PlayerState.Idle:
                holdedNode = board.GetCell(cursorX, cursorY);

                if (holdedNode.Piece == null || holdedNode.Piece.Color != currentPlayer || holdedNode.Piece.LegalMoves.Count == 0)
                {
                    holdedNode = null;
                    return;
                }
                else
                {
                    playerState = PlayerState.Holding;
                }
                break;

            case PlayerState.Holding:
                playerState = PlayerState.Holding;
                moveTo      = board.GetCell(cursorX, cursorY);
                if (!holdedNode.Piece.LegalMoves.Contains(moveTo))
                {
                    moveTo = null;
                    return;
                }
                if (board.IsPromotable(holdedNode, moveTo))
                {
                    showPromote();
                }
                else
                {
                    turnOver();
                }
                break;

            case PlayerState.AwaitPromote:
                turnOver();
                break;

            case PlayerState.GameOver:
                Running = false;
                break;
            }
        }
Example #5
0
 private void cancel()//если esc
 {
     playerState = PlayerState.Idle;
     holdedNode  = null;
 }
Example #6
0
 protected virtual bool canHit(Doska.Yacheika yacheika)
 {
     return(yacheika != null && yacheika.Piece != null && yacheika.Piece.Color != Color);
 }
Example #7
0
 public abstract bool IsBlockedIfMove(Doska.Yacheika from, Doska.Yacheika to, Doska.Yacheika blocked);
Example #8
0
 public void OnMove(Doska.Yacheika yacheika)
 {
     Parent = yacheika;
     Moved  = true;
 }
Example #9
0
 public void OnPlace(Doska.Yacheika yacheika)
 {
     Parent = yacheika;
 }