Exemplo n.º 1
0
        private static async Task Main(string[] args)
        {
            var universe = new Universe(new ILivenessRule[]
            {
                new LivenessRule1(),
                new LivenessRule2(),
                new LivenessRule3(),
                new LivenessRule4()
            });

            var board = new Board(
                rows: 10,
                columns: 10,
                liveCells: new HashSet <Coordinate>
            {
                new Coordinate(5, 4),
                new Coordinate(5, 5),
                new Coordinate(5, 6),
            });

            var presenter = new ConsolePresenter();

            presenter.PrintBoard(board);

            for (int i = 0; i < 100; i++)
            {
                board = universe.NextGeneration(board);
                presenter.PrintBoard(board);
                await Task.Delay(200);
            }
        }
Exemplo n.º 2
0
        private void MainMenu()
        {
            char item;

            do
            {
                item = ConsolePresenter.GetChar("What do you want?\n[1] Buy our product\n[2] Check our warehouse state\n[3] Add new product\n[4] Leave\nDecision: ");
                ConsolePresenter.ClearConsole();
            }while (item != '1' && item != '2' && item != '3' && item != '4');

            switch (item)
            {
            case '1':
                TradingConsole.Buy(Products);
                MainMenu();
                break;

            case '2':
                CheckingConsole.Check(Products);
                Leave();
                break;

            case '3':
                AddingConsole.Add(Products);
                MainMenu();
                break;

            case '4':
                Leave();
                break;
            }
        }
Exemplo n.º 3
0
        public void RunShould()
        {
            var display  = new ConsolePresenter();
            var instance = new Application(new AnimalIterator(display), new AnimalFactory(display));

            instance.Run();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var collector = new DataCollector();

            var consolePresenter         = new ConsolePresenter();
            var filePresenter            = new FilePresenter(@"d:\temp\persons.txt");
            var shoutingConsolePresenter = new ShoutingConsolePresenter();

            var multiplePresenter = new MultiplePresenter(new List <IPresenter> {
                shoutingConsolePresenter, consolePresenter, filePresenter
            });

            while (true)
            {
                Console.Write("Enter your name: ");
                var name = Console.ReadLine();

                Console.Write("Enter your age: ");
                var age = int.Parse(Console.ReadLine());

                collector.CollectData(name, age);

                Console.Write("Add more? (y/n) ");
                var answer = Console.ReadKey();
                Console.WriteLine();

                if (answer.Key == ConsoleKey.N)
                {
                    break;
                }
            }
            collector.PresentData(multiplePresenter);

            Console.ReadLine();
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            new ConsolePresenter().Header(2, "Interfaces");
            new AnimalFactory().Start();

            ConsolePresenter.Pause();
        }
        public void Setup()
        {
            presenter = new ConsolePresenter();
            hitShip   = new Mock <IShip>();
            hitShip.Setup(_ => _.WasHit).Returns(true);
            hitShip.Setup(_ => _.WasSank).Returns(false);

            sankShip = new Mock <IShip>();
            sankShip.Setup(_ => _.WasHit).Returns(true);
            sankShip.Setup(_ => _.WasSank).Returns(true);

            shotPoint = new Mock <IMapPoint>();
            shotPoint.Setup(_ => _.IsShip).Returns(false);
            shotPoint.Setup(_ => _.WasHit).Returns(false);

            emptyPoint = new Mock <IMapPoint>();
            emptyPoint.Setup(_ => _.IsShip).Returns(false);
            emptyPoint.Setup(_ => _.WasHit).Returns(true);
            emptyPoint.Setup(_ => _.IsBlocked).Returns(false);
            emptyPoint.Setup(_ => _.IsHidden).Returns(false);

            shotShipPoint = new Mock <IMapPoint>();
            shotShipPoint.Setup(_ => _.IsShip).Returns(true);
            shotShipPoint.Setup(_ => _.WasHit).Returns(true);
            shotShipPoint.Setup(_ => _.IsBlocked).Returns(true);
            shotShipPoint.Setup(_ => _.IsHidden).Returns(false);
            shotShipPoint.Setup(_ => _.Ship).Returns(hitShip.Object);

            sankShipPoint = new Mock <IMapPoint>();
            sankShipPoint.Setup(_ => _.IsShip).Returns(true);
            sankShipPoint.Setup(_ => _.WasHit).Returns(true);
            sankShipPoint.Setup(_ => _.IsBlocked).Returns(true);
            sankShipPoint.Setup(_ => _.IsHidden).Returns(false);
            sankShipPoint.Setup(_ => _.Ship).Returns(sankShip.Object);

            hiddenPoint = new Mock <IMapPoint>();
            hiddenPoint.Setup(_ => _.IsShip).Returns(false);
            hiddenPoint.Setup(_ => _.WasHit).Returns(false);
            hiddenPoint.Setup(_ => _.IsBlocked).Returns(false);
            hiddenPoint.Setup(_ => _.IsHidden).Returns(true);

            gameMap = new Mock <IGameMap>();
            gameMap.Setup(_ => _.MaxX).Returns(4);
            gameMap.Setup(_ => _.MaxY).Returns(3);

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    gameMap.Setup(_ => _[i, j]).Returns(hiddenPoint.Object);
                }
            }

            gameMap.Setup(_ => _[1, 2]).Returns(emptyPoint.Object);
            gameMap.Setup(_ => _[2, 0]).Returns(emptyPoint.Object);
            gameMap.Setup(_ => _[3, 1]).Returns(emptyPoint.Object);
            gameMap.Setup(_ => _[1, 1]).Returns(sankShipPoint.Object);
            gameMap.Setup(_ => _[2, 1]).Returns(shotShipPoint.Object);
        }
