<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
function Charactor(name, attack, defence, hp, CritRate) {
this.name = name;
this.attack = attack;
this.defence = defence;
this.hp = hp;
this.CritRate = CritRate;
// 函数
/**
* 打印信息
*/
this.print = function () {
console.log(`${this.name}\t攻击力:${this.attack}\t防御力:${this.defence}\t生命值:${this.hp}\t暴击率:${this.CritRate}`)
}
/**
* 攻击,返回对方是否死亡
* @param {*} ctor 攻击对象
*/
this.hit = function (ctor) {
var damage = this.attack - ctor.defence;
//
JavaScript写一个简单的英雄打怪兽
最新推荐文章于 2024-01-19 16:39:01 发布