




已阅读5页,还剩36页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
连连看java程序-论文连连看java程序package kyodai.map;import java.awt.*;import javax.swing.*;import kyodai.*;/* 消除连连看方块的类*/public class AnimateDelete implements Runnable static JButton dots;static long delay = 20l;int array = new int44; /最大距离只可能为2行1列private int count = 0;private volatile Thread thread;public AnimateDelete(JButton dots) this.dots = dots;array = new int0;/* * 初始化*/public AnimateDelete(int direct, Point a, Point b) initArray();calcTwoPoint(direct, a, b);start();/* * direct 方向 * 1表示a, b在同一直线上,b, c在同一竖线上; * 0表示a, b在同一竖线上,b, c在同一直线上 */public AnimateDelete(int direct, Point a, Point b, Point c) initArray();if (direct = 1) /先横后竖calcTwoPoint(1, a, b);count-;calcTwoPoint(0, b, c);else calcTwoPoint(0, a, b);count-;calcTwoPoint(1, b, c);start();/* * direct 方向 * 1表示a, b为横线,b, c为竖线, c, d为横线 * 0表示a, b为竖线,b, c为横线,c, d为竖线*/public AnimateDelete(int direct, Point a, Point b, Point c, Point d) initArray();if (direct = 1) /横、竖、横方式处理calcTwoPoint(1, a, b);count-;calcTwoPoint(0, b, c);count-;calcTwoPoint(1, c, d);else /竖、横、竖方式处理calcTwoPoint(0, a, b);count-;calcTwoPoint(1, b, c);count-;calcTwoPoint(0, c, d);start();/* * 计算消除的两点*/private void calcTwoPoint(int direct, Point a, Point b) int offset = 0;if (direct = 1) /横向连接if (a.y b.y) /a点向b点是从右向左在水平线上消除for (int y = a.y; y = b.y; y-) offset = a.x * Setting.COLUMN + y;arraycount = offset;count+;else /a点向b点是从左向右在水平线上消除for (int y = a.y; y b.x) /a点向b点是从下向上垂直消除for (int x = a.x; x = b.x; x-) offset = x * Setting.COLUMN + a.y;arraycount = offset;count+;else /a点向b点是从上向下垂直消除for (int x = a.x; x = b.x; x+) offset = x * Setting.COLUMN + a.y;arraycount = offset;count+;/* * 设置动画速度*/public void setSpeed(int speed) delay = speed * 10;private void initArray() if (array = null | array.length = 0) return;public void test() if (array = null | array.length = 0) return;for (int i = 0; i array.length; i+) if (arrayi != -1) message( + arrayi + );System.out.println();public void start() thread = new Thread(this);thread.start();public void run() if (count 2) return;Thread currentThread = Thread.currentThread();boolean animate = true;while (thread = currentThread & animate) for (int i = 1; i count - 1; i+) dotsarrayi.setEnabled(true);dotsarrayi.setIcon(Kyodai.GuideIcon);try thread.sleep(delay);catch (InterruptedException ex) for (int i = 1; i count - 1; i+) dotsarrayi.setIcon(null);dotsarrayi.setEnabled(false);try thread.sleep(delay);catch (InterruptedException ex) dotsarray0.setIcon(null);dotsarray0.setEnabled(false);dotsarraycount - 1.setIcon(null);dotsarraycount - 1.setEnabled(false);animate = false;stop();public void stop() if (thread != null) thread = null;void message(String str) System.out.println(str);151连连看java程序package kyodai.map;import java.awt.Point;/* 定义直线的类*/public class Linepublic Point a;public Point b;public int direct;public Line()/* * 通过两点和方向构造直线*/public Line(int direct, Point a, Point b)this.direct = direct;this.a = a;this.b = b;package kyodai.map;import java.awt.Point;import java.util.Random;import java.util.Vector;/* 生成连连看方块的类*/public class Mapprivate int level;private int map;int array;private int restBlock;private Vector vector;AnimateDelete animate;private boolean test;public Map()level = 28;map = new int1017;array = new int170;restBlock = level * 4;vector = new Vector();test = false;initMap();public Map(int level)this.level = 28;map = new int1017;array = new int170;restBlock = this.level * 4;vector = new Vector();test = false;this.level = level;restBlock = level * 4;initMap();public void setTest(boolean test)this.test = test;public void setLevel(int level)this.level = level;restBlock = level * 4;initMap();private void initMap()for(int i = 0; i level; i+)arrayi * 4 = i + 1;arrayi * 4 + 1 = i + 1;arrayi * 4 + 2 = i + 1;arrayi * 4 + 3 = i + 1;random(array);for(int i = 0; i 10; i+)for(int j = 0; j 0; i-)int j = random.nextInt(i);int temp = arrayj;arrayj = arrayi - 1;arrayi - 1 = temp;public void earse(Point a, Point b)mapa.xa.y = 0;mapb.xb.y = 0;restBlock -= 2;public int getCount()return restBlock = 0 ? 0 : restBlock;public void refresh()int count = getCount();if(count = 0)return;int temp = new intcount;count = 0;for(int row = 0; row 10; row+)for(int col = 0; col 0)tempcount = maprowcol;count+;random(temp);count = 0;for(int row = 0; row 10; row+)for(int col = 0; col 0)maprowcol = tempcount;count+;private boolean horizon(Point a, Point b, boolean recorder)if(a.x = b.x & a.y = b.y)return 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+)if(mapa.xx != 0)return false;if(!test & recorder)animate = new AnimateDelete(1, a, b);return true;private boolean vertical(Point a, Point b, boolean recorder)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 = 0; y-)if(mapa.xy = 0 & mapb.xy = 0 & vertical(new Point(a.x, y), new Point(b.x, y), false)v.add(new Line(0, new Point(a.x, y), new Point(b.x, y);for(int y = a.y; y = 0; x-)if(mapxa.y = 0 & mapxb.y = 0 & horizon(new Point(x, a.y), new Point(x, b.y), false)v.add(new Line(1, new Point(x, a.y), new Point(x, b.y);for(int x = a.x; x 10; x+)if(mapxa.y = 0 & mapxb.y = 0 & horizon(new Point(x, a.y), new Point(x, b.y), false)v.add(new Line(1, new Point(x, a.y), new Point(x, b.y);return v;private boolean twoCorner(Point a, Point b)vector = scan(a, b);if(vector.isEmpty()return false;for(int index = 0; index vector.size(); index+)Line line = (Line)vector.elementAt(index);if(line.direct = 1)if(vertical(a, line.a, false) & vertical(b, line.b, false)if(!test)animate = new AnimateDelete(0, a, line.a, line.b, b);return true; else if(horizon(a, line.a, false) & horizon(b, line.b, false)if(!test)animate = new AnimateDelete(1, a, line.a, line.b, b);return true;return false;public boolean test(Point a, Point b)if(mapa.xa.y != mapb.xb.y)return false;if(a.x = b.x & horizon(a, b, true)return true;if(a.y = b.y & vertical(a, b, true)return true;if(oneCorner(a, b)return true;elsereturn twoCorner(a, b);public Line findNext(Point a)Point b = new Point();a = findFirst(a);if(a.equals(new Point(-1, -1)return new Line(0, a, b);for(; !a.equals(new Point(-1, -1); a = findFirst(a)for(b = findSecond(a, b); !b.equals(new Point(-1, -1); b = findSecond(a, b)if(test(a, b)return new Line(1, a, b);return new Line(0, a, b);private Point findFirst(Point a)int offset = 0;if(a != null)offset = a.x * 17 + a.y;if(offset 0)offset = -1;for(int x = offset + 1; x 170; x+)int row = Math.round(x / 17);int col = x - row * 17;if(maprowcol != 0)return new Point(row, col);(Point a, Point b)if(a = null)return new Point(-1, -1);if(a.x + a.y 0)return new Point(-1, -1);if(b = null)b = new Point(0, 0);int offset = Math.max(a.x * 17 + a.y, b.x * 17 + b.y);for(int x = offset + 1; x 170; x+)int row = Math.round(x / 17);int col = x - row * 17;if(maprowcol = mapa.xa.y)return new Point(row, col);return new Point(-1, -1);public int getMap()return map;水晶连连看package kyodai.map;import javax.swing.*;import java.awt.*;import java.awt.event.*;import .*;import kyodai.*;/* 生成图形用户界面*/public class MapUI extends JPanelimplements ActionListener, Runnable private Map map;private JButton dots;private Point lastPoint = new Point(0, 0); /上一个点的坐标private boolean isSelected = false; /是否已经选择了一个点private int score = 0; /记录用户的得分private ClockAnimate clockAnimate; /同步显示时钟/AnimateDelete animate; /动画JButton goTop10;private ScoreAnimate scoreAnimate;int stepScore = 0; /计算距离的分int limitTime = 0; /限定寻找的时间(秒)private boolean isPlaying = false; /当前是否正在游戏中/* * 构造函数 */public MapUI(Map map, JButton dots) this.map = map;this.dots = dots;GridLayout gridLayout = new GridLayout();this.setLayout(gridLayout);gridLayout.setRows(Setting.ROW);gridLayout.setColumns(Setting.COLUMN);gridLayout.setHgap(2);gridLayout.setVgap(2);this.setLayout(gridLayout);this.setBackground(Kyodai.DarkColor);for (int row = 0; row Setting.ROW; row+) for (int col = 0; col Setting.COLUMN; col+) int index = row * Setting.COLUMN + col;dotsindex.addActionListener(this);this.add(dotsindex);/* * 设置地图 */public void setMap(Map map) this.map = map;/* * 获取主界面上的goTop10按钮,以便操作*/public void setTop10Button(JButton goTop10) this.goTop10 = goTop10;/* * 根据数组来绘置画面*/private void paint() for (int row = 0; row Setting.ROW; row+) for (int col = 0; col 0) dotsindex.setIcon(Kyodai.BlocksIconmap.getMap()rowcol - 1);dotsindex.setEnabled(true);else dotsindex.setIcon(null);dotsindex.setEnabled(false);public void repaint(Graphics g) paint();/* * 判断当前是否已经没有可消除的方块*/private boolean validMap(Point a) if (map.getCount() = 0) return true;Line line = new Line(0, new Point(), new Point();map.setTest(true); /只测试line = map.findNext(a);int offset = 0;if (line.direct = 1) /找到了可消除的return true;else return false;/* * 更新当前显示的分数*/private void showScore(int l, int c) if (scoreAnimate = null) return;scoreAnimate.setScore(l, c);/* * 刷新当前的排列方式*/public void refresh() if (!isPlaying) /不在游戏中,返回return;if (map.getCount() = 0) Kyodai.showHint(还刷,都没了!);if (Setting.Sound = 1) new Sound(Sound.REFRESH);if (validMap(new Point( -1, -1) score -= Setting.freshScore;showScore(score - 1, score);else showScore(score, score + Setting.freshScore);score += Setting.freshScore;score -= Setting.freshScore;showScore(score - 1, score);map.refresh();paint();/* * 消除两个点*/void earse(Point a, Point b) /paint();int offset;offset = a.x * Setting.COLUMN + a.y;dotsoffset.setIcon(null);dotsoffset.setEnabled(false);offset = b.x * Setting.COLUMN + b.y;dotsoffset.setIcon(null);dotsoffset.setEnabled(false);/如果地图清除完成,关闭if (map.getCount() = 0) int remainTime = limitTime - clockAnimate.getUsedTime();message(剩余时间 = + remainTime);if (remainTime 0) showScore(score, score + remainTime * Setting.timeScore);score += remainTime * Setting.timeScore;isPlaying = false;stop();Kyodai.showHint(时间+ + remainTime * Setting.timeScore + ,想看看你的排名吗?);goTop10.setEnabled(true);else /test1(map.getDeleteArray();/* * 自动寻找最佳答案*/public void findNext(Point a) if (!isPlaying) /不在游戏中,返回return;if (map.getCount() = 0) Kyodai.showHint(你找昏了头吧,没了!);return;Line line = new Line(0, new Point(), new Point();map.setTest(true); /告诉map当前只是测试,并不需要进行删除动画line = map.findNext(a);int offset = 0;if (line.direct = 1) /找到了可消除的if (Setting.Sound = 1) new Sound(Sound.HINT);offset = line.a.x * Setting.COLUMN + line.a.y;dotsoffset.setBorder(Kyodai.Hint);offset = line.b.x * Setting.COLUMN + line.b.y;dotsoffset.setBorder(Kyodai.Hint);score -= Setting.hintScore;showScore(score - 1, score);else Kyodai.showHint(找不到,请刷新);/* * 自动找出并消除地图上的两个点*/public boolean bomb(Point a, boolean showMessage) if (!isPlaying) /不在游戏中,返回return false;if (map.getCount() = 0) Kyodai.showHint(你炸昏了头吧,没了!);return false;Line line = new Line(0, new Point(), new Point();map.setTest(false);line = map.findNext(a);int offset = 0;if (line.direct = 1) /找到了可消除的if (Setting.Sound = 1) new Sound(Sound.BOMB);offset = line.a.x * Setting.COLUMN + line.a.y;dotsoffset.setBorder(Kyodai.unSelected);offset = line.b.x * Setting.COLUMN + line.b.y;dotsoffset.setBorder(Kyodai.unSelected);map.earse(line.a, line.b);earse(line.a, line.b);score -= Setting.bombScore;showScore(score - 1, score);return true;else if (showMessage) Kyodai.showHint(炸弹用不了,请刷新!);return false;private void message(String str) Kyodai.showHint(str);/* * 自动游戏*/public void autoPlay() if (!isPlaying) /不在游戏中,返回return;/如果使用该功能,不计时间分limitTime = 0;while (map.getCount() 0) if (bomb(new Point( -1, -1), false) message(炸弹使用成功!);else message(找不到可用点,刷新);refresh();/* * 获取系统的计分板*/public void setScore(ScoreAnimate score) this.scoreAnimate = score;/* * 获取系统的计时板 */public void setClock(ClockAnimate clock) this.clockAnimate = clock;/* * 事件处理 */public void actionPerformed(ActionEvent e) JButton button = (JButton) e.getSource();int offset = Integer.parseInt(button.getActionCommand();int row, col;row = Math.round(offset / Setting.COLUMN);col = offset - row * Setting.COLUMN;/如果上面没有图片if (map.getMap()rowcol 1) return;/选择时的声音if (Setting.Sound = 1) new Sound(Sound.SELECT);if (isSelected) message(上次已经选择了一个点);message(上次选择点的坐标为: + lastPoint.x + , + lastPoint.y + 值为: + map.getMap()lastPoint.xlastPoint.y + 位移为: + (lastPoint.x * Setting.COLUMN + lastPoint.y);/是上次选择的点if (lastPoint.x = row & lastPoint.y = col) message(这次选择的点和上次的是同一点,取消选择状态);button.setBorder(Kyodai.unSelected);isSelected = false;else /判断是否可以消除message(这次选择的点和上次的点并不相同);Point current = new Point(row, col);message(这次选择的点的坐标为: + row + , + col + 值为: +map.getMap()rowcol + 位移为: + (row * Setting.COLUMN + col);map.setTest(false);if (map.test(lastPoint, current) message(两点可以消除,执行消除);/消除前先取消当前选择点的边框,因为有可能是提示dotsrow * Setting.COLUMN + col.setBorder(Kyodai.unSelected);map.earse(current, lastPoint);earse(current, lastPoint);dotslastPoint.x * Setting.COLUMN +lastPoint.y.setBorder(Kyodai.unSelected);lastPoint = new Point(0, 0);isSelected = false;showScore(score, score + Setting.correctScore + stepScore);score += Setting.correctScore + stepScore;if (Setting.Sound = 1) new Sound(Sound.EARSE);else message(这次选择的点与上次选择的点无解,改变选择为当前点);dotslastPoint.x * Setting.COLUMN +lastPoint.y.setBorder(Ky
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 海南琼台师范学院招聘考试真题2024
- 2025年内镜检查内镜操作规范与技术培训答案及解析
- 2023一年级数学上册 2 位置第2课时 左、右说课稿 新人教版
- 2025年放射科医学影像学解读考试答案及解析
- 2025年法医学法医学常见案例分析与判断知识测验卷答案及解析
- 8.2欧洲西部 第二课时说课稿2025-2026学年人教版地理七年级下册
- 2025年中药材药理与应用知识检测答案及解析
- 2025年整形美容科面部填充材料注射技能考核答案及解析
- 2025新款劳务派遣合同范本
- 《第六单元 欣赏 摇篮曲》(教学设计)-2023-2024学年人教版(2012)音乐一年级下册
- 个人独资企业财务管理制度的简化方案
- 2024年旧钻井杆销售合同范本
- 网络安全攻防演练报告
- 2023年《安徽大学学生手册》在线考试学习通超星期末考试答案章节答案2024年
- 安全评估合同
- 《全面质量管理》习题集(含答案)
- DB21T 3947-2024 普通公路装配式混凝土桥梁下部工程施工技术规范
- DL∕T 432-2018 电力用油中颗粒度测定方法
- 《水处理生物学》课件
- 人教版五年级下册数学选择题大全带答案解析
- 线性代数精第一章第一节课件
评论
0/150
提交评论