多くの人に見て貰える様にランキングへのご協力をお願いします!
ゲーム制作 ブログランキングへ
スタート画面のJavaソースファイルになります。
MainActivityというアクティビティに中に以下の処理が含まれています。
<処理内容>
・onCreate : 画面の初期作成処理(レイアウトファイルの読み込み等)
・showYesNoDialog : Yes/No選択肢を表示するプログラム(他のプログラムに呼ばれる)
・showDialog : 画面に文字をポップアップさせるプログラム(他のプログラムに呼ばれる)
・onClick1 : 1番のボタンを押した際のプログラム
・onClick2 : 2番のボタンを押した際のプログラム
・onClick3 : 3番のボタンを押した際のプログラム
・onClick4 : 4番のボタンを押した際のプログラム
・onActivityResult : startActivityForResultで画面が移った際の戻り処理
細かなポイントとしては、画面を「図鑑」や「解説」画面に移動する際は、
「startActivity」を使ってただMainActivityの上に表示させています。
それに対して「開始」ボタンの場合は「startActivityForResult」を使い、
「onActivityResult」による画面が戻った際の処理を行う様にさせています。
これはゲーム開始後のメイン画面で「終了」ボタンを押した際に、
再びスタート画面を表示させない様にする為の工夫です。
(「終了」を押したのに終わらないとイラっとしますよね?)
それとボタン4の「初期化」ではアイテム数やイベントフラグ等の
ゲームに関するデータを消去する処理を組み込んでいます。
ポイントという程では無いですが、私の場合はここにパラメータを入れる事で、
利用中のパラメータ初期値を管理したり、パラメータの修正漏れが無い様に
チェックしたりしています。
■MainActivity.java(Javaファイル)
■イビル・スレイヤー
https://play.google.com/store/apps/details?id=com.hidefumi.kasahara.evel_slayer
ゲーム制作 ブログランキングへ
スタート画面のJavaソースファイルになります。
MainActivityというアクティビティに中に以下の処理が含まれています。
<処理内容>
・onCreate : 画面の初期作成処理(レイアウトファイルの読み込み等)
・showYesNoDialog : Yes/No選択肢を表示するプログラム(他のプログラムに呼ばれる)
・showDialog : 画面に文字をポップアップさせるプログラム(他のプログラムに呼ばれる)
・onClick1 : 1番のボタンを押した際のプログラム
・onClick2 : 2番のボタンを押した際のプログラム
・onClick3 : 3番のボタンを押した際のプログラム
・onClick4 : 4番のボタンを押した際のプログラム
・onActivityResult : startActivityForResultで画面が移った際の戻り処理
細かなポイントとしては、画面を「図鑑」や「解説」画面に移動する際は、
「startActivity」を使ってただMainActivityの上に表示させています。
それに対して「開始」ボタンの場合は「startActivityForResult」を使い、
「onActivityResult」による画面が戻った際の処理を行う様にさせています。
これはゲーム開始後のメイン画面で「終了」ボタンを押した際に、
再びスタート画面を表示させない様にする為の工夫です。
(「終了」を押したのに終わらないとイラっとしますよね?)
それとボタン4の「初期化」ではアイテム数やイベントフラグ等の
ゲームに関するデータを消去する処理を組み込んでいます。
ポイントという程では無いですが、私の場合はここにパラメータを入れる事で、
利用中のパラメータ初期値を管理したり、パラメータの修正漏れが無い様に
チェックしたりしています。
■MainActivity.java(Javaファイル)
package com.hidefumi.kasahara.evel_slayer;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.Menu;
import android.view.View;
import android.view.Window;
public class MainActivity extends Activity {
private final int REQUEST_CODE = 111;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
}
//YesNoDialog実装
private void showYesNoDialog(MainActivity mainActivity, String title,
String text, DialogInterface.OnClickListener listener) {
AlertDialog.Builder ad=new AlertDialog.Builder(mainActivity);
ad.setTitle(title);
ad.setMessage(text);
ad.setPositiveButton("YES", listener);
ad.setNegativeButton("NO", listener);
ad.show();
}
//ShowDialog実装
private void showDialog(MainActivity mainActivity, String title,String text) {
AlertDialog.Builder ad=new AlertDialog.Builder(mainActivity);
ad.setTitle(title);
ad.setMessage(text);
ad.setPositiveButton("OK", null);
ad.show();
}
//「開始」コマンド実行処理
public void onClick1(View view){
Intent intent = new Intent(MainActivity.this, SubActivity.class);
startActivityForResult(intent, REQUEST_CODE);
}
//「説明」コマンド実行処理
public void onClick2(View view){
Intent intent = new Intent();
intent.setClassName("com.hidefumi.kasahara.evel_slayer", "com.hidefumi.kasahara.evel_slayer.HelpActivity");
startActivity(intent);
}
//「図鑑」コマンド実行処理
public void onClick3(View view){
Intent intent = new Intent();
intent.setClassName("com.hidefumi.kasahara.evel_slayer", "com.hidefumi.kasahara.evel_slayer.BookActivity");
startActivity(intent);
}
//「初期化」コマンド実行処理
public void onClick4(View view){
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
showYesNoDialog(this, "初期化", "これまでのデータを消去しますか?",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which==DialogInterface.BUTTON_POSITIVE){
showDialog(MainActivity.this,"初期化","データを初期化しました");
Editor editor = sharedPreferences.edit();
editor.putInt("EV_MAIN", 0);
editor.putInt("STAGE", 1);
editor.putInt("AREA", 1);
editor.putInt("MAJIN", 0);
editor.putInt("LV", 1);
editor.putInt("EXP", 0);
editor.putInt("HP", 20);
editor.putInt("MHP", 20);
editor.putInt("SP", 10);
editor.putInt("MSP", 10);
editor.putInt("ATK", 2);
editor.putInt("WEPON", 1);
editor.putInt("SKILL_LV", 1);
editor.putInt("SKILL_EXP", 0);
editor.putInt("DRAG", 3);
editor.putInt("STONE", 3);
editor.putInt("LIFE", 0);
editor.putInt("GOLD", 100);
editor.putInt("EXP", 0);
editor.putInt("SEL_FAM", 1);
editor.putInt("FMLA", 0);
editor.putInt("FAM01", 0);
editor.putInt("FAM02", 0);
editor.putInt("FAM03", 0);
editor.putInt("FAM04", 0);
editor.putInt("FAM05", 0);
editor.putInt("FAM06", 0);
editor.putInt("FAM07", 0);
editor.putInt("FAM08", 0);
editor.putInt("FAM09", 0);
editor.putInt("FAM10", 0);
editor.putInt("FAM11", 0);
editor.putInt("FAM12", 0);
editor.putInt("FAM13", 0);
editor.putInt("FAM14", 0);
editor.putInt("FAM15", 0);
editor.putInt("FAM16", 0);
editor.putInt("FAM17", 0);
editor.putInt("FAM18", 0);
editor.putInt("SKILL_LV_MOB01", 1);
editor.putInt("SKILL_LV_MOB02", 1);
editor.putInt("SKILL_LV_MOB03", 1);
editor.putInt("SKILL_LV_MOB04", 1);
editor.putInt("SKILL_LV_MOB05", 1);
editor.putInt("SKILL_LV_MOB06", 1);
editor.putInt("SKILL_LV_MOB07", 1);
editor.putInt("SKILL_LV_MOB08", 1);
editor.putInt("SKILL_LV_MOB09", 1);
editor.putInt("SKILL_LV_MOB10", 1);
editor.putInt("SKILL_LV_MOB11", 1);
editor.putInt("SKILL_LV_MOB12", 1);
editor.putInt("SKILL_LV_MOB13", 1);
editor.putInt("SKILL_LV_MOB14", 1);
editor.putInt("SKILL_LV_MOB15", 1);
editor.putInt("SKILL_LV_MOB16", 1);
editor.putInt("SKILL_LV_MOB17", 1);
editor.putInt("SKILL_LV_MOB18", 1);
editor.putInt("SKILL_EXP_MOB01", 0);
editor.putInt("SKILL_EXP_MOB02", 0);
editor.putInt("SKILL_EXP_MOB03", 0);
editor.putInt("SKILL_EXP_MOB04", 0);
editor.putInt("SKILL_EXP_MOB05", 0);
editor.putInt("SKILL_EXP_MOB06", 0);
editor.putInt("SKILL_EXP_MOB07", 0);
editor.putInt("SKILL_EXP_MOB08", 0);
editor.putInt("SKILL_EXP_MOB09", 0);
editor.putInt("SKILL_EXP_MOB10", 0);
editor.putInt("SKILL_EXP_MOB11", 0);
editor.putInt("SKILL_EXP_MOB12", 0);
editor.putInt("SKILL_EXP_MOB13", 0);
editor.putInt("SKILL_EXP_MOB14", 0);
editor.putInt("SKILL_EXP_MOB15", 0);
editor.putInt("SKILL_EXP_MOB16", 0);
editor.putInt("SKILL_EXP_MOB17", 0);
editor.putInt("SKILL_EXP_MOB18", 0); editor.commit();
} else if (which==DialogInterface.BUTTON_NEGATIVE){
showDialog(MainActivity.this,"初期化","初期化をキャンセルしました");
}
}
}
);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
finish();
}
}
■イビル・スレイヤー
https://play.google.com/store/apps/details?id=com.hidefumi.kasahara.evel_slayer