-
Notifications
You must be signed in to change notification settings - Fork 1
/
exerc13.cs
69 lines (57 loc) · 1.63 KB
/
exerc13.cs
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
public enum IDJogadores {
jogador1, jogador2, jogador3, jogador4
}
public abstract class PokerChain {
protected PokerChain next;
protected IDJogadores identificadorDeJogadores;
public PokerChain(IDJogadores id) {
next = null;
identificadorDeJogadores = id;
}
public void setNext(PokerChain forma) {
if (next == null) {
next = forma;
} else {
next.setNext(forma);
}
}
}
public void entrarNaMesa(IDJogadores id) throws Exception {
if (podeEntrarNaMesa(id)) {
entraNaMesa();
} else {
if (next == null) {
throw new Exception("Jogador fora da Mesa");
}
next.entrarNaMesa(id);
}
}
private boolean podeEntrarNaMesa(IDJogadores id) {
if (identificadorDeJogadores == id) {
return true;
}
return false;
}
protected abstract void entraNaMesa();
public class Jogador1 extends PokerChain {
public Jogador1() {
super(IDJogadores.jogador1);
}
@Override
protected void entraNaMesa() {
System.out.println("Jogador 1 entrou na mesa");
}
}
public static void main(String[] args) {
PokerChain jogadores = new Jogador1();
jogadores.setNext(new Jogador2());
jogadores.setNext(new Jogador3());
jogadores.setNext(new Jogador4());
try {
jogadores.efetuarPagamento(IDJogadores.jogador2);
jogadores.efetuarPagamento(IDJogadores.jogador3);
jogadores.efetuarPagamento(IDJogadores.jogador4);
} catch (Exception e) {
e.printStackTrace();
}
}