Exemplo n.º 1
0
        private IRace GetPlayerRace(IConsoleWindow console)
        {
            Console.Clear();
            console.Clear();
            console.Write(Position.Zero, ConsoleColor.Green, "Choose A Race: ");
            for (var i = 0; i < AvailableRaces.Count; i++)
            {
                var currentRace = AvailableRaces[i];
                console.Write(new Position(0, i + 1), $"{i + 1}: " +
                              $"{currentRace.Name} - " +
                              $"(Health: {currentRace.Health}, Damage: {currentRace.Damage})");
            }

            while (true)
            {
                console.Render();
                var raceNumber = ConsoleInputReader.ReadKey();

                if (int.TryParse(raceNumber.KeyChar.ToString(), out int index) && index >= 1 && index <= AvailableRaces.Count)
                {
                    return(AvailableRaces[index - 1]);
                }

                console.Write(new Position(0, AvailableRaces.Count + 1), "Please enter a valid race number.");
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var reader = new ConsoleInputReader();
            var writer = new ConsoleOutputWriter();

            new Solver(reader, writer).Solve();
        }
Exemplo n.º 3
0
        private string GetPlayerName()
        {
            string name;

            ConsoleRenderer.ForegroundColor(ConsoleColor.Green);
            ConsoleRenderer.Write("Type player's name : ");
            ConsoleRenderer.ResetColor();
            ConsoleRenderer.WriteLine("(including only small and capital letters and between 2 and 10 characters)");
            while (true)
            {
                try
                {
                    name = ConsoleInputReader.ReadLine();

                    if (!PlayerNamePattern.IsMatch(name))
                    {
                        throw new ArgumentException("Invalid name. Try again.");
                    }

                    break;
                }
                catch (ArgumentException ex)
                {
                    ConsoleRenderer.WriteLine(ex.Message);
                }
            }

            ConsoleRenderer.ForegroundColor(ConsoleColor.Green);
            ConsoleRenderer.WriteLine("Player name set to: {0}", name);
            ConsoleRenderer.ResetColor();

            return(name);
        }
Exemplo n.º 4
0
 protected virtual string GetPlayerName(IConsoleWindow console)
 {
     console.Write(Position.Zero, ConsoleColor.Green, "Enter Player's Name: ");
     console.Render();
     Console.ForegroundColor = ConsoleColor.White;
     return(ConsoleInputReader.ReadLine());
 }
Exemplo n.º 5
0
        public static void Main()
        {
            var renderer = new ConsoleRenderer();
            var inputReader = new ConsoleInputReader();

            var engine = new GameEngine(renderer, inputReader);
            engine.Run();
        }
Exemplo n.º 6
0
        public static void Main()
        {
            IRenderer    renderer = new ConsoleRenderer();
            IInputReader reader   = new ConsoleInputReader();
            GameEngine   engine   = new GameEngine(reader, renderer);

            engine.Run();
        }
        public static void Main()
        {
            IRenderer renderer = new ConsoleRenderer();
            IInputReader reader = new ConsoleInputReader();

            SuperEngine engine = new SuperEngine(reader, renderer);

            engine.Run();
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            IInputReader reader   = new ConsoleInputReader();
            IRenderer    renderer = new ConsoleRenderer();

            GameEngine gameEngine = new GameEngine(reader, renderer);

            gameEngine.Run();
        }
Exemplo n.º 9
0
        public static void Main()
        {
            var database = new PerformanceDatabase();
            var reader = new ConsoleInputReader();
            var writer = new ConsoleOutputWriter();

            var engine = new Engine(database, reader, writer);
            engine.Run();
        }
Exemplo n.º 10
0
        static void Main()
        {
            IRenderer    renderer = new ConsoleRenderer();
            IInputReader reader   = new ConsoleInputReader();

            SuperEngine engine = new SuperEngine(reader, renderer);

            engine.Run();
        }
Exemplo n.º 11
0
    public static void Main()
    {
        IInputReader  inputReader  = new ConsoleInputReader();
        IOutputWriter outputWriter = new ConsoleOutputWriter();
        HeroManager   manager      = new HeroManager();

        Engine engine = new Engine(inputReader, outputWriter, manager);

        engine.Run();
    }
        public static void Main()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

            var database = new HotelBookingSystemData();
            var reader = new ConsoleInputReader();
            var writer = new ConsoleOutputWriter();
            var engine = new Engine(database, reader, writer);

            engine.StartOperation();
        }
Exemplo n.º 13
0
        public static void Main()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

            var database = new HotelBookingSystemData();
            var reader   = new ConsoleInputReader();
            var writer   = new ConsoleOutputWriter();
            var engine   = new Engine(database, reader, writer);

            engine.StartOperation();
        }
