android源码连连看

时间:2018-09-13 14:36:34
【文件属性】:

文件名称:android源码连连看

文件大小:2.02MB

文件格式:ZIP

更新时间:2018-09-13 14:36:34

link

private void init() { config=new GameConf(8, 9, 1, 10, 100000, this); gameView=(GameView) findViewById(R.id.gameview); timeTextView=(TextView) findViewById(R.id.timeText); startButton=(Button) findViewById(R.id.startButton); dis=soundPool.load(this, R.raw.dis, 1); gameSrvice=new GameServiceImpl(config); gameView.setGameSrvice(gameSrvice); startButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { gameView.startGame(); } }); gameView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if(isPlaying) { return false; } if(event.getAction()==MotionEvent.ACTION_DOWN) { gameViewTouchDown(event); } if(event.getAction()==MotionEvent.ACTION_UP) { gameViewTouchUp(event); } return true; } }); loseDialog=new AlertDialog.Builder(this); loseDialog.setTitle("Lost"); loseDialog.setMessage("游戏失败了"); loseDialog.setIcon(R.drawable.lost); loseDialog.setPositiveButton("确定", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startGame(config.ENDTIME); } }); sucessDialog=new AlertDialog.Builder(this); sucessDialog.setTitle("Sucess"); sucessDialog.setMessage("游戏成功了"); sucessDialog.setIcon(R.drawable.success); sucessDialog.setPositiveButton("确定", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startGame(config.ENDTIME); } }); } @Override protected void onPause() { stopTimer(); super.onPause(); } @Override protected void onResume() { // TODO Auto-generated method stub if(isPlaying) { startGame(gameTime); } super.onResume(); } private void stopTimer() { timer.cancel();timer=null; } private void startGame(int endtime) { if(this.timer!=null) { stopTimer(); } gameTime=endtime; if(gameTime==GameConf.ENDTIME) { gameView.startGame(); } isPlaying=true; timer=new Timer(); timer.schedule(new TimerTask() { @Override public void run() { handler.sendEmptyMessage(0x123); } }, 1000); selected=null; } private void gameViewTouchUp(MotionEvent event) { } private void gameViewTouchDown(MotionEvent event) { Piece [][] pieces=gameSrvice.getPiece(); float x=event.getX(); float y=event.getY(); Piece piece=gameSrvice.findPiece(x, y); if(piece==null) { return; } gameView.setSelectedPiece(piece); if(selected==null) { selected=piece; gameView.postInvalidate(); return; } else { LinkInfo linkInfo=gameSrvice.link(selected, piece); if(linkInfo==null) { selected=piece; gameView.postInvalidate(); } else { gameView.setLinkInfo(linkInfo); gameView.setSelectedPiece(null); gameView.postInvalidate(); pieces[piece.getIndexX()][piece.getIndexY()]=null; pieces[selected.getIndexX()][selected.getIndexY()]=null; this.selected=null; soundPool.play(dis,1, 1, 0, 0, 1); if(!gameSrvice.hasPiece()) { sucessDialog.show(); stopTimer();isPlaying=false; } } } }


网友评论