Android Open Source - Freebloks-Android View Model






From Project

Back to project page Freebloks-Android.

License

The source code is released under:

GNU General Public License

If you think the Android project Freebloks-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.saschahlusiak.freebloks.view.model;
/*from w ww  .j a  v a  2s.c  o  m*/
import java.util.ArrayList;

import android.graphics.PointF;
import de.saschahlusiak.freebloks.Global;
import de.saschahlusiak.freebloks.controller.GameMode;
import de.saschahlusiak.freebloks.controller.Spielleiter;
import de.saschahlusiak.freebloks.game.ActivityInterface;
import de.saschahlusiak.freebloks.model.Spiel;
import de.saschahlusiak.freebloks.view.Freebloks3DView;
import de.saschahlusiak.freebloks.view.effects.Effect;

@SuppressWarnings("serial")
public class ViewModel extends ArrayList<ViewElement> implements ViewElement {
  public Wheel wheel;
  public CurrentStone currentStone;
  public Spielleiter spiel;
  public Board board;
  public ActivityInterface activity;
  public Freebloks3DView view;
  public ArrayList<Effect> effects;
  public Intro intro;
  public Sounds soundPool;

  public boolean showSeeds, showOpponents, snapAid;
  public int showAnimations;
  public boolean immersiveMode = true;
  public boolean vertical_layout = true;
  boolean redraw;
  
  public final static int ANIMATIONS_FULL = 0;
  public final static int ANIMATIONS_HALF = 1;
  public final static int ANIMATIONS_OFF = 2;

  public ViewModel(Freebloks3DView view) {
    this.view = view;

    this.spiel = new Spielleiter(Spiel.DEFAULT_FIELD_SIZE_Y, Spiel.DEFAULT_FIELD_SIZE_X);

    currentStone = new CurrentStone(this);
    wheel = new Wheel(this);
    board = new Board(this, Spiel.DEFAULT_FIELD_SIZE_X);

    effects = new ArrayList<Effect>();

    add(currentStone);
    add(wheel);
    add(board);
  }
  
  public boolean hasAnimations() {
    return showAnimations != ANIMATIONS_OFF;
  }

  public void reset() {
    currentStone.startDragging(null, null, 0);
    board.resetRotation();
  }

  public void setSpiel(Spielleiter spiel) {
    this.spiel = spiel;
  }

  public boolean handlePointerDown(PointF m) {
    redraw = false;
    if (intro != null) {
      redraw = intro.handlePointerDown(m);
      return redraw;
    }
    for (int i = 0; i < size(); i++)
      if (get(i).handlePointerDown(m))
        return redraw;
    return redraw;
  }

  public boolean handlePointerMove(PointF m) {
    redraw = false;
    for (int i = 0; i < size(); i++)
      if (get(i).handlePointerMove(m))
        return redraw;
    return redraw;
  }

  public boolean handlePointerUp(PointF m) {
    redraw = false;
    for (int i = 0; i < size(); i++)
      if (get(i).handlePointerUp(m))
        return redraw;
    return redraw;
  }

  @Override
  public boolean execute(float elapsed) {
    boolean redraw = false;
    if (intro != null) {
      redraw |= intro.execute(elapsed);
      return redraw;
    }

    synchronized (effects) {
      int i = 0;
      while (i < effects.size()) {
        redraw |= effects.get(i).execute(elapsed);
        if (effects.get(i).isDone()) {
          effects.remove(i);
          redraw = true;
        } else
          i++;
      }
    }

    for (int i = 0; i < size(); i++)
      redraw |= get(i).execute(elapsed);

    return redraw;
  }

  public void addEffect(Effect effect) {
    synchronized (effects) {
      effects.add(effect);
    }
  }

  public void clearEffects() {
    synchronized (effects) {
      effects.clear();
    }
  }

  public int getPlayerColor(int player) {
    if (spiel == null)
      return Global.getPlayerColor(player, GameMode.GAMEMODE_4_COLORS_4_PLAYERS);
    return Global.getPlayerColor(player, spiel.m_gamemode);
  }
}




Java Source Code List

