复制代码
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
110package com.game.huntervsmonster03; public class Hunter { String name; int maxLife; int actualLife; int level; int attack; int defend; int experience; String weapon; boolean isLive; public Hunter(int i) { switch (i) { case 1: { this.name = "李逍遥"; this.attack = 100; this.defend = 40; this.isLive = true; this.maxLife = 200; this.weapon = "无尘剑"; this.actualLife = maxLife; this.experience = 0; this.level = 1; } break; case 2: { this.name = "景天"; this.attack = 500; this.defend = 200; this.isLive = true; this.maxLife = 1000; this.weapon = "魔剑"; this.actualLife = maxLife; this.experience = 0; this.level = 1; } break; case 3: { this.name = "孙悟空"; this.attack = 1000; this.defend = 400; this.isLive = true; this.maxLife = 3000; this.weapon = "金箍棒"; this.actualLife = maxLife; this.experience = 0; this.level = 1; } break; } } void fight(Monster monster) { if (!isLive) { return; } monster.injured(this); } void injured(Monster monster) { if (monster.attack >= this.defend) this.actualLife = this.actualLife - (monster.attack - this.defend); if (this.actualLife <= 0) { this.dead(); return; } this.show(); this.fight(monster); } void dead() { this.isLive = false; } void changeExperience(Monster moster) { this.experience += moster.experience; while (this.experience >= (this.level * 200)) { upgrade(); } } void upgrade() { this.level += 1; this.attack *= 1.2; this.defend *= 1.2; this.actualLife = (int) (this.maxLife * 1.2); this.maxLife *= 1.2; System.out.println(this.name + ":" + this.level); } void show() { if (this.isLive) System.out.println(this.name + "还有" + this.actualLife + "点血"); else { System.out.println(this.name + "壮烈牺牲了!"); return; } } }
复制代码
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149package com.game.huntervsmonster03; public class Monster { String type; int maxLife; int actualLife; boolean isLive; int attack; int defend; int experience; public Monster(int i) { switch (i) { case 1: { this.type = "小僵尸"; this.attack = 80; this.defend = 20; this.isLive = true; this.maxLife = 200; this.actualLife = maxLife; this.experience = 100; } break; case 2: { this.type = "大僵尸"; this.attack = 130; this.defend = 50; this.isLive = true; this.maxLife = 500; this.actualLife = maxLife; this.experience = 200; } break; case 3: { this.type = "僵尸老大"; this.attack = 200; this.defend = 90; this.isLive = true; this.maxLife = 1000; this.actualLife = maxLife; this.experience = 300; } break; case 4: { this.type = "小鬼"; this.attack = 210; this.defend = 100; this.isLive = true; this.maxLife = 1200; this.actualLife = maxLife; this.experience = 320; } break; case 5: { this.type = "老鬼"; this.attack = 350; this.defend = 150; this.isLive = true; this.maxLife = 2000; this.actualLife = maxLife; this.experience = 400; } break; case 6: { this.type = "火鬼王"; this.attack = 500; this.defend = 200; this.isLive = true; this.maxLife = 5000; this.actualLife = maxLife; this.experience = 500; } break; case 7: { this.type = "黑无常"; this.attack = 600; this.defend = 250; this.isLive = true; this.maxLife = 8000; this.actualLife = maxLife; this.experience = 800; } break; case 8: { this.type = "白无常"; this.attack = 600; this.defend = 250; this.isLive = true; this.maxLife = 8000; this.actualLife = maxLife; this.experience = 800; } break; case 9: { this.type = "阎王"; this.attack = 900; this.defend = 300; this.isLive = true; this.maxLife = 10000; this.actualLife = maxLife; this.experience = 1000; } break; } } public void fight(Hunter hunter) { if (!isLive) { return; } hunter.injured(this); } public void injured(Hunter hunter) { if (hunter.attack >= this.defend) this.actualLife = this.actualLife - (hunter.attack - this.defend); if (this.actualLife <= 0) { this.dead(hunter); return; } this.show(); this.fight(hunter); } void dead(Hunter hunter) { this.isLive = false; hunter.changeExperience(this); } void show() { if (this.isLive) System.out.println(this.type + "还有" + this.actualLife + "点血"); else System.out.println(this.type + "被杀死了!"); } }
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23package com.game.huntervsmonster03; public class TestGme { static int i; public static void main(String[] args) { Hunter hunter = new Hunter(3); for (i = 1; i < 10; i++) { Monster monster = new Monster(i); System.out.println(hunter.name + "VS" + monster.type); hunter.fight(monster); System.out.println("战斗结束"); // monster.show(); hunter.show(); if (!hunter.isLive) { return; } } } }
最后
以上就是甜蜜荔枝最近收集整理的关于Java小小RPG游戏第四版(基于第三版优化)的全部内容,更多相关Java小小RPG游戏第四版(基于第三版优化)内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复