-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.java
143 lines (125 loc) · 3.57 KB
/
Game.java
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
/**
* Game
*/
public class Game {
private static String[] arr = {" ", " ", " ", " ", " ", " ", "s", " ", " ", "#"};
private static String player = "@";
private static int currentPosition = 0; // Player当前位置
private static int turn = 0; // 记录当前游戏的轮次
private static int health = 100;
private static int damage = 5;
public static boolean isFinish = false;
private static Enemy enemy = null;
public static void update() {
showPlayerInfo();
generateMap();
action();
endTurn();
}
private static void action() {
if (feel()) {
attack();
} else {
walk();
}
}
/*
* 结算当前轮次
*/
private static void endTurn() {
turn++;
System.out.println("------------------ turn " + turn + " ------------------");
if (health <= 0) {
System.out.println("你GG了");
isFinish = true;
}
System.out.print("\n");
}
/*
* 显示玩家信息
*/
private static void showPlayerInfo() {
String healthMsg = "♥ " + String.valueOf(health);
PrintTool.printWithColor(healthMsg, PrintTool.RED);
}
/*
* 生成最终的结果
*/
private static void generateMap() {
int totalLength = arr.length + 2;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < totalLength; j++) {
if (i == 0) {
if (j == 0) {
System.out.print("╔");
} else if (j == totalLength - 1) {
System.out.print("╗");
} else {
System.out.print("═");
}
continue;
}
if (i == 2) {
if (j == 0) {
System.out.print("╚");
} else if (j == totalLength - 1) {
System.out.print("╝");
} else {
System.out.print("═");
}
continue;
}
if (j == 0 || j == totalLength - 1) {
System.out.print("‖");
continue;
}
if (currentPosition == (j - 1)) {
System.out.print(player);
continue;
}
System.out.print(arr[j - 1]);
}
System.out.print("\n");
}
}
private static void walk() {
if (feel()) {
if (enemy == null) {
enemy = new Enemy();
}
health -= enemy.attack();
return;
}
if (currentPosition < arr.length - 1 && arr[currentPosition + 1].equals("#")) {
System.out.println("恭喜过关!");
isFinish = true;
} else {
currentPosition++;
}
}
/*
* 检测前方有无敌人
*/
private static boolean feel() {
return arr[currentPosition + 1].equals("s");
}
/*
* 攻击
*/
private static void attack() {
if (enemy == null) {
enemy = new Enemy();
}
health -= enemy.attack();
boolean isDeath = enemy.hurt(damage);
if (isDeath) {
PrintTool.printWithColor("敌人阵亡 ~", PrintTool.YELLOW);
arr[currentPosition + 1] = " ";
}
}
/*
* 治疗
*/
private static void heal() {
}
}