Exemplo n.º 7
0
        /// <summary>
        /// This example shows dangers of using default parameters between assemblies.
        ///
        /// Usage:
        /// 0. Set this project as StartUp project.
        /// 1. Hit Start (F5) and inspect the returned value. Notice the precision of the depth value.
        /// 2. Change 03b.SensorsManager.SensorData.cs line 21 to a different precision (e.g. 0.0 instead of 0.000).
        /// 3. Rebuild 03b.SensorsManager.
        /// 4. Hit Start (F5).
        ///
        /// Explaination:
        /// The value of default parameter is stored along with the assembly where these parameters are used.
        /// If you change the value in the origin assembly (where the method with the default parameters is defined) it will have no effect
        /// on the assembly which uses this method, until you rebuild that assembly as well.
        /// </summary>
        static void Main(string[] args)
        {
            // Below objects' classes are defined in two separate assemblies (SensorsManager.SensorData & SensorDataPresenter.ConsolePresenter).
            var speed     = new SensorData("Depth", 15.1234, "meters");
            var presenter = new ConsolePresenter();

            presenter.Show(speed);
            Console.ReadKey();
        }
Exemplo n.º 8
0
Arquivo: Program.cs Projeto: T-rav/GD3
        private static IPresenter Create_Presenter(DisplayModes optsMode)
        {
            if (optsMode == DisplayModes.Web)
            {
                return(new JsonPresenter());
            }

            var consolePresenter = new ConsolePresenter();

            return(consolePresenter);
        }
        public static void Buy(List <Product> products)
        {
            string toFind;

            Product foundItem;

            int count;

            do
            {
                toFind = ConsolePresenter.GetString("What do you want to buy (Enter \"QUIT\" for back to main menu): ");

                if (toFind == "QUIT")
                {
                    ConsolePresenter.ClearConsole();
                    return;
                }

                if (products.Exists(item => item.Name.Contains(toFind)) == false)
                {
                    ConsolePresenter.GetChar("No results found, press any key. ");
                    ConsolePresenter.ClearConsole();
                }
            }while (products.Exists(item => item.Name.Contains(toFind)) == false);

            foundItem = products.Find(item => item.Name.Contains(toFind));

            count = ConsolePresenter.GetInt("Quantity: ");

            while (foundItem.Count < count)
            {
                count = ConsolePresenter.GetInt($"Sorry, we have only {foundItem.Count}, insert new value or enter \"0\" for back to main menu: ");
                if (count == 0)
                {
                    ConsolePresenter.ClearConsole();
                    return;
                }
            }

            char answer;

            do
            {
                answer = ConsolePresenter.GetChar($"Do you want to buy {count} x {foundItem.Name}? It will cost {count * (foundItem.Price)}. [(Y)es] [(N)o] ");
                ConsolePresenter.ClearConsole();
            }while (answer != 'y' && answer != 'n' && answer != 'Y' && answer != 'N');

            if (answer == 'y' || answer == 'Y')
            {
                products.Find(item => item.Name.Contains(toFind)).Count = foundItem.Count - count;
            }
        }
