如何编一个开心消消乐源代码代码

查看: 5202|回复: 8
Delphi XE5实现的一个消消乐游戏代码
主题帖子积分
论坛元老, 积分 4501, 距离下一级还需 9995498 积分
论坛元老, 积分 4501, 距离下一级还需 9995498 积分
Delphi XE5&
Windows&Android&
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
才可以下载或查看,没有帐号?
(928.12 KB, 下载次数: 438)
09:23 上传
点击文件名下载附件
无标题.png (262.51 KB, 下载次数: 130)
09:23 上传
本文章介绍了Delphi XE5实现的一个消消乐游戏代码,该代码是从外国网站下来下来,经过测试可以编译,除了图形效果稍微差了外,基本上和流行的消消乐差不多,该游戏实现了图形的拖放、自动消除、自动下移填充图形、时间限制、分数计算。
上面的截图是编译后执行出来的界面,大家有兴趣可以下载下来试试。
转载请保留当前帖子的链接: 谢谢!
搜索简单,分享不易,且分享且珍惜,您难道不想分享下您的心得?如果觉得本文章好的话,您可以在我们网站上注册,然后发布您的好的心得,让大家共同进步,谢谢!
主题帖子积分
中级会员, 积分 310, 距离下一级还需 190 积分
中级会员, 积分 310, 距离下一级还需 190 积分
其实我就想知道是从哪里 下载的啊
主题帖子积分
论坛元老, 积分 4501, 距离下一级还需 9995498 积分
论坛元老, 积分 4501, 距离下一级还需 9995498 积分
其实我就想知道是从哪里 下载的啊
我的网站在哪里下载,还是我从哪里收集到的?
主题帖子积分
中级会员, 积分 310, 距离下一级还需 190 积分
中级会员, 积分 310, 距离下一级还需 190 积分
本帖最后由 a200331 于
09:20 编辑
就是图片&&不好看,我把图片 改好看点 在上传上来,哈哈。。。十从哪里 下载的,当然 从哪里 收集到的 也可以说阿。。谢谢诶
主题帖子积分
论坛元老, 积分 4501, 距离下一级还需 9995498 积分
论坛元老, 积分 4501, 距离下一级还需 9995498 积分
就是图片&&不好看,我把图片 改好看点 在上传上来,哈哈。。。十从哪里 下载的,当然 从哪里 收集到的 也可 ...
从这个网站,里面代码不少,不过这些只有我调试成功的才会发布上来
主题帖子积分
新手上路, 积分 8, 距离下一级还需 42 积分
新手上路, 积分 8, 距离下一级还需 42 积分
试着学习来的, 天天向上.
主题帖子积分
注册会员, 积分 176, 距离下一级还需 24 积分
注册会员, 积分 176, 距离下一级还需 24 积分
在手机运行不行,在电脑上就报毒。
主题帖子积分
论坛元老, 积分 4501, 距离下一级还需 9995498 积分
论坛元老, 积分 4501, 距离下一级还需 9995498 积分
在手机运行不行,在电脑上就报毒。
在delphi xe5运行,没问题
主题帖子积分
新手上路, 积分 6, 距离下一级还需 44 积分
新手上路, 积分 6, 距离下一级还需 44 积分
压缩包损害,打不开了
Powered by再吸金!SE推出《最终幻想:全员勇者》钥匙扣
再吸金!SE推出《最终幻想:全员勇者》钥匙扣
再吸金!SE推出《最终幻想:全员勇者》钥匙扣
再吸金!SE推出《最终幻想:全员勇者》钥匙扣
再吸金!SE推出《最终幻想:全员勇者》钥匙扣
再吸金!SE推出《最终幻想:全员勇者》钥匙扣
再吸金!SE推出《最终幻想:全员勇者》钥匙扣
再吸金!SE推出《最终幻想:全员勇者》钥匙扣
威锋网7月10日消锋网7月10日消息,《植物大战僵尸2》 如今...
威锋网7月10日消息,《植物大...
近日,开发商 Esquilax Games ..
说到方块游戏,相信有很多朋友应该还会记得 Gavina Games 早...
威锋网7月10日消息,《植物大...
近日,开发商 Esquilax Games ..
说到方块游戏,相信有很多朋友应该还会记得 Gavina Games 早...
再吸金!SE推出《最终幻想:全员勇者》钥匙扣
再吸金!SE推出《最终幻想:全员勇者》钥匙扣
再吸金!SE推出《最终幻想:全员勇者》钥匙扣
再吸金!SE推出《最终幻想:全员勇者》钥匙扣
再吸金!SE推出《最终幻想:全员勇者》钥匙扣
再吸金!SE推出《最终幻想:全员勇者》钥匙扣
再吸金!SE推出《最终幻想:全员勇者》钥匙扣
再吸金!SE推出《最终幻想:全员勇者》钥匙扣
您需要通过验证再能继续浏览 3秒后开始验证
威锋旗下产品
Hi~我是威威!
 粤公网安备 11号
