package sample.game.builder;

import java.util.ArrayList;

import library.core.mainAI.RiverCrossingAI;
import library.core.model.CoreAnimation;
import library.core.model.CoreModel;
import library.core.object.CoreObjectFactory;
import library.core.system.CoreImageData;
import library.core.view.CoreView;
import sample.game.ai.Memory;
import sample.game.controller.GameController;
import sample.game.main.MainActivity;
import sample.game.manager.EndIsland;
import sample.game.manager.Island;
import sample.game.manager.LayoutManager;
import sample.game.manager.StartIsland;
import sample.game.model.AiChara;
import sample.game.model.BackToTitleButton;
import sample.game.model.BoatModel;
import sample.game.model.ButtonNextTurn;
import sample.game.model.CharaModel;
import sample.game.model.CharaModel.TARGET_TYPE;
import sample.game.model.CrossButton;
import sample.game.model.ExampleBox;
import sample.game.model.NumBox;
import sample.game.model.OnemorePlayButton;
import sample.game.model.OppositeIcon;

public class GameBuilder {


	private CoreObjectFactory objectFactory;
	private StartIsland island;
	private EndIsland endIsland;
	private BoatModel boat;
	private ButtonNextTurn buttonNextTurn;
	private LayoutManager layoutManager;

	private static final float CHARA_ANIM_SPEED=0.2f;

	private GameController gameController;


	public GameBuilder(MainActivity activity,CoreObjectFactory objectFactory,int boatSize){

		gameController=new GameController(true);

		this.objectFactory=objectFactory;
		this.layoutManager=new LayoutManager(true, boatSize);

		createEndIsLand();
		createStartIsLand();
		createBoat(boatSize);
		createUI();

		gameController.init(activity, island, endIsland, buttonNextTurn, boat, layoutManager);

	}


	/**
	 * 再生成用
	 * @param activity
	 * @param gameScreen
	 * @param sIsland
	 * @param eIsland
	 * @param boat
	 * @param layoutManager
	 */
	public GameBuilder(MainActivity activity,CoreObjectFactory objectFactory,
					StartIsland sIsland,EndIsland eIsland,BoatModel boat){

		gameController=new GameController(false);
		this.layoutManager=new LayoutManager(true, boat.getRideMaxMenberNum());

		this.objectFactory=objectFactory;
		this.layoutManager=new LayoutManager(sIsland.getNowTurn(),boat.getRideMaxMenberNum());


		this.island=sIsland;
		this.endIsland=eIsland;

		//ボートを再生成
		this.boat=boat;
		this.reCreateBoat(boat);

		this.createUI();

		gameController.init(activity, island, endIsland, buttonNextTurn, boat, layoutManager);

	}



	public GameController build(boolean isUseAi,int ministerNum ,int wolfNum,int cabbageNum,int cattleNum){

		addBackImage();

		for(int i=0;i<ministerNum;i++){
			addMaster();
		}

		for(int i=0;i<wolfNum;i++){
			addWolf();
		}

		for(int i=0;i<cabbageNum;i++){
			addCabbage();
		}

		for(int i=0;i<cattleNum;i++){
			addCattle();
		}

		gameController.setUseAi(isUseAi);

		if(isUseAi){
			RiverCrossingAI.setCanTouch(false);
		}

		if(isUseAi){	//ＡＩを使用する際の専用演出
			this.addAiChara();
			this.addAiUi();
		}

		//メモリーはAIでも使用するのでAIより先に初期化を行う
		gameController.memoryInit();
		//初期設定が終わった後でAIの設定
		gameController.aiInit();

		gameController.saveCharacterPosition();

		gameController.checkInitProduction();

		return gameController;
	}

