




已阅读5页,还剩19页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
主要功能实现伪代码1、1OnePieceGame类的伪代码连连看的主要实现过程public class OnePieceGame extends Activity /* Called when the activity is first created. */private ProgressBar pb;private TextView show_RemainTime;private CtrlView cv;public static final int START_ID = Menu.FIRST;public static final int REARRARY_ID = Menu.FIRST + 1;public static final int END_ID = REARRARY_ID + 1;private int dormant = 1000;private boolean isCancel=true;Overridepublic void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.main);findViews();mRedrawHandler.sleep(dormant);private RefreshHandler mRedrawHandler = new RefreshHandler();class RefreshHandler extends Handler Overridepublic void handleMessage(Message msg) if(isCancel)run();elsepublic void sleep(long delayMillis) this.removeMessages(0);/ 移除信息队列中最顶部的信息(从顶部取出信息)sendMessageDelayed(obtainMessage(0), delayMillis);/ 获得顶部信息并延时发送;public void run() if (cv.PROCESS_VALUE 0 & cv.much != 0) cv.PROCESS_VALUE-;pb.setProgress(cv.PROCESS_VALUE);show_RemainTime.setText(String.valueOf(cv.PROCESS_VALUE);mRedrawHandler.sleep(dormant); else if (cv.PROCESS_VALUE = 0 & cv.much != 0) cv.setEnabled(false);dialogForFail().show(); else if (cv.PROCESS_VALUE != 0 & cv.much = 0) cv.setEnabled(false);dialogForSucceed().show();private void findViews() pb = (ProgressBar) findViewById(R.id.pb);show_RemainTime = (TextView) findViewById(R.id.show_remainTime);cv = (CtrlView) findViewById(R.id.cv);pb.setMax(cv.GAMETIME);pb.incrementProgressBy(-1);pb.setProgress(cv.PROCESS_VALUE);Overridepublic boolean onCreateOptionsMenu(Menu menu) / TODO Auto-generated method stubmenu.add(0, START_ID, 0, R.string.newgame);menu.add(0, REARRARY_ID, 0, R.string.rearrage);return super.onCreateOptionsMenu(menu);Overridepublic boolean onOptionsItemSelected(MenuItem item) switch (item.getItemId() case START_ID:newPlay();break;case REARRARY_ID:cv.rearrange();cv.PROCESS_VALUE = cv.PROCESS_VALUE - 5;pb.setProgress(cv.PROCESS_VALUE);break;default:break;return super.onOptionsItemSelected(item);Overrideprotected void onStop() isCancel=false;pb = null;cv = null;super.onStop();Overrideprotected void onDestroy()isCancel=false;super.onDestroy();Overrideprotected void onStart()isCancel=false;newPlay();isCancel=true;super.onStart();/Override/protected void onRestart()/cv.reset();/super.onRestart();/public void newPlay() cv.reset();pb.setProgress(cv.GAMETIME);cv.PROCESS_VALUE = cv.GAMETIME;mRedrawHandler.sleep(dormant);cv.setEnabled(true);public AlertDialog dialogForSucceed() AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setIcon(R.drawable.icon).setMessage(R.string.succeedInfo).setPositiveButton(R.string.next,new DialogInterface.OnClickListener() public void onClick(DialogInterface dialog,int which) / TODO Auto-generated method stubdormant = dormant - 300;newPlay();).setNeutralButton(R.string.again_challenge,new DialogInterface.OnClickListener() public void onClick(DialogInterface dialog,int which) / TODO Auto-generated method stubnewPlay(););return builder.create();public AlertDialog dialogForFail() AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setIcon(R.drawable.icon).setMessage(R.string.failInfo).setPositiveButton(R.string.again_challenge,new DialogInterface.OnClickListener() public void onClick(DialogInterface dialog,int which) / TODO Auto-generated method stubnewPlay();).setNegativeButton(R.string.exit,new DialogInterface.OnClickListener() public void onClick(DialogInterface dialog,int which) / TODO Auto-generated method stubisCancel=false;finish(););return builder.create();主要功能实现伪代码2、1 CtrlView类的伪代码主要实现连连看的具体算法。public class CtrlView extends GameView /通过extends另外一个接口(gameView)来添加方法public final int GAMETIME = 300;/final:只占有一份不可改变的存储空间。public final int UPTIME = 1;public int PROCESS_VALUE = 300;public static boolean CURRENT_CH = false;/static:boolean型值不可改变current:接口public int CURRENT_TYPE = 0;private Point C_POINT;private Point P_POINT;LinkedList li;public CtrlView(Context context, AttributeSet attrs) super(context, attrs);initType();initGrid();much = (row - 2) * (col - 2);public CtrlView(Context context, AttributeSet attrs, int defStyle) super(context, attrs, defStyle);initType();initGrid();much = (row - 2) * (col - 2);public boolean onTouchEvent(MotionEvent event) if (event.getAction() != MotionEvent.ACTION_DOWN)return super.onTouchEvent(event);int selX = (int) (event.getX() / width);int selY = (int) (event.getY() / height);if (gridselXselY = 0)return true;else if (CURRENT_CH = false) select(selX, selY);CURRENT_CH = true;P_POINT = new Point(selX, selY); else C_POINT = new Point(selX, selY);lineType = 0;if (checkLink(P_POINT, C_POINT) isLine = true;much = much - 2;if (0 PROCESS_VALUE& (PROCESS_VALUE + UPTIME) GAMETIME) PROCESS_VALUE = PROCESS_VALUE + UPTIME;invalidate();mRedrawHandler.sleep(300);CURRENT_CH = false;return true;public void reset() /重启CURRENT_CH = false;CURRENT_TYPE = 0;C_POINT = null;P_POINT = null;lineType = 0;isLine = false;Point p = null;initType();initGrid();/grid:表格much = (row - 2) * (col - 2);invalidate();public void rearrange() /重新排序CURRENT_CH = false;CURRENT_TYPE = 0;C_POINT = null;P_POINT = null;lineType = 0;isLine = false;Point p = null;List temp = new ArrayList();for (int i = 0; i row; i+) for (int j = 0; j col; j+) if (gridij != 0) temp.add(gridij);type.clear();Random ad = new Random();/随机数流for (int i = 0; i temp.size(); i+) type.add(temp.get(i);temp.clear();temp = null;for (int i = 0; i row; i+) for (int j = 0; j col; j+) if (gridij != 0) int index = ad.nextInt(type.size();gridij = type.get(index);type.remove(index);invalidate();private RefreshHandler mRedrawHandler = new RefreshHandler();class RefreshHandler extends Handler Overridepublic void handleMessage(Message msg) isLine = false;gridP_POINT.xP_POINT.y = 0;gridC_POINT.xC_POINT.y = 0;CtrlView.this.invalidate();public void sleep(long delayMillis) this.removeMessages(0);/ 移除信息队列中最顶部的信息(从顶部取出信息)sendMessageDelayed(obtainMessage(0), delayMillis);/ 获得顶部信息并延时发送;public class Point public int x;public int y;public Point(int newx, int newy) this.x = newx;this.y = newy;public boolean equals(Point p) if (p.x = x & p.y = y)return true;elsereturn false;/用一二维数组存放MAP,-1表示没有tu可以连通,非-1表示不同的图案/横向检测private boolean horizon(Point a, Point b) if (a.x = b.x & a.y = b.y)/如果点击的是同一个图案,直接返回FALSEreturn false;int x_start = a.y = b.y ? a.y : b.y;int x_end = a.y = b.y ? b.y : a.y;for (int x = x_start + 1; x x_end; x+)/只要一个不是-1,直接返回FALSEif (grida.xx != 0) return false;p = new Point a, b ;lineType = H_LINE;return true;/纵向检测private boolean vertical(Point a, Point b) if (a.x = b.x & a.y = b.y)return false;int y_start = a.x = b.x ? a.x : b.x;int y_end = a.x = b.x ? b.x : a.x;for (int y = y_start + 1; y y_end; y+)if (gridya.y != 0)return false;p = new Point a, b ;lineType = V_LINE;return true;/一个拐角的检测,如果一个拐角能联通的话,则必须存在CD两点,其中c点的横坐标和A相同,/纵坐标与B相同,d点的横坐标和b相同,纵坐标与A相同,private boolean oneCorner(Point a, Point b) Point c = new Point(a.x, b.y);Point d = new Point(b.x, a.y);/c点上必须没有障碍if (gridc.xc.y = 0) boolean method1 = horizon(a, c) & vertical(b, c);p = new Point a, new Point(c.x, c.y), b ;lineType = ONE_C_LINE;return method1;if (gridd.xd.y = 0) /d点上必须没有障碍boolean method2 = vertical(a, d) & horizon(b, d);p = new Point a, new Point(d.x, d.y), b ;lineType = ONE_C_LINE;return method2; else return false;/两个拐角的检测,如果两个拐角能连通的话,则必须存在一些连线,这些连线夹在A。B的/横纵坐标之间,这样的线就Line这个类存储,direct是线的方向,用0.1表示不同的方向/Line类结构如下class Line public Point a;public Point b;public int direct;/1横线,0竖线public Line() public Line(int direct, Point a, Point b) this.direct = direct;this.a = a;this.b = b;/从AB点的横纵坐标两个方向进行扫描,就是Scan函数做的事情,把合适的线用LinkList存起来private LinkedList scan(Point a, Point b) li = new LinkedList();/保存求解后的线/从a,c连线向b扫描,扫描竖线/扫描A点左边的所有线for (int y = a.y; y = 0; y-)if (grida.xy = 0 & gridb.xy = 0& vertical(new Point(a.x, y), new Point(b.x, y)/存在完整路线li.add(new Line(0, new Point(a.x, y), new Point(b.x, y);/扫描A点右边的所有线for (int y = a.y; y = 0; x-)if (gridxa.y = 0 & gridxb.y = 0& horizon(new Point(x, a.y), new Point(x, b.y)li.add(new Line(1, new Point(x, a.y), new Point(x, b.y);/扫描A电下面的所有线for (int x = a.x; x col; x+)if (gridxa.y = 0 & gridxb.y = 0& horizon(new Point(x, a.y), new Point(x, b.y)li.add(new Line(1, new Point(x, a.y), new Point(x, b.y);return li;/两个拐角的算法,取出LinkList里面的线,测试A.B 到该线的两点是否连通/对所有找到的符合线进行判断,看看AC,DB是否同样也可以消除private boolean twoCorner(Point a, Point b) li = scan(a, b);if (li.isEmpty()/没有完整的空白线段,不能连接return false;for (int index = 0; index li.size(); index+) Line line = (Line) li.get(index);if (line.direct = 1) /横线上的扫描段,找到了竖线if (vertical(a, line.a) & vertical(b, line.b) /找到了,返回p = new Point a, line.a, line.b, b ;lineType = TWO_C_LINE;return true;/横线上的扫描段,找到了横线 else if (horizon(a, line.a) & horizon(b, line.b) p = new Point a, line.a, line.b, b ;lineType = TWO_C_LINE;return true;return false;/前面的函数由以下这个总的调用函数来调用,传入两个点,就可以判断这两个点是否符合算法了public boolean checkLink(Point a, Point b) if (grida.xa.y != gridb.xb.y)/ 如果图案不同,直接为falsereturn false;if (a.x = b.x & horizon(a, b)return true;if (a.y = b.y & vertical(a, b)return true;if (oneCorner(a, b)return true;elsereturn twoCorner(a, b);主要功能实现伪代码3、1 GameView类的伪代码主要实现游戏界面的绘制public class GameView extends Viewpublic final int row = 10;public final int col = 10;public float width;public float height;private int selY;private int selX;public boolean isLine = false;public int grid = new introwcol;/储存按钮位置private Rect selRect = new Rect();public int lineType = 0;public final int V_LINE = 1;public final int H_LINE = 1;public final int ONE_C_LINE = 2;public final int TWO_C_LINE = 3;public int much = 0;Point p;public int imageType = new int R.drawable.aa, R.drawable.bb,R.drawable.cc, R.drawable.dd, R.drawable.ee, R.drawable.ff,R.drawable.gg, R.drawable.hh, R.drawable.ii, R.drawable.jj,R.drawable.kk, R.drawable.ll, R.drawable.mm, R.drawable.nn,R.drawable.oo, R.drawable.pp ;public Bitmap image;public List type = new ArrayList();public GameView(Context context, AttributeSet attrs) super(context, attrs);this.setFocusable(true);this.setFocusableInTouchMode(true);public GameView(Context context, AttributeSet attrs, int defStyle) super(context, attrs, defStyle);this.setFocusable(true);this.setFocusableInTouchMode(true);public void reset() /图片的填充格式public void fillImage(Context context) int lth = imageType.length;image = new Bitmaplth;for (int i = 0; i lth; i+) Bitmap bitmap = Bitmap.createBitmap(int) width, (int) height,Bitmap.Config.ARGB_8888);Drawable drw;Canvas canvas = new Canvas(bitmap);drw = context.getResources().getDrawable(imageTypei);/drw.setBounds(1, 1, 30, 30);/绘制图片矩形框的大小drw.setBounds(3, 3, 31, 40);drw.draw(canvas);imagei = bitmap;public void initType() int size = (row - 2) * (col - 2);int count = size / imageType.length;for (int j = 0; j imageType.length; j+) for (int i = 0; i count; i+) type.add(imageTypej);public void select(int x, int y) invalidate(selRect);selX = Math.min(Math.max(x, 0), 9);selY = Math.min(Math.max(y, 0), 9);getRect(selX, selY, selRect);invalidate(selRect);private void getRect(int x, int y, Rect rect) rect.set(int) (x * width), (int) (y * height),(int) (x * width + width), (int) (y * height + height);Overrideprotected void onDraw(Canvas canvas) Paint background = new Paint();background.setColor(Color.DKGRAY);canvas.drawRect(0, 0, getWidth(), getHeight(), background);Paint hilite = new Paint();hilite.setColor(getResources().getColor(R.color.hilite);Paint light = new Paint();light.setColor(getResources().getColor(R.color.light);/画出网格for (int i = 0; i = 9; i+) canvas.drawLine(0, i * height, getWidth(), i * height, light);canvas.drawLine(0, i * height + 1, getWidth(), i * height + 1,hilite);canvas.drawLine(i * width, 0, i * width, getHeight(), light);canvas.drawLine(i * width + 1, 0, i * width + 1, getHeight(),hilite);if (CtrlView.CURRENT_CH) Paint selected = new Paint();selected.setColor(getResources().getColor(R.color.puzzle_selected);canvas.drawRect(selRect, selected);for (int i = 0; i 9; i+) for (int j = 0; j 9; j+) if (gridij != 0) canvas.drawBitmap(imageArrays.binarySearch(imageType,gridij), i * width, j * height, null);if (isLine) Paint lineColor = new Paint();lineColor.setColor(Color.RED);switch (lineType) case V_LINE:canvas.drawLine(p0.x * width + width / 2, p0.y * height+ height / 2, p1.x * width + width / 2, p1.y* height + height / 2, lineColor);break;case ONE_C_LINE:canvas.drawLine(p0.x * width + width / 2, p0.y * height+ height / 2, p1.x * width + width / 2, p1.y* height + height / 2, lineColor);canvas.drawLine(p1.x * width + width / 2, p1.y * height+ height / 2, p2.x * width + width / 2, p2.y* height + height / 2, lineColor);break;case TWO_C_LINE:canvas.drawLine(p0.x * width + width / 2, p0.y * height+ height / 2, p1.x * width + width / 2, p1.y* height + height / 2, lineColor);canvas.drawLine(p1.x * width + width / 2, p1.y * height+ height / 2, p2.x * width + width / 2, p2.y* height + height / 2, lineColor);canvas.drawLine(p3.x * width + width / 2, p3.y * height+ height / 2, p2.x * width + width / 2, p2.y* height + height / 2, lineColor);break;default:break;super.onDraw(canvas);Overrideprotected void onSizeChanged(int w, int h, int oldw, int oldh) width = w / row;height = h / col;/ getRect(1,1,selRect);fillImage(this.getContext();super.onSizeChanged(w, h, oldw, oldh);/产生随机数public void initGrid() Random ad = new Random();/for (int i = 0; i row; i+) for (int j = 0; j 0) int index = ad.nextInt(type.size();gridij = type.get(index);type.remove(index);主要功能实现伪代码4、1 jiemian类的伪代码在一个主容器LinearLayout下创建三个子容器LinearLayout ,再在三个子容器里分别加一个button,用来设计主界面,实现界面的跳转。主要代码:public class Jiemian extends Activity private Button button1;private Button button2;private Button button3;Overrideprotected void onCreate(Bundle savedInstanceStat
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 仓鼠养殖合同样本
- 工程招标廉洁承诺书
- 美容院转让协议书范例
- 分期付款买卖合同样式二零二五年
- 两人合伙开发公司合同标准文本
- 无中介二手房买卖简单合同范例二零二五年
- 销售部提成管理制
- 校长聘用合同校长聘用合同范文
- 产品商标授权使用合同标准文本
- 造价咨询实施方案
- 综合实践活动(1年级下册)第1课时 走近身边孝顺的好榜样-课件
- 城市道路养护技术规程
- 初中信息技术教学中的项目式学习
- 部编版语文二年级下册第3单元核心素养教案
- 基于PLC的小区排水控制系统设计毕业论文
- DB43-T 1712-2019 银行业金融机构智能预警系统安全防范要求
- 2023年云南省接受军转干部安置考试试题
- 初三英语试卷分析失分原因和改进措施
- 关于在生产过程中物料流转的交接和管理规定
- 2022年高考真题及答案解析《历史、地理、政治》(湖北卷)
- 高中数学人教A版空间几何体(省一等奖)
评论
0/150
提交评论