Exemplo n.º 14
0
    public static void Main()
    {
        IInputReader  inputReader  = new ConsoleInputReader();
        IOutputWriter outputWriter = new ConsoleOutputWriter();
        IHeroFactory  factory      = new HeroFactory();
        IInventory    inventory    = new HeroInventory();
        IList <IHero> heroes       = new List <IHero>();
        IManager      manager      = new HeroManager(factory, inventory, heroes);
        Engine        engine       = new Engine(inputReader, outputWriter, manager);

        engine.Run();
    }
Exemplo n.º 15
0
        private IRace GetPlayerRace()
        {
            ConsoleRenderer.ForegroundColor(ConsoleColor.Green);
            ConsoleRenderer.WriteLine("Choose a race : ");
            ConsoleRenderer.ResetColor();

            for (int i = 0; i < this.availableRaces.Count; i++)
            {
                IRace currentRace = Activator.CreateInstance(this.availableRaces[i]) as IRace;
                ConsoleRenderer.WriteLine("{0}: {1} - (Health: {2}, Damage: {3})",
                                          i + 1, this.availableRaces[i].Name, currentRace.Health, currentRace.Damage);
            }

            int index;

            while (true)
            {
                try
                {
                    string raceNumber = ConsoleInputReader.ReadLine();

                    if (!int.TryParse(raceNumber, out index))
                    {
                        throw new ArgumentException("Please enter a valid race number.");
                    }

                    index = int.Parse(raceNumber);

                    if (index < 1 || index > this.availableRaces.Count)
                    {
                        throw new ArgumentOutOfRangeException("Please enter a valid race number.");
                    }

                    break;
                }

                catch (ArgumentOutOfRangeException ex)
                {
                    ConsoleRenderer.WriteLine(ex.Message);
                }
                catch (ArgumentException ex)
                {
                    ConsoleRenderer.WriteLine(ex.Message);
                }
            }

            ConsoleRenderer.ForegroundColor(ConsoleColor.Green);
            ConsoleRenderer.WriteLine("Race chosen: {0}", this.availableRaces[index - 1].Name);
            ConsoleRenderer.ResetColor();

            return(Activator.CreateInstance(this.availableRaces[index - 1]) as IRace);
        }
Exemplo n.º 16
0
        /// <summary>
        /// The Main method of the project.
        /// </summary>
        /// <param name="args">Arguments passed to the Main method.</param>
        public static void Main(string[] args)
        {
            IRepository<ICommand> commandRepository = new CommandRepository();
            IHandler<ICommandArguments> commandHandler = new CommandHandler(commandRepository);
            IInputReader inputReader = new ConsoleInputReader();
            IOutputWriter outputWriter = new ConsoleOutputWriter();
            IRepository<IBlob> blobRepository = new BlobRepository();
            ICommandArguments commandArguments = new CommandArguments(blobRepository, outputWriter);
            IEngine gameEngine = new Engine(commandHandler, commandArguments, inputReader, (IUpdateable)blobRepository);
            commandArguments.Stopable = gameEngine;

            gameEngine.Run();
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            var consoleReader = new ConsoleInputReader()
                .ReadNumberOfCommands()
                .ReadStartPosition()
                .ReadCommands();
            var robot = RobotFactory.CreateCleaningRobotAt(consoleReader.StartPosition);
            var textCommander = new TextCommander(robot);
            foreach (var command in consoleReader.Commands)
            {
                textCommander.Execute(command);
            }

            Console.WriteLine("=> Cleaned: " + robot.GetLog().CleanedStations);
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            var consoleReader = new ConsoleInputReader()
                                .ReadNumberOfCommands()
                                .ReadStartPosition()
                                .ReadCommands();
            var robot         = RobotFactory.CreateCleaningRobotAt(consoleReader.StartPosition);
            var textCommander = new TextCommander(robot);

            foreach (var command in consoleReader.Commands)
            {
                textCommander.Execute(command);
            }

            Console.WriteLine("=> Cleaned: " + robot.GetLog().CleanedStations);
        }