	//前回の状況を再現する用のビルダー
	public GameController reBuild(boolean isUseAi,Memory memory){

		addBackImage();


		Island is=island;

		ArrayList<CharaModel> charas=is.getMinisters();
		for(int i=0;i<charas.size();i++){
			charas.get(i).setGameController(gameController);
			layoutManager.addRight(charas.get(i),true);
			objectFactory.create(charas.get(i), new CoreView(charas.get(i), 2));
			gameController.addAllCharacter(charas.get(i));
		}

		charas=is.getWolfs();
		for(int i=0;i<charas.size();i++){
			charas.get(i).setGameController(gameController);
			layoutManager.addRight(charas.get(i),true);
			objectFactory.create(charas.get(i), new CoreView(charas.get(i), 2));
			gameController.addAllCharacter(charas.get(i));
		}

		charas=is.getCabbages();
		for(int i=0;i<charas.size();i++){
			charas.get(i).setGameController(gameController);
			layoutManager.addRight(charas.get(i),true);
			objectFactory.create(charas.get(i), new CoreView(charas.get(i), 2));
			gameController.addAllCharacter(charas.get(i));
		}

		charas=is.getCattles();
		for(int i=0;i<charas.size();i++){
			charas.get(i).setGameController(gameController);
			layoutManager.addRight(charas.get(i),true);
			objectFactory.create(charas.get(i), new CoreView(charas.get(i), 2));
			gameController.addAllCharacter(charas.get(i));
		}


		is=endIsland;

		charas=is.getMinisters();
		for(int i=0;i<charas.size();i++){
			charas.get(i).setGameController(gameController);
			layoutManager.addLeft(charas.get(i),true);
			objectFactory.create(charas.get(i), new CoreView(charas.get(i), 2));
			gameController.addAllCharacter(charas.get(i));
		}

		charas=is.getWolfs();
		for(int i=0;i<charas.size();i++){
			charas.get(i).setGameController(gameController);
			layoutManager.addLeft(charas.get(i),true);
			objectFactory.create(charas.get(i), new CoreView(charas.get(i), 2));
			gameController.addAllCharacter(charas.get(i));
		}

		charas=is.getCabbages();
		for(int i=0;i<charas.size();i++){
			charas.get(i).setGameController(gameController);
			layoutManager.addLeft(charas.get(i),true);
			objectFactory.create(charas.get(i), new CoreView(charas.get(i), 2));
			gameController.addAllCharacter(charas.get(i));
		}

		charas=is.getCattles();
		for(int i=0;i<charas.size();i++){
			charas.get(i).setGameController(gameController);
			layoutManager.addLeft(charas.get(i),true);
			objectFactory.create(charas.get(i), new CoreView(charas.get(i), 2));
			gameController.addAllCharacter(charas.get(i));
		}

		gameController.setUseAi(isUseAi);
		gameController.memoryInit(memory);
		gameController.aiInit(memory);


		gameController.checkInitProduction();

		return	gameController;
	}






	/**
	 * 背景描画
	 */
	public void addBackImage(){
		//x座標　0〜1280を移動　0が右
		CoreModel background=new CoreModel(new CoreImageData("image/game/game.png"),0, 360,1280*2, 360*2);
		//CoreModel background=new CoreModel(new CoreImageData("image/game/game2.jpg"),640, 360,1280, 360*2);
		objectFactory.create(background, new CoreView(background, 0));
		gameController.setBackScreen(background);


		CoreModel gameOverWolf=new CoreModel(new CoreImageData("image/game/screen/miss1.png"),640, 360, 1280, 720);
		gameOverWolf.setShowView(false);
		objectFactory.create(gameOverWolf, new CoreView(gameOverWolf, 10));
		gameController.setGameoverScreenTypeWolf(gameOverWolf);

		CoreModel gameoverCabbage=new CoreModel(new CoreImageData("image/game/screen/miss2.png"),
				640, 360, 1280, 720);
		gameoverCabbage.setShowView(false);
		objectFactory.create(gameoverCabbage, new CoreView(gameoverCabbage, 10));
		gameController.setGameoverScreenTypeCabbage(gameoverCabbage);

		CoreModel gameoverAi=new CoreModel(new CoreImageData("image/game/screen/miss3.png"),
				640, 360, 1280, 720);
		gameoverAi.setShowView(false);
		objectFactory.create(gameoverAi, new CoreView(gameoverAi, 10));
		gameController.setGameoverScreenTypeAi(gameoverAi);


		//フェイド用のマスク
		CoreModel fadeMask=new CoreModel(new CoreImageData("image/game/screen/fadeMask.png"),
				640, 360, 1280, 720);
		fadeMask.setShowView(false);
		fadeMask.setAlpha(0);
		objectFactory.create(fadeMask, new CoreView(fadeMask, 20));
		gameController.setFadeMask(fadeMask);
	}


	public void addAiChara(){
		ArrayList<CoreAnimation> anims=new ArrayList<CoreAnimation>();
		ArrayList<CoreImageData> anim1=new ArrayList<CoreImageData>();
		anim1.add(new CoreImageData("image/game/chara/aiThink.png",0,0,256,256));
		anim1.add(new CoreImageData("image/game/chara/aiThink.png",1,0,256,256));
		anim1.add(new CoreImageData("image/game/chara/aiThink.png",2,0,256,256));

		ArrayList<Integer> anim1Index=new ArrayList<Integer>();
		anim1Index.add(1);
		anim1Index.add(0);
		anim1Index.add(1);
		anim1Index.add(2);
		anims.add(new CoreAnimation("aiThink", anim1,anim1Index, 0.4f, true));

		anim1=new ArrayList<CoreImageData>();
		anim1.add(new CoreImageData("image/game/chara/ai_miss.png"));
		anim1Index=new ArrayList<Integer>();
		anim1Index.add(0);
		anims.add(new CoreAnimation("aiMiss", anim1, anim1Index, 0.4f, false));

		anim1=new ArrayList<CoreImageData>();
		anim1.add(new CoreImageData("image/game/chara/ai_success.png"));
		anim1Index=new ArrayList<Integer>();
		anim1Index.add(0);
		anims.add(new CoreAnimation("aiMiss", anim1, anim1Index, 0.4f, false));

		AiChara aiChara=new AiChara(anims, 0, 540, 620, 256, 256);
		objectFactory.create(aiChara, new CoreView(aiChara, 8));
		gameController.setAiChara(aiChara);

	}


