Exemple #1
0
        private static void Init()
        {
            if (game == null)
            {
                game = new Battleships();
            }
            if (!resized && restart)
            {
                game.Init();
                System.Threading.Thread.Sleep(100);
                hasOutcome = false;
                lastAction = null;
                restart    = false;
            }
            Console.Clear();

            CLEAR_LINE = "".PadRight(Console.BufferWidth);

            #region Header
            Console.WriteLine($"\n Save game: Ctrl+{SAVE};    Exit Game: Ctrl+{EXIT};    New Game: Ctrl+{NEW}\n" +
                              $"\nSelect cell: {ENTER}/{ENTER_ALT};    Move Down: {DOWN}/{DOWN_ALT};    Move Up: {UP}/{UP_ALT};    Move Left: {LEFT}/{LEFT_ALT};    Move Right: {RIGHT}/{RIGHT_ALT};\n\n");
            playerRow = Console.CursorTop;
            WriteLine($" {(!game.Turn ? PLAYER1 : PLAYER2)}'s turn\n", ConsoleColor.Cyan);
            #endregion Header

            #region Board
            BoardRow = Console.CursorTop;
            DrawBoard();
            #endregion Board

            #region Last action
            WriteLine("\n Last action:", ConsoleColor.Yellow);
            lastActionRow = Console.CursorTop;
            if (lastAction != null)
            {
                PostLastAction(lastAction ?? "\n");
            }
            #endregion Last action

            #region Game Log
            WriteLine("\n\n Game Log:", ConsoleColor.Green);
            List <GameMove> log = game.GetLog();
            foreach (var move in log)
            {
                WriteLine($"{(!move.turn ? PLAYER1 : PLAYER2)} {move}");
            }
            lastLogRow = Console.CursorTop;
            #endregion Game Log

            ConsoleWidth  = Console.WindowWidth;
            ConsoleHeight = Console.WindowHeight;
            resized       = false;
            restart       = false;

            Console.SetCursorPosition(firstCellCol, firstCellRow);
        }