Execute() public method

public Execute ( CharacterObservable, caller, CharacterObservable, characterToAttack ) : void
caller CharacterObservable,
characterToAttack CharacterObservable,
return void
示例#1
0
        public void AttackCommand()
        {
            //check if attackcommand attacks monsters
            Game game = new Game(5, 2, 20);

            Dungeon d    = new Dungeon(1, 0);
            Pack    pack = new Pack("1", 1, d.startNode, d);

            game.dungeon         = d;
            game.player.location = d.startNode;
            d.startNode.packs.Add(pack);
            d.startNode.contested = true;
            Player p = new Player();

            p.location = d.startNode;
            p.dungeon  = d;

            //superpowers
            p.AttackRating = 100;

            AttackCommand cmd = new AttackCommand();

            cmd.Execute(game.player, game.dungeon);

            Assert.True(!p.location.contested && p.location.packs.Count == 0);
        }
示例#2
0
        public void killCreature()//Kill pack AND creature
        {
            RandomGenerator.initializeWithSeed(123);
            Game game = new Game(5, 2, 20);

            game.player.dungeon = game.dungeon;


            Node n    = new Node();
            Pack pack = new Pack("999", 1, n, null);

            game.player.location = n;
            n.packs.Add(pack);
            n.contested        = true;
            pack.members[0].HP = 5;

            Console.WriteLine(pack.members[0].HP); //hp is 5

            AttackCommand attack = new AttackCommand();

            attack.Execute(game.player, game.dungeon);


            Assert.AreEqual(1, game.player.KillPoint);
            Assert.AreEqual(0, n.packs.Count);
            Assert.AreEqual(0, pack.members.Count);
        }
示例#3
0
        public void acceleratedKillAllMonsters()
        {
            RandomGenerator.initializeWithSeed(123);
            Game game = new Game(5, 2, 20);

            game.player.dungeon = game.dungeon;


            Node n    = new Node();
            Pack pack = new Pack("999", 5, n, null);

            game.player.location = n;
            n.packs.Add(pack);
            n.contested             = true;
            game.player.accelerated = true;

            //set HP to 10, so player can't kill them.
            foreach (Monster m in pack.members.ToList())
            {
                m.HP = 1;
            }

            AttackCommand attack = new AttackCommand();

            attack.Execute(game.player, game.dungeon);


            Assert.AreEqual(5, game.player.KillPoint);
            Assert.AreEqual(0, n.packs.Count);
            Assert.AreEqual(0, pack.members.Count);
        }
示例#4
0
 void ExecuteOnAttack(IonianTone?tone)
 {
     if (AttackCommand?.CanExecute(tone) ?? false)
     {
         AttackCommand.Execute(tone);
     }
 }
示例#5
0
 private void AttackKey()
 {
     if (AttackCommand?.CanExecute(this) ?? false)
     {
         AttackCommand.Execute(this);
         attacked       = true;
         Rectangle.Fill = Sharp ? SharpAttackKeyFill : AttackKeyFill;
     }
 }
示例#6
0
        /// <summary>
        /// Provides a very basic finite-state machine to control the interactions
        /// with the game. When a case is clicked, there are several possible
        /// actions according to the UI's current state.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CaseClicked(object sender, CaseClickedEventArgs e)
        {
            switch (_state)
            {
            case CommandState.Selecting:
                var select = new SelectCaseCommand(_game, _gameControl);
                if (select.CanExectute(e.ClickedCase))
                {
                    select.Execute(e.ClickedCase);
                }
                else
                {
                    _gameControl.DisplayInvalidCommandOn(e.ClickedCase);
                }

                break;

            case CommandState.Moving:
                var unitToMove = ((UnitView)_units.SelectedItem).Unit;
                var move       = new MoveUnitCommand(_game, unitToMove);

                if (move.CanExectute(e.ClickedCase))
                {
                    move.Execute(e.ClickedCase);
                    ResetUIState();
                    _gameControl.SelectCase(e.ClickedCase);
                }
                else
                {
                    _gameControl.DisplayInvalidCommandOn(e.ClickedCase);
                }

                break;

            case CommandState.Attacking:
                var attackWithUnit = ((UnitView)_units.SelectedItem).Unit;
                var attack         = new AttackCommand(attackWithUnit);

                if (attack.CanExectute(e.ClickedCase))
                {
                    attack.Execute(e.ClickedCase);
                    ResetUIState();
                    _gameControl.SelectCase(e.ClickedCase);
                }
                else
                {
                    _gameControl.DisplayInvalidCommandOn(e.ClickedCase);
                }
                break;

            default:
                _state = CommandState.Selecting;
                CaseClicked(sender, e);
                break;
            }
        }
