I also want to develop the configuration interface design of 2048.

Source: Internet
Author: User

Of course, our program is not as rigid as the 2048 on the market now. We have a 4x4 Panel for a lifetime. Now, people pay attention to what they want, and everything is under my control.

Therefore, our program must have a configuration interface, which is an international convention ,:



This configuration interface mainly provides the following functions:

1. You can configure the dimension of the game panel, that is, 4X4, 5X5, 6X6. In fact, it is okay to continue writing, but the desire must be limited. It is almost enough.

2. If you want to achieve the goal, you can choose 1024 to enjoy it, or 2048 to be good, or 4096 to be good. In fact, you can keep writing about it. Old rules, don't put yourself too tight, it's almost enough. Why abuse yourself?

3. Contact Me to advertise my blog

The configuration function is basically written to SharedPreferences. This is not detailed because many users use it.

The following is the source code:

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;}    }}

Above

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.