Esempio n. 1
0
        private static void RunGameLoop(Config config, char[] board, char[] hints)
        {
            var gameLogger = new GameLogger();

            var canBlackMove = true;
            var canWhiteMove = true;

            while (canBlackMove || canWhiteMove)
            {
                switch (config.Player)
                {
                case Constants.Black:
                    Console.Write("BLACK, make your move: ");
                    break;

                case Constants.White:
                    Console.Write("WHITE, make your move: ");
                    break;

                default:
                    return;
                }

                var move = InputHandler.ReadInput(config, board, hints);

                gameLogger.WriteToGamelog(move);
                InputHandler.MakeMove(board, move, config.Player);
                InputHandler.PlacePiece(board, move, config.Player);

                // Change the current player
                config.Player = InputHandler.GetOtherPlayer(config.Player);

                // Test if players can move
                canBlackMove = CanPlayerMove(board, Constants.Black);
                canWhiteMove = CanPlayerMove(board, Constants.White);

                // And change player if current player can't
                if (config.Player == Constants.Black && !canBlackMove)
                {
                    Console.WriteLine("\nBLACK, can't make a move");
                    config.Player = Constants.White;
                }

                if (config.Player == Constants.White && !canWhiteMove)
                {
                    Console.WriteLine("\nWHITE, can't make a move");
                    config.Player = Constants.Black;
                }

                CalculateHints(config, board, hints, config.Player);

                Graphics.DrawBoard(board, hints);
            }
        }
Esempio n. 2
0
        public void RunGameLoop()
        {
            var gameLogger = new GameLogger();

            var canBlackMove = true;
            var canWhiteMove = true;

            var hintBoard = new Board(GameBoard);

            while (canBlackMove || canWhiteMove)
            {
                hintBoard = CalculateHints(GameConfig.Hints, CurrentPlayer);
                Graphics.DrawBoard(GameBoard, hintBoard);
                Graphics.PrintScore(GameBoard);
                Graphics.AnnouncePlayerMove(CurrentPlayer);

                var move = InputHandler.ReadInput(GameConfig, GameBoard, CurrentPlayer);

                gameLogger.WriteToGamelog(move);
                MakeMove(move, CurrentPlayer);
                PlacePiece(move, CurrentPlayer);

                // Change the current player
                CurrentPlayer = GetOtherPlayer(CurrentPlayer);

                // Test if players can move
                canBlackMove = CanPlayerMove(Constants.Black);
                canWhiteMove = CanPlayerMove(Constants.White);

                // And change player if current player can't move
                if (CurrentPlayer == Constants.Black && !canBlackMove)
                {
                    Console.WriteLine("\nBLACK, can't make a move");
                    CurrentPlayer = GetOtherPlayer(CurrentPlayer);
                }

                if (CurrentPlayer == Constants.White && !canWhiteMove)
                {
                    Console.WriteLine("\nWHITE, can't make a move");
                    CurrentPlayer = GetOtherPlayer(CurrentPlayer);
                }
            }

            Graphics.DrawBoard(GameBoard, hintBoard);
            Graphics.PrintFinalScore(GameBoard);
        }