示例#1
0
  // Create all the Objects needed for a new Game and add them to the pl ParameterList.
  private void startGame() {

    mix();
    ParameterList pl = new ParameterList();
    pl.addParameter(GameActivity.PARAMS_PIC, model.getImage());
    pl.addParameter(GameActivity.PARAMS_BLACK, model.getBlack());
    pl.addParameter(GameActivity.PARAMS_SORT, model.getSort());
    pl.addParameter(GameActivity.PARAMS_NEIGHBORS, model.getNeighbors());
    pl.addParameter(GameActivity.PARAMS_TIME, model.getRoundTime());
    gameActivity = new GameActivity(this);
    model.setRoundTime(0);
    view.startActivity(gameActivity, pl);
    if (null == counter) {
      counter = new Counter(model, gameActivity);
      counter.start();
    } else counter.setActivity(gameActivity);
  }
示例#2
0
  public void returnData(String activityClass, ParameterList params) {

    // A new ParameterList for starting new Activitys
    ParameterList pl = new ParameterList();

    // If MenuActivity returns data.
    if (activityClass.equals(MenuActivity.class.getSimpleName())) {

      // Switches based on the selected entry.
      switch ((Integer) params.getValue(MenuActivity.PARAM_MENUITEM)) {

          // When new game is clicked.
        case MainMenuModel.NEW_GAME:

          // Add the actual playername to the PArameters.
          pl.addParameter(PlayernameActivity.PARAMS_NAME, model.getPlayerName());

          // Start a new PlayernameActivity.
          view.startActivity(new PlayernameActivity(this), pl);

          break;

          // When new highscore is clicked.
        case MainMenuModel.HIGHSCORE:
          ArrayList<String> s = new ArrayList<String>();
          s.add("Hans");
          s.add("Peter");
          s.add("Olaf");

          ArrayList<Integer> i = new ArrayList<Integer>();
          i.add(20);
          i.add(30);
          i.add(120);

          pl.addParameter(HighscoreActivity.PARAM_USERS, s);
          pl.addParameter(HighscoreActivity.PARAM_SCORES, i);

          view.startActivity(new HighscoreActivity(this), pl);
          break;

          // When options is clicked.
        case MainMenuModel.OPTIONS:
          pl.addParameter(OptionsActivity.PARAMS_DIF, model.getDifficulty());
          pl.addParameter(OptionsActivity.PARAMS_SIZE, model.getSize());

          view.startActivity(new OptionsActivity(this), pl);
          break;

          // When credits is clicked.
        case MainMenuModel.CREDITS:
          view.startActivity(new CreditsActivity(this), null);
          break;

          // When quit is clicked.
        case MainMenuModel.QUIT:
          view.startActivity(new QuitActivity(this), null);
          break;
      }
    }

    // If QuitActivity returns data.
    else if (activityClass.equals(QuitActivity.class.getSimpleName())) {
      if ((Boolean) params.getValue(QuitActivity.RETURN_QUIT)) System.exit(0);
      start();
    }

    // If HighscoreActivity returns data.
    else if (activityClass.equals(HighscoreActivity.class.getSimpleName())) start();

    // If CreditsActivity returns data.
    else if (activityClass.equals(CreditsActivity.class.getSimpleName())) start();

    // If ImageLoader returns data.
    else if (activityClass.equals(ImageLoder.class.getSimpleName())) {

      pl.addParameter(GalleryActivity.PARAM_PICS, params.getValue(ImageLoder.RETURN_PICS));
      view.startActivity(new GalleryActivity(this), params);
    }

    // If PlayernameActivity returns data.
    else if (activityClass.equals(PlayernameActivity.class.getSimpleName())) {
      model.setPlayerName((String) params.getValue(PlayernameActivity.RETURN_NAME));
      if ((Boolean) params.getValue(PlayernameActivity.RETURN_BACK)) start();
      else if ((Boolean) params.getValue(PlayernameActivity.RETURN_GALLARY)) {
        pl.addParameter(LoadingActivity.PARAM_MESSAGE, "Loading Gallery");
        view.startActivity(new LoadingActivity(this), pl);
        ImageLoder il = new ImageLoder(this, galleryModel);
        il.start();
      } else {
        view.startActivity(new ChoosePicActivity(this), params);
      }

    }

    // If ChoosePicActivity returns data.
    else if (activityClass.equals(ChoosePicActivity.class.getSimpleName())) {
      try {
        pl.addParameter(LoadingActivity.PARAM_MESSAGE, "Loading Image");
        // view.startActivity(new LoadingActivity(this), pl);
        Image image =
            ImageIO.read(new File((String) params.getValue(ChoosePicActivity.RETURN_PATH)));
        model.setImage(
            Graphics.subImage(Graphics.scale(image, 800, 600), model.getSize(), 700, 400));
        startGame();
      } catch (IOException e) {
        view.startActivity(new MenuActivity(this), null);
      }
    }

    // If GalleryActivity returns data.
    else if (activityClass.equals(GalleryActivity.class.getSimpleName())) {
      Image image =
          Graphics.scale(
              (Image) params.getValue(GalleryActivity.RETURN_PIC),
              view.getWidth(),
              view.getHeight());
      model.setImage(Graphics.subImage(Graphics.scale(image, 800, 600), model.getSize(), 700, 400));
      startGame();
    }

    // If OptionsActivity returns data.
    else if (activityClass.equals(OptionsActivity.class.getSimpleName())) {
      model.setDifficulty((Integer) params.getValue(OptionsActivity.RETURN_DIF));
      model.setSize((Integer) params.getValue(OptionsActivity.RETURN_SIZE));
      view.startActivity(new MenuActivity(this), null);
    }

    // If GameActivity returns data.
    else if (activityClass.equals(GameActivity.class.getSimpleName())) {

      // if returnbutton ore shufflebutton is clicked.
      if (params.getValue(GameActivity.RETURN_SELECTED).equals(GameActivity.RETURN_BACK)) {
        view.startActivity(new MenuActivity(this), null);
        return;
      }
      if (params.getValue(GameActivity.RETURN_SELECTED).equals(GameActivity.RETURN_SHUFFLE)) {
        startGame();
        return;
      }

      // Change the black picture with the selected one.
      int[] sort = model.getSort();
      int temp = sort[model.getBlack()];
      sort[model.getBlack()] = sort[(Integer) params.getValue(GameActivity.RETURN_SELECTED)];
      sort[(Integer) params.getValue(GameActivity.RETURN_SELECTED)] = temp;

      // Set the new order to the model.
      model.setBlack((Integer) params.getValue(GameActivity.RETURN_SELECTED));
      model.setSort(sort);
      model.setNeighbors(getNeighbors());

      // Check if the pictures are in the correct order.
      boolean t = true;
      for (int i = 0; i < sort.length; i++) {
        if (i != sort[i]) {
          t = false;
          break;
        }
      }
      // If correct order.
      if (t) {
        pl.addParameter(WonActivity.PARAMS_NAME, model.getPlayerName());
        pl.addParameter(WonActivity.PARAMS_TIME, model.getRoundTime());
        view.startActivity(new WonActivity(this), pl);
      }
      // If order is incorrect.
      else {

        // Set all the parameters needed for the new GameActivity.
        pl.addParameter(GameActivity.PARAMS_PIC, model.getImage());
        pl.addParameter(GameActivity.PARAMS_BLACK, model.getBlack());
        pl.addParameter(GameActivity.PARAMS_SORT, model.getSort());
        pl.addParameter(GameActivity.PARAMS_NEIGHBORS, model.getNeighbors());
        pl.addParameter(GameActivity.PARAMS_TIME, model.getRoundTime());

        view.startActivity(gameActivity, pl);
      }

    }

    // If WonActivity returns data.
    else if (activityClass.equals(WonActivity.class.getSimpleName())) start();
  }