Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            var hero       = new Hero();
            var littleHeal = new HealCommand(10);
            var bigHeal    = new HealCommand(50);
            var dmg        = new DamageCommand(20);

            var queue = new Queue <ICommand>();

            queue.Enqueue(dmg);
            queue.Enqueue(littleHeal);
            queue.Enqueue(dmg);
            queue.Enqueue(bigHeal);

            foreach (var cmd in queue)
            {
                hero.ConsumeCommand(cmd);
                Console.WriteLine("Current health: {0}", hero.CurrentHealth());
            }

            /*
             * Taking 20 damage
             * Current health: 80
             * Healing by 10 hp
             * Current health: 90
             * Taking 20 damage
             * Current health: 70
             * Healing by 50 hp
             * Current health: 100
             */
        }
Exemplo n.º 2
0
        public void WrongUndo()
        {
            _character.Hp = 50;
            HealCommand command = new HealCommand(_character, 50);

            Assert.Throws <NullReferenceException>(() => _mediator.Undo(command));
        }
        static void Main(string[] args)
        {
            DIConfigurer.ConfigureCore();

            HealCommand command = new HealCommand(new Character(), 10);

            Console.ReadLine();
        }
Exemplo n.º 4
0
        public void ReturnValue()
        {
            _character.Hp = 50;
            HealCommand command = new HealCommand(_character, 50);

            IMediatorCommandResponse response = _mediator.Execute(command);
            NoResponse _response = response as NoResponse;

            Assert.IsNotNull(_response);
        }
Exemplo n.º 5
0
        public void NegativeHeal()
        {
            _character.Hp = 50;
            HealCommand command = new HealCommand(_character, -10);

            _mediator.Execute(command);
            Assert.AreEqual(50, _character.Hp);

            _mediator.Undo(command);
            Assert.AreEqual(50, _character.Hp);
        }
Exemplo n.º 6
0
        public void OverHeal()
        {
            _character.Hp = 50;
            HealCommand command = new HealCommand(_character, 60);

            _mediator.Execute(command);
            Assert.AreEqual(100, _character.Hp);

            _mediator.Undo(command);
            Assert.AreEqual(50, _character.Hp);
        }
