Android Open Source - ShootEmOff Score Board Activity






From Project

Back to project page ShootEmOff.

License

The source code is released under:

Copyright (c) 2011 Andrey Moiseev, http://o2genum.ru Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),...

If you think the Android project ShootEmOff 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 com.shootemoff.game;
/*from  w  w  w  .j  a  v  a2s. c  om*/
import java.util.ArrayList;
import java.util.Arrays;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.shootemoff.shootemoffgame.R;

public class ScoreBoardActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_score_board);
    
    Resources res = getResources();
    String[] scores = res.getStringArray(R.array.scores_array);
    String[] score_names = res.getStringArray(R.array.score_names_array);
    
    SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
    
    String defaultValueString = res.getString(R.string.saved_score_default);
    int defaultValue = Integer.parseInt(defaultValueString);
    String defaultName = res.getString(R.string.saved_score_name_default);
    
    String max_scores_saved_string = res.getString(R.string.max_scores_saved);
    int max_scores_saved = Integer.parseInt(max_scores_saved_string);
    
    StorageHandler handler = new StorageHandler(max_scores_saved);
    
    for(int i = 0; i < max_scores_saved; i++){

      int score = sharedPref.getInt(scores[i], defaultValue);

      if(score != defaultValue){
        String name = sharedPref.getString(score_names[i], defaultName);
        handler.AddScore(name, score);
      }
      else{
        break;
      }
    }
    
    Button back_button = (Button)findViewById(R.id.back_to_menu);
    back_button.setBackgroundResource(R.drawable.start_button);
    Typeface myTypeface = Typeface.createFromAsset(getAssets(), "bay6.ttf");
    back_button.setTypeface(myTypeface);
    
    //Typeface myTypeface = Typeface.createFromAsset(getAssets(), "molten.ttf");
    //text.setTypeface(myTypeface);
    
    int size = handler.GetSize();
    ListView scoreListView = (ListView)findViewById(R.id.list);

    String[] scoreArray = new String[size];

    ScoreObject[] scores_from_file = handler.GetHighScores();
    
    for(int i = 0; i < size; i++){
      String score_line;
      
      int minutes = (scores_from_file[i].score / 100);
      int seconds = scores_from_file[i].score - (minutes * 100);
      score_line = (i+1) + ". NAME : " + scores_from_file[i].name + "\t\t\t SCORE : ";
      
      if(minutes < 10){
        score_line += "0";
      }
      score_line += minutes + ":";
      if(seconds < 10){
        score_line += "0";
      }
      score_line += seconds;
      
      scoreArray[i] = score_line;
    }
    
    // Create and populate a List of names and scores.
    ArrayList<String> planetList = new ArrayList<String>();  
      planetList.addAll( Arrays.asList(scoreArray) );
    
      // Create ArrayAdapter using the planet list.  
      ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow, planetList);
      
      scoreListView.setAdapter( listAdapter );
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.score_board, menu);
    return true;
  }
  
  public void BackToMenu(View view)
  {
    Intent intent = new Intent (this, StartScreenActivity.class);
    startActivity(intent);
  }
  
  public void onBackPressed(){
    Intent intent = new Intent (this, StartScreenActivity.class);
    startActivity(intent);
  }

}




Java Source Code List

com.shootemoff.framework.Audio.java
com.shootemoff.framework.FileIO.java
com.shootemoff.framework.Game.java
com.shootemoff.framework.Graphics.java
com.shootemoff.framework.Input.java
com.shootemoff.framework.Pool.java
com.shootemoff.framework.Screen.java
com.shootemoff.framework.Sound.java
com.shootemoff.framework.Vibration.java
com.shootemoff.framework.impl.AndroidAudio.java
com.shootemoff.framework.impl.AndroidFastRenderView.java
com.shootemoff.framework.impl.AndroidFileIO.java
com.shootemoff.framework.impl.AndroidGame.java
com.shootemoff.framework.impl.AndroidGraphics.java
com.shootemoff.framework.impl.AndroidInput.java
com.shootemoff.framework.impl.AndroidOrientationHandler.java
com.shootemoff.framework.impl.AndroidSound.java
com.shootemoff.framework.impl.AndroidVibration.java
com.shootemoff.framework.impl.KeyboardHandler.java
com.shootemoff.framework.impl.MultiTouchHandler.java
com.shootemoff.framework.impl.OrientationHandler.java
com.shootemoff.framework.impl.SingleTouchHandler.java
com.shootemoff.framework.impl.TouchHandler.java
com.shootemoff.game.ControlPad.java
com.shootemoff.game.Core.java
com.shootemoff.game.Dot.java
com.shootemoff.game.GameActivity.java
com.shootemoff.game.GameOverActivity.java
com.shootemoff.game.GameScreen.java
com.shootemoff.game.OptionsObject.java
com.shootemoff.game.Point.java
com.shootemoff.game.ScoreBoardActivity.java
com.shootemoff.game.ScoreObject.java
com.shootemoff.game.SettingsActivity.java
com.shootemoff.game.StartScreenActivity.java
com.shootemoff.game.StorageHandler.java
com.shootemoff.game.VectorF.java
com.shootemoff.game.World.java