	public void addAiUi(){
		CoreModel returnBack=new CoreModel(new CoreImageData("image/game/ui/return1.png"),
				640, 360, 1280, 720);
		returnBack.setShowView(false);
		objectFactory.create(returnBack, new CoreView(returnBack, 7));
		gameController.setReturnBackScreen(returnBack);

		CoreModel returnIcon=new CoreModel(new CoreImageData("image/game/ui/return2.png"),
				640, 360, 200, 100);
		returnIcon.setShowView(false);
		objectFactory.create(returnIcon, new CoreView(returnIcon, 8));
		gameController.setReturnIcon(returnIcon);
	}


	/**
	 * 牧師追加
	 */
	public void addMaster(){


		ArrayList<CoreAnimation> anims=new ArrayList<CoreAnimation>();
		ArrayList<CoreImageData> anim1=new ArrayList<CoreImageData>();
		anim1.add(new CoreImageData("image/game/chara/minami_game1.png"));

		ArrayList<Integer> anim1Index=new ArrayList<Integer>();
		anim1Index.add(0);
		anims.add(new CoreAnimation("minamiClear", anim1,anim1Index, 0.4f, false));


		ArrayList<CoreImageData> anim2=new ArrayList<CoreImageData>();
		anim2.add(new CoreImageData("image/game/chara/minamiGame.png",0,0,144,144));
		anim2.add(new CoreImageData("image/game/chara/minamiGame.png",1,0,144,144));
		anim2.add(new CoreImageData("image/game/chara/minamiGame.png",2,0,144,144));

		ArrayList<Integer> anim2Index=new ArrayList<Integer>();
		anim2Index.add(1);
		anim2Index.add(0);
		anim2Index.add(1);
		anim2Index.add(2);

		anims.add(new CoreAnimation("minamiLeft", anim2,anim2Index, CHARA_ANIM_SPEED, true));


		ArrayList<CoreImageData> anim3=new ArrayList<CoreImageData>();
		anim3.add(new CoreImageData("image/game/chara/minamiGameR.png",0,0,144,144));
		anim3.add(new CoreImageData("image/game/chara/minamiGameR.png",1,0,144,144));
		anim3.add(new CoreImageData("image/game/chara/minamiGameR.png",2,0,144,144));

		ArrayList<Integer> anim3Index=new ArrayList<Integer>();
		anim3Index.add(1);
		anim3Index.add(0);
		anim3Index.add(1);
		anim3Index.add(2);

		anims.add(new CoreAnimation("minamiRight", anim3,anim3Index, CHARA_ANIM_SPEED, true));


		ArrayList<CoreImageData> anim4=new ArrayList<CoreImageData>();
		anim4.add(new CoreImageData("image/game/chara/minami_clear.png"));

		ArrayList<Integer> anim4Index=new ArrayList<Integer>();
		anim4Index.add(0);
		anims.add(new CoreAnimation("minamiClear", anim4,anim4Index, 0.4f, false));


		CharaModel chara=new CharaModel(gameController, TARGET_TYPE.MINISTART,
				anims, 0, 0, 0, 144, 144);
		objectFactory.create(chara, new CoreView(chara, 3));

		island.addCharacter(chara);
		layoutManager.addRight(chara,true);
		gameController.addAllCharacter(chara);
/*
		CharaModel chara=new CharaModel(gameController, TARGET_TYPE.MINISTART,
				new CoreImageData("image/konanC1.png"),1000, 100, 100,100);
		this.objectFactory.create(chara,new CoreView(chara, 2));

		island.addCharacter(chara);
		layoutManager.addRight(chara);*/
	}

