/
Joueur.java
197 lines (164 loc) · 4.68 KB
/
Joueur.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import java.sql.Statement;
public class Joueur {
private String pseudo;
private Carte carteMain1;
private Carte carteMain2;
private boolean dealer;
private int stack;
private int mise;
private int id;
private Boolean historique;
public Joueur(String pseudo, Carte carteMain1, Carte carteMain2, boolean dealer, boolean historique) {
this.pseudo = pseudo;
this.carteMain1 = carteMain1;
this.carteMain2 = carteMain2;
this.dealer = dealer;
this.stack = stack;
this.mise = mise;
this.historique = historique;
if (historique) {
//Ajout du Joueur et récupèration en cas d'existance
try{
Statement stat = CmdSql.GererBD();
String cmd = new String("SELECT COUNT(ID_Joueur) as ID_Joueur FROM Joueur WHERE Pseudo = '" + pseudo + "';");
id = CmdSql.RecupererJoueur(cmd);
if (id == 0) {
stat.executeUpdate("insert into Joueur(Pseudo) values('" + pseudo + "')");
cmd = new String("SELECT ID_Joueur FROM Joueur WHERE Pseudo = '" + pseudo + "';");
id = CmdSql.RecupererJoueur(cmd);
} else {
cmd = new String("SELECT ID_Joueur FROM Joueur WHERE Pseudo = '" + pseudo + "';");
id = CmdSql.RecupererJoueur(cmd);
}
}catch (Exception e){
e.printStackTrace();
}
} else {
String cmd = new String("SELECT ID_Joueur FROM Joueur WHERE Pseudo = '" + pseudo + "';");
try {
id = CmdSql.RecupererJoueur(cmd);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
this.id = id;
}
public int getId() {
return this.id;
}
public String getPseudo() {
return pseudo;
}
public void setPseudo(String pseudo) {
this.pseudo = pseudo;
}
public Carte getCarteMain1() {
return carteMain1;
}
public void setCarteMain1(Carte carteMain1) {
this.carteMain1 = carteMain1;
}
public Carte getCarteMain2() {
return carteMain2;
}
public void setCarteMain2(Carte carteMain2) {
this.carteMain2 = carteMain2;
}
public boolean isDealer() {
return dealer;
}
public void setDealer(boolean dealer) {
this.dealer = dealer;
}
public void setStack(int pot, String idPartie){
this.stack = pot;
if (historique) {
//Ajout a historique
try{
Statement stat = CmdSql.GererBD();
stat.executeUpdate("insert into Coups(ID_Action, ID_Joueur, ID_Partie, Montant) values('7','"+this.getId()+"','"+idPartie+"', '"+pot+"')");
}catch (Exception e){
e.printStackTrace();
}
}
}
public int getStack() {
return this.stack;
}
public void mise(int m, String idPartie) {
this.stack = this.stack - m;
this.mise+=m;
if (historique) {
//Ajout a historique
try{
Statement stat = CmdSql.GererBD();
stat.executeUpdate("insert into Coups(ID_Action, ID_Joueur, ID_Partie, Montant) values('1','"+this.getId()+"','"+idPartie+"', '"+m+"')");
}catch (Exception e){
e.printStackTrace();
}
}
}
public int getMise() {
return this.mise;
}
public void deleteMise() {
this.mise = 0;
}
public void check(String idPartie) {
if (historique) {
//Ajout a historique
try{
Statement stat = CmdSql.GererBD();
stat.executeUpdate("insert into Coups(ID_Action, ID_Joueur, ID_Partie) values('2','"+this.getId()+"','"+idPartie+"')");
}catch (Exception e){
e.printStackTrace();
}
}
}
public void aligner(Joueur adversaire, String idPartie) {
int difference = adversaire.getMise() - this.getMise();
this.stack = this.stack - difference;
this.mise += difference;
if (historique) {
//Ajout a historique
try{
Statement stat = CmdSql.GererBD();
stat.executeUpdate("insert into Coups(ID_Action, ID_Joueur, ID_Partie) values('6','"+this.getId()+"','"+idPartie+"')");
}catch (Exception e){
e.printStackTrace();
}
}
}
public void seCouche(Partie p) {
//Ajouter � Historique
if (historique) {
//Ajout a historique
try{
Statement stat = CmdSql.GererBD();
stat.executeUpdate("insert into Coups(ID_Action, ID_Partie, ID_Joueur) values('8','"+p.getIdPartie()+"','"+this.id+"')");
}catch (Exception e){
e.printStackTrace();
}
}
p.InitManche(this, false);
}
public void gagne(Partie p) {
//Ajouter � Historique
if (historique) {
//Ajout a historique
try{
Statement stat = CmdSql.GererBD();
stat.executeUpdate("insert into Coups(ID_Action, ID_Partie, ID_Joueur) values('8','"+p.getIdPartie()+"','"+this.getId()+"')");
}catch (Exception e){
e.printStackTrace();
}
}
p.InitManche(this, true);
}
@Override
public String toString() {
return "Joueur [pseudo=" + pseudo + ", carteMain1=" + carteMain1 + ", carteMain2=" + carteMain2 + ", dealer="
+ dealer + ", stack=" + stack + ", mise=" + mise + ", id=" + id + ", historique=" + historique + "]";
}
}