---
title: "做了个拼图游戏"
author: "java.zhangshuling"
date: "2011-11-03T12:56:54Z"
tags: []
categories: ["移动开发"]
slug: "untitled"
draft: false
lastmod: "2011-11-03T13:06:52Z"
id: 1233277
url: "https://java-zhangshuling.iteye.com/blog/1233277"
---

工作之余，对android颇有兴趣，只是武汉从事android的企业貌似不多，所有自学着玩一下，就坐个简单的拼图游戏，只当实验一下

简单的功能有  查找手机或sd卡的图片，等比缩放，分割，乱序，排列

还有再次点选择图片的时候，会记录图片所属目录(免得每次从根目录开始找)


![](http://dl.iteye.com/upload/attachment/581392/5729eaae-d694-3b6e-82de-b125b7f79840.png)

![](http://dl.iteye.com/upload/attachment/581402/dcb1b56b-8e35-3445-a9be-9decbdfe4308.png)

![](http://dl.iteye.com/upload/attachment/581394/ca28b55d-fc4d-3f3d-a0b1-fded1dca1cac.png)


![](http://dl.iteye.com/upload/attachment/581396/8356754f-fd52-395b-9799-102e7509dceb.png)

部分代码(其实我用的最土的办法，一个小图片记录两个坐标，一个是原始的，一个是随机的，最后判断每个小图片的  这两个坐标是否一致，如果都相同，则 Game Over)


```java


	public synchronized void check(){
			boolean over = true;
			for(BitmapView  bitmapView : bitmapViewList){
	    		if(bitmapView.getX() != bitmapView.getRandomX() || bitmapView.getY() != bitmapView.getRandomY()){
	    			over = false;
	    			isContinue = true;
	    			isOver = false;
	    			break;
	    		}
	    		
	    	}
			
			if(over){
    			isContinue = false;
    			isOver = true;
    			Message msg = new Message();
    			Bundle bundle = new Bundle();
    			bundle.putBoolean("isOver", isOver);
    			msg.setData(bundle);
    			GameViewActivity.this.handler.sendMessage(msg);
			}
		}




class BitmapView{
    	Bitmap bitmap;
    	int x;
    	int y;
    	int randomX;
    	int randomY;
		public BitmapView(Bitmap bitmap, int x, int y) {
			super();
			this.bitmap = bitmap;
			this.x = x;
			this.y = y;
		}
		public Bitmap getBitmap() {
			return bitmap;
		}
		public void setBitmap(Bitmap bitmap) {
			this.bitmap = bitmap;
		}
		public int getX() {
			return x;
		}
		public void setX(int x) {
			this.x = x;
		}
		public int getY() {
			return y;
		}
		public void setY(int y) {
			this.y = y;
		}
		public int getRandomX() {
			return randomX;
		}
		public void setRandomX(int randomX) {
			this.randomX = randomX;
		}
		public int getRandomY() {
			return randomY;
		}
		public void setRandomY(int randomY) {
			this.randomY = randomY;
		}
		
    }


```