// // Corrigé type // Ce code n'a pas été testé, il est tout a fait possible // qu'il y ait de petites erreurs syntaxiques // // // Exercice I // // Question 1.a class Case { // 10% Terrain terrain; // 10% List unites; // 20% (ArrayList ou LinkedList admis) Ville ville; // 10% Case() { // constructeur 20% terrain = null; // pas sanctionné ville = null; // pas sanctionné unites = new ArrayList(); // 30% } } // Question 1.b // 0 ou 100% void ajouteUnite(Unite unite) { unites.add(unite); } // Question 1.c class Plateau { int lignes; // 5% int colonnes; // 5% Case[][] grille; // 10% Plateau(int lignes, int colonnes) { // 20% this.lignes = lignes; // 5% this.colonnes = colonnes; // 5% grille = new Case[lignes][colonnes]; // 10% // double boucle: 30% for(int i=0; i 0) { // changement terrain: 20% if(grille[x][y].terrain != terrain) { grille[x][y].terrain = terrain; n--; } // déplacement: 30% switch(rand(3)) { case 0: if(x > 0) x--; break; case 1: if(x < lignes - 1) x++; break; case 2: if(y > 0) y--; break; case 3: if(y < colonnes - 1) y++; break; } } } // Question 3.c // 30% class ContinentTropGrand extends Exception { } // signature: 30% void construitContinent(Terrain terrain, int n) throws ContinentTropGrand { // test: 20% // throw: 20% if(n > colonnes * lignes) throw new ContinentTropGrand(); } // // Exercice 4 // // Question 4.a // 0 ou 100% // Autre chose à la place de Plateau ou Plateau manquant : 50% interface Contrainte { boolean initOk(Plateau plateau, int x, int y); boolean deplOk(Plateau plateau, int x, int y); } // Question 4.b // implements: 30% class ContraintesAutre implements Contrainte { // 70% boolean initOk(Plateau plateau, int x, int y) { return plateau.grille[x][y].terrain != mer; } // si il manque l'une des deux fonctions, on ne pénalise pas (une seule suffit pour avoir les points) boolean deplOk(Plateau plateau, int x, int y) { return initOk(plateau, x, y); } } // Question 4.c // nouvelle signature: 20% void construitContinent(Contrainte contrainte, Terrain terrain, int n) throws ContinentTropGrand { int x; int y; // nouveau calcul position initiale: 30% do { x = rand(lignes); y = rand(colonnes); } while(!contrainte.initOk(this, x, y)); while(n > 0) { if(grille[x][y].terrain != terrain) { grille[x][y].terrain = terrain; n--; } // nouveau déplacement: 50% switch(rand(3)) { case 0: if(x > 0 && contrainte.deplOk(x - 1, y)) x--; break; case 1: if(x < (lignes - 1) && contrainte.deplOk(x + 1, y)) x++; break; case 2: if(y > 0 && contrainte.deplOk(x, y - 1)) y--; break; case 3: if(x < (colonnes - 1) && contrainte.deplOk(x, y + 1)) y++; break; } } }