package com.pig.puzzle;
import java.util.ArrayList;
import java.util.Vector;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import com.pig.piece.Piece;
import com.pig.piece.PieceFactory;
import com.pig.piece.PieceImageButton;
import com.pig.util.bitmap.MyBitmapFactory;
import com.pig.util.db.MyDBAdapter;
public class Game extends Activity {
private int screenWidth;
private int screenHeight;
private int INACCURACY = 12;
//private Vector<PieceImageButton> allImagePieces = new Vector<PieceImageButton>();
private ArrayList allImagePieces = new ArrayList();
//private Vector<PieceImageButton> movePieces = new Vector<PieceImageButton>();
private ArrayList movePieces = new ArrayList();
private AbsoluteLayout puzzle = null;
private MyDBAdapter db = new MyDBAdapter(this);
private int _id;
private int imageId;
private int levelId;
private int row;
private int line;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
System.gc(); //回收空间
////////////////////////////
Intent i = this.getIntent();
String action = i.getAction();
Log.i("Game", "action = " + action);
Bundle bundle = i.getExtras();
imageId = bundle.getInt("imageId");
Log.i("Game", "imageId = " + imageId);
//////////////////////
db.open();
Cursor cursor = db.getLastEntry("pt_game", "_id");
_id = cursor.getInt(cursor.getColumnIndexOrThrow("_id"));
levelId = cursor.getInt(cursor.getColumnIndexOrThrow("level_id"));
cursor.close();
cursor = db.getEntry("pt_level", "level_id", levelId);
cursor.moveToFirst();
row = cursor.getInt(cursor.getColumnIndexOrThrow("piece_row"));
line = cursor.getInt(cursor.getColumnIndexOrThrow("piece_line"));
Log.i("Game", "row = " + row + ", line = " + line);
cursor.close();
String where = "image_id=" + imageId + " and level_id=" + levelId + " ";
int count = db.getEntryCount("pt_piece", where);
db.close();
/////////////////////////////
//获得屏幕的宽和高
DisplayMetrics dm = getResources().getDisplayMetrics();
screenWidth = dm.widthPixels;
screenHeight = dm.heightPixels;
LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
puzzle = (AbsoluteLayout) inflater.inflate(R.layout.game, null);
setContentView(puzzle);
initBtnReview();
Drawable dg = MyBitmapFactory.readDrawable(this, imageId, screenWidth, screenHeight);
puzzle.setBackgroundDrawable(dg);
puzzle.getBackground().setAlpha(120);
//////////////////////
if("RETURN_GAME_ACTION".equals(action) && count>0){
//setContentView(getOldPuzzle(imageId, levelId));
getOldPuzzle(imageId, levelId);
}else if("NEW_GAME_ACTION".equals(action)){
recordGame(_id, imageId);
if(count == (row * line)){
//setContentView(getReadyPuzzle(imageId, levelId));
getReadyPuzzle(imageId, levelId);
}else{
//将图片根据row行line列切开,并返回切块数组
//row = 5;
//line = 3;
getNewPuzzle(imageId, row, line);
}
}else{
//default
}
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
private void saveGame(){
db.open();
int n = db.getEntryCount("pt_piece", "image_id", imageId);
if(n > 0){
db.removeEntry("pt_piece", "image_id", "" + imageId);
}
int count = allImagePieces.size();
for(int i=0; i<count; i++){
PieceImageButton pib = (PieceImageButton) allImagePieces.get(i);
db.insertPiece("pt_piece", pib, imageId, levelId);
pib = null;
}
db.close();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
saveGame();
allImagePieces = null;
db = null;
System.gc();
super.onPause();
}
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onRestoreInstanceState(savedInstanceState);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
}
private void nextGame(){
db.open();
//如果已经是最大难度,则没有下一关
int max_level = db.getMaxValue("pt_level", "level_id", "level_id");
int next_level = levelId + 1;
if(next_level > max_level){
next_level = max_level;
}
ContentValues values = new ContentValues();
values.put("level_id", next_level);
db.insertEntry("pt_game", values);
db.close();
}
private void recordGame(int game_id, int game_imageid){
db.open();
db.updateEntry("pt_game", game_id, "image_id", game_imageid);
db.close();
}
private void initBtnReview(){
/////////////
progressBar = (ProgressBar) findViewById(R.id.ProgressBar01);
progressBar.setProgress(0);
new Thread(new Runnable(){
public void run() {
// TODO Auto-generated method stub
for(int i=0; i<10; i++){
try {
intCounter = (i + 1) * 20;
Thread.sleep(1000);
Message msg = new Message();
msg.what = Game.GUI_THREADING_NOTIFIER;
Game.this.myMessageHandler.sendMessage(msg);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Message stop_msg = new Message();
stop_msg.what = Game.GUI_STOP_NOTIFIER;
Game.this.myMessageHandler.sendMessage(stop_msg);
}
}).start();
Button btnBack = (Button) findViewById(R.id.btnReview);
AbsoluteLayout.LayoutParams lp = new AbsoluteLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 5, screenHeight-20);
btnBack.setLayoutParams(lp);
btnBack.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(Game.this, PicView.class);
i.setAction("GAME_REVIEW_ACTION");
Bundle bundle = new Bundle();
bundle.putInt("imageId", imageId);
i.putExtras(bundle);
startActivity(i);
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
finish();
}
});
}
private View getReadyPuzzle(int resid, int levelid){
// //获得屏幕的宽和高
// DisplayMetrics dm = getResources().getDisplayMetrics();
没有合适的资源?快使用搜索试试~ 我知道了~
android 凹凸拼图
共76个文件
jpg:29个
java:20个
xml:18个
4星 · 超过85%的资源 需积分: 9 111 下载量 113 浏览量
2011-08-03
16:14:50
上传
评论
收藏 2.96MB RAR 举报
温馨提示
一个模拟纸质的凹凸拼图。 载入图片,即可自动将图片做出拼图切块。 随意拖动切块,当靠近时,自定吸附在一起。
资源推荐
资源详情
资源评论
收起资源包目录
Puzzle1.2.rar (76个子文件)
.project 845B
default.properties 380B
AndroidManifest.xml 1KB
src
com
pig
gallery
GalleryFlow.java 4KB
ImageAdapter.java 2KB
palette
Palette.java 2KB
test
SurfaceViewTest.java 2KB
TestHandler.java 2KB
piece
PieceImageButton.java 2KB
Piece.java 2KB
PieceFactory.java 13KB
game
framework
GameActivity.java 1KB
GameThread.java 269B
GameSurfaceView.java 770B
puzzle
PuzzleMain.java 1KB
ChoosePic.java 6KB
Game.java 28KB
PicView.java 2KB
Setting.java 4KB
MainMenu.java 6KB
util
db
MyDBAdapter.java 13KB
bitmap
MyBitmapFactory.java 3KB
res
values
styles.xml 743B
colors.xml 222B
array.xml 156B
strings.xml 953B
layout
main_menu.xml 2KB
choose_pic.xml 2KB
pic_view.xml 1KB
game.xml 719B
setting.xml 1KB
main.xml 527B
drawable-ldpi
img0200.jpg 38KB
img0300.jpg 12KB
Thumbs.db 68KB
icon.png 2KB
drawable-hdpi
light.jpg 40KB
face5.jpg 678KB
face1.jpg 148KB
face4.jpg 237KB
face3.jpg 100KB
Thumbs.db 45KB
face2.jpg 323KB
icon.png 4KB
drawable
menu_selector.xml 1KB
anim
popup_exit.xml 1KB
show.xml 303B
zoomout.xml 586B
hide.xml 303B
popup_enter.xml 1KB
zoomin.xml 401B
drawable-mdpi
pinkgirl2.jpg 14KB
whitegirl.jpg 177KB
f1.jpg 38KB
sky1.jpg 69KB
whitegirl2.jpg 122KB
g4.jpg 22KB
g6.jpg 56KB
g3.jpg 57KB
g7.jpg 106KB
seagirl.jpg 45KB
wednesday.jpg 130KB
g8.jpg 46KB
purplegirl.jpg 38KB
g2.jpg 71KB
Thumbs.db 90KB
pinkgirl.jpg 35KB
blackgirl.jpg 37KB
love.jpg 37KB
redgirl.jpg 75KB
g1.jpg 53KB
orangegirl.jpg 57KB
thelove.jpg 101KB
icon.png 3KB
.classpath 280B
gen
com
pig
puzzle
R.java 5KB
assets
共 76 条
- 1
zhu410289616
- 粉丝: 49
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页