-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJeuHandler.java
More file actions
97 lines (92 loc) · 3.77 KB
/
JeuHandler.java
File metadata and controls
97 lines (92 loc) · 3.77 KB
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
package Jcoinche.server;
import org.apache.mina.core.service.IoAcceptor;
import java.util.ArrayList;
public class JeuHandler
{
public JeuHandler(IoAcceptor ioa, int nb_players) throws InterruptedException {
boolean debut = true;
int nb = -1;
while (debut)
{
if (ioa.getManagedSessionCount() == nb_players)
debut = false;
else
{
if (ioa.getManagedSessionCount() != nb)
{
nb = ioa.getManagedSessionCount();
System.out.println("Waiting for players to connect : " + ioa.getManagedSessionCount() + "/" + nb_players + " connected");
}
}
}
Paquet pack = new Paquet();
System.out.println("--------------------------------------------");
System.out.println("Let's Go !");
System.out.println("--------------------------------------------");
ArrayList<Long> intKeys = new ArrayList<>(ioa.getManagedSessions().keySet());
Joueurs jA;
Joueurs jB;
Joueurs jC;
Joueurs jD;
if (nb_players >= 1)
jA = new Joueurs(1, intKeys.get(0), ioa.getManagedSessions().get(intKeys.get(0)));
else
jA = new Joueurs("Jean", 1, 42);
if (nb_players >= 2)
jB = new Joueurs(2, intKeys.get(1), ioa.getManagedSessions().get(intKeys.get(1)));
else
jB = new Joueurs("Frederique", 2, 42);
if (nb_players >= 3)
jC = new Joueurs(1, intKeys.get(2), ioa.getManagedSessions().get(intKeys.get(2)));
else
jC = new Joueurs("Yoan", 1, 42);
if (nb_players >= 4)
jD = new Joueurs(2, intKeys.get(3), ioa.getManagedSessions().get(intKeys.get(3)));
else
jD = new Joueurs("Paul", 2, 42);
Jeu game = new Jeu(ioa, jA, jB, jC, jD, pack);
System.out.println("--------------------------------------------");
TimeServerHandler toto;
toto = (TimeServerHandler) ioa.getHandler();
toto.setJeu(game);
int turn = 1;
while (game.getScoreTeamA() < 1000 && game.getScoreTeamB() < 1000)
{
while (game.players[0].getNbCards() != 0 && game.getScoreTeamA() < 1000 && game.getScoreTeamB() < 1000) {
Thread.sleep(4000);
System.out.println("--------------------------------------------");
System.out.println("Turn #" + turn);
System.out.println("--------------------------------------------\n");
game.players[0].printMain();
game.players[1].printMain();
game.players[2].printMain();
game.players[3].printMain();
turn++;
game.turn();
}
pack = new Paquet();
game.players[0].setCards(pack);
game.players[1].setCards(pack);
game.players[2].setCards(pack);
game.players[3].setCards(pack);
}
if (game.getScoreTeamA() > game.getScoreTeamB())
{
for (int i = 0; i < 4; i++)
if (!game.players[i].isIA())
game.players[i].session.write("END: Team A won with " + game.getScoreTeamA() + " points");
}
else
{
for (int i = 0; i < 4; i++)
if (!game.players[i].isIA())
game.players[i].session.write("END: Team B won with " + game.getScoreTeamB() + " points");
}
if (game.getScoreTeamA() > game.getScoreTeamB())
System.out.println("END: Team A won with " + game.getScoreTeamA() + " points");
else
System.out.println("END: Team B won with " + game.getScoreTeamB() + " points");
System.exit(0);
game.end();
}
}