-
Notifications
You must be signed in to change notification settings - Fork 1
/
GestioTauler
50 lines (50 loc) · 1.28 KB
/
GestioTauler
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
/*S'encarrega de retornar un objecte tauler*/
/**
*@author Marc Ortiz
*@author Joan Grau
**/
public class GestioTauler extends Transaction{
public TableroH creaTauler(String nomkenken) {
int mida = dataEngine.getMidaKenken(nomkenken);
TableroH tablero = new TableroH(mida);
try{
int[][] caselles;
caselles = dataEngine.getCasellaValors(nomkenken);
for (int i = 0; i < mida;++i){
for (int j = 0; j < mida;++j){
int valor = -1;
Boolean fija;
int sol = caselles[i*mida+j][1];
if(caselles[i*mida+j][0] == 1){
fija = true;
valor = sol;
}else{
fija = false;
}
Casilla cas = new Casilla(valor,fija,sol);
tablero.setCasilla(cas,i,j);
}
}
String[] operacions = dataEngine.getOperacions(nomkenken);
int total_areas = operacions.length;
int idarea = 0;
while (idarea < total_areas){
String varS = operacions[idarea];
char var2[] = varS.toCharArray();
Area a = new Area(idarea,var2[0]);
tablero.afegirArea(a,0);
++idarea;
}
for(int i = 0;i < mida; i++){
for(int j=0; j < mida; j++){
idarea = caselles[i*mida+j][2];
tablero.setid(idarea, i, j);
}
}
tablero.colocaRes();
}catch(IOException e){
System.out.println("Error en la càrrega del tauler");
}
return tablero;
}
}