feat: modification permettant de cloner réellement les cells et les grids.

This commit is contained in:
Nicolas Hordé 2016-02-03 17:17:23 +01:00
parent 9a537e2839
commit 7a9d8aeb01
4 changed files with 38 additions and 16 deletions

View File

@ -2,12 +2,13 @@ package fr.evolving.automata;
import java.io.Serializable;
public class Cell implements Serializable {
public class Cell implements Serializable,Cloneable {
public int Fiber;
public boolean Copper;
public Transmuter Transmuter;
public transient int Copper_calc;
public transient int Fiber_old;
public Transmuter Transmuter;
public transient int Transmuter_calc;
public transient int Transmuter_movex;
public transient int Transmuter_movey;
@ -21,5 +22,13 @@ public class Cell implements Serializable {
this.Transmuter_movex = 0;
this.Transmuter_movey = 0;
}
public Object clone() {
Cell result = new Cell();
result.Copper=this.Copper;
result.Fiber=this.Fiber;
if (this.Transmuter!=null)
result.Transmuter=(Transmuter)this.Transmuter.clone();
return result;
}
}

View File

@ -7,7 +7,7 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.ObjectMap.Entry;
public class Grid implements Serializable {
public class Grid implements Serializable,Cloneable {
public Cell[][] Cells;
public Integer sizeX, sizeY;
@ -269,5 +269,13 @@ public class Grid implements Serializable {
else
return cell.Copper_calc;
}
public Object clone() {
Grid result = new Grid(this.sizeX,this.sizeY);
for (int x = 0; x < this.sizeX; x++)
for (int y = 0; y < this.sizeY; y++)
result.Cells[x][y] = (Cell)this.Cells[x][y].clone();
return result;
}
}

View File

@ -166,14 +166,14 @@ public class Worlds extends Actor {
ReadLastGrid();
if (usedlevel.Grid == null || force) {
Gdx.app.debug(getClass().getSimpleName(), "Copie monde original.");
usedlevel.Grid = usedlevel.Grid_orig;
usedlevel.Grid = (Grid)usedlevel.Grid_orig.clone();
} else {
Gdx.app.debug(getClass().getSimpleName(),
"Récupération de la dernière grille.");
usedlevel.Grid.tiling_copper();
usedlevel.Grid.tiling_transmuter();
Gdx.app.debug(getClass().getSimpleName(),"Récupération de la dernière grille.");
ReadLastGrid();
}
usedlevel.Grid.tiling_copper();
usedlevel.Grid.tiling_transmuter();
}
public void setLevel(int alevel) {

View File

@ -201,7 +201,9 @@ public class LevelScreen implements Screen {
}
buttonLevels = null;
buttonLevels = new ButtonLevel[10];
for (Level level : worlds.getLevels()) {
Array<Level> levels=worlds.getLevels();
if (levels!=null)
for (Level level : levels) {
if (level != null) {
if (level.Name.isEmpty())
level.Name=AssetLoader.language.get("[level"+(level.aWorld+1)+"/"+(level.aLevel+1)+"-name]");
@ -268,15 +270,17 @@ public class LevelScreen implements Screen {
}
if (worlds.getInformations()==null)
selected=buttonLevels[0];
selected.setChecked(true);
showlevel(selected);
if (selected!=null) {
selected.setChecked(true);
buttonPlay.setVisible(true);
TextDescriptive.setVisible(true);
showlevel(selected);
}
Previous.setVisible(!worlds.isFirstWorld());
if (worlds.isDebug())
Next.setVisible(!worlds.isRealLastWorld());
else
Next.setVisible(!worlds.isLastWorld());
buttonPlay.setVisible(true);
TextDescriptive.setVisible(true);
}
else {
Previous.setVisible(false);
@ -623,8 +627,9 @@ public class LevelScreen implements Screen {
}
public void showlevel(ButtonLevel button) {
Gdx.app.debug(getClass().getSimpleName(), "Reading button "
+ button.level.Name);
if (button==null)
return;
Gdx.app.debug(getClass().getSimpleName(), "Reading button " + button.level.Name);
TextDescriptive.setText(button.level.Description);
if (button.level.Maxcycle < 99999 && button.level.Maxcycle > 0) {
cycle.setText(String.valueOf(button.level.Maxcycle));