package cn.wd.logic; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.database.sqlite.SQLiteDatabase; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.util.DisplayMetrics; import android.util.Log; import android.view.MotionEvent; import android.view.View; import cn.wd.R; import cn.wd.database.MyDataBase; import cn.wd.tools.Shipei; import cn.wd.ui.GameView; import cn.wd.ui.UIviewActivity; import cn.wd.util.Guan_Information; public class guanqia_view_logic extends View { // public int leixin_type = -1; /** * @author wuweidong 声明 */ // 声明数据库对象 // SQLiteDatabase database; // 游戏类型 // String type_select = "动物世界"; // 声明对象 public static MyDataBase mdb; // 没关的小关数 // private int[] px = new int[101]; // private int[] py = new int[101]; private int Count = 5; private Paint paint; Rect[] rect; Rect[] rect_star; Rect[] rect_all; Rect litter_icon_rect; Rect Back_bnt_rect; int src_x; int src_y; private Bitmap bmp_start, bmp_star_l; private Bitmap bmp_guanqia, bmp_no; private Bitmap bmp_icon_bg, bmp_icon; private Bitmap bmp_bg, bmp_bg_blewo; private Bitmap bmp_back; private Bitmap[] bmp_number; private Bitmap bmp_numbersrc; private int Screen_index; // private int screenW, screenH; private int dw, dh; private Context context; int number_cellwidth; // GuanLogic gl; private int screen_size = 4; private int icon_line = 3; private int icon_line_count = 5; public guanqia_view_logic(Context context) { super(context); this.context = context; paint = new Paint(); mdb = new MyDataBase(context); // DisplayMetrics dm = new DisplayMetrics(); // ((Activity) // context).getWindowManager().getDefaultDisplay().getMetrics( // dm); // dw = dm.widthPixels; // dh = dm.heightPixels; // for (int i = 0; i < 101; i++) { // px[i] = (int) (dw * 0.01 * i); // py[i] = (int) (dh * 0.01 * i); // } src_x = Shipei.px[8]; src_y = Shipei.py[8]; setFocusable(true); bmp_number = new Bitmap[10]; bmp_numbersrc = BitmapFactory.decodeResource(getResources(), R.drawable.number); number_cellwidth = bmp_numbersrc.getWidth() / 10; for (int index = 0; index < 10; index++) { bmp_number[index] = Bitmap.createBitmap(bmp_numbersrc, index * number_cellwidth, 0, number_cellwidth, bmp_numbersrc .getHeight()); } bmp_start = BitmapFactory.decodeResource(getResources(), R.drawable.start_bg); bmp_star_l = BitmapFactory.decodeResource(getResources(), R.drawable.star_l); bmp_guanqia = BitmapFactory.decodeResource(getResources(), R.drawable.launcer); bmp_no = BitmapFactory.decodeResource(getResources(), R.drawable.no); bmp_icon = BitmapFactory.decodeResource(getResources(), R.drawable.litter_icon); bmp_icon_bg = BitmapFactory.decodeResource(getResources(), R.drawable.litter_icon_bg); bmp_bg = BitmapFactory.decodeResource(getResources(), R.drawable.bg_); bmp_back = BitmapFactory.decodeResource(getResources(), R.drawable.select_back); // bmp_bg_blewo = BitmapFactory.decodeResource(getResources(), // R.drawable.bg); rect_star = new Rect[5]; rect_all = new Rect[4]; rect = new Rect[60]; litter_icon_rect = new Rect(Shipei.px[50] - Shipei.px[15], Shipei.py[100] - Shipei.py[7], Shipei.px[50] + Shipei.px[9], Shipei.py[100]); Back_bnt_rect = new Rect(Shipei.px[0], Shipei.py[100] - Shipei.py[13], Shipei.px[10], Shipei.py[100]); System.out.println("------>" + Shipei.px[50]); mdb = new MyDataBase((Activity) this.context); // if(MyDataBase.list.size()!=0){ // System.out.println("guanqia_view_------>"+MyDataBase.list.size()); // MyDataBase.list.clear(); // } } private void MyDraw(Canvas canvas) { for (int i = 0; i < screen_size; i++) { for (int line = 0; line < icon_line; line++) for (int k = 0; k < icon_line_count; k++) drawCell(canvas, rect_all[i].left + Shipei.px[14] * k, rect_all[i].top, Guan_Information.guan_star_number, k + line * 5 + i * 15, line, i); } } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); canvas.drawBitmap(bmp_bg, 0, 0, null); paint.setColor(Color.BLACK); paint.setAlpha(70); for (int j = 0; j < screen_size; j++) { rect_all[j] = new Rect(src_x + (Shipei.px[90] * j + Shipei.px[8]), src_y, src_x + (Shipei.px[90] * j + Shipei.px[8]) + Shipei.px[70], Shipei.py[90]); canvas.drawRect(rect_all[j], paint); } MyDraw(canvas); for (int k = 0; k < screen_size; k++) { canvas.drawBitmap(bmp_icon_bg, litter_icon_rect.left + k * Shipei.px[9], litter_icon_rect.top, null); if (k == Screen_index) canvas.drawBitmap(bmp_icon, litter_icon_rect.left + k * Shipei.px[9], litter_icon_rect.top, null); } canvas .drawBitmap(bmp_back, Back_bnt_rect.left, Back_bnt_rect.top, null); } // 画每一个单元的小模块 public void drawCell(Canvas canvas, int x, int y, int number, int id, int line, int screen_id) { rect[id] = new Rect(x + Shipei.px[1], y + Shipei.py[3] + line * (bmp_guanqia.getHeight() + Shipei.py[6]), x + Shipei.px[1] + bmp_guanqia.getWidth(), y + Shipei.py[3] + line * (bmp_guanqia.getHeight() + Shipei.py[6]) + bmp_guanqia.getHeight()); // canvas.drawRect(rect[id], paint); // if (Guan_Information.Count_number > id) // canvas.drawBitmap(bmp_guanqia, null, rect[id], null); // else // canvas.drawBitmap(bmp_no, null, rect[id], null); if (Guan_Information.game_type == Type_select.jstd_index) { Type_guan(canvas, Guan_Information.jstd_count_number, id); } else if (Guan_Information.game_type == Type_select.typd_index) { Type_guan(canvas, Guan_Information.typd_count_number, id); } else if (Guan_Information.game_type == Type_select.ylbg_index) { Type_guan(canvas, Guan_Information.ylbg_count_number, id); } else if (Guan_Information.game_type == Type_select.wxsj_index) { Type_guan(canvas, Guan_Information.wxsj_count_number, id); } else if (Guan_Information.game_type == Type_select.zrbk_index) { Type_guan(canvas, Guan_Information.zrbk_count_number, id); } else if (Guan_Information.game_type == Type_select.sjzz_index) { Type_guan(canvas, Guan_Information.rcsh_count_number, id); } else if (Guan_Information.game_type == Type_select.gxgc_index) { Type_guan(canvas, Guan_Information.lydl_count_number, id); } else if (Guan_Information.game_type == Type_select.rwls_index) { Type_guan(canvas, Guan_Information.rwls_count_number, id); } else if (Guan_Information.game_type == Type_select.lydl_index) { Type_guan(canvas, Guan_Information.lydl_count_number, id); } else if (Guan_Information.game_type == Type_select.rcsh_index) { Type_guan(canvas, Guan_Information.rcsh_count_number, id); } else if (Guan_Information.game_type == Type_select.qn_index) { Type_guan(canvas, Guan_Information.qn_Count_number, id); } // 全能争霸的星星图 if (Guan_Information.game_type == Type_select.qn_index) { for (int k = 0; k < Count; k++) { rect_star[k] = new Rect(x + Shipei.px[1] + Shipei.px[2] * k, y + Shipei.py[2] + line * (bmp_guanqia.getHeight() + Shipei.py[7]) + bmp_guanqia.getHeight(), x + Shipei.px[1] + Shipei.px[2] * (k + 1), y + Shipei.py[7] + line * (bmp_guanqia.getHeight() + Shipei.py[7]) + bmp_guanqia.getHeight()); } for (int i = 0; i < Count; i++) { if (number > i + id * Count) canvas.drawBitmap(bmp_star_l, null, rect_star[i], null); else canvas.drawBitmap(bmp_start, null, rect_star[i], null); } } int shuzi = id + 1; DrawNumber(canvas, shuzi); } int old_x; int old_y; int new_x; int new_y; int click_x; int click_y; @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub int type = event.getAction(); switch (type) { case MotionEvent.ACTION_DOWN: old_x = (int) event.getX(); old_y = (int) event.getY(); click_x = (int) event.getX(); click_y = (int) event.getY(); break; case MotionEvent.ACTION_MOVE: new_x = (int) event.getX(); new_y = (int) event.getY(); if ((old_x - new_x) > 30) { src_x -= 50; click_x = 0; click_y = 0; old_x = new_x; old_y = new_y; } else if ((old_x - new_x) < -30) { src_x += 50; click_x = 0; click_y = 0; old_x = new_x; old_y = new_y; } break; case MotionEvent.ACTION_UP: if ((src_x > Shipei.px[0]) || (src_x > -Shipei.px[40])) { src_x = Shipei.px[8]; Screen_index = 0; } else if ((src_x <= -Shipei.px[40] && src_x >= -(Shipei.px[80] + Shipei.px[50]))) { src_x = -Shipei.px[80]; Screen_index = 1; } else if ((src_x < -(Shipei.px[80] + Shipei.px[50]) && src_x >= -(Shipei.px[85] * 2 + Shipei.px[50]))) { src_x = -Shipei.px[85] * 2; Screen_index = 2; } else if (src_x < -(Shipei.px[85] * 2 + Shipei.px[50])) { src_x = -Shipei.px[87] * 3; Screen_index = 3; } System.out.println("---->Up"); for (int k = 0; k < 3; k++) for (int i = 0; i < 5; i++) if (rect[i + k * 5 + Screen_index * 15].contains(click_x, click_y)) { /** *进入选择的关卡 * */ if (ISboolean((i + k * 5 + Screen_index * 15))) { int temp = (i + k * 5 + Screen_index * 15); // 记录当前点击的count值 Guan_Information.star_temp = temp + 1; if (Guan_Information.game_type == Type_select.qn_index) { if (Guan_Information.star_temp < Guan_Information.Count_number) Guan_Information.guan_again_index = 0; } // int count = 1; // int star = 11; // if(leixin_type!=0) mdb.openDatabase(); mdb.fromDataBaseGetData( Guan_Information.game_type, Guan_Information.star_temp); mdb.cancelCursorAndDataBase(); Log.e("guanqia_view--->", "" + MyDataBase.list.size()); // if(MyDataBase.list.size()!=0){ // MyDataBase.list.clear(); // } // gl.getQuestions(count, star); // mdb.questionsIsNullRestart(); // mdb.fromDataBaseGetData1("20", // Guan_Information.star_temp); // mdb.cancelCursorAndDataBase(); // if ((i + k * 6 + Screen_index * 18) == 0) { // // Databases_Tool(Guan_Information.Type_temp); // // 关数 Intent intent = new Intent(context, UIviewActivity.class); context.startActivity(intent); // } System.out.println("----->Down--" + (i + k * 6 + Screen_index * 18)); } } old_x = 0; old_y = 0; new_x = 0; new_y = 0; break; } this.postInvalidate(); return true; } // 关卡是否开锁 private boolean ISboolean(int index) { if (((index + 1) <= Guan_Information.qn_Count_number) || ((index + 1) <= Guan_Information.jstd_count_number) || ((index + 1) <= Guan_Information.typd_count_number) ||((index + 1) <= Guan_Information.ylbg_count_number) ||((index + 1) <= Guan_Information.wxsj_count_number) ||((index + 1) <= Guan_Information.zrbk_count_number) ||((index + 1) <= Guan_Information.sjzz_count_number) ||((index + 1) <= Guan_Information.rcsh_count_number) ||((index + 1) <= Guan_Information.gxgc_count_number) ||((index + 1) <= Guan_Information.lydl_count_number) ||((index + 1) <= Guan_Information.rwls_count_number)) { return true; } else return false; } // 绘制数字 private void DrawNumber(Canvas canvas, int number) { int number1 = number / 10; int number2 = number - number1 * 10; if (number1 != 0) { canvas.drawBitmap(bmp_number[number1], rect[number - 1].left + bmp_guanqia.getWidth() / 2 - bmp_number[number1].getWidth(), rect[number - 1].top + bmp_guanqia.getHeight() - bmp_number[number1].getHeight() * 2, null); canvas.drawBitmap(bmp_number[number2], rect[number - 1].left + bmp_guanqia.getWidth() / 2, rect[number - 1].top + bmp_guanqia.getHeight() - bmp_number[number2].getHeight() * 2, null); } else { canvas.drawBitmap(bmp_number[number2], rect[number - 1].left + bmp_guanqia.getWidth() / 2 - bmp_number[number2].getWidth() / 2, rect[number - 1].top + bmp_guanqia.getHeight() - bmp_number[number2 - 1].getHeight() * 2, null); } } // 绘制小关卡 private void Type_guan(Canvas canvas, int count, int id) { if (count > id) canvas.drawBitmap(bmp_guanqia, null, rect[id], null); else canvas.drawBitmap(bmp_no, null, rect[id], null); } }