	/**
	 * オオカミ追加
	 */
	public void addWolf(){


		ArrayList<CoreAnimation> anims=new ArrayList<CoreAnimation>();
		ArrayList<CoreImageData> anim1=new ArrayList<CoreImageData>();
		anim1.add(new CoreImageData("image/game/chara/snake_game1.png"));

		ArrayList<Integer> anim1Index=new ArrayList<Integer>();
		anim1Index.add(0);
		anims.add(new CoreAnimation("snakeClear", anim1,anim1Index, 0.4f, false));


		ArrayList<CoreImageData> anim2=new ArrayList<CoreImageData>();
		anim2.add(new CoreImageData("image/game/chara/snakeGame.png",0,0,144,144));
		anim2.add(new CoreImageData("image/game/chara/snakeGame.png",1,0,144,144));

		ArrayList<Integer> anim2Index=new ArrayList<Integer>();
		anim2Index.add(0);
		anim2Index.add(1);


		anims.add(new CoreAnimation("snakeLeft", anim2,anim2Index,CHARA_ANIM_SPEED, true));


		ArrayList<CoreImageData> anim3=new ArrayList<CoreImageData>();
		anim3.add(new CoreImageData("image/game/chara/snakeGameR.png",0,0,144,144));
		anim3.add(new CoreImageData("image/game/chara/snakeGameR.png",1,0,144,144));

		ArrayList<Integer> anim3Index=new ArrayList<Integer>();
		anim3Index.add(0);
		anim3Index.add(1);

		anims.add(new CoreAnimation("snakeRight", anim3,anim3Index,CHARA_ANIM_SPEED, true));


		ArrayList<CoreImageData> anim4=new ArrayList<CoreImageData>();
		anim4.add(new CoreImageData("image/game/chara/snake_clear.png"));

		ArrayList<Integer> anim4Index=new ArrayList<Integer>();
		anim4Index.add(0);
		anims.add(new CoreAnimation("snakeClear", anim4,anim4Index, 0.4f, false));


		CharaModel chara=new CharaModel(gameController, TARGET_TYPE.WOLF,
				anims, 0, 0, 0, 144, 144);
		objectFactory.create(chara, new CoreView(chara, 3));

		island.addCharacter(chara);
		layoutManager.addRight(chara,true);
		gameController.addAllCharacter(chara);

/*		CharaModel chara=new CharaModel(gameController, TARGET_TYPE.WOLF,
				new CoreImageData("image/wolf.jpg"),  1000,250, 100,100);
		this.objectFactory.create(chara,new CoreView(chara, 2));

		island.addCharacter(chara);
		layoutManager.addRight(chara);*/
	}

	/**
	 * 牛追加
	 */
	public void addCattle(){


		ArrayList<CoreAnimation> anims=new ArrayList<CoreAnimation>();
		ArrayList<CoreImageData> anim1=new ArrayList<CoreImageData>();
		anim1.add(new CoreImageData("image/game/chara/nanbou_game1.png"));

		ArrayList<Integer> anim1Index=new ArrayList<Integer>();
		anim1Index.add(0);
		anims.add(new CoreAnimation("nanbouClear", anim1,anim1Index, 0.4f, false));


		ArrayList<CoreImageData> anim2=new ArrayList<CoreImageData>();
		anim2.add(new CoreImageData("image/game/chara/nanbouGame.png",0,0,144,144));
		anim2.add(new CoreImageData("image/game/chara/nanbouGame.png",1,0,144,144));
		anim2.add(new CoreImageData("image/game/chara/nanbouGame.png",2,0,144,144));

		ArrayList<Integer> anim2Index=new ArrayList<Integer>();
		anim2Index.add(1);
		anim2Index.add(0);
		anim2Index.add(1);
		anim2Index.add(2);

		anims.add(new CoreAnimation("nanbouLeft", anim2,anim2Index,CHARA_ANIM_SPEED, true));


		ArrayList<CoreImageData> anim3=new ArrayList<CoreImageData>();
		anim3.add(new CoreImageData("image/game/chara/nanbouGameR.png",0,0,144,144));
		anim3.add(new CoreImageData("image/game/chara/nanbouGameR.png",1,0,144,144));
		anim3.add(new CoreImageData("image/game/chara/nanbouGameR.png",2,0,144,144));

		ArrayList<Integer> anim3Index=new ArrayList<Integer>();
		anim3Index.add(1);
		anim3Index.add(0);
		anim3Index.add(1);
		anim3Index.add(2);

		anims.add(new CoreAnimation("nanbouRight", anim3,anim3Index,CHARA_ANIM_SPEED, true));


		ArrayList<CoreImageData> anim4=new ArrayList<CoreImageData>();
		anim4.add(new CoreImageData("image/game/chara/nanbou_clear.png"));

		ArrayList<Integer> anim4Index=new ArrayList<Integer>();
		anim4Index.add(0);
		anims.add(new CoreAnimation("nanbouClear", anim4,anim4Index, 0.4f, false));


		CharaModel chara=new CharaModel(gameController, TARGET_TYPE.CATTLE,
				anims, 0, 0, 0, 144, 144);
		objectFactory.create(chara, new CoreView(chara, 3));

		island.addCharacter(chara);
		layoutManager.addRight(chara,true);
		gameController.addAllCharacter(chara);

/*
		CharaModel chara=new CharaModel(gameController, TARGET_TYPE.CATTLE,
				new CoreImageData("image/cattle.jpg"), 1000,400, 100,100);

		this.objectFactory.create(chara,new CoreView(chara, 2));

		island.addCharacter(chara);
		layoutManager.addRight(chara);*/
	}