com.google.example.games.basegameutils.BaseGameActivity.java
com.google.example.games.basegameutils.GameHelperUtils.java
com.google.example.games.basegameutils.GameHelper.java
de.saschahlusiak.freebloks.AboutActivity.java
de.saschahlusiak.freebloks.Global.java
de.saschahlusiak.freebloks.backup.FreebloksBackupAgent.java
de.saschahlusiak.freebloks.controller.GameMode.java
de.saschahlusiak.freebloks.controller.JNIServer.java
de.saschahlusiak.freebloks.controller.PlayerData.java
de.saschahlusiak.freebloks.controller.SpielClientInterface.java
de.saschahlusiak.freebloks.controller.SpielClient.java
de.saschahlusiak.freebloks.controller.Spielleiter.java
de.saschahlusiak.freebloks.database.FreebloksDBOpenHandler.java
de.saschahlusiak.freebloks.database.FreebloksDB.java
de.saschahlusiak.freebloks.database.HighscoreDB.java
de.saschahlusiak.freebloks.donate.DonateActivity.java
de.saschahlusiak.freebloks.game.ActivityInterface.java
de.saschahlusiak.freebloks.game.AddScoreTask.java
de.saschahlusiak.freebloks.game.CustomGameDialog.java
de.saschahlusiak.freebloks.game.FreebloksActivity.java
de.saschahlusiak.freebloks.game.GameFinishActivity.java
de.saschahlusiak.freebloks.game.GameMenu.java
de.saschahlusiak.freebloks.game.RateAppDialog.java
de.saschahlusiak.freebloks.game.RetainedConfig.java
de.saschahlusiak.freebloks.game.SpielClientThread.java
de.saschahlusiak.freebloks.lobby.ChatEntry.java
de.saschahlusiak.freebloks.lobby.ChatListAdapter.java
de.saschahlusiak.freebloks.lobby.ColorAdapter.java
de.saschahlusiak.freebloks.lobby.LobbyDialog.java
de.saschahlusiak.freebloks.model.Player.java
de.saschahlusiak.freebloks.model.Spiel.java
de.saschahlusiak.freebloks.model.Stone.java
de.saschahlusiak.freebloks.model.Turn.java
de.saschahlusiak.freebloks.model.Turnpool.java
de.saschahlusiak.freebloks.network.NET_CHAT.java
de.saschahlusiak.freebloks.network.NET_CURRENT_PLAYER.java
de.saschahlusiak.freebloks.network.NET_GAME_FINISH.java
de.saschahlusiak.freebloks.network.NET_GRANT_PLAYER.java
de.saschahlusiak.freebloks.network.NET_HEADER.java
de.saschahlusiak.freebloks.network.NET_REQUEST_GAME_MODE.java
de.saschahlusiak.freebloks.network.NET_REQUEST_HINT.java
de.saschahlusiak.freebloks.network.NET_REQUEST_PLAYER.java
de.saschahlusiak.freebloks.network.NET_REQUEST_UNDO.java
de.saschahlusiak.freebloks.network.NET_REVOKE_PLAYER.java
de.saschahlusiak.freebloks.network.NET_SERVER_STATUS.java
de.saschahlusiak.freebloks.network.NET_SET_STONE.java
de.saschahlusiak.freebloks.network.NET_START_GAME.java
de.saschahlusiak.freebloks.network.NET_UNDO_STONE.java
de.saschahlusiak.freebloks.network.Network.java
de.saschahlusiak.freebloks.preferences.AboutFragment.java
de.saschahlusiak.freebloks.preferences.DisplayFragment.java
de.saschahlusiak.freebloks.preferences.FreebloksPreferences.java
de.saschahlusiak.freebloks.preferences.InterfaceFragment.java
de.saschahlusiak.freebloks.preferences.MiscFragment.java
de.saschahlusiak.freebloks.preferences.StatisticsFragment.java
de.saschahlusiak.freebloks.preferences.ThemePreference.java
de.saschahlusiak.freebloks.stats.StatisticsActivity.java
de.saschahlusiak.freebloks.stats.StatisticsAdapter.java
de.saschahlusiak.freebloks.view.BackgroundRenderer.java
de.saschahlusiak.freebloks.view.BoardRenderer.java
de.saschahlusiak.freebloks.view.Freebloks3DView.java
de.saschahlusiak.freebloks.view.FreebloksRenderer.java
de.saschahlusiak.freebloks.view.SimpleModel.java
de.saschahlusiak.freebloks.view.effects.AbsEffect.java
de.saschahlusiak.freebloks.view.effects.AbsStoneEffect.java
de.saschahlusiak.freebloks.view.effects.BoardStoneGlowEffect.java
de.saschahlusiak.freebloks.view.effects.EffectSet.java
de.saschahlusiak.freebloks.view.effects.Effect.java
de.saschahlusiak.freebloks.view.effects.PhysicalStoneEffect.java
de.saschahlusiak.freebloks.view.effects.StoneFadeEffect.java
de.saschahlusiak.freebloks.view.effects.StoneRollEffect.java
de.saschahlusiak.freebloks.view.effects.StoneUndoEffect.java
de.saschahlusiak.freebloks.view.model.Board.java
de.saschahlusiak.freebloks.view.model.CurrentStone.java
de.saschahlusiak.freebloks.view.model.Intro.java
de.saschahlusiak.freebloks.view.model.Sounds.java
de.saschahlusiak.freebloks.view.model.Theme.java
de.saschahlusiak.freebloks.view.model.ViewElement.java
de.saschahlusiak.freebloks.view.model.ViewModel.java
de.saschahlusiak.freebloks.view.model.Wheel.java