我也來開發2048之配置介面設計

來源:互聯網
上載者:User

我們的程式當然不像現在市面上的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() {@Overridepublic 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() {@Overridepublic 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;}    }}

以上

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.