	/**
	 * キャベツ追加
	 */
	public void addCabbage(){

		ArrayList<CoreAnimation> anims=new ArrayList<CoreAnimation>();
		ArrayList<CoreImageData> anim1=new ArrayList<CoreImageData>();
		anim1.add(new CoreImageData("image/game/chara/apple.png"));

		ArrayList<Integer> anim1Index=new ArrayList<Integer>();
		anim1Index.add(0);
		anims.add(new CoreAnimation("apple", anim1,anim1Index, 0.4f, false));


		CharaModel chara=new CharaModel(gameController, TARGET_TYPE.CABBAGE,
				anims, 0, 0, 0, 96, 144);
		objectFactory.create(chara, new CoreView(chara, 3));

		island.addCharacter(chara);
		layoutManager.addRight(chara,true);
		gameController.addAllCharacter(chara);


	/*	CharaModel chara=new CharaModel(gameController, TARGET_TYPE.CABBAGE,
				new CoreImageData("image/cabbage.jpg"),1000, 550, 100,100);

		this.objectFactory.create(chara,new CoreView(chara, 2));
		island.addCharacter(chara);
		layoutManager.addRight(chara);*/
	}



	/**
	 * スタート区画の設定
	 */
	public void createStartIsLand(){

		island=new StartIsland();

	}

	/***
	 * 終了区画の設定
	 */
	public void createEndIsLand(){
		endIsland=new EndIsland();
	}



	/**
	 * ボート関連を作成
	 */
	private void createBoat(int boatSize){

		//左右のアニメーションを追加
		ArrayList<CoreImageData> animImagesL=new ArrayList<CoreImageData>();
		animImagesL.add(new CoreImageData("image/game/ui/boat_l.png",0,0,272,130));
		animImagesL.add(new CoreImageData("image/game/ui/boat_l.png",1,0,272,130));
		animImagesL.add(new CoreImageData("image/game/ui/boat_l.png",2,0,272,130));


		ArrayList<CoreImageData> animImagesR=new ArrayList<CoreImageData>();
		animImagesR.add(new CoreImageData("image/game/ui/boat_r.png",0,0,272,130));
		animImagesR.add(new CoreImageData("image/game/ui/boat_r.png",1,0,272,130));
		animImagesR.add(new CoreImageData("image/game/ui/boat_r.png",2,0,272,130));


		ArrayList<Integer> animLIndex=new ArrayList<Integer>();
		animLIndex.add(0);
		animLIndex.add(1);
		animLIndex.add(2);

		ArrayList<Integer> animRIndex=new ArrayList<Integer>();
		animRIndex.add(0);
		animRIndex.add(1);
		animRIndex.add(2);

		ArrayList<CoreAnimation> boatAnims=new ArrayList<CoreAnimation>();
		boatAnims.add(new CoreAnimation("boatLeft", animImagesL,animLIndex, 0.2f, true));
		boatAnims.add(new CoreAnimation("boatRight", animImagesR,animRIndex, 0.2f, true));


		boat=new BoatModel(boatSize, boatAnims, 0, 420,400, 272, 130);
		this.objectFactory.create(boat, new CoreView(boat, 4));

	}

	/**
	 * ボートの再生成
	 * @param b
	 */
	private void reCreateBoat(BoatModel b){
		//boatAreaが無くなったのでｓとりあえず空
	}


