-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathPlayer.java
53 lines (51 loc) · 1.27 KB
/
Player.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
package io.innofang.state.example;
/**
* Created by Inno Fang on 2017/3/7.
*/
public class Player {
/*游戏状态*/
GameState state;
/*游戏状态的设置*/
public void setState(GameState state) {
this.state = state;
}
/*游戏开始*/
public void gameStart() {
setState(new GameStartState());
System.out.println("\n-----Game Start, ready to fight-----\n");
}
/*游戏结束*/
public void gameOver(){
setState(new GameOverState());
System.out.println("\n----- Game Over -----\n");
}
/*打怪*/
public void killMonster(){
state.killMonster();
}
/*获得经验*/
public void gainExperience() {
state.gainExperience();
}
/*下一关*/
public void next(){
state.next();
}
/*捡东西*/
public void pick(){
state.pick();
}
public static void main(String[] args) {
/*游戏开始后的一系列操作和结束后的操作*/
Player player = new Player();
player.gameStart();
player.killMonster();
player.gainExperience();
player.next();
player.pick();
player.gameOver();
player.next();
player.killMonster();
player.pick();
}
}