-
Notifications
You must be signed in to change notification settings - Fork 1
/
weapon.cpp
133 lines (121 loc) · 2.82 KB
/
weapon.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <time.h>
#include <stdlib.h>
#include<string>
using namespace std;
class Dice //投6面骰子
{
public:
int num; // 投掷数量
int result; // 投掷结果
Dice(int n) : num(n) {
result = 0;
for (int i = 1; i <= num; i++) {
result += rand()%6 + 1;
}
}
};
class weapon{
public:
int type; // 武器编号 fist 0; sword 1; gun 2
double lv; // 装备等级
int atk; // 最大攻击力
int price; // 装备价格
int range; // 射程,近战为0
weapon(double level) {
lv = level;
}
};
class fist: public weapon{
public:
fist():weapon(0.5) {
type = 0;
atk = 1;
range = 0;
}
void attack(int & targetHp) {
targetHp -= atk;
}
};
class sword : public weapon {
public:
sword(double level):weapon(level){
range = 0;
type = 1;
if (level == 1) {
atk = 1;
price = 1;
}
else if (level == 2) {
atk = 2;
price = 3;
}
else if (level == 3) {
atk = 3;
price = 5;
}
}
void attack(int & targetHp) {
if (lv == 1)
targetHp -= atk;
else if (lv == 2) {
// 75% 2伤害; 25% 1伤害
if (Dice(2).result >= 10)
targetHp -= atk;
else
targetHp -= 1;
}
else if (lv == 3) {
// 75% 3伤害; 25% 1伤害
if (Dice(2).result >= 10) {
targetHp -= atk;
}
else {
targetHp -= 1;
}
}
}
};
class gun : public weapon{
public:
gun(double level):weapon(level) {
type = 2;
if (level == 3) {
atk = 3;
price = 6;
range = 3;
}
else if (level == 2) {
atk = 2;
price = 4;
range = 2;
}
else if (level == 1) {
atk = 1;
price = 2;
range = 1;
}
}
void attack(int & targetHp) {
if (lv == 1) {
// 50% 1伤害; 50% 0伤害
if (Dice(1).result >= 4)
targetHp -= atk;
}
else if (lv == 2) {
// 50% 2伤害; 25% 1伤害; 25% 0伤害
int t = Dice(2).result;
if (t >= 7)
targetHp -= atk;
else if (t >= 4)
targetHp -= 1;
}
else if (lv == 3) {
// 50% 3伤害; 25% 2伤害; 25% 0伤害
int t = Dice(2).result;
if (t >= 7)
targetHp -= atk;
else if (t >= 4)
targetHp -= 2;
}
}
};