(里面有六张绿豆蛙的图片)

1、选中会有红色框

2、可以直线连(横竖相邻或是横竖间隔空格)

3、可以拐一次弯连接

4、可以拐两次弯连接

5、连接时会有线显示

6、绿色代表进度条,蓝色代表时间条

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory; public class Getpic {
public static Bitmap createBitmap(Context context,int resId){
Bitmap map = BitmapFactory.decodeResource(context.getResources(),resId);
return map;
}
}
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.Window;
import android.view.WindowManager; public class MainActivity extends Activity { private Wall pic;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//全屏显示
super.onCreate(savedInstanceState);
int width =getWindowManager().getDefaultDisplay().getWidth();//获得屏幕宽度
int height = getWindowManager().getDefaultDisplay().getHeight();//获得屏幕高度
pic = new Wall(this,width,height);
setContentView(pic);
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }
import java.util.Random;

import android.R.integer;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.text.format.Time;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnTouchListener; public class Wall extends SurfaceView implements Callback,OnTouchListener{ private Context context;
private SurfaceHolder holder;
private int screenw;//传递屏幕宽度
private int screenh;//传递屏幕高度
private static int HH = 40;//获得pic的高度,设置为全局变量
private static int WW = 40;//获得pic的宽度,设置为全局变量
private static int Xroad = 0;//X轴的格数
private static int Yroad = 0;//Y轴的格数
private static int score = 0;//总分数
private static int[][] ranpoint;//坐标数组
private static int psy1 = 0;
private static int psy2 = 0;
private static int psy3 = 0;
private static int psy4 = 0;
private static int psy5 = 0;
private static int psy6 = 0;
private static int[] hoo=new int [6];
private static int mm=0;
private static int lastpointx = 0;//上一次点击的x坐标,初始化为0
private static int lastpointy = 0;//上一次点击的y坐标,初始化为0
private static int nowpointx = 0;//当前点击的x坐标,初始化为0
private static int nowpointy = 0;//当前点击的y坐标,初始化为0
private static long sleeptime = 10;
private static float inch = 0;//进度条的单位进度/减度
private static float bbc = 0;//时间条的单位进度/减度
private static long btime = 0;//时间条的初始时间
private static long ctime = 0;//进度条的当前时间
private static int [][] app = new int[2][2];
private static int [][] corner = new int[2][2];
public Wall(Context context,int screenwidth,int screenheight) {
super(context);
this.context = context;
this.screenh = screenheight;
this.screenw = screenwidth;
holder = this.getHolder();
holder.addCallback(this);
setOnTouchListener(this);
getset();//获取高、宽、进度单位等
setzero();//直接初始化二位数组ranpoint[][]为0
setcountzero();//直接初始化一维数组hoo[]为0
setpoint();//随即产生成双数的图案
checknum();//检查实际图案的分配
}
private void draw(){//绘制初始化
Canvas canvas = holder.lockCanvas();
drawline(canvas);//绘制网格线
// drawgrid(canvas);//绘制分割线
drawpic(canvas);//绘制图片
Log.i("state","nowpointx:"+nowpointx+"nowpointy:"+nowpointy);
drawtime(canvas);
drawsquare(canvas, nowpointx, nowpointy);
if(nearline(canvas)){//相邻图像一致判断
ranpoint[nowpointx][nowpointy]=0;
ranpoint[lastpointx][lastpointy]=0;
lastpointx = 0;
lastpointy = 0;
nowpointx = 0;
nowpointy = 0;
score++;
}else if(nearnotline(canvas)){//空格图像一致判断
ranpoint[nowpointx][nowpointy]=0;
ranpoint[lastpointx][lastpointy]=0;
lastpointx = 0;
lastpointy = 0;
nowpointx = 0;
nowpointy = 0;
score++;
}else if(besure()){//两次转角
drawtwocorner(canvas);//绘制两次转角线
ranpoint[nowpointx][nowpointy]=0;
ranpoint[lastpointx][lastpointy]=0;
lastpointx = 0;
lastpointy = 0;
nowpointx = 0;
nowpointy = 0;
score++;
}
drawgrid(canvas);//绘制分割线、文字、分数
// try {
// Thread.sleep(sleeptime);
// } catch (Exception e) {
// // TODO: handle exception
// }
// nearby(canvas);
// blanketjudge(canvas);
// drawsquare(canvas,3,4);
// Bitmap map1 = Getpic.createBitmap(context, R.drawable.pic1);
// canvas.drawBitmap(map1, 1*WW, 1*HH, null);
holder.unlockCanvasAndPost(canvas);
}
// public void drawonce(){
// Canvas canvas = holder.lockCanvas();
// drawline(canvas);//绘制网格线
//// drawgrid(canvas);//绘制分割线
// drawpic(canvas);//绘制图片
// holder.unlockCanvasAndPost(canvas);
// }
public void drawline(Canvas canvas){
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(Color.GREEN);
canvas.drawColor(Color.WHITE);
for(int x=0;x<=Xroad-2;x++){//绘制纵轴线
canvas.drawLine(x*WW, 0, x*WW, (Yroad-2)*HH, paint);
}
for(int y=0;y<=Yroad-2;y++){//绘制横轴线
canvas.drawLine(0, y*HH, (Xroad-2)*WW, y*HH, paint);
}
}
public void getset(){//获得图片的高和宽
Bitmap standard = Getpic.createBitmap(context, R.drawable.pic1);
WW = standard.getWidth();
HH = standard.getHeight();
Log.i("Widthstandard", "标准pic宽度"+WW);
Log.i("Heightstandard", "标准pic高度"+HH);
Xroad = screenw/WW;
Yroad = screenh/HH;
Log.i("Width", "宽度格数"+(Xroad-2));
Log.i("Height", "高度格数"+(Yroad-2));
ranpoint = new int[Xroad-2][Yroad-2];
// inch = (Yroad-2)*HH/(((Xroad-2)*(Yroad-2))/2);
inch = HH*2/(Xroad-2);//化简后
btime = java.lang.System.currentTimeMillis();
bbc = (Yroad-2)*HH/600;
}
public void drawsquare(Canvas canvas,int x,int y){//绘制点击正方形
super.onDraw(canvas);
Paint paintline = new Paint();
paintline.setColor(Color.RED);
paintline.setTextSize(550);
if(x<Xroad-2&&y<Yroad-2){
canvas.drawLine(x*WW, y*HH, (x+1)*WW, y*HH, paintline);//上横线
canvas.drawLine(x*WW, (y+1)*HH, (x+1)*WW, (y+1)*HH, paintline);//下横线
canvas.drawLine(x*WW, y*HH, x*WW, (y+1)*HH, paintline);//左竖线
canvas.drawLine((x+1)*WW, y*HH, (x+1)*WW, (y+1)*HH, paintline);//右竖线
}
}
public void drawgrid(Canvas canvas){//绘制网格标识
super.onDraw(canvas);
Paint paintline = new Paint();
paintline.setColor(Color.GRAY);
paintline.setTextSize(80);
Paint paint = new Paint();
paint.setColor(Color.RED);
paint.setTextSize(30);
canvas.drawLine((Xroad-2)*WW, (Yroad-2)*HH, screenw, (Yroad-2)*HH, paintline);//剩余区间分块划线之横轴
canvas.drawLine((Xroad-2)*WW, (Yroad-2)*HH, (Xroad-2)*WW, screenh, paintline);//剩余区间分块划线之纵轴
canvas.drawText("网格", (Xroad-2)*WW,(Yroad-2)*HH+30, paint);//确定绘制网格标识位置
canvas.drawText("绿豆蛙版连连看", 0,(Yroad-2)*HH+30, paint);//确定绘制标题位置
canvas.drawText((Xroad-2)+"x"+(Yroad-2), (Xroad-2)*WW,(Yroad-2)*HH+70, paint);//确定绘制网格标识位置
canvas.drawText("最后得分:"+score, 0,(Yroad-2)*HH+70, paint);//确定绘制分数
}
public void drawtime(Canvas canvas){//绘制进度条和时间条
super.onDraw(canvas);
Paint paint = new Paint();
// paint.setStyle(Style.FILL);
paint.setStyle(Style.STROKE);
paint.setColor(Color.BLACK);
paint.setTextSize(100);
canvas.drawRect((Xroad-2)*WW, 0, (Xroad-1)*WW, (Yroad-2)*HH, paint);//绘制进度条外框
canvas.drawRect((Xroad-1)*WW+10, 0, screenw, (Yroad-2)*HH, paint);//绘制时间条外框
Paint paintin = new Paint();
paintin.setStyle(Style.FILL);
paintin.setColor(Color.GREEN);
canvas.drawRect((Xroad-2)*WW, score*inch, (Xroad-1)*WW, (Yroad-2)*HH, paintin);//绘制进度条外框
Paint paintti = new Paint();
paintti.setStyle(Style.FILL);
paintti.setColor(Color.BLUE);
ctime = java.lang.System.currentTimeMillis();
long abb = (ctime-btime)/1000;
canvas.drawRect((Xroad-1)*WW+10, (Yroad-2)*HH-abb*bbc, screenw, (Yroad-2)*HH, paintti);//绘制时间条外框
}
public void setzero(){//二位数组初始化为0
for(int i=0;i<ranpoint.length;i++){
for(int j=0;j<ranpoint[0].length;j++){
ranpoint[i][j]=0;
}
}
}
public void setcountzero(){//一维数组初始化为0
for(int i=0;i<hoo.length;i++){
hoo[i]=0;
}
}
public boolean nearline(Canvas canvas){//相邻的两个图案是一样的
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(550);
//当前点击图片在上一次点击的上面/下面
if(ranpoint[nowpointx][nowpointy]==ranpoint[lastpointx][lastpointy]&&ranpoint[nowpointx][nowpointy]!=0&&lastpointx==nowpointx&&Math.abs(lastpointy-nowpointy)>=1){
// ranpoint[nowpointx][nowpointy]=0;
// ranpoint[lastpointx][lastpointy]=0;
if(judgezeroy(nowpointx, lastpointy, nowpointy)){
canvas.drawLine(lastpointx*WW+WW/2, lastpointy*HH+HH/2, nowpointx*WW+WW/2, nowpointy*HH+HH/2, paint);
return true;
}
}
//当前点击图片在上一次点击的左面/右面
if(ranpoint[nowpointx][nowpointy]==ranpoint[lastpointx][lastpointy]&&ranpoint[nowpointx][nowpointy]!=0&&lastpointy==nowpointy&&Math.abs(lastpointx-nowpointx)>=1){
// ranpoint[nowpointx][nowpointy]=0;
// ranpoint[lastpointx][lastpointy]=0;
if(judgezerox(lastpointx, nowpointx, nowpointy)){
canvas.drawLine(lastpointx*WW+WW/2, lastpointy*HH+HH/2, nowpointx*WW+WW/2, nowpointy*HH+HH/2, paint);
return true;
}
}
// try {
// Thread.sleep(sleeptime);
// } catch (Exception e) {
// // TODO: handle exception
// }
// ranpoint[nowpointx][nowpointy]=0;
// ranpoint[lastpointx][lastpointy]=0;
return false;
}
public boolean nearnotline(Canvas canvas){//中间至少隔一个空格是一样的两个空格
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(550);
if (difpoint(lastpointx, nowpointx, lastpointy, nowpointy)) {
if(judgezerox(nowpointx, lastpointx,nowpointy)){
if(judgezeroy(lastpointx, nowpointy, lastpointy)&&ranpoint[lastpointx][nowpointy]==0&&ranpoint[nowpointx][nowpointy]==ranpoint[lastpointx][lastpointy]&&ranpoint[nowpointx][nowpointy]!=0){
canvas.drawLine(lastpointx*WW+WW/2, lastpointy*HH+HH/2, lastpointx*WW+WW/2, nowpointy*HH+HH/2, paint);
canvas.drawLine(lastpointx*WW+WW/2, nowpointy*HH+HH/2, nowpointx*WW+WW/2, nowpointy*HH+HH/2, paint);
// ranpoint[nowpointx][nowpointy]=0;
// ranpoint[lastpointx][lastpointy]=0;
return true;
}
}else if (judgezeroy(nowpointx, nowpointy, lastpointy)) {
if (judgezerox(nowpointx, lastpointx, lastpointy)&&ranpoint[nowpointx][lastpointy]==0&&ranpoint[nowpointx][nowpointy]==ranpoint[lastpointx][lastpointy]&&ranpoint[nowpointx][nowpointy]!=0) {
canvas.drawLine(lastpointx*WW+WW/2, lastpointy*HH+HH/2, nowpointx*WW+WW/2, lastpointy*HH+HH/2, paint);
canvas.drawLine(nowpointx*WW+WW/2, lastpointy*HH+HH/2, nowpointx*WW+WW/2, nowpointy*HH+HH/2, paint);
// ranpoint[nowpointx][nowpointy]=0;
// ranpoint[lastpointx][lastpointy]=0;
return true;
}
}
}
// try {
// Thread.sleep(sleeptime);
// } catch (Exception e) {
// // TODO: handle exception
// }
// ranpoint[nowpointx][nowpointy]=0;
// ranpoint[lastpointx][lastpointy]=0;
return false;
}
public boolean difpoint(int x1,int x2,int y1,int y2){
if(x1!=x2){
return true;
}else if (y1!=y2) {
return true;
}
return false;
}
public boolean judgezeroy(int x,int y1,int y2){//(x,y1)到(x,y2),竖直方向,中间有不为0的返回false,否者返回true
if(y1<y2){
for(int i=y1+1;i<y2;i++){
if(ranpoint[x][i]!=0){
Log.i("judgezeroy", "false");
return false;
}
}
}else if(y1>y2){
for(int i=y1-1;i>y2;i--){
if(ranpoint[x][i]!=0){
Log.i("judgezeroy", "false");
return false;
}
}
}
Log.i("judgezeroy", "true");
return true;
}
public boolean judgezerox(int x1,int x2,int y){//(x1,y)到(x2,y),横直方向,中间有不为0的返回false,否者返回true
if(x1<x2){
for(int i=x1+1;i<x2;i++){
if(ranpoint[i][y]!=0){
Log.i("judgezerox", "false");
return false;
}
}
}else if(x1>x2){
for(int i=x1-1;i>x2;i--){
if(ranpoint[i][y]!=0){
Log.i("judgezerox", "false");
return false;
}
}
}
Log.i("judgezerox", "true");
return true;
}
public int[][] selectpoint( int x1,int y1,int x2 ,int y2){//交换两个点的位置,左上右下原则
int amd[][] = new int [2][2];
if (x1<x2||y1<y2) {
amd[0][0]=x1;
amd[01][1]=y1;
amd[1][0]=x2;
amd[1][1]=y2;
}else if (x1>x2||y1>y2) {
amd[0][0]=x2;
amd[01][1]=y2;
amd[1][0]=x1;
amd[1][1]=y1;
}
return amd;
}
public boolean besure(){//判断两个乖点能否联通
// app = selectpoint(lastpointx, lastpointy, nowpointx, nowpointy);
// Log.i("交换两点位置", app[0][0]+" "+app[0][1]+" "+app[1][0]+" "+app[1][1]);
if (lastpointx==nowpointx&&lastpointy==nowpointy) {//两次的点位置一样则不记录
return false;
}
for (int i = 0; i < Xroad-2; i++) {//先判走断竖直方向
if (judgezeroy(i, lastpointy, nowpointy)) {//判断竖直方向有无通路
Log.i("竖直方向有无通路", "有");
if (judgezerox(i, lastpointx,lastpointy)&&judgezerox(i, nowpointx, nowpointy)&&ranpoint[lastpointx][lastpointy]==ranpoint[nowpointx][nowpointy]
&&ranpoint[i][lastpointy]==0&&ranpoint[i][nowpointy]==0) {//竖直前提下横向的通路
corner[0][0]=i;
corner[0][1]=lastpointy;
corner[1][0]=i;
corner[1][1]=nowpointy;
Log.i("竖直前提下横向的通路", "有");
return true;
}
}
}
for (int j = 0; j < Yroad-2; j++) {//先判断横直方向
if (judgezerox(lastpointx, nowpointx, j)) {//判断横直方向有无通路
Log.i("横直方向有无通路", "有");
if (judgezeroy(lastpointx, lastpointy, j)&&judgezeroy(nowpointx, nowpointy, j)&&ranpoint[lastpointx][lastpointy]==ranpoint[nowpointx][nowpointy]
&&ranpoint[lastpointx][j]==0&&ranpoint[nowpointx][j]==0) {//横向前提下的竖直通路
corner[0][0]=lastpointx;
corner[01][1]=j;
corner[1][0]=nowpointx;
corner[1][1]=j;
Log.i("横直前提下竖直方向有无通路", "有");
return true;
}
}
}
return false;
}
public void drawtwocorner(Canvas canvas){//绘制两个拐点的线路
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(550);
// int [][] pop1 = new int[2][2];
// int [][] pop2 = new int[2][2];
// int [][] pop3 = new int[2][2];
// pop1 = selectpoint(lastpointx, lastpointy, corner[0][0], corner[0][1]);
// pop2 = selectpoint(corner[0][0], corner[0][1], corner[1][0], corner[1][1]);
// pop3 = selectpoint(corner[1][0], corner[1][1], nowpointx, nowpointy);
// if (pop1[0][1]==pop1[1][1]) {
// canvas.drawLine(p, startY, stopX, stopY, paint)
// }
canvas.drawLine(lastpointx*WW+WW/2, lastpointy*HH+HH/2, corner[0][0]*WW+WW/2, corner[0][1]*HH+HH/2, paint);
canvas.drawLine(corner[0][0]*WW+WW/2, corner[0][1]*HH+HH/2, corner[1][0]*WW+WW/2, corner[1][1]*HH+HH/2, paint);
canvas.drawLine(corner[1][0]*WW+WW/2, corner[1][1]*HH+HH/2, nowpointx*WW+WW/2,nowpointy*HH+HH/2, paint);
}
public void setpoint(){//分配坐标
Random ranpic = new Random();
// Random ranx = new Random();
// Random rany = new Random();
// int x1,x2,y1,y2;
// do{
// int pic = ranpic.nextInt(6)+1;
// do{
// x1 = ranx.nextInt(10);
// y1 = rany.nextInt(18);
// }while(ranpoint[x1][y1]!=0);
// do{
// x2 = ranx.nextInt(10);
// y2 = rany.nextInt(18);
// }while(ranpoint[x2][y2]!=0);
// ranpoint[x1][y1]=pic;
// ranpoint[x2][y2]=pic;
// }while(getright(ranpoint));
for(int i=0;i<ranpoint.length;i++){
for(int j=0;j<ranpoint[0].length;j++){
int pic = ranpic.nextInt(6)+1;
switch (pic) {
case 1:
psy1++;
break;
case 2:
psy2++;
break;
case 3:
psy3++;
break;
case 4:
psy4++;
break;
case 5:
psy5++;
break;
default:
psy6++;
break;
}
ranpoint[i][j]=pic;
}
}
Log.i("初始分配", "psy1:"+psy1+"psy2:"+psy2+"psy3:"+psy3+"psy4:"+psy4+"psy5:"+psy5+"psy6:"+psy6);
sethoo();
smallchange();
// Log.i("调理后分配", "psy1:"+psy1+"psy2:"+psy2+"psy3:"+psy3+"psy4:"+psy4+"psy5:"+psy5+"psy6:"+psy6);
// for(int i=0;i<ranpoint.length;i++){
// for(int j=ranpoint[0].length/2;j<ranpoint[0].length;j++){
// do{
// int pic = ranpic.nextInt(6)+1;
// switch (pic) {
// case 1:
// if (psy1>0) {
// ranpoint[i][j]=pic;
// psy1--;
// }
// break;
// case 2:
// if (psy2>0) {
// ranpoint[i][j]=pic;
// psy2--;
// }
// break;
// case 3:
// if (psy3>0) {
// ranpoint[i][j]=pic;
// psy3--;
// }
// break;
// case 4:
// if (psy4>0) {
// ranpoint[i][j]=pic;
// psy4--;
// }
// break;
// case 5:
// if (psy5>0) {
// ranpoint[i][j]=pic;
// psy5--;
// }
// break;
// default:
// if (psy6>0) {
// ranpoint[i][j]=pic;
// psy6--;
// }
// break;
// }
// }while(ranpoint[i][j]>0);
// }
// }
// Log.i("YYY", "psy1:"+psy1+"psy2:"+psy2+"psy3:"+psy3+"psy4:"+psy4+"psy5:"+psy5+"psy6:"+psy6);
}
public void sethoo(){//配置hoo[]数组
if(psy1%2==1){
hoo[mm]=1;
Log.i("hoo["+mm+"]有记录", ""+hoo[mm]);
mm++;
}
if(psy2%2==1){
hoo[mm]=2;
Log.i("hoo["+mm+"]有记录", ""+hoo[mm]);
mm++;
}
if(psy3%2==1){
hoo[mm]=3;
Log.i("hoo["+mm+"]有记录", ""+hoo[mm]);
mm++;
}
if(psy4%2==1){
hoo[mm]=4;
Log.i("hoo["+mm+"]有记录", ""+hoo[mm]);
mm++;
}
if(psy5%2==1){
hoo[mm]=5;
Log.i("hoo["+mm+"]有记录", ""+hoo[mm]);
mm++;
}
if(psy6%2==1){
hoo[mm]=6;
Log.i("hoo["+mm+"]有记录", ""+hoo[mm]);
mm++;
}
Log.i("hoo[]数组有数字的个数", ""+mm);
}
public void smallchange(){//调整数组,使得几个图案的个数成偶数个出现
for (int i = -1; i < mm;) {
// for (int i = -1; i < mm;i+=2) {//用这个会直接跳过有两队数据的时候跳出
// int llx,lly;
int num1=0,num2=0;
i++;
num1 = hoo[i];
num2 = hoo[++i];
for (int m = 0; m < ranpoint.length; m++) {
for (int n = 0; n < ranpoint[0].length; n++) {
if(ranpoint[m][n]==num2){
ranpoint[m][n]=num1;
m=ranpoint.length;//设置跳出外层循环
n=ranpoint[0].length;//设置跳出内层循环
}
}
}
// while (ranpoint[llx][lly]==num2) {//这个直接不起作用
// llx++;
// lly++;
// }
// ranpoint[llx][lly]=num1;
}
}
public void checknum(){
int pic1num=0;
int pic2num=0;
int pic3num=0;
int pic4num=0;
int pic5num=0;
int pic6num=0;
for (int i = 0; i < ranpoint.length; i++) {
for (int j = 0; j < ranpoint[0].length; j++) {
switch (ranpoint[i][j]) {
case 1:
pic1num++;
break;
case 2:
pic2num++;
break;
case 3:
pic3num++;
break;
case 4:
pic4num++;
break;
case 5:
pic5num++;
break;
default:
pic6num++;
break;
}
}
}
Log.i("检测图案个数:", "psy1:"+pic1num+""+"psy2:"+pic2num+"psy3:"+pic3num+"psy4:"+pic4num+"psy5:"+pic5num+"psy6:"+pic6num);
}
public void getchangepoint(){//交换坐标
lastpointx = nowpointx;
lastpointy = nowpointy;
if(ranpoint[lastpointx][lastpointy]==0){
lastpointx=0;
lastpointy=0;
}
}
public boolean getright(int a[][]){//判断二位数组是否所有元素都等于0,全部是0返回true,否者返回false
for(int i=0;i<a.length;i++){
for(int j=0;j<a[0].length;j++){
if(a[i][j]!=0){
Log.i("ooo", "含有非0元素");
return false;
}
}
}
Log.i("ooo", "全部为0元素");
return true;
}
public void drawpic(Canvas canvas){//绘制所有图片
super.onDraw(canvas);
for(int i=0;i<ranpoint.length;i++){
for(int j=0;j<ranpoint[0].length;j++){
switch (ranpoint[i][j]) {
case 0:
//为0就什么都不绘制
break;
case 1:
Bitmap map1 = Getpic.createBitmap(context, R.drawable.pic1);
canvas.drawBitmap(map1, i*WW, j*HH, null);
break;
case 2:
Bitmap map2 = Getpic.createBitmap(context, R.drawable.pic2);
canvas.drawBitmap(map2, i*WW, j*HH, null);
break;
case 3:
Bitmap map3 = Getpic.createBitmap(context, R.drawable.pic3);
canvas.drawBitmap(map3, i*WW, j*HH, null);
break;
case 4:
Bitmap map4 = Getpic.createBitmap(context, R.drawable.pic4);
canvas.drawBitmap(map4, i*WW, j*HH, null);
break;
case 5:
Bitmap map5 = Getpic.createBitmap(context, R.drawable.pic5);
canvas.drawBitmap(map5, i*WW, j*HH, null);
break;
default:
Bitmap map6 = Getpic.createBitmap(context, R.drawable.pic6);
canvas.drawBitmap(map6, i*WW, j*HH, null);
break;
}
// if(ranpoint[i][j]==1){
// Bitmap map1 = Getpic.createBitmap(context, R.drawable.pic1);
// canvas.drawBitmap(map1, i*WW, j*HH, null);
// }else if(ranpoint[i][j]==2){
// Bitmap map2 = Getpic.createBitmap(context, R.drawable.pic2);
// canvas.drawBitmap(map2, i*WW, j*HH, null);
// }else if(ranpoint[i][j]==3){
// Bitmap map3 = Getpic.createBitmap(context, R.drawable.pic3);
// canvas.drawBitmap(map3, i*WW, j*HH, null);
// }else if(ranpoint[i][j]==4){
// Bitmap map4 = Getpic.createBitmap(context, R.drawable.pic4);
// canvas.drawBitmap(map4, i*WW, j*HH, null);
// }else if(ranpoint[i][j]==5){
// Bitmap map5 = Getpic.createBitmap(context, R.drawable.pic5);
// canvas.drawBitmap(map5, i*WW, j*HH, null);
// }else if(ranpoint[i][j]==6){
// Bitmap map6 = Getpic.createBitmap(context, R.drawable.pic6);
// canvas.drawBitmap(map6, i*WW, j*HH, null);
// }
}
}
/* try {
Thread.sleep(sleeptime);
} catch (Exception e) {
// TODO: handle exception
}*/
}
@Override
public boolean onTouch(View v, MotionEvent event) {
getchangepoint();//将当前坐标值赋值给上一次的坐标值
// drawonce();
int x,y;
x = (int) (event.getX()/WW);
y = (int) (event.getY()/HH);
nowpointx=x;
nowpointy=y;
Log.i("FFF"," "+x+" "+y);
return false;
}
class drawThread implements Runnable{//创建线程
@Override
public void run() {
// while(getright(ranpoint)){
while(true){
draw();
}
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub }
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
// draw();
// drawonce();
new Thread(new drawThread()).start();
} @Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub } }

