예제 #1
0
        public virtual GameFlow ApplyAction(Board board, string action)
        {
            GameFlow flow = GameFlow.KEEP_PLAYING;

            if (movementDisplayNamesResolver.TryResolve(action, out Movement movement))
            {
                if (!tileMover.TryMove(board, movement, out string error))
                {
                    io.WriteLine($"Failed moving a tile: {error}", 3000);
                }
            }
            else if (action == newGameSymbol)
            {
                flow = GameFlow.NEW_GAME;
            }
            else if (action == endGameSymbol)
            {
                flow = GameFlow.END_GAME;
            }
            else
            {
                io.WriteLine($"'{action}' is not a legal input", 3000);
            }

            return(flow);
        }
        private bool TryResolve(string action, out Movement movement)
        {
            Dictionary <Movement, string> movementDisplayNames = new Dictionary <Movement, string>()
            {
                { Movement.DOWN, "D" }
            };
            MovementDisplayNamesResolver movementDisplayNamesResolver = new MovementDisplayNamesResolver(movementDisplayNames);

            return(movementDisplayNamesResolver.TryResolve(action, out movement));
        }