示例#1
0
        public void execute(Piece user, Piece target)
        {
            Random r = new Random();
            if (target.getName().Equals("Pikeman") && !user.getName().Equals("Pikeman"))
            {
                int chanceToHit = 99 - 2 * (user.getDefense() - target.getAttack());

                if (r.Next(100) < chanceToHit)
                {
                    user.applyDamage(target.getDamage());
                }

                chanceToHit = 99 - 2 * (target.getDefense() - user.getAttack());

                if (r.Next(100) < chanceToHit)
                {
                    target.applyDamage(user.getDamage());
                }
            }
            else
            {
                int chanceToHit = 99 - 2 * (target.getDefense() - user.getAttack());

                if (r.Next(100) < chanceToHit)
                {
                    target.applyDamage(user.getDamage());
                }

                chanceToHit = 99 - 2 * (user.getDefense() - target.getAttack());

                if (r.Next(100) < chanceToHit)
                {
                    user.applyDamage(target.getDamage());
                }
            }
        }