Exemplo n.º 19
0
        public static void Main(string[] args)
        {
            string stopJSON;
            string transportAndScheduleJSON;

            using (WebClient webClient = new WebClient())
            {
                stopJSON = webClient.DownloadString("https://api.trafi.com/api/stops?userLocationId=kaunas");
                transportAndScheduleJSON = webClient.DownloadString("https://api.trafi.com/api/v3/schedules?userLocationId=kaunas");
            }

            ILocationParser locationParser   = new TrafiApiLocationParser(stopJSON);
            var             locationsWithIds = ((TrafiApiLocationParser)locationParser).ParseLocationsWithIds();

            ITransportParser transportParser = new TrafiApiTransportParser(transportAndScheduleJSON);
            var transports = transportParser.ParseTransports(locationsWithIds);

            IGraphFormer <AStarNode> graphFormer = new GraphFormer <AStarNode>();
            var stopGraph = graphFormer.FormGraph(locationsWithIds, transports);

            ITransitAdder pedestrianPathAdder = new PedestrianTransitAdder();

            stopGraph = pedestrianPathAdder.AddTransits(stopGraph);

            IWeightCalculator       weightCalculator    = new PenalisingWeightCalculator(new WeightCalculator());
            IWeightCalculator       heuristicCalculator = new HeuristicCalculator();
            IPathFinder <AStarNode> pathFinder          = new AStarPathFinder(stopGraph, weightCalculator, heuristicCalculator);

            IInputReader  inputReader  = new ConsoleInputReader();
            IOutputWriter outputWriter = new ConsoleOutputWriter();
            var           stopWatch    = new Stopwatch();

            var startingStopID = ((ConsoleInputReader)inputReader).ReadStopID(locationsWithIds);
            var endingStopID   = ((ConsoleInputReader)inputReader).ReadStopID(locationsWithIds);
            var departureTime  = inputReader.ReadTime();

            stopWatch.Reset();
            stopWatch.Start();
            var path = pathFinder.FindBestPath(stopGraph.Nodes[startingStopID], stopGraph.Nodes[endingStopID], departureTime);

            stopWatch.Stop();

            path.Squash();
            outputWriter.WriteElapsedTime(stopWatch.Elapsed);
            outputWriter.WritePath(path);
        }
Exemplo n.º 20
0
        public void UserInputValidatorTest()
        {
            //arrange
            var           inputreader = new ConsoleInputReader();
            var           printer     = new ConsolePrinter();
            MatrixBuilder m           = new MatrixBuilder(inputreader, printer);

            //act

            int    min = 0, max = 100;
            Random random = new Random();

            m.BuildMatrix((uint)random.Next(min, max), (uint)random.Next(min, max));

            //assert
            Assert.IsTrue(m.MatrixTrail >= 0);
        }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            IInputReader reader = new ConsoleInputReader();
            var          input  = reader.Read();

            IParser <MaterialReport> parser = new MaterialParser();
            var materials = parser.Parse(input);

            IMagazineService magazineService = new MagazineService();
            var magazines = magazineService.ProcessMaterialReportsIntoMagazines(materials).ToList();

            IWriter <IEnumerable <Magazine> > writer = new ConsoleWriter();

            writer.Write(magazines);

            Console.ReadLine();
        }
Exemplo n.º 22
0
        public static void Main(string[] args)
        {
            IInputReader reader   = new ConsoleInputReader();
            IRenderer    renderer = new ConsoleRenderer();

            Engine engine = new Engine(reader, renderer);

            engine.Run();

//			Scooter scooter = new Scooter ("Scooter 1", new Position (0));
//			Console.WriteLine (scooter);
//
//			Catamaran catamaran = new Catamaran ("Catamaran 1", new Position (8));
//			Console.WriteLine (catamaran);
//
//			BattleCruiser battleCruiser = new BattleCruiser ("BattleCruiser", new Position (16));
//			Console.WriteLine (battleCruiser);
//
//			Console.WriteLine ("Game begins ...");
        }
Exemplo n.º 23
0
        static void Main()
        {
            // var pluginReader = new OperationPluginReader();
            List <IOperation> operations;

            try
            {
                operations = GetOperations();
                // operations = pluginReader.ReadPluginsFrom(Environment.CurrentDirectory + "\\Plugins");
            }
            catch (DirectoryNotFoundException)
            {
                Console.WriteLine("Ошибка! Отсутсвует директория Plugins");
                Console.WriteLine("Нажмите любую клавишу, чтобы выйти...");
                Console.ReadKey();
                return;
            }
            var recognizer = new BaseRecognizer();
            var calculator = new PostfixCalculator(recognizer.CraeteOperations(operations));

            ShowAvailableOperations(calculator.GetAvailableOperations());
            var reader = new ConsoleInputReader();

            while (true)
            {
                try
                {
                    var result = calculator.Calculate(reader.GetExpression());
                    Console.WriteLine($"Результат: {result}");
                }
                catch (UnrecognizedOperationException e)
                {
                    Console.WriteLine(e.Message);
                }
                Console.WriteLine("Нажмите Enter, чтобы продолжить или Esc, чтобы выйти");
                if (Console.ReadKey().Key == ConsoleKey.Escape)
                {
                    return;
                }
            }
        }