1 package ru.bosony.model.mine;
3 import ru.bosony.model.cellscontents.CellContent;
4 import ru.bosony.model.io.TextRepresentable;
6 public class Mine implements TextRepresentable {
12 public Mine(String text) {
17 public String toText() {
19 for (int y = 0; y < sizeY; y++) {
20 for (int x = 0; x < sizeX; x++) {
21 text += cells[x][y].getContent().toText();
25 return text.replaceAll("\n*$", "");
28 private void fromText(String text) {
29 String[] rows = text.split("\n+");
32 for (String row : rows) {
38 cells = new Cell[x][y];
39 for (int curY = 0; curY < rows.length; curY++) {
40 String row = rows[curY];
41 for (int curX = 0; curX < row.length() || curX < x; curX++) {
42 CellContent content = null;
43 if (curX < row.length())
44 content = CellContent.fromText("" + row.charAt(curX));
46 content = CellContent.Empty;
47 Cell cell = new Cell(curX + 1, rows.length - curY, content);
48 cells[curX][curY] = cell;
54 public String toString() {