| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 | // 玩家var Player = /** @class */ (function () {    function Player(name) {        this.name = name;        this.hp = 5;        this.power = 1;        this.defense = 0;        this.chargeCount = 0;        this.reboundUsed = false;    }    Player.prototype.attack = function (target) {        target.receiveDamage(this.power);        console.log("".concat(this.name, "\u53D1\u52A8\u4E86\u653B\u51FB\uFF01"));    };    Player.prototype.charge = function () {        this.chargeCount++;        console.log("".concat(this.name, "\u5F00\u59CB\u84C4\u529B\uFF01"));    };    Player.prototype.defenseMove = function () {        this.defense++;        console.log("".concat(this.name, "\u91C7\u53D6\u4E86\u9632\u5FA1\u59FF\u6001\uFF01"));    };    Player.prototype.ultimateStrike = function (target) {        if (this.chargeCount === 2) {            target.receiveDamage(999); // 直接秒杀            this.chargeCount = 0;            console.log("".concat(this.name, "\u4F7F\u7528\u4E86\u7EC8\u6781\u5927\u62DB\uFF01").concat(target.name, "\u88AB\u51FB\u8D25\u4E86\uFF01"));        }        else if (this.chargeCount === 1) {            target.receiveDamage(this.power * 2); // 大招伤害为攻击的双倍            this.chargeCount = 0;            console.log("".concat(this.name, "\u91CA\u653E\u4E86\u5927\u62DB\uFF01").concat(target.name, "\u53D7\u5230\u4E86").concat(this.power * 2, "\u70B9\u4F24\u5BB3\uFF01"));        }        else {            console.log("".concat(this.name, "\u5C1A\u672A\u84C4\u529B\u8DB3\u591F\uFF0C\u65E0\u6CD5\u91CA\u653E\u5927\u62DB\uFF01"));        }    };    Player.prototype.reboundMove = function () {        if (this.reboundUsed) {            console.log("".concat(this.name, "\u672C\u5C40\u5DF2\u7ECF\u4F7F\u7528\u8FC7\u53CD\u5F39\u4E86\uFF01"));        }        else {            this.reboundUsed = true;            console.log("".concat(this.name, "\u91CA\u653E\u4E86\u53CD\u5F39\u6280\u80FD\uFF01"));        }    };    Player.prototype.receiveDamage = function (damage) {        var actualDamage = Math.max(damage - this.defense, 0); // 考虑防御        this.hp -= actualDamage;        console.log("".concat(this.name, "\u53D7\u5230\u4E86").concat(actualDamage, "\u70B9\u4F24\u5BB3\uFF01"));        if (this.hp <= 0) {            console.log("".concat(this.name, "\u88AB\u51FB\u8D25\u4E86\uFF01"));        }    };    return Player;}());// 游戏主逻辑function playGame() {    var player1 = new Player('玩家1');    var player2 = new Player('玩家2');    while (player1.hp > 0 && player2.hp > 0) {        // 玩家1的回合        console.log('\n===== 玩家1的回合 =====');        player1.attack(player2);        // 玩家2的回合        console.log('\n===== 玩家2的回合 =====');        player2.charge();        // 玩家1的回合        console.log('\n===== 玩家1的回合 =====');        player1.defenseMove();        // 玩家2的回合        console.log('\n===== 玩家2的回合 =====');        player2.ultimateStrike(player1);        // 重置防御        player1.defense = 0;        player2.defense = 0;        // 判断玩家1是否被击败        if (player1.hp <= 0) {            break;        }        // 玩家1的回合        console.log('\n===== 玩家1的回合 =====');        player1.charge();        // 玩家2的回合        console.log('\n===== 玩家2的回合 =====');        player2.attack(player1);        // 玩家1的回合        console.log('\n===== 玩家1的回合 =====');        player1.reboundMove();        // 判断玩家2是否被击败        if (player2.hp <= 0) {            break;        }    }}// 运行游戏playGame();
 |