Ajout d'un compteur de tours
This commit is contained in:
16
Equipe.pde
16
Equipe.pde
@@ -1,5 +1,5 @@
|
||||
class Equipe {
|
||||
int id, score;
|
||||
int id, score, tour;
|
||||
float radius;
|
||||
float posX, posY;
|
||||
Pion pion;
|
||||
@@ -7,6 +7,7 @@ class Equipe {
|
||||
Equipe(int id) {
|
||||
this.id = id;
|
||||
this.score = 0;
|
||||
this.tour = 0;
|
||||
// générer un pion pour l'équipe
|
||||
this.pion = new Pion(this.id);
|
||||
|
||||
@@ -41,11 +42,20 @@ class Equipe {
|
||||
void setScore(int score) {
|
||||
if (this.score==score) return;
|
||||
int oldScore = this.score;
|
||||
//println("Equipe", this.id+1, "setScore from", oldScore, "to", score);
|
||||
this.incTour();
|
||||
println("Equipe", this.id+1, "setScore from", oldScore, "to", score, "turn updated to", this.tour);
|
||||
this.score = score;
|
||||
this.update();
|
||||
Scoreboard.applyScore(this.id, this.score);
|
||||
Scoreboard.applyScore(this.id, this.score, this.tour);
|
||||
drawAround(oldScore);
|
||||
drawAround(this.score);
|
||||
}
|
||||
|
||||
void incTour() {
|
||||
this.tour++;
|
||||
}
|
||||
|
||||
void setTour(int tour) {
|
||||
this.tour = tour;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ boolean EDITING=false;
|
||||
Table positionTable;
|
||||
|
||||
void setup() {
|
||||
|
||||
size(displayWidth, displayHeight);
|
||||
fullScreen(1);
|
||||
//randomSeed(3);
|
||||
@@ -61,7 +60,7 @@ void drawAround(int score) {
|
||||
// positionnement des pions dont le score n'est pas nul
|
||||
if (pions.size()>0) {
|
||||
float angle = PI;
|
||||
// ce bloc est incompréhensible... mais il fait son taf
|
||||
// ce bloc est incompréhensible... mais il fait son taf de répartition des pions selon leur nombre
|
||||
for(int j=0; j<pions.size(); j++) {
|
||||
angle += TWO_PI / pions.size();
|
||||
equipes[pions.get(j)].pion.posX = pions.size() * 5.5 * cos(angle) + positions[i].posX;
|
||||
|
||||
@@ -31,16 +31,19 @@ class Scoreboard {
|
||||
this.table = new Table();
|
||||
this.table.addColumn("equipe");
|
||||
this.table.addColumn("score");
|
||||
this.table.addColumn("tour");
|
||||
for (int i = 0 ; i < nombreEquipes; i++) {
|
||||
TableRow scoreEquipe = this.table.addRow();
|
||||
|
||||
scoreEquipe.setInt("equipe", i+1);
|
||||
scoreEquipe.setInt("score", 0);
|
||||
scoreEquipe.setInt("tour", 0);
|
||||
}
|
||||
}
|
||||
|
||||
// typage forcé pour que .sort() fonctionne sur la colonne score
|
||||
this.table.setColumnType("score", "int");
|
||||
this.table.setColumnType("tour", "int");
|
||||
this.dataIntegrityCheck();
|
||||
}
|
||||
|
||||
@@ -50,6 +53,7 @@ class Scoreboard {
|
||||
|
||||
this.table.addColumn("equipe");
|
||||
this.table.addColumn("score");
|
||||
this.table.addColumn("tour");
|
||||
|
||||
for (int i = 0 ; i < equipes.length; i++) {
|
||||
Equipe e = equipes[i];
|
||||
@@ -57,6 +61,7 @@ class Scoreboard {
|
||||
|
||||
scoreEquipe.setInt("equipe", e.id+1);
|
||||
scoreEquipe.setInt("score", e.score);
|
||||
scoreEquipe.setInt("tour", e.tour);
|
||||
}
|
||||
|
||||
saveTable(this.table, "data/"+this.dataSource, "csv");
|
||||
@@ -72,14 +77,20 @@ class Scoreboard {
|
||||
return this.table.getInt(i, "score");
|
||||
}
|
||||
|
||||
int getTour(int i) {
|
||||
return this.table.getInt(i, "tour");
|
||||
}
|
||||
|
||||
void applyScores() {
|
||||
for (TableRow row : this.table.rows()) {
|
||||
equipes[row.getInt("equipe")-1].setScore(row.getInt("score"));
|
||||
equipes[row.getInt("equipe")-1].setTour(row.getInt("tour"));
|
||||
}
|
||||
}
|
||||
|
||||
void applyScore(int equipe, int score) {
|
||||
void applyScore(int equipe, int score, int tour) {
|
||||
this.table.findRow(str(equipe+1), "equipe").setInt("score", score);
|
||||
this.table.findRow(str(equipe+1), "equipe").setInt("tour", tour);
|
||||
}
|
||||
|
||||
Iterable <TableRow> findRows(String value, String name) {
|
||||
@@ -113,7 +124,7 @@ class Scoreboard {
|
||||
// suppression des dernières lignes jusqu'à revenir à l'équilibre
|
||||
for (int i = rowCount; i>rowCount-diff; i--) {
|
||||
this.table.removeRow(i-1);
|
||||
//println("Socreboard.removeRow", i-1);
|
||||
//println("Scoreboard.removeRow", i-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user