Beispiel #1
0
        //
        // Summary:
        //     Show a home screen.
        public static void HomeScreen(DraughtsMatch match)
        {
            //
            // Write "DRAUGHTS" centered while changing the color of the letters between red and gray.
            Console.Write("    ");
            foreach (var letter in "DRAUGHTS")
            {
                Console.ForegroundColor = (Console.ForegroundColor == ConsoleColor.Gray) ? ConsoleColor.Red : ConsoleColor.Gray;
                Console.Write(letter);
            }
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine();
            Console.WriteLine();

            WriteLineBoard(match.Board);
            Console.WriteLine();

            Console.Write("Press any key to continue...");
            Console.ReadKey(true);
        }
Beispiel #2
0
        static void Main()
        {
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Gray;

            var actualMatch = new DraughtsMatch();

            GameScreen.HomeScreen(actualMatch);

            do
            {
                Console.Clear();
                GameScreen.WriteLineBoard(actualMatch.Board, actualMatch.PossibleSelections());
                Console.WriteLine();

                GameScreen.WriteLineMatchReport(actualMatch);
                Console.WriteLine();

                Console.Write("Select a piece: ");
                try
                {
                    Piece selectedPiece = actualMatch.SelectPiece();

TryMovementAgain:
                    Console.Clear();
                    GameScreen.WriteLineBoard(actualMatch.Board, selectedPiece.PossibleTargets(), selectedPiece);
                    Console.WriteLine();

                    GameScreen.WriteLineMatchReport(actualMatch);
                    Console.WriteLine();

                    Console.Write("Selected piece: ");
                    GameScreen.WritePiece(selectedPiece);
                    Console.WriteLine($" ({selectedPiece.BoardPosition})");

                    Console.Write("Select a target: ");
                    try
                    {
                        actualMatch.MakeMovement(selectedPiece, actualMatch.SelectTarget(selectedPiece));
                        actualMatch.PassTurn();
                    }
                    catch (FormatException e)
                    {
                        GameScreen.WriteError(e.Message, "Try to follow the next example: e4");
                        goto TryMovementAgain;
                    }
                    catch (InvalidPositionException e)
                    {
                        GameScreen.WriteError(e.Message, "Select a position with white highlight.");
                        goto TryMovementAgain;
                    }
                }
                catch (FormatException e)
                {
                    GameScreen.WriteError(e.Message, "Try to follow the next example: e4");
                }
                catch (InvalidPositionException e)
                {
                    GameScreen.WriteError(e.Message, "Please, select a valid piece.");
                }
            } while (!actualMatch.IsFinished());
        }
Beispiel #3
0
 //
 // Summary:
 //     Write all information about the match.
 //
 // Parameters:
 //   match:
 //     The departure from where the information will be analyzed.
 public static void WriteLineMatchReport(DraughtsMatch match)
 {
     Console.WriteLine("Turn: " + match.Round);
     Console.Write("Waiting movement: ");
     WriteLineTeam(match.TurnPlayer);
 }