Цитата:
|
не получается реализовать функцию
|
Странно... работает
<script>
function Tank(name,hp,damage){
this.name = name;
this.hp = hp;
this.damage = damage;
this.move = function() {
alert (this.name + ' поехал' )
}
this.attack = function(target){
alert(target.hp);
alert(this.name+' атаковал ' + target.name);
target.hp -= this.damage;
alert('нанесено урона ' + this.damage);
alert(target.name + ' живучесть '+target.hp);
}
}
var T34 = new Tank('Т-34', 1300, 250);
var Tiger = new Tank('Тигр', 2300, 450);
alert (T34.name + ' '+ T34.hp + ' '+ T34.damage);
T34.move();
T34.attack(Tiger);
Tiger.attack(T34);
</script>