Add methods to generate the code necessary for sharing a specific sudoku board

This commit is contained in:
uykek 2020-05-09 18:36:22 +02:00
parent 4134013fe9
commit 5a098d8ac5
2 changed files with 16 additions and 0 deletions

View file

@ -414,6 +414,7 @@ public class GameController implements IModelChangedListener, Parcelable {
return gameBoard.toString(); return gameBoard.toString();
} }
public String getCodeOfField() { return gameBoard.transformToCode(); }

View file

@ -3,6 +3,7 @@ package org.secuso.privacyfriendlysudoku.game;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import org.secuso.privacyfriendlysudoku.controller.Symbol;
import org.secuso.privacyfriendlysudoku.game.listener.IModelChangedListener; import org.secuso.privacyfriendlysudoku.game.listener.IModelChangedListener;
import java.util.LinkedList; import java.util.LinkedList;
@ -214,6 +215,20 @@ public class GameBoard implements Cloneable, Parcelable {
return sb.toString(); return sb.toString();
} }
public String transformToCode () {
StringBuilder sb = new StringBuilder();
for(int i = 0; i < field.length; i++) {
for (int j = 0; j < field[0].length; j++) {
if (field[i][j].getValue() == 0) {
sb.append(0);
} else {
sb.append(Symbol.getSymbol(Symbol.SaveFormat, field[i][j].getValue()-1));
}
}
}
return sb.toString();
}
public boolean isFilled() { public boolean isFilled() {
return actionOnCells(new ICellAction<Boolean>() { return actionOnCells(new ICellAction<Boolean>() {
@Override @Override