package de.sopa;

import android.graphics.Point;
import android.view.Display;
import java.util.Map;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.ui.activity.SimpleBaseGameActivity;


public class MainActivity extends SimpleBaseGameActivity {


    private static int CAMERA_HEIGHT;
    private static int CAMERA_WIDTH;
    private GameFieldService gameFieldService;
    private FieldCreator fieldCreator;
    private Map<Character, TextureRegion> regionMap;

    @Override
    protected Scene onCreateScene() {
        fieldCreator = new FieldCreator();

        gameFieldService = new GameFieldService(fieldCreator.fromString(new String[]{"nnnnnn",
                "noooon",
                "noouas",
                "nooion",
                "nooion",
                "nnnfnn"
        }));
        final Scene scene = new Scene();

        int width = gameFieldService.getField().length;
        int heigth = gameFieldService.getField()[0].length;
        int spacePerTile = CAMERA_WIDTH / width;
        int tilePositionY = 0;
        for (int y = 0; y < heigth; y++) {
            int tilePositionX = 0;
            for (int x = 0; x < width; x++) {
                if (gameFieldService.getField()[x][y].getTileType() != TileType.NONE) {
                    TextureRegion pTextureRegion = regionMap.get(gameFieldService.getField()[x][y].getShortcut());
                    Sprite tileSprite = new Sprite(tilePositionX, tilePositionY, spacePerTile, spacePerTile, pTextureRegion, getVertexBufferObjectManager());
                    scene.attachChild(tileSprite);
                }
                tilePositionX += spacePerTile;
            }
            tilePositionY += spacePerTile;
        }
        return scene;
    }

    @Override
    public EngineOptions onCreateEngineOptions() {
        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        CAMERA_WIDTH = size.x;
        CAMERA_HEIGHT = size.y;
        final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
        return new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED,
                new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);

    }

    @Override
    protected void onCreateResources() {
        TileResourceLoader tileResourceLoader = new TileResourceLoader(getTextureManager(), getAssets());
        regionMap = tileResourceLoader.getTileTextures();
    }
}

@@ -1136,22 +1136,16 @@
         
-final 
 Scene sc
@@ -1176,17 +1176,22 @@
     
-int width
+Tile%5B%5D%5B%5D field
  = g
@@ -1216,16 +1216,43 @@
 tField()
+;%0A        int width = field
 .length;
@@ -1277,35 +1277,13 @@
 h = 
-gameFieldService.getF
+f
 ield
-()
 %5B0%5D.
@@ -1518,35 +1518,13 @@
 if (
-gameFieldService.getF
+f
 ield
-()
 %5Bx%5D%5B
@@ -1629,35 +1629,13 @@
 get(
-gameFieldService.getF
+f
 ield
-()
 %5Bx%5D%5B

refactor gameField to local variable