Exemplo n.º 10
0
        public void ConsolePresenterTest()
        {
            Int64 number = 369;

            Int64[] primeFactors = new Int64[] { 3, 3, 41 };
            using (StringWriter sw = new StringWriter())
            {
                Console.SetOut(sw);
                IPresenter presenter = new ConsolePresenter();
                presenter.Present(number, primeFactors);
                string expected = string.Format("{0} has these prime factors: {1}{2}", number, "3,3,41", Environment.NewLine);

                Assert.That(sw.ToString(), Is.EqualTo(expected));
            }
        }
Exemplo n.º 11
0
        private void Leave()
        {
            char answer;

            do
            {
                answer = ConsolePresenter.GetChar("\nDo you want to leave shop? [(Y)es] [(N)o] ");
                ConsolePresenter.ClearConsole();
            }while (answer != 'y' && answer != 'n' && answer != 'Y' && answer != 'N');

            if (answer == 'y' || answer == 'Y')
            {
                return;
            }
            else
            {
                MainMenu();
            }
        }
        public static void Check(List <Product> products)
        {
            int spaceForName  = 30;
            int spaceForPrice = 6;
            int spaceForCount = 6;
            int tableWidth    = spaceForName + spaceForPrice + spaceForCount + 4;

            ConsolePresenter.PrintString($"PRODUCTS");
            ConsolePresenter.PrintString($"{Line(tableWidth)}");
            ConsolePresenter.PrintString($"|{Indent("Name", spaceForName)}|{Indent("Price", spaceForPrice)}|{Indent("Count", spaceForCount)}|");
            ConsolePresenter.PrintString($"{Line(tableWidth)}");

            foreach (var product in products)
            {
                ConsolePresenter.PrintString($"|{Indent(product.Name, spaceForName)}|{Indent(product.Price, spaceForPrice)}|{Indent(product.Count, spaceForCount)}|");
            }

            ConsolePresenter.PrintString($"{Line(tableWidth)}");
        }
Exemplo n.º 13
0
        public void Render_WhenErrorsPresent_ShouldRenderErrors()
        {
            //---------------Arrange------------------
            var errors = new ErrorOutputMessage {
                Errors = { "error 1", "error 2", "error 3" }
            };

            var fakeoutput = new StringBuilder();

            Console.SetOut(new StringWriter(fakeoutput));

            var sut = new ConsolePresenter();

            //---------------Act----------------------
            sut.Respond(errors);
            sut.Render();
            //---------------Assert-------------------
            var expected = $"The following errors occured:{Environment.NewLine}" +
                           $"error 1{Environment.NewLine}" +
                           $"error 2{Environment.NewLine}" +
                           $"error 3{Environment.NewLine}";

            fakeoutput.ToString().Should().Be(expected);
        }
Exemplo n.º 14
0
 public ConsoleView(ConsoleDao dao) : this()
 {
     m_presenter = new ConsolePresenter(this, dao);
 }
Exemplo n.º 15
0
 /// <summary>
 /// <see cref="MainTui"/> constructor will pass it's own instance to the presenter.
 /// </summary>
 public MainTui()
 {
     _presenter = new ConsolePresenter(this);
 }
Exemplo n.º 16
0
        public static void Add(List <Product> products)
        {
            products.Add(new Product(ConsolePresenter.GetString("Producer: "), ConsolePresenter.GetString("Model: "), ConsolePresenter.GetInt("Price: "), ConsolePresenter.GetInt("Count: ")));

            ConsolePresenter.ClearConsole();
        }
Exemplo n.º 17
0
        public void DisplayOnLine()
        {
            var instance = new ConsolePresenter();

            instance.DisplayOnLine("test");
        }