-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlayer.java
More file actions
44 lines (37 loc) · 1015 Bytes
/
Player.java
File metadata and controls
44 lines (37 loc) · 1015 Bytes
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
package Strategy_Pattern;
public class Player {
private String name;
private Strategy strategy; // 전략을 사용하는 객체
private int wincount;
private int losecount;
private int gamecount;
// 이름과 전략을 받아서 플레이어를 만든다
public Player(String name, Strategy strategy) {
this.name = name;
this.strategy = strategy; // 초기 전략 설정
}
// 전략에 따라 다음 손을 결정한다.
public Hand nextHand() {
return strategy.nextHand();
}
// 승리
public void win() {
strategy.study(true);
wincount++;
gamecount++;
}
// 패배
public void lose() {
strategy.study(false);
losecount++;
gamecount++;
}
// 무승부
public void even() {
gamecount++;
}
@Override
public String toString() {
return "[" + name + ":" + gamecount + " games, " + wincount + " win, " + losecount + " lose" + "]";
}
}