




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、android连连看01 package com.ghost.picmatch; 02 03 import com.ghost.picmatch.gui.render.myrender; 04 05 import android.os.bundle; 06 import android.app.activity; 07 import android.content.pm.activityinfo; 08 import android.view.menu; 09 import android.view.window; 10 import android.view.windowmanager; 1
2、1 12 public class mainactivity extends activity 13 14 override 15 public void oncreate(bundle savedinstancestate) 16 super.oncreate(savedinstancestate); 17 this.getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, 18 windowmanager.layoutparams.flag_fullscreen); 19 this.requestwindowfeatu
3、re(window.feature_no_title); 20 this.setrequestedorientation(activityinfo.screen_orientation_portrait); 21 setcontentview(new myrender(this); 22 23 24 override 25 public boolean oncreateoptionsmenu(menu menu) 26 getmenuinflater().inflate(r.menu.activity_main, menu); 27 return true; 28 29 30 001 pack
4、age com.ghost.picmatch.util; 002 003 import java.io.file; 004 import java.io.fileinputstream; 005 import java.io.filenotfoundexception; 006 import java.io.fileoutputstream; 007 import java.io.ioexception; 008 import java.util.properties; 009 010 import com.ghost.picmatch.data.gamedata; 011 import co
5、m.ghost.picmatch.data.imagedata; 012 013 import android.graphics.bitmap; 014 import android.graphics.bitmapfactory; 015 import android.graphics.canvas; 016 import android.graphics.paint; 017 018 /* 019 * 工具类,主要存放跟平台有关代码 020 * 021 * author ghost 022 * 023 */ 024 public class tool 025 026 /* 027 * 从as
6、sets文件夹下面加载图片 028 * 029 * param name 030 * return 031 */ 032 public static bitmap loadimage(string name) 033 try 034 return bitmapfactory.decodestream(gamedata.context.getresources() 035 .getassets().open(name); 036 catch (ioexception e) 037 e.printstacktrace(); 038 system.err.println(failed to load
7、 + name); 039 return null; 040 041 042 043 /* 044 * 加载所有的图片资源 045 * 046 * return 047 */ 048 public static boolean loadallimage() 049 050 / /加载图块 051 imagedata.red = loadimage(image/func/red.png); 052 imagedata.green = loadimage(image/func/green.png); 053 imagedata.black = loadimage(image/func/black.
8、png); 054 imagedata.line = loadimage(image/func/line.png); 055 056 for (int i = 1; i = 57; +i) 057 string filename = image/pics/ + i + .png; 058 imagedata.picsi - 1 = loadimage(filename); 059 060 061 / /按钮图片 062 imagedata.start_button0 = loadimage(image/button/start1.png); 063 imagedata.start_button
9、1 = loadimage(image/button/start2.png); 064 065 imagedata.return_button0 = loadimage(image/button/return1.png); 066 imagedata.return_button1 = loadimage(image/button/return2.png); 067 068 imagedata.help_button0 = loadimage(image/button/help1.png); 069 imagedata.help_button1 = loadimage(image/button/
10、help2.png); 070 071 imagedata.exit_button0 = loadimage(image/button/exit1.png); 072 imagedata.exit_button1 = loadimage(image/button/exit2.png); 073 074 imagedata.rank_button0 = loadimage(image/button/rank1.png); 075 imagedata.rank_button1 = loadimage(image/button/rank2.png); 076 077 imagedata.pause_
11、button0 = loadimage(image/button/pause1.png); 078 imagedata.pause_button1 = loadimage(image/button/pause2.png); 079 080 imagedata.resume_button0 = loadimage(image/button/resume1.png); 081 imagedata.resume_button1 = loadimage(image/button/resume2.png); 082 083 imagedata.ad_button = loadimage(image/bu
12、tton/unknow.png); 084 085 / /背景图片 086 imagedata.background0 = loadimage(image/background/background1.png); 087 imagedata.background1 = loadimage(image/background/background2.png); 088 imagedata.background2 = loadimage(image/background/background3.png); 089 imagedata.background3 = loadimage(image/bac
13、kground/background4.png); 090 imagedata.background4 = loadimage(image/background/background5.png); 091 092 / /logo 093 imagedata.logo = loadimage(image/logo/logo.png); 094 095 / /帮助信息 096 imagedata.help_text = loadimage(image/func/help.png); 097 098 / /排行榜背景 099 imagedata.rank_back = loadimage(image
14、/func/rank.png); 100 101 / /计分板 102 imagedata.score_display = loadimage(image/func/score.png); 103 return true; 104 105 106 /* 107 * 在屏幕指定绘制绘制图像 108 * 109 * param image 110 * param x 111 * param y 112 * param w 113 * param h 114 * param g2d 115 */ 116 public static void drawimage(bitmap image, int x
15、, int y, int w, int h, 117 canvas canvas, paint paint) 118 if (image = null) 119 system.err.println(image is null!); 120 return; 121 122 image = bitmap.createscaledbitmap(image, (int) (w * gamedata.scalew), 123 (int) (h * gamedata.scaleh), true); 124 canvas.drawbitmap(image, (int) (x * gamedata.scal
16、ew), 125 (int) (y * gamedata.scaleh), paint); 126 127 128 /* 129 * 在屏幕指定位置绘制文字 130 * 131 * param text 132 * param x 133 * param y 134 * param g2d 135 */ 136 public static void drawtext(string text, int x, int y, canvas canvas, 137 paint paint) 138 paint.settextsize(20); 139 canvas.drawtext(text, (in
17、t) (x * gamedata.scalew), 140 (int) (y * gamedata.scaleh), paint); 141 142 143 /* 144 * 获得当前排行榜 145 * 146 * return 147 */ 148 public static int getscorelist() 149 file file = new file(mnt/sdcard/picmatch.data); 150 if (!file.exists() 151 try 152 file.createnewfile(); 153 catch (ioexception e) 154 e.
18、printstacktrace(); 155 156 157 int result = new int8; 158 properties prop = new properties(); 159 try 160 prop.load(new fileinputstream(file); 161 for (int i = 0; i 8; +i) 162 resulti = integer 163 .parseint(prop.getproperty( + (i + 1) = null ? 0 164 : (prop.getproperty( + (i + 1); 165 166 catch (io
19、exception e) 167 e.printstacktrace(); 168 169 return result; 170 171 172 /* 173 * 更新分数排行榜 174 * 175 * param score 176 */ 177 public static void updatescorelist(int score) 178 file file = new file(mnt/sdcard/picmatch.data); 179 if (!file.exists() 180 try 181 file.createnewfile(); 182 catch (ioexcepti
20、on e) 183 e.printstacktrace(); 184 185 186 int result = new int8; 187 properties prop = new properties(); 188 try 189 prop.load(new fileinputstream(file); 190 for (int i = 0; i 8; +i) 191 resulti = integer 192 .parseint(prop.getproperty( + (i + 1) = null ? 0 193 : (prop.getproperty( + (i + 1); 194 1
21、95 catch (ioexception e) 196 e.printstacktrace(); 197 198 for (int i = 0; i 8; +i) 199 if (resulti i; -j) 201 resultj = resultj - 1; 202 203 resulti = score; 204 break; 205 206 207 for (int i = 0; i 8; +i) 208 prop.setproperty( + (i + 1), resulti + ); 209 210 try 211 prop.save(new fileoutputstream(f
22、ile), auto list); 212 catch (filenotfoundexception e) 213 e.printstacktrace(); 214 215 216 217 01 package com.ghost.picmatch.util; 02 03 import com.ghost.picmatch.logic.gamehelp; 04 import com.ghost.picmatch.logic.gameloss; 05 import com.ghost.picmatch.logic.gamemenu; 06 import com.ghost.picmatch.lo
23、gic.gameobject; 07 import com.ghost.picmatch.logic.gamepanel; 08 import com.ghost.picmatch.logic.gamepause; 09 import com.ghost.picmatch.logic.gamerank; 10 import com.ghost.picmatch.logic.gamewin; 11 12 /* 13 * gameobject的简单工厂,用于得到对应的面板 14 * author ghost 15 * 16 */ 17 public class gameobjectfactory
24、implements common 18 19 private static gamemenu menu; 20 private static gamepanel run; 21 private static gamepause pause; 22 private static gamewin win; 23 private static gameloss loss; 24 private static gamehelp help; 25 private static gamerank rank; 26 27 public static void inilization() 28 menu =
25、 new gamemenu(); 29 run = new gamepanel(); 30 pause = new gamepause(); 31 win = new gamewin(); 32 loss = new gameloss(); 33 help = new gamehelp(); 34 rank = new gamerank(); 35 36 37 public static gameobject getinstance(int status) 38 switch (status) 39 case loading: 40 return null; 41 case menu: 42
26、return menu; 43 case pause: 44 return pause; 45 case rank: 46 return rank; 47 case win: 48 return win; 49 case loss: 50 return loss; 51 case help: 52 return help; 53 case run: 54 return run; 55 default: 56 return null; 57 58 59 01 package com.ghost.picmatch.util; 02 03 /* 04 * 定义游戏状态类 05 * author gh
27、ost 06 * 07 */ 08 public interface common 09 public static final int loading=0;/游戏加载状态 10 public static final int menu=1;/菜单界面 11 public static final int run=2;/游戏进行中 12 public static final int pause=3;/暂停 13 public static final int rank=4;/查看排行榜 14 public static final int win=5;/胜利界面 15 public stat
28、ic final int loss=6;/失败界面 16 public static final int help=7;/查看帮助界面 17 001 package com.ghost.picmatch.logic; 002 003 import java.util.arraylist; 004 import java.util.random; 005 006 import android.graphics.point; 007 008 /* 009 * 游戏地图操作类 010 * author ghost 011 * 012 */ 013 public class mapfunction 0
29、14 015 private static arraylist temp_point; 016 017 /* 018 * 创建一个新的地图数组 019 * param map 020 * param num 021 */ 022 public static void createmap(int map, int num) 023 int values = new int56; 024 random rand = new random(); 025 / 生成28对随机数 026 for (int i = 0; i 56;) 027 int temp = rand.nextint(num); 02
30、8 valuesi+ = temp; 029 valuesi+ = temp; 030 031 032 / 生成随机地图(一维的) 033 int mapvalue = new int56; 034 int size = 56; 035 for (int i = 0; i 56; +i) 036 int temp = rand.nextint(size); 037 mapvaluei = valuestemp; 038 for (int j = temp; j size - 1; +j) 039 valuesj = valuesj + 1; 040 041 size-; 042 043 044
31、 / 将一维随机地图转换为二维 045 for (int i = 0; i 56; +i) 046 mapi / 7i % 7 = mapvaluei; 047 048 049 050 051 /* 052 * 判断指定的两个点能否消除 053 * param pp1 054 * param pp2 055 * param map 056 * return 057 */ 058 public static boolean candecrease(point pp1, point pp2, int map) 059 temp_point = new arraylist(); 060 if (ma
32、ppp1.xpp1.y != mappp2.xpp2.y) | mappp1.xpp1.y = -1 061 | pp1.equals(pp2) 062 return false; 063 064 point p1 = new point(pp1.x + 1, pp1.y + 1); 065 point p2 = new point(pp2.x + 1, pp2.y + 1); 066 int data = new int109; 067 for (int i = 0; i 10; i+) 068 for (int j = 0; j 9; j+) 069 dataij = -1; 070 07
33、1 072 for (int i = 0; i 8; +i) 073 for (int j = 0; j 7; +j) 074 datai + 1j + 1 = mapij; 075 076 077 if (judgenone(p1, p2, data) 078 temp_point.clear(); 079 return true; 080 081 if (judgeone(p1, p2, data) 082 return true; 083 084 if (judgetwo(p1, p2, data) 085 return true; 086 087 return false; 088 0
34、89 090 /* 091 * 判断游戏是否结束 092 * param map 093 * return 094 */ 095 public static boolean ckeckover(int map) 096 boolean result = true; 097 for (int i = 0; i 8; +i) 098 for (int j = 0; j 7; +j) 099 if (mapij != -1) 100 result = false; 101 break; 102 103 104 105 if (!result) 106 break; 107 108 if (resul
35、t) 109 return true; 110 result = true; 111 for (int i = 0; i 8; +i) 112 for (int j = 0; j 7; +j) 113 for (int m = 0; m 8; +m) 114 for (int n = 0; n 7; +n) 115 if (candecrease(new point(i, j), new point(m, n), map) 116 return false; 117 118 119 120 121 122 return result; 123 124 125 /* 126 * 返回当前的联通路
36、径 127 * return 128 */ 129 public static arraylist getlist() 130 return temp_point; 131 132 133 / 判断竖 134 private static boolean judgevertical(point p1, point p2, int map) 135 if (p1.x != p2.x) 136 return false; 137 138 for (int i = (p1.y p2.y) ? p1.y : p2.y) + 1; i p2.y) ? p1.y 139 : p2.y); i+) 140 if (mapp1.xi != -1) 141 return false; 142 143 144 return true; 145 146 147 / 判断横 148 private static boolean judgehorizontal(point p1, point p2, int map) 149 if (p1.y != p2.y) 150 return false; 151 152 for (int i = (p1.x p2.x) ? p1.x : p2.x) + 1; i p2.x
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 38055.1-2025越野叉车安全使用要求第1部分:伸缩臂式叉车
- 毛巾产品的生命周期评估考核试卷
- 社会心理学在人机交互设计中的应用考核试卷
- 涂料配方设计考核试卷
- 电子元器件识别与应用考核试卷
- 社交心理学与消费者心理分析考核试卷
- 纺织机械的边缘计算服务发展趋势预测考核试卷
- 服装批发过程中的质量控制考核试卷
- 禽类屠宰行业绿色可持续发展考核试卷
- 海底设施施工质量控制与验收考核试卷
- 《内科常见病的诊治》课件
- 离心泵有效汽蚀余量计算公式
- 第十一章计划调控法律制度
- 《我的家乡日喀则》课件
- 语文版一年级下册语文阅读理解(15篇)
- 华文版书法五年级下册 第12课 同字框 教案
- 国网装表接电(初级)理论考试复习题库(含答案)
- 实验四酸性磷酸酶及值测定
- 劳动保障协理员试题
- 《多边形的面积》单元整体作业设计
- 同济大学《高等数学》第七版上、下册答案(详解)
评论
0/150
提交评论