public void nextLevel() { boolean loaded = false; final GameBoard boardView = (GameBoard) this.findViewById(R.id.gameBoard); this.level++; AssetManager am = getResources().getAssets(); try { List<String> allTutoLevels = new LinkedList<String>(Arrays.asList(am.list("levels/tutorial"))); // if(addMsg){ // allTutoLevels.addAll(Arrays.asList(am.list("msg"))); // } Log.d(TAG, allTutoLevels.toString()); for (String name : allTutoLevels) { if (name.startsWith(this.level + ".")) { BufferedReader br = new BufferedReader(new InputStreamReader(am.open("levels/tutorial/" + name))); String line; String levelJSON = ""; while ((line = br.readLine()) != null) { levelJSON += line + "\n"; } br.close(); game.initGame( levelJSON, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60); loaded = true; } } } catch (IOException e) { e.printStackTrace(); } if (!loaded) { Random r = new Random(); List<String> allLevels = new ArrayList<>(); try { allLevels = Arrays.asList(am.list("levels")); } catch (IOException e) { } if (r.nextBoolean() && !allLevels.isEmpty() && allLevels.size() != allDoneLevels.size()) { try { int nLevel; do { nLevel = r.nextInt(allLevels.size()); } while (allDoneLevels.contains(allLevels.get(nLevel))); String name = allLevels.get(nLevel); BufferedReader br = new BufferedReader(new InputStreamReader(am.open("levels/" + name))); String line; String levelJSON = ""; while ((line = br.readLine()) != null) { levelJSON += line + "\n"; } br.close(); allDoneLevels.add(name); game.initGame( levelJSON, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60); } catch (IOException e) { this.game.initGame( level, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60); } } else { this.game.initGame( level, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60); } } // am.close(); boardView.setGame(this.game); boardView.invalidate(); boardView.getHowdyShadeView().invalidate(); Toast.makeText(this, this.level + "", Toast.LENGTH_SHORT).show(); Log.i( TAG, "Max tiles : " + (boardView.getMeasuredWidth() / 60) * (boardView.getMeasuredHeight() / 60)); }
/** * コンストラクタ ここでファイルからデータを読み込んでいる * * @param in_gl OpenGLコマンド群をカプセル化したクラス * @param in_texPool テクスチャ管理クラス * @param i_provider ファイルデータプロバイダ * @param mqoFile 読み込みファイル * @param scale モデルの倍率 * @param isUseVBO 頂点配列バッファを使用するかどうか */ protected KGLMetaseq( GL10 gl, KGLTextures in_texPool, AssetManager am, String msqname, float scale) { super(in_texPool, am, scale); // targetMQO = in_moq; material mats[] = null; InputStream fis = null; // InputStreamReader isr = null ; // BufferedReader br = null; multiInput br = null; String chankName[] = null; GLObject glo = null; ArrayList<GLObject> globjs = new ArrayList<GLObject>(); try { fis = am.open(msqname); // isr = new InputStreamReader(fis) ; // br = new BufferedReader(isr); br = new multiInput(fis); while ((chankName = Chank(br, false)) != null) { /* * for( int i = 0 ; i < chankName.length ; i++ ) { * System.out.print(chankName[i]+" ") ; } System.out.println() ; */ if (chankName[0].trim().toUpperCase().equals("MATERIAL")) { try { mats = new material[Integer.parseInt(chankName[1])]; for (int m = 0; m < mats.length; m++) { mats[m] = new material(); mats[m].set(br.readLine().trim()); // Log.i("KGLMetaseq", "Material(" + m+") :" + mats[m].toString()); } } catch (Exception mat_e) { Log.e("KGLMetaseq", "MQOファイル Materialチャンク読み込み例外発生 " + mat_e.getMessage()); throw new KGLException(mat_e); } } try { if (chankName[0].trim().toUpperCase().equals("OBJECT")) { objects object = new objects(); object.set(chankName[1], br, scale); // System.out.println(object.toString()) ; if (object.face == null) { continue; // 面情報のないオブジェクトは飛ばす } glo = makeObjs(gl, mats, object); if (glo != null) { globjs.add(glo); } } } catch (Exception obj_e) { Log.e( "KGLMetaseq", "MQOファイル Object[" + chankName[1] + "]チャンク読み込み例外発生 " + obj_e.toString()); throw new KGLException(obj_e); } } br.close(); // 読み込み終了 br = null; glObj = globjs.toArray(new GLObject[0]); } catch (Exception e) { e.printStackTrace(); } finally { try { if (br != null) br.close(); } catch (IOException e) { e.printStackTrace(); } } }