《连连看的详细设计文档》由会员分享,可在线阅读,更多相关《连连看的详细设计文档(23页珍藏版)》请在金锄头文库上搜索。
1、主要功能实现伪代码1、1OnePieceGame 类的伪代码连连看的主要实现过程public class OnePieceGame extends Activity /* Called when the activity is first created. */private ProgressBar pb;private TextView show_RemainTime;private CtrlView cv;public static final int START_ID = Menu.FIRST;public static final int REARRARY_ID = Menu.FIRS
2、T + 1;public static final int END_ID = REARRARY_ID + 1;private int dormant = 1000;private boolean isCancel=true;Overridepublic void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.main);findViews();mRedrawHandler.sleep(dormant);private RefreshHandler mR
3、edrawHandler = new RefreshHandler();class RefreshHandler extends Handler Overridepublic void handleMessage(Message msg) if(isCancel)run();elsepublic void sleep(long delayMillis) this.removeMessages(0);/ 移除信息队列中最顶部的信息(从顶部取出信息)sendMessageDelayed(obtainMessage(0), delayMillis);/ 获得顶部信息并延时发送;public void
4、 run() if (cv.PROCESS_VALUE 0 & cv.much != 0) cv.PROCESS_VALUE-;pb.setProgress(cv.PROCESS_VALUE);show_RemainTime.setText(String.valueOf(cv.PROCESS_VALUE);mRedrawHandler.sleep(dormant); else if (cv.PROCESS_VALUE = 0 & cv.much != 0) cv.setEnabled(false);dialogForFail().show(); else if (cv.PROCESS_VALU
5、E != 0 & cv.much = 0) cv.setEnabled(false);dialogForSucceed().show();private void findViews() pb = (ProgressBar) findViewById(R.id.pb);show_RemainTime = (TextView) findViewById(R.id.show_remainTime);cv = (CtrlView) findViewById(R.id.cv);pb.setMax(cv.GAMETIME);pb.incrementProgressBy(-1);pb.setProgres
6、s(cv.PROCESS_VALUE);Overridepublic boolean onCreateOptionsMenu(Menu menu) / TODO Auto-generated method stubmenu.add(0, START_ID, 0, R.string.newgame);menu.add(0, REARRARY_ID, 0, R.string.rearrage);return super.onCreateOptionsMenu(menu);Overridepublic boolean onOptionsItemSelected(MenuItem item) swit
7、ch (item.getItemId() case START_ID:newPlay();break;case REARRARY_ID:cv.rearrange();cv.PROCESS_VALUE = cv.PROCESS_VALUE - 5;pb.setProgress(cv.PROCESS_VALUE);break;default:break;return super.onOptionsItemSelected(item);Overrideprotected void onStop() isCancel=false;pb = null;cv = null;super.onStop();O
8、verrideprotected void onDestroy()isCancel=false;super.onDestroy();Overrideprotected void onStart()isCancel=false;newPlay();isCancel=true;super.onStart();/ Override/ protected void onRestart()/ cv.reset();/ super.onRestart();/ /public void newPlay() cv.reset();pb.setProgress(cv.GAMETIME);cv.PROCESS_V
9、ALUE = cv.GAMETIME;mRedrawHandler.sleep(dormant);cv.setEnabled(true);public AlertDialog dialogForSucceed() AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setIcon(R.drawable.icon).setMessage(R.string.succeedInfo).setPositiveButton(R.string.next,new DialogInterface.OnClickListener
10、() public void onClick(DialogInterface dialog,int which) / TODO Auto-generated method stubdormant = dormant - 300;newPlay();).setNeutralButton(R.string.again_challenge,new DialogInterface.OnClickListener() public void onClick(DialogInterface dialog,int which) / TODO Auto-generated method stubnewPlay
11、(););return builder.create();public AlertDialog dialogForFail() AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setIcon(R.drawable.icon).setMessage(R.string.failInfo).setPositiveButton(R.string.again_challenge,new DialogInterface.OnClickListener() public void onClick(DialogInterf
12、ace dialog,int which) / TODO Auto-generated method stubnewPlay();).setNegativeButton(R.string.exit,new DialogInterface.OnClickListener() public void onClick(DialogInterface dialog,int which) / TODO Auto-generated method stubisCancel=false;finish(););return builder.create();主要功能实现伪代码2、1 CtrlView 类的伪代
13、码主要实现连连看的具体算法。public class CtrlView extends GameView /通过extends 另外一个接口(gameView)来添加方法public final int GAMETIME = 300;/final:只占有一份不可改变的存储空间。public final int UPTIME = 1;public int PROCESS_VALUE = 300;public static boolean CURRENT_CH = false;/static:boolean型值不可改变current:接口public int CURRENT_TYPE = 0;pr
14、ivate Point C_POINT;private Point P_POINT;LinkedList li;public CtrlView(Context context, AttributeSet attrs) super(context, attrs);initType();initGrid();much = (row - 2) * (col - 2);public CtrlView(Context context, AttributeSet attrs, int defStyle) super(context, attrs, defStyle);initType();initGrid
15、();much = (row - 2) * (col - 2);public boolean onTouchEvent(MotionEvent event) if (event.getAction() != MotionEvent.ACTION_DOWN)return super.onTouchEvent(event);int selX = (int) (event.getX() / width);int selY = (int) (event.getY() / height);if (gridselXselY = 0)return true;else if (CURRENT_CH = fal
16、se) select(selX, selY);CURRENT_CH = true;P_POINT = new Point(selX, selY); else C_POINT = new Point(selX, selY);lineType = 0;if (checkLink(P_POINT, C_POINT) isLine = true;much = much - 2;if (0 temp = new ArrayList();for (int i = 0; i scan(Point a, Point b) li = new LinkedList();/保存求解后的线/从a,c连线向b扫描,扫描竖线/扫描A点左边的所有线for (int y = a.y; y = 0; y-)if (grida.x