文档详情

基于Android系统的连连看详细设计说明书

痛***
实名认证
店铺
DOC
727KB
约15页
文档ID:135393121
基于Android系统的连连看详细设计说明书_第1页
1/15

基于Android系统的连连看详细设计说明书引言1.1、编写目的本文档用于说明本游戏开发的详细过程,使委托方了解软件的内部结构,从而对连连看有更深入的了解,便于后期的维护和修改工作 1.2、背景说明:a. 待开发软件系统的名称:基于Android系统的连连看游戏设计  b. 本项目的任务提出者:学校开发者:游戏开发小组用户:喜欢玩游戏的人项目开发环境:eclipse、Android系统平台1.3、定义 Android 连连看 详细设计1.4、参考资料 《Android开发指南》Eoeandroid开发论坛2、程序系统的结构   连连看游戏结构如下:连连看消息响应设计算法设计界面设计菜单设计绘图响应时间响应画线设计消除算法设计鼠标响应进度条设计框架设计结束游戏规则说明游戏设置开始游戏主要有四个大类:class GameView //游戏视类,搭建游戏基框架Class BoardView //游戏视类 处理游戏中的情况,包括界面生成,算法,一部分消息响应Class SoundPlay //用于处理游戏中的音乐播放class DotaActivity //用于处理游戏中的消息提示class GameSetDialog //用于菜单的设计,游戏难度的设定等Class DotaDialog //处理游戏结束对话框事件 3、菜单设计说明 3.1、程序描述   主要功能:用于为玩家提供操作提示,便于玩家了解游戏的规则。

 可扩展性:能够适应应用要求的变化和修改,具有灵活的可扩充性3.2、功能开始界面,有开始游戏,设置游戏难度功能游戏设置框3.3、性能   当用户选择菜单时能够快速反应,以满足用户的要求  3.4、输人项用户点击按钮3.5、输出项 4个菜单选项3.6、算法   //定义菜单类,接口为OnClickListener,用于接收用户的单击消息 public class GameSetDialog extends Dialog implements OnClickListener{ private GameView gameview; private Context context; private RadioButton radioButton_pt; private RadioButton radioButton_yg; private RadioButton radioButton_hs; private RadioButton radioButton_music; private Button button_ok; private Button button_cancle; private TextView textView; private boolean music_set = true; public GameSetDialog(Context context, GameView gameview) { super(context); this.gameview = gameview; this.context = context; this.setContentView(R.layout.game_set); radioButton_pt = (RadioButton) findViewById(R.id.RadioButton_PT);//普通难度 radioButton_yg = (RadioButton) findViewById(R.id.RadioButton_YG);//中等难度 radioButton_hs = (RadioButton) findViewById(R.id.RadioButton_HS);//苦难难度 radioButton_music = (RadioButton) findViewById(R.id.RadioButton_Music);//音乐状态 button_ok = (Button)findViewById(R.id.set_ok); button_cancle = (Button) findViewById(R.id.set_cancle); textView = (TextView)findViewById(R.id.text_message); radioButton_pt.setOnClickListener(this); radioButton_yg.setOnClickListener(this); radioButton_hs.setOnClickListener(this); radioButton_music.setOnClickListener(this); button_ok.setOnClickListener(this); button_cancle.setOnClickListener(this); this.setCancelable(false); } @Override public void onClick(View v) { // this.dismiss(); switch(v.getId()){ case R.id.RadioButton_PT: if (radioButton_pt.isChecked()) { textView.setText("当前难度你有3次帮助机会"); } break; case R.id.RadioButton_YG: if (radioButton_yg.isChecked()) { textView.setText("当前难度你有1次帮助机会"); } break; case R.id.RadioButton_HS: if (radioButton_hs.isChecked()) { textView.setText("当前难度你有0次帮助机会"); } break; case R.id.RadioButton_Music: if (radioButton_music.isChecked() && music_set == true) { radioButton_music.setText("音乐状态(关闭)"); music_set = false; } else if (music_set == false && radioButton_music.isChecked()) { radioButton_music.setText("音乐状态(开启)"); music_set = true; } break; case R.id.set_cancle: this.dismiss(); return; case R.id.set_ok: if (radioButton_pt.isChecked()) {// Toast.makeText(context, "pt", Toast.LENGTH_SHORT).show(); gameview.setHelpTimes(3); } else if (radioButton_yg.isChecked()){// Toast.makeText(context, "yao", Toast.LENGTH_SHORT).show(); gameview.setHelpTimes(1); } else if (radioButton_hs.isChecked()) { gameview.setHelpTimes(0); Toast.makeText(context, "hs", Toast.LENGTH_SHORT).show(); } gameview.setMusicOpen(music_set); this.dismiss(); break; } }}3.7、接口API函数 3.8、限制条件无明显限制条件4、界面设计说明4.1、程序描述   主要功能:用于为玩家提供可视化的游戏界面,增加了游戏的可玩性。

 可扩展性:能够适应应用要求的变化和修改,具有灵活的可扩充性4.2、功能生成游戏界面,生成进度条如下图:4.3、性能   能够快速的随机生成符合用户需要的界面 4.4、输人项无输入4.5、输出项 游戏界面4.6、算法     /** * 产生随机的图片下标,用于每次产生随机的图片 */ private void RandomNum() { random = new Random(); int i = 0; int t; int j; int flag = 0; for (j = 0; j < tmp.length; j++) { tmp[j] = 1000000; } while (true) { t = random.nextInt(totalIcon); for (j = 0; j < tmp.length; j++) { if (t != tmp[j]) { continue; } else { flag = 1; } } if (flag == 1) { flag = 0; continue; } tmp[i] = t; i++; if (i == (iconCounts)) break; } } public BoardView(Context context, AttributeSet atts) { super(context, atts); calIconSize(); int i; Resources r = getResources(); for (i = 0; i < totalIcon; i++) { myIcon[i] = R.drawable.dota_face1 + i; } RandomNum(); for (i = 0; i < iconCounts; i++) { // loadBitmaps(i, r.getDrawable(reArray[tmp[i]])); loadBitmaps(i, r.getDrawable(myIcon[tmp[i]])); } } /** * * 重新排列 */ public void reSetBoardView() { Resources r = getResources(); RandomNum(); int i; for (i = 1; i < iconCounts; i++) { loadBitmaps(i, r.getDrawable(myIcon[tmp[i]])); } } /** * * 计算图标的长宽 */ private void calIconSize() { DisplayMetrics dm = new DisplayMetrics(); ((Activity) this.getContext()).getWindowManager().getDefaultDisplay() .getMetrics(dm); iconSize = dm.widthPixels / (xCount); }4.7、接口API函数 4.8、限制条件无明显限制条件5、主要算法设计说明5.1、程序描述   主要功能:完成图片的消除功能,消除时画线功能,重新排列功能。

 可扩展性:能够适应应用要求的变化和修改,具有灵活的可扩充性5.2、功能完成连连看游戏的核心算法5.3、性能   能够快速判断两图片是否能消除,并能在消除时进行画线操作隔一段时间,能够打乱顺序进行重新排列 5.4、输人项用户点击、时间条5.5、输出项 消除匹配的图片5.6、算法    List p1E = new ArrayList(); List p2E = new ArrayList(); private boolean link(Point p1, Point p2) { if (p1.equals(p2)) { return false; } path.clear(); if (map[p1.x][p1.y] == map[p2.x][p2.y]) { if (linkD(p1, p2)) { path.add(p1); path.add(p2); return true; } Point p = new Point(p1.x, p2.y); if (map[p.x][p.y] == 0) { if (linkD(p1, p) && linkD(p, p2)) { path.add(p1); path.add(p); path.add(p2); return true; } } p = new Point(p2.x, p1.y); if (map[p.x][p.y] == 0) { if (linkD(p1, p) && linkD(p, p2)) { path.add(p1); path.add(p); path.add(p2); return true; } } expandX(p1, p1E); expandX(p2, p2E); for (Point pt1 : p1E) { for (Point pt2 : p2E) { if (pt1.x == pt2.x) { if (linkD(pt1, pt2)) { path.add(p1); path.add(pt1); path.add(pt2); path.add(p2); return true; } } } } expandY(p1, p1E); expandY(p2, p2E); for (Point pt1 : p1E) { for (Point pt2 : p2E) { if (pt1.y == pt2.y) { if (linkD(pt1, pt2)) { path.add(p1); path.add(pt1); path.add(pt2); path.add(p2); return true; } } } } return false; } return false; } private boolean linkD(Point p1, Point p2) { if (p1.x == p2.x) { int y1 = Math.min(p1.y, p2.y); int y2 = Math.max(p1.y, p2.y); boolean flag = true; for (int y = y1 + 1; y < y2; y++) { if (map[p1.x][y] != 0) { flag = false; break; } } if (flag) { return true; } } if (p1.y == p2.y) { int x1 = Math.min(p1.x, p2.x); int x2 = Math.max(p1.x, p2.x); boolean flag = true; for (int x = x1 + 1; x < x2; x++) { if (map[x][p1.y] != 0) { flag = false; break; } } if (flag) { return true; } } return false; } private void expandX(Point p, List l) { l.clear(); for (int x = p.x + 1; x < xCount; x++) { if (map[x][p.y] != 0) { break; } l.add(new Point(x, p.y)); } for (int x = p.x - 1; x >= 0; x--) { if (map[x][p.y] != 0) { break; } l.add(new Point(x, p.y)); } } private void expandY(Point p, List l) { l.clear(); for (int y = p.y + 1; y < yCount; y++) { if (map[p.x][y] != 0) { break; } l.add(new Point(p.x, y)); } for (int y = p.y - 1; y >= 0; y--) { if (map[p.x][y] != 0) { break; } l.add(new Point(p.x, y)); } }5.6.2、图片消除的画线 @Override protected void onDraw(Canvas canvas) { /** * 绘制连通路径,然后将路径以及两个图标清除 */ if (path != null && path.length >= 2) { for (int i = 0; i < path.length - 1; i++) { Paint paint = new Paint(); paint.setColor(Color.CYAN); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(3); Point p1 = indextoScreen(path[i].x, path[i].y); Point p2 = indextoScreen(path[i + 1].x, path[i + 1].y); canvas.drawLine(p1.x + iconSize / 2, p1.y + iconSize / 2, p2.x + iconSize / 2, p2.y + iconSize / 2, paint); } Point p = path[0]; map[p.x][p.y] = 0; p = path[path.length - 1]; map[p.x][p.y] = 0; selected.clear(); path = null; } /** * 绘制棋盘的所有图标 当这个坐标内的值大于0时绘制 */ for (int x = 1; x < map.length; x += 1) { for (int y = 0; y < map[x].length; y += 1) { if (map[x][y] > 0) { Point p = indextoScreen(x, y); canvas.drawBitmap(icons[map[x][y]], p.x, p.y, null); } } } /** * 绘制选中图标,当选中时图标放大显示 */ for (Point position : selected) { Point p = indextoScreen(position.x, position.y); if (map[position.x][position.y] >= 1) { canvas.drawBitmap(icons[map[position.x][position.y]], null, new Rect(p.x - 5, p.y - 5, p.x + iconSize + 5, p.y + iconSize + 5), null); } } }5.6.3、重新排列隔一段时间后,将原有的排列随机打乱,进行重新排列/** * 产生随机的图片下标,用于每次产生随机的图片 */ private void RandomNum() { random = new Random(); int i = 0; int t; int j; int flag = 0; for (j = 0; j < tmp.length; j++) { tmp[j] = 1000000; } while (true) { t = random.nextInt(totalIcon); for (j = 0; j < tmp.length; j++) { if (t != tmp[j]) { continue; } else { flag = 1; } } if (flag == 1) { flag = 0; continue; } tmp[i] = t; i++; if (i == (iconCounts)) break; } } /** * * 重新排列 */ public void reSetBoardView() { Resources r = getResources(); RandomNum(); int i; for (i = 1; i < iconCounts; i++) { loadBitmaps(i, r.getDrawable(myIcon[tmp[i]])); } }5.7、接口API函数 5.8、限制条件无明显限制条件   5.9、尚未解决的问题不能进行死锁判断,但是有重新排列的功能,可以很大程度上避免死锁。

没有加分功能没有提示功能。

下载提示
相关文档
正为您匹配相似的精品文档