我们的程序当然不像现在市面上的2048那样死板,一辈子4X4的面板,现在的人,讲究的就是随心所欲,所有的东西都在我的掌控中,这才爽。
所以我们的程序也得有个配置界面,国际惯例,上图:
这个配置界面主要完成以下几个功能:
1、可配置游戏面板的维数,即4X4,5X5,6X6,其实继续写下去也是可以的,但是,欲望也是要有限度的啊,差不多就够了
2、要达到的目标,你可以选择到1024就爽了呢,还是2048才爽,还是4096才爽,其实也是可以一直写下去的,老规矩,不要把自己逼的太紧了,差不多就行了,虐自己何必呢
3、Contact Me,给我的博客打个广告啦
配置功能,基本写入SharedPreferences,这个因为大家使用都比较多了,就不详细说了
下面是源码:
package com.xys.game2048.activity;import com.xys.game2048.R;import com.xys.game2048.config.Config;import androID.app.Activity;import androID.app.AlertDialog;import androID.content.DialogInterface;import androID.content.SharedPreferences;import androID.content.SharedPreferences.Editor;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.vIEw.VIEw.OnClickListener;import androID.Widget.button;public class ConfigPreference extends Activity implements OnClickListener { private button btnGamelines; private button btnGoal; private button btnBack; private button btnDone; private String[] gamelinesList; private String[] gameGoalList; private AlertDialog.Builder builder; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.config_preference); initVIEw(); } private voID initVIEw() { btnGamelines = (button) findVIEwByID(R.ID.btn_gamelines); btnGoal = (button) findVIEwByID(R.ID.btn_goal); btnBack = (button) findVIEwByID(R.ID.btn_back); btnDone = (button) findVIEwByID(R.ID.btn_done); btnGamelines.setText("" + Config.sp.getInt(Config.KEY_Gamelines, 4)); btnGoal.setText("" + Config.sp.getInt(Config.KEY_GameGoal, 2048)); btnGamelines.setonClickListener(this); btnGoal.setonClickListener(this); btnBack.setonClickListener(this); btnDone.setonClickListener(this); gamelinesList = new String[] { "4", "5", "6" }; gameGoalList = new String[] { "1024", "2048", "4096" }; } private voID saveConfig() { Editor editor = Config.sp.edit(); editor.putInt(Config.KEY_Gamelines, Integer.parseInt(btnGamelines.getText().toString())); editor.putInt(Config.KEY_GameGoal, Integer.parseInt(btnGoal.getText().toString())); editor.commit(); } @OverrIDe public voID onClick(VIEw v) { switch (v.getID()) { case R.ID.btn_gamelines: builder = new AlertDialog.Builder(this); builder.setTitle("choose the lines of the game"); builder.setItems(gamelinesList, new DialogInterface.OnClickListener() { @OverrIDe public voID onClick(DialogInterface dialog, int which) { btnGamelines.setText(gamelinesList[which]); } }); builder.create().show(); break; case R.ID.btn_goal: builder = new AlertDialog.Builder(this); builder.setTitle("choose the goal of the game"); builder.setItems(gameGoalList, new DialogInterface.OnClickListener() { @OverrIDe public voID onClick(DialogInterface dialog, int which) { btnGoal.setText(gameGoalList[which]); } }); builder.create().show(); break; case R.ID.btn_back: this.finish(); break; case R.ID.btn_done: saveConfig(); setResult(RESulT_OK); this.finish(); break; default: break; } }}
以上 总结
以上是内存溢出为你收集整理的我也来开发2048之配置界面设计全部内容,希望文章能够帮你解决我也来开发2048之配置界面设计所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)