-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsumable.cs
More file actions
56 lines (51 loc) · 1.73 KB
/
Consumable.cs
File metadata and controls
56 lines (51 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Text;
namespace HW6
{
public class Consumable : Item
{
public int heal;
public int addAtk; //目前消耗品有兩種用途:補血/加攻擊力
public override bool OnUse(ref Hero hero)
{
bool use = false;
string description = $"物品名稱:{name}\n";
if (heal != 0)
{
description += $"恢復血量:{heal}\n";
}
if (addAtk != 0)
{
description += $"增加攻擊力:{addAtk}\n";
}
Console.WriteLine($"物品資訊:\n{description}");
Console.WriteLine("按Y使用,或按其他鍵返回");
switch (Console.ReadLine().ToUpper())
{
case "Y":
hero.atk += addAtk;
use = true;
Console.WriteLine($"成功使用道具{name}");
if (heal != 0)
{
if ((hero.maxHp - hero.hp) < heal)
{
heal = hero.maxHp - hero.hp;
}
hero.hp += heal;
Console.WriteLine($"恢復血量:{heal}\t目前血量{hero.hp}/{hero.maxHp}");
}
if (addAtk != 0)
{
Console.WriteLine( $"增加攻擊力:{addAtk}\t目前攻擊力{hero.atk}");
}
break;
default:
Console.WriteLine("取消使用");
break;
}
return use;
}
}
}