-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTasCartes.java
125 lines (111 loc) · 2.32 KB
/
TasCartes.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
import java.lang.*;
import java.util.*;
public class TasCartes
{
public ArrayList <Carte> jeu;
private boolean carteAs = false;
public TasCartes ()
{
this.jeu = new ArrayList <Carte>();
}
public void addCarte (Carte c)
{
this.jeu.add(c);
}
public static TasCartes creerJeu52Cartes (boolean asCarteMax)
{
TasCartes jeu52 = new TasCartes();
for (int c = 0; c < 4; c++)
{
int r = 0;
if (!asCarteMax)
jeu52.addCarte (new Carte(c,r));
else
jeu52.addCarte (new Carte(c,r,13));
for (r = 1; r < 13; r++)
{
jeu52.addCarte (new Carte (c, r));
}
}
return jeu52;
}
public static TasCartes creerJeu52CartesImg ()
{
TasCartes jeu52 = new TasCartes();
for (int c = 0; c < 4; c++)
{
for (int r = 0; r < 13; r++)
{
String strImg = "/img/" + c + "_" + r + ".png";
jeu52.addCarte (new Carte (c, r, strImg));
}
}
return jeu52;
}
public void battreLesCartes ()
{
Collections.shuffle(this.jeu);
}
public void distribuerLesCartes (ArrayList<TasCartes> jeuJoueurs, int nbCartes)
{
int nbJoueurs = jeuJoueurs.size();
ListIterator <TasCartes> it = jeuJoueurs.listIterator();
for(int j = 0; j < nbJoueurs; j++)
{
for (int i = 0; i < nbCartes; i++)
{
Carte c = jeu.get(i);
if(it.hasNext())
{
it.next().jeu.add(c);
}
else
{
it = jeuJoueurs.listIterator(0);
it.next().jeu.add(c);
}
jeu.remove(i);
}
}
}
public void resetTasCartes52 ()
{
this.jeu.clear();
}
public void redistribTas (TasCartes tasCartes)
{
for (int i = 0; i < this.jeu.size(); i++)
{
Carte tmp = this.jeu.get(i);
if (tasCartes.getJeu().contains(tmp) == false)
{
tasCartes.addCarte(tmp);
}
}
this.jeu.clear();
}
public int getsize () {return this.jeu.size();}
public int getValeurTas ()
{
int r = 0;
for (int i = 0; i < this.jeu.size(); i++)
{
r += this.jeu.get(i).getForce();
if (this.jeu.get(i).getForce() == 0)
{
if(r < 11)
r += 11;
else if(r >= 11)
r += 1;
}
}
return r;
}
public boolean getCarteAs () {return this.carteAs;}
public ArrayList <Carte> getJeu () {return this.jeu;}
@Override
public String toString ()
{
return jeu.toString();
}
}