예제 #1
0
파일: Program.cs 프로젝트: lucyelle/Chess
        static bool PlayerTurn(Board board, FigureColor color)
        {
            StepPossibility stepState = board.GetStepPossibilities(color);

            if (stepState == StepPossibility.CheckMate)
            {
                Console.WriteLine($"Checkmate! {color} lost!");
                return(false);
            }
            if (stepState == StepPossibility.StaleMate)
            {
                Console.WriteLine($"Stalemate! It's a draw!");
                return(false);
            }

            Console.WriteLine(color);
            while (true)
            {
                (int, int)from = GetValidCoordinates(board, color);
                Figure figure = board.Figures[from.Item1, from.Item2];
                if (figure != null && figure.Color == color)
                {
                    (int, int)to = GetValidCoordinates(board, color);
                    if (board.StepWithoutCheck(from.Item1, from.Item2, to.Item1, to.Item2, color))
                    {
                        board.Figures[from.Item1, from.Item2] = null;
                        board.Figures[to.Item1, to.Item2]     = figure;
                        return(true);
                    }
                    else
                    {
                        Console.Clear();
                        board.Draw();
                        Console.WriteLine(color);
                        Console.WriteLine("You can't step there!");
                    }
                }
                else
                {
                    Console.Clear();
                    board.Draw();
                    Console.WriteLine(color);
                    Console.WriteLine("Not your figure you naughty boy!");
                }
            }
        }