新三板上市公司威锋科技(836555)
增值电信业务经营许可证:
Powered by Discuz!消消乐游戏算法实现(三消乐) - CSDN博客
消消乐游戏算法实现(三消乐)
先上前端效果图
3消乐地图初始化的时候不允许有下面两种情况的发生,就是不允许个(个以上已经包含个,所以只要判断个就可以了)相同颜色的格子连在一起,
下图是两种情况,细分分为种情况,就是初始点为个格子中的一个为一种情况,所以细分种情况
代码中的方法是
private boolean isLine(int x, int y){....}
代码过多,不写出来了
首先初始化地图,看代码注释应该看差不多了
3消规则,只要地图中包含其中以下种情况就可以判断该地图不是死图,红色部分表示
相同颜色的格子,黄色代表如果这个位置如果也是相同颜色只要一动一个位置就可以
3个相同颜色格子并排在一起
比如第一张图,首先判断它上或者下是否有相同颜色
如果格子是初始格子是红色
先判断标识格子是否为红色,如果不是一图的情况不用判断了,如果也是红色
那么只要判断上面第一张图的个黄色位置的格子只要有一个是红色,那么格子就不是死格子,那么这个图就不是死图
第张图,只要判断任意两个相邻黄色位置的格子有种情况:跟同时为红,跟跟,跟的颜色也是红色那么该格子不是死格子,该图不是死图
跟第二种很像,不过相邻变成了左右,我就不说了
细分的话应该有&种情况,所以这个方法的代码量最大,不细说了
代码方法是private&boolean&isDie(int&x,&int&y)&{...}
判断这个格子是否是个以上颜色相同格子相连
比如以格子为起点,然后向前后左右个方向扩张
用递归的方法,就有个方法,每个方法添加相
代码大概如下
colSet&=上下相邻颜色相同的格子=向上颜色的格子+向下颜色的格子&&&&&&&
rowSet&=左右相邻颜色相同的格子=向左颜色的格子+向右颜色的格子&&&&&
如果他们等于3个或者3个以上,那么他们就要被消,先存起来&&removeCellSet&&&&
后面再一次性消玩&&i为格子的x坐标,j为y坐标
客户端要求如果不相连的区域要分离出来发给他们,分离出来的列表都要排序,这个要求比较蛋疼
格子坐标(x,y)
格子还有颜色属性Color
比如上图,removeCellSet包含上面格子的key=x+”_”+y;
只能用递归,
向相邻的格子扩张,如果相同颜色并且在removeCellSet里面&
格子消掉并下降
例如上图给子格子下降
获取所有要消除的给子的x轴
比如有x=0;x=2;x=3这3列中都有空格
然后给这3列的非空格子排序,并重新按顺序填充格子,y大排下面,排完后剩下就为空,效果如下(我这是最简单的方法,不易出错,这个可以优化,优化就比较复杂了)
3消中最重要的的方法在这里,上面的方法都在这下面按顺序执行
上面代码的流程图
因为能消,所以再消
再消,但不能再消乐,得移动其中的格子
package com.eyugame.tade.module.glops.
* 宝石颜色
public enum Color {
package com.eyugame.tade.module.glops.
import java.util.ArrayL
import java.util.C
import java.util.HashS
import java.util.L
import java.util.R
import java.util.S
import com.eyugame.tade.module.glops.constant.C
import com.eyugame.tade.module.glops.exception.NearCellE
import com.eyugame.tade.module.glops.exception.NoSpoilageE
import com.eyugame.tade.module.glops.model.C
import com.eyugame.tade.module.glops.model.RemoveScaleR
* @author pengwei
public class BasePlay {
private final static String LINK = &_&;
private Cell[][]
* 横轴单元格数量
private int xS
* 竖轴单元格数量
private int yS
* 可以供随机的颜色
private List&String& liveColorList = new ArrayList&String&();
* 一次移动的一组(可能多次消除和生成)
private List&RemoveScaleResult& removeScaleResultL
* 要移除的位置
private Set&String& removeCellSet = new HashSet&String&();
* 构造方法
* @param xSize
* @param ySize
public BasePlay(int xSize, int ySize) {
this.xSize = xS
this.ySize = yS
this.maps = new Cell[xSize][ySize];
random = new Random();
this.initMaps();
while (this.isDieMap()) {
this.initMaps();
* 初始化地图,给地图上色
private void initMaps() {
this.initLiveColor();
for (int i = 0; i & this.xS i++) {
for (int j = 0; j & this.yS j++) {
// 可供选择的颜色
int liveSize = liveColorList.size();
// 判断该位置是否有可供选择的颜色
if (liveSize & 0) {
// 随机颜色
int tem = random.nextInt(liveSize);
Cell cell = new Cell();
String liveColor = liveColorList.get(tem);
// 给格子上坐标跟颜色
cell.setX(i);
cell.setY(j);
cell.setColor(Color.valueOf(liveColor));
// 放进地图
maps[i][j] =
// 判断该格子是否有3个连在一起
if (this.isLine(i, j)) {
// 如果是有颜色重叠,从供选择的颜色中去掉该颜色,并重新随机颜色
j = j - 1;
liveColorList.remove(liveColor);
// 如果颜色没有3个重复,则初始化可供选择颜色
this.initLiveColor();
// 如果没有可以选择的颜色,初始化地图
this.maps = new Cell[xSize][ySize];
this.initMaps();
* 初始化随机颜色
private void initLiveColor() {
liveColorList = new ArrayList&String&();
Color[] colors = Color.values();
for (Color color : colors) {
liveColorList.add(new String(color.toString()));
* 填充地图 不允许3格一排或者一列
* @param x
填充格子的x轴
* @param y
填充格子的y轴
* @return 是否填充成功
private boolean isLine(int x, int y) {
boolean lx1 = x - 1 & -1;
boolean lx2 = x - 2 & -1;
boolean bx1 = x + 1 & this.xS
boolean bx2 = x + 2 & this.xS
boolean ly1 = y - 1 & -1;
boolean ly2 = y - 2 & -1;
boolean by1 = y + 1 & this.yS
boolean by2 = y + 2 & this.yS
if (ly1 && by1) {
if (isCellColorEqual(maps[x][y - 1], maps[x][y], maps[x][y + 1])) {
if (lx1 && bx1) {
if (isCellColorEqual(maps[x - 1][y], maps[x][y], maps[x + 1][y])) {
if (ly2) {
if (isCellColorEqual(maps[x][y], maps[x][y - 1], maps[x][y - 2])) {
if (by2) {
if (isCellColorEqual(maps[x][y], maps[x][y + 1], maps[x][y + 2])) {
if (lx2) {
if (isCellColorEqual(maps[x][y], maps[x - 1][y], maps[x - 2][y])) {
if (bx2) {
if (isCellColorEqual(maps[x][y], maps[x + 1][y], maps[x + 2][y])) {
* 相邻3个格子是否同一颜色
* @param cell1
* @param cell2
* @param cell3
* @return 统一颜色为true,不同为false
private boolean isCellColorEqual(Cell cell1, Cell cell2, Cell cell3) {
if (cell1 != null && cell2 != null && cell3 != null) {
Color color1 = cell1.
Color color2 = cell2.
Color color3 = cell3.
if (color1 != null && color2 != null && color3 != null) {
return (color1 == color2 && color1 == color3);
* 在补图要添加的格子中相邻3个格子是否同一颜色
* @param cell1
* @param cell2
* @param cell3
* @return 统一颜色为true,不同为false
private boolean isCellColorEqualInAddCell(Cell cell1, Cell cell2, Cell cell3, Set&Cell& set) {
if (cell1 != null && cell2 != null && cell3 != null) {
if (set.contains(cell1) && set.contains(cell2) && set.contains(cell3)) {
Color color1 = cell1.
Color color2 = cell2.
Color color3 = cell3.
if (color1 != null && color2 != null && color3 != null) {
return (color1 == color2 && color1 == color3);
* 右边颜色一样的格子
private void isCellColorEqualRight(int x, int y, Color color, Set&String& set) {
set.add(this.getKey(x, y));
int newX = x + 1;
if (newX & this.xSize) {
if (maps[newX][y] != null && maps[newX][y].color == color) {
this.isCellColorEqualRight(newX, y, color, set);
* 左边颜色一样的格子
private void isCellColorEqualLeft(int x, int y, Color color, Set&String& set) {
set.add(this.getKey(x, y));
int newX = x - 1;
if (newX &= 0) {
if (maps[newX][y] != null && maps[newX][y].color == color) {
this.isCellColorEqualLeft(newX, y, color, set);
* 主键生成
* @param x
* @param y
private String getKey(int x, int y) {
return x + BasePlay.LINK +
* 上边颜色一样的格子
private void isCellColorEqualUp(int x, int y, Color color, Set&String& set) {
set.add(this.getKey(x, y));
int newY = y - 1;
if (newY &= 0) {
if (maps[x][newY] != null && maps[x][newY].color == color) {
this.isCellColorEqualUp(x, newY, color, set);
* 下边颜色一样的格子
private void isCellColorEqualDown(int x, int y, Color color, Set&String& set) {
set.add(this.getKey(x, y));
int newY = y + 1;
if (newY & this.ySize) {
if (maps[x][newY] != null && maps[x][newY].color == color) {
this.isCellColorEqualDown(x, newY, color, set);
* 在删除的节点中,找到相邻的相同颜色的格子
* @param x
* @param y
* @param color
* @param set
* @param cSet
private void nearAdd(int x, int y, Color color, Set&String& set, Set&String& cSet) {
if (!cSet.isEmpty()) {
String nKey = this.getKey(x, y);
cSet.remove(nKey);
set.add(nKey);
if (x - 1 & -1) {
String key = this.getKey(x - 1, y);
if (removeCellSet.contains(key) && !set.contains(key) && maps[x - 1][y].color == color) {
this.nearAdd(x - 1, y, color, set, cSet);
if (x + 1 & this.xSize) {
String key = this.getKey(x + 1, y);
if (removeCellSet.contains(key) && !set.contains(key) && maps[x + 1][y].color == color) {
this.nearAdd(x + 1, y, color, set, cSet);
if (y - 1 & -1) {
String key = this.getKey(x, y - 1);
if (removeCellSet.contains(key) && !set.contains(key) && maps[x][y - 1].color == color) {
this.nearAdd(x, y - 1, color, set, cSet);
if (y + 1 & this.ySize) {
String key = this.getKey(x, y + 1);
if (removeCellSet.contains(key) && !set.contains(key) && maps[x][y + 1].color == color) {
this.nearAdd(x, y + 1, color, set, cSet);
* 移动 将source 移动至target
* @param source
* @param target
* @throws Exception
public List&RemoveScaleResult& move(Cell source, Cell target) {
if (source != null && target != null) {
if (this.near(source, target)) {
Color targetColor = maps[target.X][target.Y].
Color sourceColor = maps[source.X][source.Y].
maps[source.X][source.Y].color = targetC
maps[target.X][target.Y].color = sourceC
if (!this.isLine(source.X, source.Y) && !this.isLine(target.X, target.Y)) {
maps[source.X][source.Y].color = sourceC
maps[target.X][target.Y].color = targetC
throw new NoSpoilageException(&这次移动没有可消除的格子&);
removeScaleResultList = new ArrayList&RemoveScaleResult&();
this.fadeCircle();
throw new NearCellException(&目标不在起点旁边&);
throw new NullPointerException(&起点或者目标为空&);
return removeScaleResultL
* 起点跟目标点是否相邻
* @param source
* @param target
private boolean near(Cell source, Cell target) {
if (this.isInMap(source) && this.isInMap(target) && source.nearCell(target)) {
* 判断该点是否超界
* @param cell
private boolean isInMap(Cell cell) {
if (cell.X & -1 && cell.X & this.xSize && cell.Y & -1 && cell.Y & this.ySize) {
* 补图 随机添加格子
private Set&Cell& addCell(RemoveScaleResult result) {
Set&Cell& addCellSet = this.getNonePoint();
if (!addCellSet.isEmpty()) {
this.addCell(addCellSet, result);
return addCellS
* @param addCellSet
private void addCell(Set&Cell& addCellSet, RemoveScaleResult result) {
List&Cell& list = new ArrayList&Cell&();
this.initLiveColor();
for (Cell cell : addCellSet) {
while (true) {
if (!this.liveColorList.isEmpty()) {
int tem = random.nextInt(liveColorList.size());
String liveColor = liveColorList.get(tem);
cell.setColor(Color.valueOf(liveColor));
if (!this.isLineOnAddCell(cell, addCellSet)) {
maps[cell.X][cell.Y] =
list.add(cell);
liveColorList.remove(liveColor);
this.addCell(addCellSet, result);
if (this.isDieMap()) {
this.addCell(addCellSet, result);
if (!list.isEmpty()) {
result.setNewCellList(list);
* 判断在补图要添加的给子中是否有3个连线
* @param x
* @param y
* @param set
private boolean isLineOnAddCell(Cell cell, Set&Cell& set) {
int x=cell.X;
int y=cell.Y;
boolean lx1 = x - 1 & -1;
boolean lx2 = x - 2 & -1;
boolean bx1 = x + 1 & this.xS
boolean bx2 = x + 2 & this.xS
boolean ly1 = y - 1 & -1;
boolean ly2 = y - 2 & -1;
boolean by1 = y + 1 & this.yS
boolean by2 = y + 2 & this.yS
if (ly1 && by1) {
if (isCellColorEqualInAddCell(maps[x][y - 1], cell, maps[x][y + 1], set)) {
if (lx1 && bx1) {
if (isCellColorEqualInAddCell(maps[x - 1][y], cell, maps[x + 1][y], set)) {
if (ly2) {
if (isCellColorEqualInAddCell(cell, maps[x][y - 1], maps[x][y - 2], set)) {
if (by2) {
if (isCellColorEqualInAddCell(cell, maps[x][y + 1], maps[x][y + 2], set)) {
if (lx2) {
if (isCellColorEqualInAddCell(cell, maps[x - 1][y], maps[x - 2][y], set)) {
if (bx2) {
if (isCellColorEqualInAddCell(cell, maps[x + 1][y], maps[x + 2][y], set)) {
private void fadeCircle() {
removeCellSet = new HashSet&String&();
RemoveScaleResult result = new RemoveScaleResult();
List&List&Cell&& removeCellList = new ArrayList&List&Cell&&();
// 判断选出要消除的格子
this.createRemoveCell();
// 给要消除的给子分块
this.blockRemoveCell(removeCellList);
// 消除格子,并且降落
this.removeCellAndDown();
if (!removeCellList.isEmpty()) {
result.setRemoveCellList(removeCellList);
// 添加格子
if (!removeCellSet.isEmpty()) {
this.addCell(result);
removeScaleResultList.add(result);
// 添加格子后再消除格子
this.fadeCircle();
* 生成要消掉的节点 同颜色同列或者同行超过3个的都要消掉
private void createRemoveCell() {
for (int i = 0; i & this.xS i++) {
for (int j = 0; j & this.yS j++) {
Cell source = maps[i][j];
String cellKey = this.getKey(i, j);
if (source != null && !removeCellSet.contains(cellKey)) {
source.setX(i);
source.setY(j);
Set&String& rowSet = new HashSet&String&();
Set&String& colSet = new HashSet&String&();
this.isCellColorEqualLeft(i, j, source.color, rowSet);
this.isCellColorEqualRight(i, j, source.color, rowSet);
this.isCellColorEqualUp(i, j, source.color, colSet);
this.isCellColorEqualDown(i, j, source.color, colSet);
if (rowSet.size() & 2) {
for (String key : rowSet) {
removeCellSet.add(key);
if (colSet.size() & 2) {
for (String key : colSet) {
removeCellSet.add(key);
* 给要消除的给子分区域
private void blockRemoveCell(List&List&Cell&& removeCellList) {
// 复制一份要消掉的格子的集合
Set&String& cSet = new HashSet&String&(removeCellSet);
for (String key : removeCellSet) {
// 不在cSet里面的格子说明被归某一区域了,不需要在分区域了
if (!cSet.isEmpty() && cSet.contains(key)) {
String[] xy = key.split(BasePlay.LINK);
int x = Integer.parseInt(xy[0]);
int y = Integer.parseInt(xy[1]);
Set&String& set = new HashSet&String&();
// 为该格子相邻的格子迭代扩张,并从cSet中移除掉
this.nearAdd(x, y, maps[x][y].color, set, cSet);
if (!set.isEmpty()) {
List&Cell& list = new ArrayList&Cell&();
for (String key2 : set) {
String[] xy2 = key2.split(BasePlay.LINK);
int x2 = Integer.parseInt(xy2[0]);
int y2 = Integer.parseInt(xy2[1]);
maps[x2][y2].X = x2;
maps[x2][y2].Y = y2;
list.add(maps[x2][y2]);
// 对同属于同一区域的要消除的格子排序
Collections.sort(list, new Comparator&Cell&() {
public int compare(Cell o1, Cell o2) {
if (o1.Y == o2.Y) {
} else if (o1.Y & o2.Y) {
return -1;
removeCellList.add(list);
* 消除要消除的格子跟并且地图格子下降
private void removeCellAndDown() {
Set&Integer& set = new HashSet&Integer&();
for (String key : removeCellSet) {
String[] xy = key.split(BasePlay.LINK);
int x = Integer.parseInt(xy[0]);
int y = Integer.parseInt(xy[1]);
maps[x][y] =
if (!set.contains(x)) {
set.add(x);
for (Integer x : set) {
List&Cell& list = new ArrayList&Cell&();
for (int j = this.ySize - 1; j & -1; j--) {
Cell cell = maps[x][j];
if (cell != null) {
cell.setX(x);
cell.setY(j);
list.add(cell.clone());
maps[x][j] =
int j = this.ySize - 1;
for (Cell cell : list) {
cell.setX(x);
maps[x][j] =
* 获取空的节点
private Set&Cell& getNonePoint() {
Set&Cell& set = new HashSet&Cell&();
for (int i = 0; i & this.xS i++) {
for (int j = 0; j & this.yS j++) {
if (maps[i][j] == null) {
Cell cell = new Cell();
cell.setX(i);
cell.setY(j);
set.add(cell);
* 是否为死图
private boolean isDieMap() {
for (int i = 0; i & this.xS i++) {
for (int j = 0; j & this.yS j++) {
maps[i][j].X =
maps[i][j].Y =
if (isDie(i, j) == false) {
* 判断该格子是否为死格子
* @param x
格子的x坐标
* @param y
格子的y坐标
private boolean isDie(int x, int y) {
boolean lx1 = x - 1 & -1;
boolean lx2 = x - 2 & -1;
boolean lx3 = x - 3 & -1;
boolean bx1 = x + 1 & this.xS
boolean bx2 = x + 2 & this.xS
boolean bx3 = x + 3 & this.xS
boolean ly1 = y - 1 & -1;
boolean ly2 = y - 2 & -1;
boolean ly3 = y - 3 & -1;
boolean by1 = y + 1 & this.yS
boolean by2 = y + 2 & this.yS
boolean by3 = y + 3 & this.yS
Color color = maps[x][y].
if (bx1) {
if (maps[x + 1][y].color == color) {
if (bx3) {
if (maps[x + 3][y].color == color) {
if (bx2 && by1) {
if (maps[x + 2][y + 1].color == color) {
if (bx2 && ly1) {
if (maps[x + 2][y - 1].color == color) {
if (lx2) {
if (maps[x - 2][y].color == color) {
if (lx1 && ly1) {
if (maps[x - 1][y - 1].color == color) {
if (lx1 && by1) {
if (maps[x - 1][y + 1].color == color) {
if (ly1 && by1) {
if (maps[x + 1][y - 1].color == color && maps[x + 1][y + 1].color == color) {
if (lx1) {
if (maps[x - 1][y].color == color) {
if (lx3) {
if (maps[x - 3][y].color == color) {
if (lx2 && by1) {
if (maps[x - 2][y + 1].color == color) {
if (lx2 && ly1) {
if (maps[x - 2][y - 1].color == color) {
if (bx2) {
if (maps[x + 2][y].color == color) {
if (bx1 && ly1) {
if (maps[x + 1][y - 1].color == color) {
if (bx1 && by1) {
if (maps[x + 1][y + 1].color == color) {
if (ly1 && by1) {
if (maps[x - 1][y - 1].color == color && maps[x - 1][y + 1].color == color) {
if (by1) {
if (maps[x][y + 1].color == color) {
if (by3) {
if (maps[x][y + 3].color == color) {
if (lx1 && by2) {
if (maps[x - 1][y + 2].color == color) {
if (bx1 && by2) {
if (maps[x + 1][y + 2].color == color) {
if (ly2) {
if (maps[x][y - 2].color == color) {
if (bx1 && ly1) {
if (maps[x + 1][y - 1].color == color) {
if (lx1 && ly1) {
if (maps[x - 1][y - 1].color == color) {
if (lx1 && bx1) {
if (maps[x - 1][y + 1].color == color && maps[x + 1][y + 1].color == color) {
if (ly1) {
if (maps[x][y - 1].color == color) {
if (ly3) {
if (maps[x][y - 3].color == color) {
if (lx1 && ly2) {
if (maps[x - 1][y - 2].color == color) {
if (bx1 && ly2) {
if (maps[x + 1][y - 2].color == color) {
if (by2) {
if (maps[x][y + 2].color == color) {
if (bx1 && by1) {
if (maps[x + 1][y + 1].color == color) {
if (lx1 && by1) {
if (maps[x - 1][y + 1].color == color) {
if (lx1 && bx1) {
if (maps[x - 1][y - 1].color == color && maps[x + 1][y - 1].color == color) {
public Cell[][] getMaps() {
public void setMaps(Cell[][] maps) {
this.maps =
public int getxSize() {
public void setxSize(int xSize) {
this.xSize = xS
public int getySize() {
public void setySize(int ySize) {
this.ySize = yS
package com.eyugame.tade.module.glops.
import com.eyugame.tade.module.glops.constant.C
* @author k60
public class Cell {
public int X;
public int Y;
public Cell() {
public Cell(int x, int y) {
public int getX() {
public void setX(int x) {
public int getY() {
public void setY(int y) {
public Color getColor() {
public void setColor(Color color) {
this.color =
public boolean nearCell(Cell cell) {
if (cell != null) {
if (this.X == cell.X && this.Y == (cell.Y + 1)) {
} else if (this.X == cell.X && this.Y == (cell.Y - 1)) {
} else if (this.X == (cell.X + 1) && this.Y == cell.Y) {
} else if (this.X == (cell.X - 1) && this.Y == cell.Y) {
public String toString() {
return this.X+&_&+this.Y+&:&+this.
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + X;
result = prime * result + Y;
public boolean equals(Object obj) {
if (this == obj)
if (obj == null)
if (getClass() != obj.getClass())
Cell other = (Cell)
if (X != other.X)
if (Y != other.Y)
public Cell clone(){
Cell cell=new Cell();
cell.setX(this.X);
cell.setY(this.Y);
cell.setColor(this.color);
package com.eyugame.tade.module.glops.
import java.util.L
* 消除刻度结果
public class RemoveScaleResult {
* 消除的单元格
private List&List&Cell&& removeCellL
* 新产生的单元格颜色列表
* 产生规则:
* X轴,由左至右补
* Y轴,由下至上补
private List&Cell& newCellL
public List&List&Cell&& getRemoveCellList() {
return removeCellL
public void setRemoveCellList(List&List&Cell&& removeCellList) {
this.removeCellList = removeCellL
public List&Cell& getNewCellList() {
return newCellL
public void setNewCellList(List&Cell& newCellList) {
this.newCellList = newCellL
package com.eyugame.tade.module.glops.
* 当起点向目标移动,目标跟起点不是相邻时异常
public class NearCellException extends RuntimeException {
private static final long serialVersionUID = -0566849L;
public NearCellException(String message){
super(message);
package com.eyugame.tade.module.glops.
* 当起点向目标移动,但是不能3消异常
public class NoSpoilageException extends RuntimeException {
private static final long serialVersionUID = 4414593L;
public NoSpoilageException(String message) {
super(message);
本文已收录于以下专栏:
相关文章推荐
三消游戏可以说是游戏界的常青树,也是一个玩法深受大家喜爱并且经久不衰的游戏种类,今天主要在这为大家分析一下三消游戏的核心算法的实现。
我自己也开发过几款三消类游戏,正所谓万变不离其宗,在我看来真正影响...
#pragma mark 填充空缺位置
void GameScene::fillVacancies()
m_isAnimationing =
// 让存在的精...
消消乐游戏自动求解
前段时间很喜欢玩"开心消消乐"这个休闲小游戏, 刚好大学的一位同学也在玩,后来就想着如果让自己来写这个逻辑要怎么写, 经过一天的构思, 找到一种利用深度优先搜索思想来实现的方式.
三消游戏的规则
消消乐,游戏规则很简单,点击的位置颜色相连的区域抵消。
实现思路:从点击位置开始深搜(递归),记录搜索的坐标并抵消。
贴上关键代码:
map数组保存每个点的颜色,state保存是否搜索过...
突然想要在android上写一个消消乐的代码,在此之前没有系统地学过java的面向对象,也没有任何android相关知识,不过还是会一点C++。8月初开始搭建环境,在这上面花了相当多的时间,然后看了一...
1. 游戏视频演示
2.三消游戏我的理解
上面视频中的游戏,我做了2个星期时间,只能算个简单Demo,还有bug,特效也几乎没有。感觉三消游戏主要靠磨,越磨越精品。...
查找数组中某个元素
将该元素的地址分别存放在两个数组里面
查看该数组8个方向有没有相同元素,假如有继续沿该方向判断,没有则判断下一个
将该元素变为x
然后进行塌的算法...
public void act(float delta) {
super.act(delta);
if (isCouldTouch()) {
1. 游戏视频演示2.三消游戏我的理解上面视频中的游戏,我做了2个星期时间,只能算个简单Demo,还有bug,特效也几乎没有。感觉三消游戏主要靠磨,越磨越精品。市场上三消游戏已经超级多了。主流的是地图...
他的最新文章
讲师:王禹华
讲师:宋宝华
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)

我要回帖

更多关于 消消乐小游戏源代码 的文章

 

随机推荐