Exemplo n.º 7
0
        public void HealNormal()
        {
            _character.Hp = 50;
            HealCommand command = new HealCommand(_character, 40);

            _mediator.Execute(command);
            Assert.AreEqual(90, _character.Hp);

            _mediator.Undo(command);
            Assert.AreEqual(50, _character.Hp);
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            //Animal animal = new Bear("LION");
            //Console.WriteLine(animal.GetType().Name);


            IRepository repository = new ZooRepository();
            Person      zooWorker  = new ZooWorker();

            var showAnimalsCommand = new ShowAllCommand(repository);
            var insertCommand      = new InsertCommand(repository);
            var feedCommand        = new FeedCommand(repository);
            var healCommand        = new HealCommand(repository);
            var deleteCommand      = new DeleteCommand(repository);

            //repository.ShowAnimalsGroupedByKind();
            //repository.ShowAnimalsByState(State.Full);

            Console.BufferHeight = 200;

            TimerCallback destFunc = new TimerCallback(repository.ChangeRandomAnimalState);
            Timer         changeRandomAnimalStateFiveSec = new Timer(destFunc, null, 5000, 5000);

            while (repository.IsAnythingAlive())
            {
                Console.WriteLine("Name\t\tHP\tMaxHP\tState\n");

                Console.WriteLine("Показать всех животных, сгруппированных по виду животного");
                repository.ShowAnimalsGroupedByKind();

                Console.WriteLine("Показать животных по состоянию - в параметрах передать Состояние");
                repository.ShowAnimalsByState(State.Full);

                Console.WriteLine("Показать всех тигров, которые больны");
                repository.ShowTigersWhichAreSick();

                Console.WriteLine("Показать слона с определенной кличкой, которая задается в параметре");
                repository.ShowElephantWithSpecifiedName("Слониха");

                Console.WriteLine("Показать список всех кличек животных, которые голодны");
                repository.ShowAnimalsNamesWhichAreHungry();

                Console.WriteLine("Показать самых здоровых животных каждого вида (по одному на каждый вид)");
                repository.ShowTheHealthestAnimalEachKinds();

                Console.WriteLine("Показать количество мертвых животных каждого вида");
                repository.ShowCountDeadAnimalsEachKinds();

                Console.WriteLine("Показать всех волков и медведей, у которых здоровье выше 3");
                repository.ShowAllWolfAndBearsWhichHealthAboveThree();

                Console.WriteLine("Показать животное с максимальным здоровьем и животное с минимальным здоровьем (описать одним выражением)");
                repository.ShowAnimalWithMaxHealthAndAnimalWithMinHealth();

                Console.WriteLine("Показать средней количество здоровья у животных в зоопарке");
                repository.ShowAverageHealthAllAnimals();

                zooWorker.Command = showAnimalsCommand;
                zooWorker.Run();

                showCommands();

                int commandNumber;
                int.TryParse(Console.ReadLine().Trim(), out commandNumber);

                zooWorker.Command = null;

                switch (commandNumber)
                {
                case 0:
                    Console.WriteLine("Unknown command");
                    break;

                case 1:
                    zooWorker.Command = insertCommand;
                    break;

                case 2:
                    zooWorker.Command = feedCommand;
                    break;

                case 3:
                    zooWorker.Command = healCommand;
                    break;

                case 4:
                    zooWorker.Command = deleteCommand;
                    break;

                case 5:
                    break;

                default:
                    Console.WriteLine("Unknown command");
                    break;
                }

                zooWorker.Run();

                Console.WriteLine("Press any button for continue...");
                Console.ReadLine();

                Console.Clear();
            }

            zooWorker.Command = showAnimalsCommand;
            zooWorker.Run();
            Console.WriteLine("All animals died. :((99((9((");
        }
Exemplo n.º 9
0
 private void Awake()
 {
     Command = new HealCommand(GetComponentInParent <IHeal>());
 }
Exemplo n.º 10
0
        protected virtual void ExecuteCommand(IKeyInfo commandKey)
        {
            IGameCommand currentCommand;

            switch (commandKey.Key)
            {
            case ConsoleKey.F1:
                currentCommand = new HelpCommand(this);
                currentCommand.Execute();
                break;

            case ConsoleKey.M:
                ConsoleRenderer.Clear();
                currentCommand = new PrintMapCommand(this);
                currentCommand.Execute();
                break;

            case ConsoleKey.LeftArrow:
            case ConsoleKey.RightArrow:
            case ConsoleKey.UpArrow:
            case ConsoleKey.DownArrow:
                ConsoleRenderer.Clear();
                RenderSuccessMoveMessage(commandKey);
                currentCommand = new MovePlayerCommand(this);
                currentCommand.Execute(commandKey);
                currentCommand = new PrintMapCommand(this);
                currentCommand.Execute();
                break;

            case ConsoleKey.S:
                currentCommand = new PlayerStatusCommand(this);
                currentCommand.Execute();
                break;

            case ConsoleKey.C:
                ConsoleRenderer.Clear();
                break;

            case ConsoleKey.H:
                currentCommand = new HealCommand(this);
                currentCommand.Execute();
                break;

            case ConsoleKey.I:
                currentCommand = new BoostHealthCommand(this);
                currentCommand.Execute();
                break;

            case ConsoleKey.R:
                this.Player.Inventory.BackPack.RemoveLastItem();
                break;

            case ConsoleKey.B:
                currentCommand = new BackPackCommand(this);
                currentCommand.Execute();
                break;

            case ConsoleKey.Escape:
                this.ExitApplication();
                break;

            default:
            {
                throw new ArgumentException("Unknown command");
            }
            }
        }
Exemplo n.º 11
0
 public void Handle(HealCommand command)
 {
     ThrowExceptionIfGameIsNotStarted();
     _doctor.Heal(Player);
 }