Exemple #1
0
        public virtual string ReadAction(Board board)
        {
            List <Movement> legalMoves = legalMovesCalculator.GetLegalMoves(board);
            string          movements  = movementDisplayNamesResolver.Render(legalMoves);

            return(io.Read($"Please select movement: {movements} - Or New Game ({newGameSymbol}) / End Game ({endGameSymbol})"));
        }
        public virtual int Read()
        {
            while (true)
            {
                io.Clear();
                string candidateSize = io.Read("Please enter board size. The size must be a natural number bigger then 0");

                if (!string.IsNullOrEmpty(candidateSize) && int.TryParse(candidateSize, out int size) && size > 0)
                {
                    return(size);
                }
                else
                {
                    io.Read($"{candidateSize} is not a valid board size! Press Enter to continue.");
                }
            }
        }
Exemple #3
0
        public virtual GameFlow Play(Board board)
        {
            GameFlow flow = GameFlow.KEEP_PLAYING;

            while (flow == GameFlow.KEEP_PLAYING)
            {
                PrintBoard(board);
                if (board.IsSolved)
                {
                    io.Read("Congrats! you solved the game! Press Enter to continue");
                    flow = GameFlow.NEW_GAME;
                }
                else
                {
                    string action = actionReader.ReadAction(board);

                    flow = actionApplier.ApplyAction(board, action);
                }
            }
            return(flow);
        }