示例#7
0
        public void AttackCommandNoEnemy()
        {
            //check if attackcommand throws exception on no enemy to attack
            Game    game = new Game(5, 2, 20);
            Dungeon d    = new Dungeon(1, 0);

            game.dungeon = d;

            game.player.location = d.startNode;

            AttackCommand cmd = new AttackCommand();

            Assert.Throws <ArgumentException>(() => cmd.Execute(game.player, game.dungeon));
        }
示例#8
0
        void ExecuteOnAttack(PianoKey view)
        {
            var tone = new IonianTone()
            {
                Scale  = view.Scale,
                Sharp  = view.Sharp,
                Octave = view.Scale == IonianScale.A || view.Scale == IonianScale.B ? Octave + 1 : Octave,
            };

            if (AttackCommand?.CanExecute(tone) ?? false)
            {
                AttackCommand.Execute(tone);
            }
        }
示例#9
0
        public void AttackCommandReturnsLostWhenHeroDead()
        {
            GameState expected = GameState.Lost;

            var hero = new Mock <IBattler>();

            hero.Setup(h => h.IsAlive()).Returns(false);
            var enemy = new Mock <IBattler>();

            enemy.Setup(e => e.IsAlive()).Returns(true);

            ICommand command = new AttackCommand(hero.Object, enemy.Object);

            var result = command.Execute();

            Assert.AreEqual(expected, result);
        }
示例#10
0
 private void Update()
 {
     if (Input.GetButtonDown("Jump"))
     {
         jumpCom.Execute(gameObject);
     }
     else if (Input.GetKeyDown(KeyCode.S))
     {
         crouchCom.Execute(gameObject);
     }
     else if (Input.GetKeyDown(KeyCode.Mouse0))
     {
         attackCom.Execute(gameObject);
     }
     else if (Input.GetKeyDown(KeyCode.Mouse1))
     {
         specialCom.Execute(gameObject);
     }
     else if (Input.GetKeyDown(KeyCode.B))
     {
         altSpecialCom.Execute(gameObject);
     }
     else if (Input.GetKeyDown(KeyCode.Q))
     {
         mindControlCom.Execute(gameObject);
     }
     else if (Input.GetKey(KeyCode.A))
     {
         leftCom.Execute(gameObject);
     }
     else if (Input.GetKey(KeyCode.D))
     {
         rightCom.Execute(gameObject);
     }
     else
     {
         idleCom.Execute(gameObject);
     }
 }
示例#11
0
    private void Update()
    {
        accumMx += Input.GetAxisRaw("Mouse X") * Time.deltaTime;
        if (Mathf.Abs(accumMx) > lockOnChangeMx && LockOnTarget != null)
        {
            accumMx = 0f;
            if (lockOnChange.IsValid())
            {
                lockOnChange.Execute(accumMx);
            }
        }
        accumMx = Mathf.Lerp(accumMx, 0f, Time.deltaTime);

        if (!player.IsInAnyState(States.Dodging))
        {
            RotationUpdate();
        }

        if (LockOnTarget != null)
        {
            if (LockOnTarget.IsInAnyState(States.Dead))
            {
                LockOnTarget = null;
            }
        }

        if (Input.GetButtonDown("Dodge"))
        {
            if (dodge.IsValid())
            {
                dodge.Execute();
            }
        }
        if (Input.GetButtonDown("LightAttack"))
        {
            if (attack.IsValid())
            {
                attack.Execute(0);
            }
        }
        if (Input.GetButtonDown("HeavyAttack"))
        {
            if (attack.IsValid())
            {
                attack.Execute(1);
            }
        }
        if (Input.GetButtonDown("LockOn"))
        {
            if (lockOn.IsValid())
            {
                lockOn.Execute();
            }
        }



        if (block.IsValid())
        {
            block.Execute(Input.GetButton("Block"));
        }
    }
示例#12
0
 public override void Execute(StateManager states)
 {
     attackCom.Execute(states.gameObject);
 }