ITeye博客

做了个拼图游戏

java.zhangshuling · 2011-11-03 12:56 · android · 移动开发 · Markdown

工作之余,对android颇有兴趣,只是武汉从事android的企业貌似不多,所有自学着玩一下,就坐个简单的拼图游戏,只当实验一下

简单的功能有 查找手机或sd卡的图片,等比缩放,分割,乱序,排列

还有再次点选择图片的时候,会记录图片所属目录(免得每次从根目录开始找)

部分代码(其实我用的最土的办法,一个小图片记录两个坐标,一个是原始的,一个是随机的,最后判断每个小图片的 这两个坐标是否一致,如果都相同,则 Game Over)



	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;
		}
		
    }


评论(1)

  1. #1 楼 · chenqirang · 2011-11-16 10:21

    :x 还好我只是来看界面的

评论功能维护中,当前仅展示历史评论。