Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在“kick”方法中实现“规避”属性?_Javascript - Fatal编程技术网

Javascript 如何在“kick”方法中实现“规避”属性?

Javascript 如何在“kick”方法中实现“规避”属性?,javascript,Javascript,我想在kick方法中实现英雄闪避的逻辑。对于英雄,设置了一定数量的闪避属性,根据其闪避百分比,闪避弓箭手的一个例子是0.6,即60%的几率闪避kick。如何正确实现此逻辑以及消息的结果,显示损坏或规避 功能单元MaxHealth、基本损坏、规避、类型{ this.maxHealth=maxHealth; this.currentHeaalth=maxHealth; this.basicDamage=basicDamage; 这个。逃避=逃避; this.type=type; /*显示生命状态的

我想在kick方法中实现英雄闪避的逻辑。对于英雄,设置了一定数量的闪避属性,根据其闪避百分比,闪避弓箭手的一个例子是0.6,即60%的几率闪避kick。如何正确实现此逻辑以及消息的结果,显示损坏或规避

功能单元MaxHealth、基本损坏、规避、类型{ this.maxHealth=maxHealth; this.currentHeaalth=maxHealth; this.basicDamage=basicDamage; 这个。逃避=逃避; this.type=type; /*显示生命状态的方法,如果生命值更大,则为true 小于0,如果等于或小于,则为false*/ this.isAlive=函数{ 返回此值。currentHeaalth>0 }; /*一种方法 显示健康水平*/ this.getFormattedHealth=函数{ 返回this.currentHealth+'/'+this.maxHealth+'HP'; }; /*一种方法,用于返回角色的基本伤害和角色的伤害 武器,如果它被设置*/ this.getDamage=函数{ 归还这个武器?这个武器。获得伤害:0+这个基本伤害; }; /*击球法 为所选择的目的而奋斗的英雄*/ this.kick=功能目标{ 如果这是我的生活{ target.currentHeaalth=Math.max0,target.currentHeaalth-this.getDamage; } 归还这个; }; /*显示英雄的所有特征和变化的方法 和他们在一起*/ this.toString=函数{ 返回类型-+this.Type+,处于活动状态-+this.isAlive+,+this.getFormattedHealth+',英雄当前伤害-“+this.getDamage+”点数”+ ,英雄逃避-+这个逃避; } } 功能、健康、基本损害、逃避{ 单位。应用程序,参数; this.type=弓箭手; } var archer=新archer 60,5,0.6; 功能:最大健康、基本损害、逃避{ 单位。应用程序,参数; 这个类型=剑客; } var剑客=新剑客100,10,0.3 而archer.isAlive和剑客.isAlive{ 阿切尔·斯曼; 剑客、弓箭手; } console.logarcher.toString;
console.logbrowsman.toString 编写一个函数,根据规避情况用10位0和1填充数组,并随机返回1或0:

设规避=0.4, 概率=函数{ var notRandomNumbers=[], maxEvasion=0; 如果规避+0.split'.[0]==1&&evasion+0.split'.[1]==0{ 最大规避=10; }否则{ maxEvasion=Evision+.split'.[1]; } 对于变量i=0;i控制台。日志'4',概率;代码中有语法错误。在if this.isAlive{In kick中,开始括号{没有匹配的结束括号}。您需要在返回此行之前添加一个。谢谢,但是如何正确地插入console.log关于未命中和命中,以便分别插入方法getDamage和概率I每次输出消息,而不管结果如何。getDamage函数只返回单位的损坏。在重新执行之前记录值在概率中,在返回语句之前,根据随机值记录命中或未命中。@IgorShvets