1、运行出来效果如下:MainActivity:package games.llk;import android.app.Activity;import android.os.Bundle;public class Main extends Activity /* Called when the activity is first created. */ Override public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); /setContentView(R.layout.main)
2、; setContentView(new GameView(this); GameView:package games.llk;import java.util.Random;import android.content.Context;import android.content.res.Resources;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Paint;import android
3、.graphics.Point;import android.graphics.Rect;import android.graphics.Bitmap.Config;import android.os.Handler;import android.view.MotionEvent;import android.view.View;public class GameView extends View private int m_w;private int m_h;private int top_client;private int right_client;private int bottom_
4、client;private int left_client;private Rect client_r;private Paint p_client_r;private boolean display_moreInfo;private boolean isInited;private Paint p;private Paint p_line;private Paint p_line_2;private Paint p_text;private Paint p_pross_b;private Paint p_pross;private int point_w;private int point
5、_h;private Rect btn_r_1;private Rect btn_r_2;private Rect btn_r_close;private Bitmap bmp_btn;private Rect pross_r;private Rect pross_r_2;private Rect t_r;private Rect t_r_2;private boolean ispause=false;private boolean isstart=false;private String s_pause=暂停中。;private Bitmap buff;private Bitmap bmp_
6、point;private Bitmap bmp_hint;private Canvas buff_Canvas;private int flevel ;private int ffen =0;private int timecount=0;private int timecountper_l = 480;private boolean isdrawing=false ;private Random random=new Random();private Resources res;private Point pointlist_tmp ;private int pointlist_tmp_c
7、ount=0;private RefreshHandler mRedrawHandler = new RefreshHandler();private Point mousept ;private Point lastpt ;private Point hintpt_1 ;private Point hintpt_2 ;private boolean isontimering=false;private boolean isonmousedown=false;private int ontimercount=0;class RefreshHandler extends Handler Over
8、ridepublic void handleMessage(android.os.Message msg)GameView.this.ontimer(); nexttimer(240);public void nexttimer( long delayMillis) this.removeMessages(0);sendMessageDelayed(obtainMessage(0), delayMillis);private Pointlist fpointlist =new Pointlist();class Pointlistprivate int fxcount;private int
9、fycount;private int l1;private int l2;private PointData fpointreclist;class PointDatapublic int x;public int y;public boolean value;public Object data;public Rect rect;public int stat;public int imgidx;private Point plist_1;private int plist_1_len;private Point plist_2;private int plist_2_len;privat
10、e Point pathlist;public int pcount =0;public void init(int xcount, int ycount)fxcount=xcount;fycount=ycount;fpointreclist=new PointDatafxcount+2fycount+2;for (int x_i = 0; x_i fpointreclist.length; x_i+)for (int y_i = 0; y_i fpointreclistx_i.length; y_i+)fpointreclistx_iy_i=new PointData();fpointrec
11、listx_iy_i.x=x_i;fpointreclistx_iy_i.y=y_i;fpointreclistx_iy_i.value=false;fpointreclistx_iy_i.data=null;fpointreclistx_iy_i.rect=new Rect(0,0,0,0);fpointreclistx_iy_i.stat=-1;fpointreclistx_iy_i.imgidx=-1;plist_1=new Point(fxcount+fycount+2)*4;for (int i = 0; i plist_1.length; i+)plist_1i=new Point
12、(0,0);plist_1_len=0;plist_2=new Point(fxcount+fycount+2)*4;for (int i = 0; i plist_2.length; i+)plist_2i=new Point(0,0);plist_2_len=0;pathlist=new Point2;for (int i = 0; i pathlist.length; i+)pathlisti=new Point(0,0);l1=new intfxcount*2;l2=new intfxcount*2;public void setValue(int x,int y,Boolean va
13、lue) fpointreclistxy.value = value;public boolean getValue(int x,int y)return fpointreclistxy.value ;public void setData(int x,int y,Object data) fpointreclistxy.data = data;public void setrect(int x,int y,Rect r) fpointreclistxy.rect.left = r.left; fpointreclistxy.rect.top = r.top; fpointreclistxy.
14、rect.right = r.right; fpointreclistxy.rect.bottom = r.bottom; public Rect getrect(int x,int y) return fpointreclistxy.rect;public void setstat(int x,int y,int v) fpointreclistxy.stat=v;public int getstat(int x,int y)return fpointreclistxy.stat;public void setimgidx(int x,int y,int v) fpointreclistxy
15、.imgidx=v;public int getimgidx(int x,int y)return fpointreclistxy.imgidx;public boolean checkpp(Point p1,Point p2)boolean result=false; if (p1.x = p2.x) & (p1.y = p2.y) return true; if (p1.y = p2.y) int x1 = p1.x p2.x?p1.x:p2.x; for (int i=x1+1 ;i=x2-1;i+) if (fpointreclistip1.y.value ) return false
16、; result = true; if (p1.x = p2.x) int y1 = p1.y p2.y?p1.y:p2.y; for (int i=y1+1 ;i=y2-1;i+) if (fpointreclistp1.xi.value ) return false; result = true; return result;public void mousetoxy(int x,int y ,Point pt)for (int x_i = 1; x_i = fxcount; x_i+)for (int y_i = 1; y_i = fycount; y_i+)if (fpointrecl
17、istx_iy_i.rect.contains(x,y)pt.x=x_i;pt.y=y_i;return;pt.x=-1;pt.y=-1;public boolean isallok()for (int x_i = 1; x_i = fxcount; x_i+)for (int y_i = 1; y_i =0)return false;return true;public void changeplace(int v)int idx=0;if ( (v = 2)| (v = 6) for (int i = 1 ;i=fxcount;i+ ) idx = 0; for (int j = 1 ;j
18、= 0 ) idx=idx+1; l1idx = getimgidx(i, j); l2idx = getstat(i, j); for (int j = 1 ;j idx) setimgidx(i, j, -1); setstat(i, j, -1); setValue(i, j, false); else setimgidx(i, j, l1j); setstat(i, j, l2j); setValue(i, j, true); if ( (v = 3)| (v = 7) for (int i = 1 ;i=1 ;j-) if (getstat(i, j) = 0 ) idx=idx-1
19、; l1idx = getimgidx(i, j); l2idx = getstat(i, j); for (int j = fycount ;j=1;j-) if (j idx) setimgidx(i, j, -1); setstat(i, j, -1); setValue(i, j, false); else setimgidx(i, j, l1j); setstat(i, j, l2j); setValue(i, j, true); if( (v = 4)| (v = 8) for (int j = 1 ;j= fycount ;j+) idx = 0; for (int i = 1
20、;i= 0 ) idx=idx+1; l1idx = getimgidx(i, j); l2idx = getstat(i, j); for (int i = 1 ;i idx) setimgidx(i, j, -1); setstat(i, j, -1); setValue(i, j, false); else setimgidx(i, j, l1i); setstat(i, j, l2i); setValue(i, j, true); if ( (v = 5)| (v = 9) for (int j = 1 ;j=1;i- ) if (getstat(i, j) = 0 ) idx=idx
21、-1; l1idx = getimgidx(i, j); l2idx = getstat(i, j); for (int i = fxcount ;i=1;i- ) if (i idx) setimgidx(i, j, -1); setstat(i, j, -1); setValue(i, j, false); else setimgidx(i, j, l1i); setstat(i, j, l2i); setValue(i, j, true); public void findstat(int v ,Point pt)for (int x_i = 0; x_i fpointreclist.l
22、ength; x_i+)for (int y_i = 0; y_i =0;i-) x = x1;y = i;if (fpointreclistxy.value)break; else plist_1plist_1_len.x = x; plist_1plist_1_len.y = y; plist_1_len=plist_1_len+1; for (int i = y1 + 1;i=0;i-) x = i; y = y1; if (fpointreclistxy.value ) break; else plist_1plist_1_len.x = x; plist_1plist_1_len.y
23、 = y; plist_1_len=plist_1_len+1; for (int i = x1 + 1 ;i= 0;i- ) x = x2; y = i; if (fpointreclistxy.value ) break; else plist_2plist_2_len.x = x; plist_2plist_2_len.y = y; plist_2_len=plist_2_len+1; for( int i = y2 + 1 ;i= 0 ;i-) x = i; y = y2; if (fpointreclistxy.value ) break; else plist_2plist_2_l
24、en.x = x; plist_2plist_2_len.y = y; plist_2_len=plist_2_len+1; for (int i = x2 + 1 ;i= fxcount + 1;i+) x = i; y = y2; if (fpointreclistxy.value) break; else plist_2plist_2_len.x = x; plist_2plist_2_len.y = y; plist_2_len=plist_2_len+1; pcount = 0; for (int i = 0 ;i plist_1_len;i+) for (int j = 0 ;j 0) pathlistpcount.x = plist_1i.x; pathlistpcount.y = plist_1i.y; pcount=pcount+1; if (j 0)