	/**
	 * UIの作成
	 */
	private void createUI(){

		buttonNextTurn=new ButtonNextTurn(gameController, new CoreImageData("image/goText.png"),
				 640,670, 400,100);
		this.objectFactory.create(buttonNextTurn, new CoreView(buttonNextTurn, 1));


		////////////////////////////////////////
		//説明欄
		////////////////////////////////////////
		ArrayList<CoreImageData> examples=new ArrayList<CoreImageData>();
		examples.add(new CoreImageData("image/game/ui/textbox_s0.png"));
		examples.add(new CoreImageData("image/game/ui/textbox_s1.png"));
		examples.add(new CoreImageData("image/game/ui/textbox_s2.png"));
		examples.add(new CoreImageData("image/game/ui/textbox_s3.png"));
		examples.add(new CoreImageData("image/game/ui/textbox_s4.png"));
		ExampleBox exampleBox=new ExampleBox(examples, boat.getRideMaxMenberNum(),
				920, 644, 528, 96);

		objectFactory.create(exampleBox, new CoreView(exampleBox, 1));
		gameController.setExampleBox(exampleBox);

		/////////////////////////////////////////
		//右側の向こう岸アイコン
		////////////////////////////////////////

		//ミナミ
		CoreModel numIconX2=new CoreModel(new CoreImageData("image/game/ui/opposite_2.png"),
				150, 247, 112, 112);
		objectFactory.create(numIconX2, new CoreView(numIconX2, 2));

		CoreModel numIconX3=new CoreModel(new CoreImageData("image/game/ui/opposite_3.png"),
				150, 247, 112, 112);
		objectFactory.create(numIconX3, new CoreView(numIconX3, 2));


		OppositeIcon oppositeIcon=new OppositeIcon(TARGET_TYPE.MINISTART,
				new CoreModel[]{numIconX2,numIconX3},
				new CoreImageData("image/game/ui/opposite_blank_l.png"),
				new CoreImageData("image/game/ui/opposite_minami_l.png"),
				endIsland.getCharaNum(TARGET_TYPE.MINISTART),
				140, 247, 144, 112);
		this.objectFactory.create(oppositeIcon, new CoreView(oppositeIcon, 1));
		gameController.addoppositeRightIcon(oppositeIcon,island.getNowTurn());

		//リンゴ
		numIconX2=new CoreModel(new CoreImageData("image/game/ui/opposite_2.png"),
				150, 247+130, 112, 112);
		objectFactory.create(numIconX2, new CoreView(numIconX2, 2));

		numIconX3=new CoreModel(new CoreImageData("image/game/ui/opposite_3.png"),
				150, 247+130, 112, 112);
		objectFactory.create(numIconX3, new CoreView(numIconX3, 2));


		oppositeIcon=new OppositeIcon(TARGET_TYPE.CABBAGE,
				new CoreModel[]{numIconX2,numIconX3},
				new CoreImageData("image/game/ui/opposite_blank_l.png"),
				new CoreImageData("image/game/ui/opposite_apple_l.png"),
				endIsland.getCharaNum(TARGET_TYPE.CABBAGE),
				140, 247+130, 144, 112);
		this.objectFactory.create(oppositeIcon, new CoreView(oppositeIcon, 1));
		gameController.addoppositeRightIcon(oppositeIcon,island.getNowTurn());


		//なんぼう
		numIconX2=new CoreModel(new CoreImageData("image/game/ui/opposite_2.png"),
				150, 247+130*2, 112, 112);
		objectFactory.create(numIconX2, new CoreView(numIconX2, 2));

		numIconX3=new CoreModel(new CoreImageData("image/game/ui/opposite_3.png"),
				150, 247+130*2, 112, 112);
		objectFactory.create(numIconX3, new CoreView(numIconX3, 2));


		oppositeIcon=new OppositeIcon(TARGET_TYPE.CATTLE,
				new CoreModel[]{numIconX2,numIconX3},
				new CoreImageData("image/game/ui/opposite_blank_l.png"),
				new CoreImageData("image/game/ui/opposite_nanbou_l.png"),
				endIsland.getCharaNum(TARGET_TYPE.CATTLE),
				140, 247+130*2, 144, 112);
		this.objectFactory.create(oppositeIcon, new CoreView(oppositeIcon, 1));
		gameController.addoppositeRightIcon(oppositeIcon,island.getNowTurn());


		//へび
		numIconX2=new CoreModel(new CoreImageData("image/game/ui/opposite_2.png"),
				150, 247+130*3, 112, 112);
		objectFactory.create(numIconX2, new CoreView(numIconX2, 2));

		numIconX3=new CoreModel(new CoreImageData("image/game/ui/opposite_3.png"),
				150, 247+130*3, 112, 112);
		objectFactory.create(numIconX3, new CoreView(numIconX3, 2));


		oppositeIcon=new OppositeIcon(TARGET_TYPE.WOLF,
				new CoreModel[]{numIconX2,numIconX3},
				new CoreImageData("image/game/ui/opposite_blank_l.png"),
				new CoreImageData("image/game/ui/opposite_snake_l.png"),
				endIsland.getCharaNum(TARGET_TYPE.WOLF),
				140, 247+130*3, 144, 112);
		this.objectFactory.create(oppositeIcon, new CoreView(oppositeIcon, 1));
		gameController.addoppositeRightIcon(oppositeIcon,island.getNowTurn());


		/////////////////////////////////////////
		//左側の向こう岸アイコン
		////////////////////////////////////////

		//ミナミ
		numIconX2=new CoreModel(new CoreImageData("image/game/ui/opposite_2.png"),
				1280-150, 247, 112, 112);
		objectFactory.create(numIconX2, new CoreView(numIconX2, 2));

		numIconX3=new CoreModel(new CoreImageData("image/game/ui/opposite_3.png"),
				1280-150, 247, 112, 112);
		objectFactory.create(numIconX3, new CoreView(numIconX3, 2));


		oppositeIcon=new OppositeIcon(TARGET_TYPE.MINISTART,
				new CoreModel[]{numIconX2,numIconX3},
				new CoreImageData("image/game/ui/opposite_blank_r.png"),
				new CoreImageData("image/game/ui/opposite_minami_r.png"),
				island.getCharaNum(TARGET_TYPE.MINISTART),
				1280-140, 247, 144, 112);
		this.objectFactory.create(oppositeIcon, new CoreView(oppositeIcon, 1));
		gameController.addoppositeLeftIcon(oppositeIcon,!island.getNowTurn());

		//リンゴ
		numIconX2=new CoreModel(new CoreImageData("image/game/ui/opposite_2.png"),
				1280-150, 247+130, 112, 112);
		objectFactory.create(numIconX2, new CoreView(numIconX2, 2));

		numIconX3=new CoreModel(new CoreImageData("image/game/ui/opposite_3.png"),
				1280-150, 247+130, 112, 112);
		objectFactory.create(numIconX3, new CoreView(numIconX3, 2));


		oppositeIcon=new OppositeIcon(TARGET_TYPE.CABBAGE,
				new CoreModel[]{numIconX2,numIconX3},
				new CoreImageData("image/game/ui/opposite_blank_r.png"),
				new CoreImageData("image/game/ui/opposite_apple_r.png"),
				island.getCharaNum(TARGET_TYPE.CABBAGE),
				1280-140, 247+130, 144, 112);
		this.objectFactory.create(oppositeIcon, new CoreView(oppositeIcon, 1));
		gameController.addoppositeLeftIcon(oppositeIcon,!island.getNowTurn());


		//なんぼう
		numIconX2=new CoreModel(new CoreImageData("image/game/ui/opposite_2.png"),
				1280-150, 247+130*2, 112, 112);
		objectFactory.create(numIconX2, new CoreView(numIconX2, 2));

		numIconX3=new CoreModel(new CoreImageData("image/game/ui/opposite_3.png"),
				1280-150, 247+130*2, 112, 112);
		objectFactory.create(numIconX3, new CoreView(numIconX3, 2));


		oppositeIcon=new OppositeIcon(TARGET_TYPE.CATTLE,
				new CoreModel[]{numIconX2,numIconX3},
				new CoreImageData("image/game/ui/opposite_blank_r.png"),
				new CoreImageData("image/game/ui/opposite_nanbou_r.png"),
				island.getCharaNum(TARGET_TYPE.CATTLE),
				1280-140, 247+130*2, 144, 112);
		this.objectFactory.create(oppositeIcon, new CoreView(oppositeIcon, 1));
		gameController.addoppositeLeftIcon(oppositeIcon,!island.getNowTurn());


		//へび
		numIconX2=new CoreModel(new CoreImageData("image/game/ui/opposite_2.png"),
				1280-150, 247+130*3, 112, 112);
		objectFactory.create(numIconX2, new CoreView(numIconX2, 2));

		numIconX3=new CoreModel(new CoreImageData("image/game/ui/opposite_3.png"),
				1280-150, 247+130*3, 112, 112);
		objectFactory.create(numIconX3, new CoreView(numIconX3, 2));


		oppositeIcon=new OppositeIcon(TARGET_TYPE.WOLF,
				new CoreModel[]{numIconX2,numIconX3},
				new CoreImageData("image/game/ui/opposite_blank_r.png"),
				new CoreImageData("image/game/ui/opposite_snake_r.png"),
				island.getCharaNum(TARGET_TYPE.WOLF),
				1280-140, 247+130*3, 144, 112);
		this.objectFactory.create(oppositeIcon, new CoreView(oppositeIcon, 1));
		gameController.addoppositeLeftIcon(oppositeIcon,!island.getNowTurn());



		//////////////////////////////////////////////////
		///左上の渡した回数
		///////////////////////////////////////////////////

		ArrayList<CoreModel> rightNumbers=new ArrayList<CoreModel>();

		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",0,0,48,64), 176, 118, 48, 64));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",1,0,48,64), 176, 118, 48, 64));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",2,0,48,64), 176, 118, 48, 64));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",0,1,48,64), 176, 118, 48, 64));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",1,1,48,64), 176, 118, 48, 64));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",2,1,48,64), 176, 118, 48, 64));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",0,2,48,64), 176, 118, 48, 64));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",1,2,48,64), 176, 118, 48, 64));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",2,2,48,64), 176, 118, 48, 64));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",0,3,48,64), 176, 118, 48, 64));

		for(int i=0;i<rightNumbers.size();i++){
			objectFactory.create(rightNumbers.get(i), new CoreView(rightNumbers.get(i), 2));
		}

		ArrayList<CoreModel> leftNumbers=new ArrayList<CoreModel>();

		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",0,0,48,64), 124, 118, 48, 64));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",1,0,48,64), 124, 118, 48, 64));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",2,0,48,64), 124, 118, 48, 64));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",0,1,48,64), 124, 118, 48, 64));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",1,1,48,64), 124, 118, 48, 64));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",2,1,48,64), 124, 118, 48, 64));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",0,2,48,64), 124, 118, 48, 64));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",1,2,48,64), 124, 118, 48, 64));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",2,2,48,64), 124, 118, 48, 64));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",0,3,48,64), 124, 118, 48, 64));

		for(int i=0;i<leftNumbers.size();i++){
			objectFactory.create(leftNumbers.get(i), new CoreView(leftNumbers.get(i), 2));
		}

		NumBox numBox=new NumBox(boat.getMoveNum(), leftNumbers, rightNumbers,
				new CoreImageData("image/game/ui/cross_numbox.png"),170, 96, 176, 128);

		objectFactory.create(numBox, new CoreView(numBox, 1));
		gameController.setNumBox(numBox);

		//////////////////////////////////////////////////
		///最短経路回数の表示
		///////////////////////////////////////////////////

		rightNumbers=new ArrayList<CoreModel>();

		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",0,0,48,64), 1137,234, 20,26));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",1,0,48,64), 1137,234, 20,26));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",2,0,48,64), 1137,234, 20,26));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",0,1,48,64), 1137,234, 20,26));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",1,1,48,64), 1137,234, 20,26));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",2,1,48,64), 1137,234, 20,26));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",0,2,48,64), 1137,234, 20,26));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",1,2,48,64), 1137,234, 20,26));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",2,2,48,64), 1137,234, 20,26));
		rightNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",0,3,48,64), 1137,234, 20,26));

		for(int i=0;i<rightNumbers.size();i++){
			objectFactory.create(rightNumbers.get(i), new CoreView(rightNumbers.get(i), 2));
		}

		leftNumbers=new ArrayList<CoreModel>();

		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",0,0,48,64), 1118,234, 20,26));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",1,0,48,64), 1118,234, 20,26));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",2,0,48,64), 1118,234, 20,26));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",0,1,48,64), 1118,234, 20,26));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",1,1,48,64), 1118,234, 20,26));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",2,1,48,64), 1118,234, 20,26));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",0,2,48,64), 1118,234, 20,26));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",1,2,48,64), 1118,234, 20,26));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",2,2,48,64), 1118,234, 20,26));
		leftNumbers.add(new CoreModel(new CoreImageData("image/game/ui/numbers.png",0,3,48,64), 1118,234, 20,26));

		for(int i=0;i<leftNumbers.size();i++){
			objectFactory.create(leftNumbers.get(i), new CoreView(leftNumbers.get(i), 2));
		}

		NumBox numBox2=new NumBox(0, leftNumbers, rightNumbers,
				new CoreImageData("image/game/ui/cross_minbox.png"),1280-170, 220, 176, 80);

		numBox2.setShowView(false);
		objectFactory.create(numBox2, new CoreView(numBox2, 1));
		gameController.setNumboxS(numBox2);


		//////////////////////////////////////////////////////
		//セレクト枠	船の乗船人数は最大４なので４つ作成
		//////////////////////////////////////////////////////

		CoreModel icon=null;

		for(int i=0;i<4;i++){
			icon=new CoreModel(new CoreImageData("image/game/ui/select.png"), -100, -100,128,176);
			objectFactory.create(icon, new CoreView(icon, 2));
			gameController.addSelectIcons(icon);
		}

		//////////////////////////////////////////////////////
		//渡るボタンの追加
		//////////////////////////////////////////////////////

		CrossButton crossButton=new CrossButton(new CoreImageData("image/game/ui/cross_off.png"),
				new CoreImageData("image/game/ui/cross_on.png"),
				gameController, -100, -100, 272, 130);
		objectFactory.create(crossButton, new CoreView(crossButton, 5));
		gameController.addCrossButton(crossButton);

		//////////////////////////////////////////////////////
		//リスタートボタン
		//////////////////////////////////////////////////////
		OnemorePlayButton onemorePlayButton=new OnemorePlayButton(gameController, new CoreImageData("image/game/ui/onemoreplay.png"),
				641, 623, 352, 96);
		onemorePlayButton.setShowView(false);
		objectFactory.create(onemorePlayButton, new CoreView(onemorePlayButton, 11));
		gameController.setOnemorePlayButton(onemorePlayButton);

		//////////////////////////////////////////////////////
		//タイトルへ戻るボタンの追加
		//////////////////////////////////////////////////////
		BackToTitleButton backToTitleButton=new BackToTitleButton(gameController, new CoreImageData("image/game/ui/backtotitle.png"),
				1025, 623, 352, 96);
		backToTitleButton.setShowView(false);
		objectFactory.create(backToTitleButton, new CoreView(backToTitleButton, 11));
		gameController.setBackToTitleButton(backToTitleButton);


		//////////////////////////////////////////////////////
		//クリアロゴ
		//////////////////////////////////////////////////////
		CoreModel clearLogo=new CoreModel(new CoreImageData("image/game/ui/clear.png"),
				925, 366, 414, 124);
		clearLogo.setShowView(false);
		objectFactory.create(clearLogo, new CoreView(clearLogo, 5));
		gameController.setClearLogo(clearLogo);

		CoreModel perfectLogo=new CoreModel(new CoreImageData("image/game/ui/perfect.png"),
				925, 366, 558, 118);
		perfectLogo.setShowView(false);
		objectFactory.create(perfectLogo, new CoreView(perfectLogo, 5));
		gameController.setPerfectLogo(perfectLogo);


	}




}
