<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script type="text/javascript">
function People(name,attacknum,defense,ph){
this.name = name;
this.attacknum = attacknum;
this.defense = defense;
this.ph = ph;
}
People.prototype.attack = function(zhao){
var round = 0;
console.log(this.name + '对' + zhao.name + '发起了攻击')
while(this.ph > 0 && zhao.ph > 0){
zhao.ph -= this.attacknum - zhao.defense;
this.ph -= zhao.attacknum - this.defense;
round ++
console.log('第' + round + '回合')
console.log(zhao.name + '的剩余血量' + zhao.ph + ' ' + this.name + '的剩余血量' + this.ph)
}
if(zhao.ph <= 0){
console.log(zhao.name+'失败')
}else if(this.ph <= 0){
console.log(this.name + '失败')
}
}
var song = new People('宋小宝',120,80,200);
var zhao = new People('赵四',100,80,200);
song.attack(zhao);
</script>
</body>
</html>