Android Open Source - Gloomy-Dungeons-3D End Level View






From Project

Back to project page Gloomy-Dungeons-3D.

License

The source code is released under:

MIT License

If you think the Android project Gloomy-Dungeons-3D 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 zame.game.views;
/*  w  ww.j  ava 2 s.com*/
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.Timer;
import java.util.TimerTask;
import zame.game.Common;
import zame.game.GameActivity;
import zame.game.R;
import zame.game.SoundManager;
import zame.game.engine.Game;

public class EndLevelView extends zame.libs.FrameLayout implements IZameView
{
  private GameActivity activity;
  private Timer increaseValuesTimer;
  private final Handler handler = new Handler();
  private TextView txtKills;
  private TextView txtItems;
  private TextView txtSecrets;
  private float currentKills;
  private float currentItems;
  private float currentSecrets;
  private float currentAdd;
  private boolean increaseValuesTaskActive = false;
  private TimerTask increaseValuesTask;

  private final Runnable updateValues = new Runnable() {
    public void run() {
      boolean shouldCancel = true;

      currentKills += currentAdd;
      currentItems += currentAdd;
      currentSecrets += currentAdd;

      if (currentKills >= Game.endlTotalKills) {
        currentKills = (float)Game.endlTotalKills;
      } else {
        shouldCancel = false;
      }

      if (currentItems >= Game.endlTotalItems) {
        currentItems = (float)Game.endlTotalItems;
      } else {
        shouldCancel = false;
      }

      if (currentSecrets >= Game.endlTotalSecrets) {
        currentSecrets = (float)Game.endlTotalSecrets;
      } else {
        shouldCancel = false;
      }

      currentAdd += 0.2f;
      updateTxtValues();

      if (shouldCancel) {
        if (increaseValuesTaskActive) {
          increaseValuesTaskActive = false;
          increaseValuesTask.cancel();
        }
      } else {
        SoundManager.playSound(SoundManager.SOUND_SHOOT_PIST);
      }
    }
  };

  private void updateTxtValues()
  {
    txtKills.setText(String.format(activity.getString(R.string.endl_kills), (int)currentKills));
    txtItems.setText(String.format(activity.getString(R.string.endl_items), (int)currentItems));
    txtSecrets.setText(String.format(activity.getString(R.string.endl_secrets), (int)currentSecrets));
  }

  public EndLevelView(Context context, AttributeSet attrs)
  {
    super(context, attrs);
    activity = (GameActivity)context;
  }

  @Override
  protected void onFinishInflate()
  {
    super.onFinishInflate();

    Common.setTypeface(this, new int[] {
      R.id.TxtKills,
      R.id.TxtItems,
      R.id.TxtSecrets,
      R.id.BtnNextLevel,
    });

    txtKills = (TextView)findViewById(R.id.TxtKills);
    txtItems = (TextView)findViewById(R.id.TxtItems);
    txtSecrets = (TextView)findViewById(R.id.TxtSecrets);

    ((Button)findViewById(R.id.BtnNextLevel)).setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
        SoundManager.playSound(SoundManager.SOUND_BTN_PRESS);

        currentKills = Game.endlTotalKills;
        currentItems = Game.endlTotalItems;
        updateTxtValues();

        SoundManager.setPlaylist(SoundManager.LIST_MAIN);
        GameActivity.changeView(R.layout.pre_level);
      }
    });

    currentKills = 0.0f;
    currentItems = 0.0f;
    currentSecrets = 0.0f;
    currentAdd = 1.0f;

    updateTxtValues();
    startTask();
  }

  private void startTask()
  {
    if (!increaseValuesTaskActive) {
      increaseValuesTask = new TimerTask() {
        public void run() {
          handler.post(updateValues);
        }
      };

      increaseValuesTimer = new Timer();
      increaseValuesTaskActive = true;
      increaseValuesTimer.schedule(increaseValuesTask, 100, 100);
    }
  }

  private void stopTask()
  {
    if (increaseValuesTaskActive) {
      increaseValuesTaskActive = false;
      increaseValuesTask.cancel();
    }
  }

  @Override
  public void onWindowFocusChanged(boolean hasFocus)
  {
    super.onWindowFocusChanged(hasFocus);

    if (hasFocus) {
      startTask();
    } else {
      stopTask();
    }
  }

  public void onResume()
  {
  }

  public void onPause()
  {
    stopTask();
  }
}




Java Source Code List

zame.game.AppConfig.java
zame.game.AppConfig.java
zame.game.Common.java
zame.game.ConfigZeemote.java
zame.game.ConfigZeemote.java
zame.game.Config.java
zame.game.GameActivityZeemoteHelper.java
zame.game.GameActivityZeemoteHelper.java
zame.game.GameActivity.java
zame.game.GamePreferencesActivity.java
zame.game.GamePreferencesActivity.java
zame.game.MenuActivityHelper.java
zame.game.MenuActivityHelper.java
zame.game.MenuActivity.java
zame.game.Renderer.java
zame.game.SoundManager.java
zame.game.ZameApplicationAnalyticsHelper.java
zame.game.ZameApplicationAnalyticsHelper.java
zame.game.ZameApplication.java
zame.game.ZameGame.java
zame.game.ZameJniRenderer.java
zame.game.engine.Action.java
zame.game.engine.AutoWall.java
zame.game.engine.Controls.java
zame.game.engine.Door.java
zame.game.engine.GameHelper.java
zame.game.engine.GameHelper.java
zame.game.engine.Game.java
zame.game.engine.Labels.java
zame.game.engine.LevelConfig.java
zame.game.engine.LevelRenderer.java
zame.game.engine.Level.java
zame.game.engine.Mark.java
zame.game.engine.Monster.java
zame.game.engine.Overlay.java
zame.game.engine.PortalTracer.java
zame.game.engine.State.java
zame.game.engine.Stats.java
zame.game.engine.TextureLoader.java
zame.game.engine.Weapons.java
zame.game.views.EndLevelView.java
zame.game.views.GameOverView.java
zame.game.views.GameView.java
zame.game.views.IZameView.java
zame.game.views.MenuViewHelper.java
zame.game.views.MenuViewHelper.java
zame.game.views.MenuView.java
zame.game.views.PreLevelView.java
zame.game.views.ZameGameView.java
zame.libs.FrameLayout.java
zame.libs.GLSurfaceView21.java
zame.libs.Grid.java
zame.libs.KeyMapPreference.java
zame.libs.LabelMaker.java
zame.libs.ListPreference.java
zame.libs.NumericSprite.java
zame.libs.SeekBarPreference.java
zame.promo.PromoView.java