Esempio n. 1
0
    // 새로운 도형을 목록에 추가한다.
    void AddNewShape() {
      Shape shape = new Shape();
      int idx;
      boolean bFindIntersect;
      Rect rt = new Rect();

      // 기존 도형과 겹치지 않는 새 위치를 찾는다.
      for (; ; ) {
        // 크기는 32, 48, 64 중 하나 선택
        int Size = 32 + 16 * Rnd.nextInt(3);

        // 위치는 난수로 선택
        rt.left = Rnd.nextInt(getWidth());
        rt.top = Rnd.nextInt(getHeight());
        rt.right = rt.left + Size;
        rt.bottom = rt.top + Size;

        // 화면을 벗어나면 안된다.
        if (rt.right > getWidth() || rt.bottom > getHeight()) {
          continue;
        }

        // 기존 도형 순회하며 겹치는지 조사한다.
        bFindIntersect = false;
        for (idx = 0; idx < arShape.size(); idx++) {
          if (rt.intersect(arShape.get(idx).rt) == true) {
            bFindIntersect = true;
          }
        }

        // 겹치지 않을 때 확정한다. 겹치면 계속 새 위치 선정한다.
        if (bFindIntersect == false) {
          break;
        }
      }

      // 새 도형 정보 작성. 모양, 색상 등을 난수 선택한다.
      shape.what = Rnd.nextInt(3);

      switch (Rnd.nextInt(5)) {
        case 0:
          shape.color = Color.WHITE;
          break;
        case 1:
          shape.color = Color.RED;
          break;
        case 2:
          shape.color = Color.GREEN;
          break;
        case 3:
          shape.color = Color.BLUE;
          break;
        case 4:
          shape.color = Color.YELLOW;
          break;
      }

      shape.rt = rt;
      arShape.add(shape);
    }
Esempio n. 2
0
  // 새로운 볼 생성
  static Ball Create(int x, int y, int Rad) {
    Random Rnd = new Random();
    Ball NewBall = new Ball();

    NewBall.x = x;
    NewBall.y = y;
    NewBall.rad = Rad;
    do {
      NewBall.dx = Rnd.nextInt(11) - 5;
      NewBall.dy = Rnd.nextInt(11) - 5;
    } while (NewBall.dx == 0 || NewBall.dy == 0);

    NewBall.count = 0;
    NewBall.color = Color.rgb(Rnd.nextInt(256), Rnd.nextInt(256), Rnd.nextInt(256));

    return NewBall;
  }
 public float pickTranslation(int n, float f) {
   return n * (f - 1.0f) * (random.nextFloat() - 0.5f);
 }
 public float pickScale() {
   return minScaleFactor + random.nextFloat() * (maxScaleFactor - minScaleFactor);
 }
  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));
  }