Skip to content

Commit

Permalink
修剪小遊戲
Browse files Browse the repository at this point in the history
  • Loading branch information
ykyyykk committed Oct 9, 2024
1 parent f1f0f7a commit 0862a59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 47 deletions.
55 changes: 11 additions & 44 deletions src/minigame.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default {
enemy_energy: "",
player_action: "",
enemy_action: "",
history_log: "",
attack_value: 6,
counterattack_value: 8,
recover_value: 3,
Expand All @@ -29,37 +28,15 @@ export default {
this.UpdateLog("遊戲開始");
},
methods: {
AttackBtnOnClick() {
ActionBtnOnClick(actionName, cost) {
if (!this.IsPlaying) return;
if (this.player_energy < this.attack_cost) return;
if (this.player_energy < cost) return;

this.player_energy -= this.attack_cost;
this.player_action = "attack";
this.player_energy -= cost;
this.player_action = actionName;
this.enemy_action = this.GetRandomAction();
this.UpdateLog(`===========================================`);
this.UpdateLog(`玩家使用: ${this.player_action}`);
this.CheckResult();
},
CounterAttackBtnOnClick() {
if (!this.IsPlaying) return;
if (this.player_energy < this.counterattack_cost) return;

this.player_energy -= this.counterattack_cost;
this.player_action = "counterattack";
this.enemy_action = this.GetRandomAction();
this.UpdateLog(`===========================================`);
this.UpdateLog(`玩家使用: ${this.player_action}`);
this.CheckResult();
},
RecoverBtnOnClick() {
if (!this.IsPlaying) return;
if (this.player_energy < this.recover_cost) return;

this.player_energy -= this.recover_cost;
this.player_action = "recover";
this.enemy_action = this.GetRandomAction();
this.UpdateLog(`===========================================`);
this.UpdateLog(`玩家使用: ${this.player_action}`);
this.UpdateLog(`玩家使用: ${actionName}`);
this.CheckResult();
},
NextGameBtnOnClick() {
Expand Down Expand Up @@ -166,10 +143,7 @@ export default {
this.enemy_action == "attack" &&
this.player_action != "counterattack"
) {
this.player_health =
this.player_health >= this.attack_value
? +this.player_health - +this.attack_value
: 0;
this.player_health -= +this.attack_value;
this.UpdateLog(
`玩家受到: ${this.attack_value} 點傷害 剩餘血量: ${this.player_health}`
);
Expand All @@ -179,10 +153,7 @@ export default {
this.player_action == "attack" &&
this.enemy_action != "counterattack"
) {
this.enemy_health =
this.enemy_health >= this.attack_value
? +this.enemy_health - +this.attack_value
: 0;
this.enemy_health -= +this.attack_value;
this.UpdateLog(
`敵人受到: ${this.attack_value} 點傷害 剩餘血量: ${this.enemy_health}`
);
Expand All @@ -192,10 +163,7 @@ export default {
this.player_action == "counterattack" &&
this.enemy_action == "attack"
) {
this.enemy_health =
this.enemy_health >= this.counterattack_value
? +this.enemy_health - +this.counterattack_value
: 0;
this.enemy_health -= +this.counterattack_value;
this.UpdateLog(`玩家反擊 玩家剩餘血量: ${this.player_health}`);
this.UpdateLog(
`敵人受到: ${this.counterattack_value} 點傷害 剩餘血量: ${this.enemy_health}`
Expand All @@ -206,10 +174,7 @@ export default {
this.enemy_action == "counterattack" &&
this.player_action == "attack"
) {
this.player_health =
this.player_health >= this.counterattack_value
? +this.player_health - +this.counterattack_value
: 0;
this.player_health -= +this.counterattack_value;
this.UpdateLog(`敵人反擊 敵人剩餘血量: ${this.enemy_health}`);
this.UpdateLog(
`玩家受到: ${this.counterattack_value} 點傷害 剩餘血量: ${this.player_health}`
Expand All @@ -221,6 +186,8 @@ export default {
) {
this.UpdateLog(`雙方都使用 反擊 沒有發生任何事`);
}
this.player_health = this.player_health <= 0 ? 0 : +this.player_health;
this.enemy_health = this.enemy_health <= 0 ? 0 : +this.enemy_health;
this.player_energy += +this.default_recover_energy;
this.enemy_energy += +this.default_recover_energy;
this.CheckHealth();
Expand Down
6 changes: 3 additions & 3 deletions src/pages/MiniGame.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
:class="{
hovering: this.hoverBtn == 'Attack' && player_energy >= attack_cost,
}"
@click="AttackBtnOnClick()"
@click="ActionBtnOnClick('attack', attack_cost)"
id="attack_btn"
class="card col-sm-3 border-black me-3"
>
Expand All @@ -119,7 +119,7 @@
this.hoverBtn == 'CounterAttack' &&
player_energy >= counterattack_cost,
}"
@click="CounterAttackBtnOnClick()"
@click="ActionBtnOnClick('counterattack', counterattack_cost)"
id="counterattack_btn"
class="card col-sm-3 border-black me-3"
>
Expand All @@ -141,7 +141,7 @@
// hovering: Useable('Recover', recover_cost),
hovering: this.hoverBtn == 'Recover' && player_energy >= recover_cost,
}"
@click="RecoverBtnOnClick()"
@click="ActionBtnOnClick('recover', recover_cost)"
id="recover_btn"
class="card col-sm-3 border-black me-3"
>
Expand Down

0 comments on commit 0862a59

Please sign in to comment.