@Override
  public void Init() {
    DBManager.getInstance().setNetState(NetState.SINGLEGAME);
    try {
      sendMessage("1");
    } catch (IOException e) {
      e.printStackTrace();
    }
    AppManager.getInstance().state = AppManager.S_STORY1;
    GraphicManager.getInstance().Init();
    Sound.getInstance().addList(1, R.raw.buildingsaw);
    Sound.getInstance().backgroundPlay(R.raw.story_1);
    Sound.getInstance().addList(2, R.raw.smallchain);
    Sound.getInstance().addList(3, R.raw.zombie_create_sound);
    Sound.getInstance().addList(4, R.raw.hello);
    Sound.getInstance().addList(5, R.raw.smash);
    Sound.getInstance().addList(6, R.raw.text_call);
    currentTime = System.currentTimeMillis() / 1000;
    tileColl = new ArrayList<ActiveCollusion>();
    UnitDataList = new ArrayList<UnitList>();
    DisplayMetrics metrics = AppManager.getInstance().getResources().getDisplayMetrics();
    m_Width = metrics.widthPixels;
    m_Height = metrics.heightPixels;
    Units = new UnitManager();
    matrix.setScale(m_matrix_x, m_matrix_y);
    InitMap();
    GraphicManager.getInstance().background.resizebitmap((int) (m_Width * 2), (int) (m_Height * 2));
    UnitAdd(); // 데이터 베이스로 부터 유닛 목록 받아온다.

    UI = new UI_Create_Bottom(m_Width, m_Height, UnitDataList.size(), 0, UnitDataList);

    Unit Mtemp;
    Mtemp = new Unit(GraphicManager.getInstance().mTownHall.m_bitmap);
    GraphicManager.getInstance().m_airplane.Air(5);
    fade_in = new ScreenAnimation((int) m_Width, (int) m_Height);
    fade_out = new ScreenAnimation((int) m_Width, (int) m_Height);
    fade_out.InitFadeOut();
    fade_in.InitFadeIn();
    r = new Rect((int) m_Width / 20 * 18, 0, (int) (m_Width), (int) m_Height / 20);
  }
  public void TouchGame(float x, float y) {
    int count = 0;
    if (y > (int) m_Height - (int) m_Height / 6) {
      for (int i = 0; i < UI.Button.size(); i++) {
        if (UI.Button.get(i).Collusion(m_click_x, m_click_y, UI.rsizex, UI.rsizey)) {
          m_UI_Touch_Postion = i;
        }
      }
    } else {
      for (int i = 0; i < 50; i++) {
        for (int j = 0; j < 50; j++) {
          Unit temp;
          if (tileColl
                      .get(count)
                      .resultCal(m_click_x / m_matrix_x - m_diffX, m_click_y / m_matrix_y - m_diffY)
                  == true
              && UnitValue.m_bmap[i][j] != MapState.NotMove) {
            //  UnitValue.m_map[i][j]=3;
            // 점핑 트랩 생산
            switch (UI.CheckTable.get(m_UI_Touch_Postion).retruncode()) {
              case UnitValue.F_ROCK1:
                // CreateRock(i, j);

                break;
              case UnitValue.F_ROCKE2:
                // CreateRock2(i, j);

                break;
              case UnitValue.F_TREE1:
                //  CreateTree1(i, j);

                break;
              case UnitValue.F_TOWER:
                CreateUnit.CreateArchorTower(i, j, Units.MyUnits, Units.EnemyUnits, true);
                break;
              case UnitValue.F_BOOM:
                CreateUnit.CreateBoom(i, j, Units.MyUnits);
                break;
              case UnitValue.F_ELSATOWER:
                Unit temped = new Unit(GraphicManager.getInstance().mElsa_Tower.m_bitmap);
                CreateUnit.CreateMagicTower(i, j, temped, Units.MyUnits, Units.EnemyUnits, false);
                break;
              case UnitValue.F_ANNA:
                CreateUnit.CreateAnna(i, j, Units.MyUnits, Units.EnemyUnits, false);
                break;
            }
          }
          count++;
        }
      }
    }
  }
  public void LoadMap(String a) {
    String[] result = a.split("=");
    String[] imfors;
    for (int i = 0; i < result.length; i++) {

      int x = 0;
      int y = 0;
      int level = 0;
      int type = 0;
      imfors = result[i].split("a");

      x = Integer.parseInt(imfors[0]);
      y = Integer.parseInt(imfors[1]);
      level = Integer.parseInt(imfors[2]);
      type = Integer.parseInt(imfors[3]);
      switch (type) {
        case UnitValue.F_TOWER:
          CreateUnit.CreateArchorTower(x, y, Units.MyUnits, Units.EnemyUnits, false);
          break;
        case UnitValue.F_JUMPINGTRAP:
          break;
        case UnitValue.F_ZOMBIE:
          break;
        case UnitValue.F_GOLDRUN:
          break;
        case UnitValue.F_ELSATOWER:
          Unit temp = new Unit(GraphicManager.getInstance().mElsa_Tower.m_bitmap);
          CreateUnit.CreateMagicTower(x, y, temp, Units.MyUnits, Units.EnemyUnits, false);
          break;
        case UnitValue.F_ANNA:
          CreateUnit.CreateAnna(x, y, Units.MyUnits, Units.EnemyUnits, false);
          break;
        case UnitValue.F_TOWNHALL:
          break;
        case UnitValue.F_TREE1:
          CreateUnit.CreateTree1(x, y, Units.Enviroment);
          break;

        case UnitValue.F_ROCK1:
          CreateUnit.CreateRock(x, y, Units.Enviroment);

          break;
        case UnitValue.F_ROCKE2:
          CreateUnit.CreateRock2(x, y, Units.Enviroment);
          break;
        case UnitValue.F_BOOM:
          CreateUnit.CreateBoom(x, y, Units.EnemyUnits);
          break;
      }
    }
  }
  @Override
  public void Render(Canvas canvas) {

    Paint paint;
    paint = new Paint();
    paint.setColor(Color.WHITE);
    canvas.drawColor(0, PorterDuff.Mode.CLEAR);
    canvas.save();
    canvas.setMatrix(matrix);
    canvas.translate(m_diffX, m_diffY);
    // 타일 한번 깔아준다.
    GraphicManager.getInstance().background.Draw(canvas, -750, -450);
    for (int i = 0; i < 50; i++) {
      for (int j = 0; j < 50; j++) {
        switch (UnitValue.m_dmap[i][j]) {
          case UnitValue.M_GRASS1:
            GraphicManager.getInstance()
                .temptile1
                .Draw(canvas, 750 + 50 / 2 * (j - i), -300 + 25 / 2 * (j + i));
            break;
          case UnitValue.M_GRASS2:
            GraphicManager.getInstance()
                .temptile2
                .Draw(canvas, 750 + 50 / 2 * (j - i), -300 + 25 / 2 * (j + i));
            break;
          case UnitValue.M_EMPTY:
            GraphicManager.getInstance()
                .temptitle3
                .Draw(canvas, 750 + 50 / 2 * (j - i), -300 + 25 / 2 * (j + i));
            break;
          case UnitValue.M_NOTMOVE:
            GraphicManager.getInstance()
                .temptile5
                .Draw(canvas, 750 + 50 / 2 * (j - i), -300 + 25 / 2 * (j + i));
            break;
        }
      }
    }
    // 나무가 타일에 겹쳐지지 않게 그려주기 위해 한번더 연산해 주었다.
    for (int i = 0; i < 50; i++) {
      for (int j = 0; j < 50; j++) {
        if (UnitValue.m_dmap[i][j] == 4) {
          GraphicManager.getInstance()
              .temptile2
              .Draw(canvas, 750 + 50 / 2 * (j - i), -300 + 25 / 2 * (j + i));
          GraphicManager.getInstance()
              .temptitle4
              .Draw(canvas, 750 + 50 / 2 * (j - i), -300 + 25 / 2 * (j + i) - 25);
        }
      }
    }

    Units.RenderUnit(canvas);
    canvas.restore();
    GraphicManager.getInstance()
        .ButtonView_Image
        .Draw(canvas, 0, (int) m_Height - (int) m_Height / 6);
    for (int i = 0; i < UI.Button.size(); i++) {
      UI.Button.get(i).Draw(canvas);
      canvas.drawText(
          "" + i, (int) (UI.Button.get(i).GetX()), (int) (UI.Button.get(i).GetY()), paint);
    }

    canvas.drawRect(m_Width / 20 * 18, 0, m_Width, m_Height / 20, paint);
  }