示例#1
0
文件: Player.cs 项目: Onin1/shootmup
        public AttackStateEnum Attack()
        {
            // check if we have a primary weapon
            if (Primary == null)
            {
                return(AttackStateEnum.Melee);
            }
            // check if there is a round in the clip
            int rounds;

            Primary.RoundsInClip(out rounds);
            if (rounds <= 0)
            {
                if (Primary.HasAmmo())
                {
                    return(AttackStateEnum.NeedsReload);
                }
                else
                {
                    return(AttackStateEnum.NoRounds);
                }
            }
            // check if gun ready to fire
            if (!Primary.CanShoot())
            {
                return(AttackStateEnum.LoadingRound);
            }

            bool fired = Primary.Shoot();

            if (fired)
            {
                return(AttackStateEnum.Fired);
            }
            else
            {
                throw new Exception("Failed to fire");
            }
        }