地址:http://download.csdn.net/detail/u011566000/5860991

Android 绿豆蛙版连连看(简陋版)的更多相关文章

  1. android贪吃蛇(超级简陋版)

    public class body { public int ax;//代表X周变量 public int ay;//代表Y轴变量 public int getAx() { return ax; } ...

  2. [转]Android 学习资料分享(2015 版)

    转 Android 学习资料分享(2015 版) 原文地址:http://www.jianshu.com/p/874ff12a4c01 目录[-] 我是如何自学Android,资料分享(2015 版) ...

  3. flask 第七章 简陋版智能玩具 +MongoDB初识和基本操作

    1.简陋版web智能玩具 FAQ.py文件 import os from aip import AipSpeech, AipNlp from uuid import uuid4 "" ...

  4. 【Android】家庭记账本手机版开发报告四

    一.说在前面 昨天 对界面显示和逻辑结构进行完善 今天 1.添加菜单(查询.清除所有等) 2.使用滑动删除 问题 1.在做查询时获取SearchView时引 入包错误经过长时间的尝试后才修正 2.滑动 ...

  5. Android编程权威指南第三版 第32章

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/qq_35564145/article/de ...

  6. 本人第一个android游戏《新连连看》上架

    经过艰苦奋战了几天,本人的第一个android游戏<新连连看>最终完毕了第一个版本号,比較简陋.另一部分功能保留没有开放.等第二个版本号再上.用的libgdx框架.可能不是非常出名,可是本 ...

  7. 微软发布 Windows Server 2016 预览版第三版,开发者要重点关注Nano Server

    微软已经发布 Windows Server 2016 和 System Center 2016 第三个技术预览版,已经提供下载.Windows Server 2016 技术预览版第三版也是首个包括了容 ...

  8. 【BZOJ3036】绿豆蛙的归宿 概率与期望

    最水的概率期望,推荐算法合集之<浅析竞赛中一类数学期望问题的解决方法> #include <iostream> #include <cstdio> using na ...

  9. 使用VNET-to-VNET连接Microsoft Azure国际版和中国版

    Microsoft Azure的VNET-to-VNET功能可以实现跨虚拟网络的VPN连接,通过VNET-to-VNET互联的两个虚拟网络可以在同一个订阅下或者隶属不同的订阅,而且可以跨数据中心.这实 ...

随机推荐

  1. CentOS7下安装Mysql和Memcached 以及 使用C#操作Mysql和Memcached

    我本身是学.net的,但是现在很多主流SQL和NOSQL都是部置在linux下,本着好学的精神,前段时间装了个虚拟机,在其装上CentOS64位的服务器系统,对于英文0基础,linux0基础的我来说, ...

  2. 161221、bootstrap table 实例

    bootstrap table 封装了一套完善的数据表格组件,把下面的代码复制一下估计你需要的基本功能都有了,没有的再看看手册对比着我给的实例也能很快的熟悉了 客户端 <!DOCTYPE htm ...

  3. DirectUI 收集资料

    1.[ZsUI]一步一步写个DirectUI.[连载贴] (http://tieba.baidu.com/p/1625954225) ps: 虽然是vb写的,也很简陋,不过有代码,并且作者每节都给出了 ...

  4. 华东交通大学2016年ACM“双基”程序设计竞赛 1008

    Problem Description halfyarn找你写个简单的题?好哒!给你n个整数,现在要求你选择两个位置的数,例如选择第pos_a个数a,和第pos_b个数b,给定ans=min(a,b) ...

  5. Failed to create the part's controls [eclipse]

    查看源码 出现 Failed to create the part's controls 解决方法: eclipse.ini  中添加: -startup plugins/org.eclipse.eq ...

  6. 图片溢出div问题的最终解决方案

    2016.11.20备注: 此问题通过css的max-width:100%;即可解决. 前两天编写了一个前端页面,在本机上显示一切正常.不过在不断的测试中,发现了一个严重的问题,如果图片过大,会撑破d ...

  7. Beaglebone Black – 智能家居控制系统 LAS - 插座组装

    上一篇完成了服务端,这次是拼图的最后一块,插座. 插座一个,准备废掉它其中一个插头 预想电路草图 物料清单: 两路插座一个 继电器一个,3.3V 能驱动即可: 交流转直流 3.3V,我买了现成的模块: ...

  8. Deep Learning Papers Reading Roadmap

    Deep Learning Papers Reading Roadmap https://github.com/songrotek/Deep-Learning-Papers-Reading-Roadm ...

  9. applicationContext.xml简单笔记

    applicationContext.xml简单笔记 <?xml version="1.0" encoding="UTF-8"?> <bean ...

  10. json化 datatable

    /// <summary> /// 将DataSet中数据,json化 /// </summary> /// <param name="source" ...