ne reste que les sources

This commit is contained in:
Patrick
2025-03-30 22:02:58 +02:00
parent 743bc35e8a
commit cdfc289a27
50 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
package com.example.flow_free;
import android.content.Context;
import android.content.res.AssetManager;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class PuzzleParser {
public static Puzzle parsePuzzle(Context context, String filename) {
AssetManager assetManager = context.getAssets();
try {
InputStream inputStream = assetManager.open("puzzles/" + filename);
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
parser.setInput(inputStream, "UTF-8");
int size = -1;
String name = filename.replace(".xml", "");
List<int[]> pairs = new ArrayList<>();
int[] currentPair = new int[4];
int pointIndex = 0;
int currentColorId=0; //test pour coleur
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
String tagName = parser.getName();
if (tagName.equals("puzzle")) {
size = Integer.parseInt(parser.getAttributeValue(null, "size"));
if (parser.getAttributeValue(null, "nom") != null) {
name = parser.getAttributeValue(null, "nom");
}
} else if (tagName.equals("point")) {
int col = Integer.parseInt(parser.getAttributeValue(null, "colonne"));
int row = Integer.parseInt(parser.getAttributeValue(null, "ligne"));
currentPair[pointIndex * 2] = col;
currentPair[pointIndex * 2 + 1] = row;
pointIndex++;
if (pointIndex == 2) {
pairs.add(new int[]{currentPair[0], currentPair[1], currentPair[2], currentPair[3]});
currentColorId++;
currentPair = new int[4];
pointIndex = 0;
}
}
}
eventType = parser.next();
}
return new Puzzle(size, name, pairs);
} catch (IOException | XmlPullParserException | NumberFormatException e) {
e.printStackTrace();
return null;
}
}
}