先上前端效果图

3消乐地图初始化的时候不允许有下面两种情况的发生,就是不允许3个(3个以上已经包含3个,所以只要判断3个就可以了)相同颜色的格子连在一起,

下图是两种情况,细分分为6种情况,就是初始点为3个格子中的一个为一种情况,所以细分2*3=6种情况

代码中的方法是

private boolean isLine(int x, int y){....}

代码过多,不写出来了

首先初始化地图,看代码注释应该看差不多了

3消规则,只要地图中包含其中以下3种情况就可以判断该地图不是死图,红色部分表示

相同颜色的格子,黄色代表如果这个位置如果也是相同颜色只要一动一个位置就可以

3个相同颜色格子并排在一起

比如第一张图,首先判断它上或者下是否有相同颜色

如果1格子是初始格子是红色

第一种

先判断标识2格子是否为红色,如果不是一图的情况不用判断了,如果也是红色

那么只要判断上面第一张图的4个黄色位置的格子只要有一个是红色,那么1格子就不是死格子,那么这个图就不是死图

第二种

第2张图,只要判断任意两个相邻黄色位置的格子(有4种情况:a跟b同时为红,b跟d,d跟c,a跟c)的颜色也是红色那么该格子不是死格子,该图不是死图

第三种

跟第二种很像,不过相邻变成了左右,我就不说了

细分的话应该有 2*4+4+2*4=20种情况,所以这个方法的代码量最大,不细说了

代码方法是privatebooleanisDie(intx,inty){...}

判断这个格子是否是3个以上颜色相同格子相连

比如以1格子为起点,然后向前后左右4个方向扩张

用递归的方法,就有4个方法,每个方法添加相

代码大概如下

colSet=上下相邻颜色相同的格子=向上颜色的格子+向下颜色的格子

rowSet=左右相邻颜色相同的格子=向左颜色的格子+向右颜色的格子

如果他们等于3个或者3个以上,那么他们就要被消,先存起来removeCellSet

后面再一次性消玩  i为格子的x坐标,j为y坐标

客户端要求如果不相连的区域要分离出来发给他们,分离出来的列表都要排序,这个要求比较蛋疼

格子坐标(x,y)

格子还有颜色属性Color

比如上图,removeCellSet包含上面格子的key=x+”_”+y;

只能用递归,

向相邻的格子扩张,如果相同颜色并且在removeCellSet里面

格子消掉并下降

0 1 2 3

例如上图给子格子下降

获取所有要消除的给子的x轴

比如有x=0;x=2;x=3这3列中都有空格

然后给这3列的非空格子排序,并重新按顺序填充格子,y大排下面,排完后剩下就为空,效果如下(我这是最简单的方法,不易出错,这个可以优化,优化就比较复杂了)

3消中最重要的的方法在这里,上面的方法都在这下面按顺序执行

上面代码的流程图

1跟2交换

1

2

交换后

消除后

下降后

补图

因为能消,所以再消

下降

再补图

再消,但不能再消乐,得移动其中的格子

代码结构

package com.eyugame.tade.module.glops.constant;

/**

* 宝石颜色

*

* @author k60

*/

public enum Color {

/**

* 红

*/

RED,

/**

* 黄

*/

YELLOW,

/**

* 蓝

*/

BLUE,

/**

* 绿

*/

GREEN,

/**

* 紫

*/

PURPLE

}

package com.eyugame.tade.module.glops.play;

import java.util.ArrayList;

import java.util.Collections;

import parator;

import java.util.HashSet;

import java.util.List;

import java.util.Random;

import java.util.Set;

import com.eyugame.tade.module.glops.constant.Color;

import com.eyugame.tade.module.glops.exception.NearCellException;

import com.eyugame.tade.module.glops.exception.NoSpoilageException;

import com.eyugame.tade.module.glops.model.Cell;

import com.eyugame.tade.module.glops.model.RemoveScaleResult;

/**

*

*

* @author pengwei

*/

public class BasePlay {

private final static String LINK = "_";

/**

* 地图

*/

private Cell[][] maps;

/**

* 横轴单元格数量

*/

private int xSize;

/**

* 竖轴单元格数量

*/

private int ySize;

/**

* 随机数

*/

private Random random;

/**

* 可以供随机的颜色

*/

private List liveColorList = new ArrayList();

/**

* 一次移动的一组(可能多次消除和生成)

*/

private List removeScaleResultList;

/**

* 要移除的位置

*/

private Set removeCellSet = new HashSet();

/**

* 构造方法

*

* @param xSize

* @param ySize

*/

public BasePlay(int xSize, int ySize) {

super();

this.xSize = xSize;

this.ySize = ySize;

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.xSize; i++) {

for (int j = 0; j < this.ySize; 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] = cell;

// 判断该格子是否有3个连在一起

if (this.isLine(i, j)) {

// 如果是有颜色重叠,从供选择的颜色中去掉该颜色,并重新随机颜色

j = j - 1;

liveColorList.remove(liveColor);

} else {

// 如果颜色没有3个重复,则初始化可供选择颜色

this.initLiveColor();

}

} else {

// 如果没有可以选择的颜色,初始化地图

this.maps = new Cell[xSize][ySize];

this.initMaps();

return;

}

}

}

}

/**

* 初始化随机颜色

*/

private void initLiveColor() {

liveColorList = new ArrayList();

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.xSize;

boolean bx2 = x + 2 < this.xSize;

boolean ly1 = y - 1 > -1;

boolean ly2 = y - 2 > -1;

boolean by1 = y + 1 < this.ySize;

boolean by2 = y + 2 < this.ySize;

if (ly1 && by1) {

if (isCellColorEqual(maps[x][y - 1], maps[x][y], maps[x][y + 1])) {

return true;

}

}

if (lx1 && bx1) {

if (isCellColorEqual(maps[x - 1][y], maps[x][y], maps[x + 1][y])) {

return true;

}

}

if (ly2) {

if (isCellColorEqual(maps[x][y], maps[x][y - 1], maps[x][y - 2])) {

return true;

}

}

if (by2) {

if (isCellColorEqual(maps[x][y], maps[x][y + 1], maps[x][y + 2])) {

return true;

}

}

if (lx2) {

if (isCellColorEqual(maps[x][y], maps[x - 1][y], maps[x - 2][y])) {

return true;

}

}

if (bx2) {

if (isCellColorEqual(maps[x][y], maps[x + 1][y], maps[x + 2][y])) {

return true;

}

}

return false;

}

/**

* 相邻3个格子是否同一颜色

*

* @param cell1

* 格子1

* @param cell2

* 格子2

* @param cell3

* 格子3

* @return 统一颜色为true,不同为false

*/

private boolean isCellColorEqual(Cell cell1, Cell cell2, Cell cell3) {

if (cell1 != null && cell2 != null && cell3 != null) {

Color color1 = cell1.color;

Color color2 = cell2.color;

Color color3 = cell3.color;

if (color1 != null && color2 != null && color3 != null) {

return (color1 == color2 && color1 == color3);

}

}

return false;

}

/**

* 在补图要添加的格子中相邻3个格子是否同一颜色

*

* @param cell1

* 格子1

* @param cell2

* 格子2

* @param cell3

* 格子3

* @return 统一颜色为true,不同为false

*/

private boolean isCellColorEqualInAddCell(Cell cell1, Cell cell2, Cell cell3, Set set) {

if (cell1 != null && cell2 != null && cell3 != null) {

if (set.contains(cell1) && set.contains(cell2) && set.contains(cell3)) {

Color color1 = cell1.color;

Color color2 = cell2.color;

Color color3 = cell3.color;

if (color1 != null && color2 != null && color3 != null) {

return (color1 == color2 && color1 == color3);

}

}

}

return false;

}

/**

* 右边颜色一样的格子

*/

private void isCellColorEqualRight(int x, int y, Color color, Set 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 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

* x坐标

* @param y

* y坐标

* @return

*/

private String getKey(int x, int y) {

return x + BasePlay.LINK + y;

}

/**

* 上边颜色一样的格子

*/

private void isCellColorEqualUp(int x, int y, Color color, Set 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 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 set, Set 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 move(Cell source, Cell target) {

if (source != null && target != null) {

if (this.near(source, target)) {

Color targetColor = maps[target.X][target.Y].color;

Color sourceColor = maps[source.X][source.Y].color;

maps[source.X][source.Y].color = targetColor;

maps[target.X][target.Y].color = sourceColor;

if (!this.isLine(source.X, source.Y) && !this.isLine(target.X, target.Y)) {

maps[source.X][source.Y].color = sourceColor;

maps[target.X][target.Y].color = targetColor;

throw new NoSpoilageException("这次移动没有可消除的格子");

} else {

removeScaleResultList = new ArrayList();

this.fadeCircle();

}

} else {

throw new NearCellException("目标不在起点旁边");

}

} else {

throw new NullPointerException("起点或者目标为空");

}

return removeScaleResultList;

}

/**

* 起点跟目标点是否相邻

*

* @param source

* @param target

* @return

*/

private boolean near(Cell source, Cell target) {

if (this.isInMap(source) && this.isInMap(target) && source.nearCell(target)) {

return true;

}

return false;

}

/**

* 判断该点是否超界

*

* @param cell

* @return

*/

private boolean isInMap(Cell cell) {

if (cell.X > -1 && cell.X < this.xSize && cell.Y > -1 && cell.Y < this.ySize) {

return true;

}

return false;

}

/**

* 补图 随机添加格子

*

* @return

*/

private Set addCell(RemoveScaleResult result) {

Set addCellSet = this.getNonePoint();

if (!addCellSet.isEmpty()) {

this.addCell(addCellSet, result);

}

return addCellSet;

}

/**

* 补图

*

* @param addCellSet

*/

private void addCell(Set addCellSet, RemoveScaleResult result) {

List list = new ArrayList();

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] = cell;

list.add(cell);

break;

} else {

liveColorList.remove(liveColor);

}

} else {

this.addCell(addCellSet, result);

return;

}

}

}

if (this.isDieMap()) {

this.addCell(addCellSet, result);

} else {

if (!list.isEmpty()) {

result.setNewCellList(list);

}

}

}

/**

* 判断在补图要添加的给子中是否有3个连线

*

* @param x

* @param y

* @param set

* @return

*/

private boolean isLineOnAddCell(Cell cell, Set set) {

int x=cell.X;

int y=cell.Y;

boolean lx1 = x - 1 > -1;

boolean lx2 = x - 2 > -1;

boolean bx1 = x + 1 < this.xSize;

boolean bx2 = x + 2 < this.xSize;

boolean ly1 = y - 1 > -1;

boolean ly2 = y - 2 > -1;

boolean by1 = y + 1 < this.ySize;

boolean by2 = y + 2 < this.ySize;

if (ly1 && by1) {

if (isCellColorEqualInAddCell(maps[x][y - 1], cell, maps[x][y + 1], set)) {

return true;

}

}

if (lx1 && bx1) {

if (isCellColorEqualInAddCell(maps[x - 1][y], cell, maps[x + 1][y], set)) {

return true;

}

}

if (ly2) {

if (isCellColorEqualInAddCell(cell, maps[x][y - 1], maps[x][y - 2], set)) {

return true;

}

}

if (by2) {

if (isCellColorEqualInAddCell(cell, maps[x][y + 1], maps[x][y + 2], set)) {

return true;

}

}

if (lx2) {

if (isCellColorEqualInAddCell(cell, maps[x - 1][y], maps[x - 2][y], set)) {

return true;

}

}

if (bx2) {

if (isCellColorEqualInAddCell(cell, maps[x + 1][y], maps[x + 2][y], set)) {

return true;

}

}

return false;

}

/**

* 3消

*/

private void fadeCircle() {

removeCellSet = new HashSet();

RemoveScaleResult result = new RemoveScaleResult();

List> removeCellList = new ArrayList>();

// 判断选出要消除的格子

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.xSize; i++) {

for (int j = 0; j < this.ySize; 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 rowSet = new HashSet();

Set colSet = new HashSet();

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> removeCellList) {

// 复制一份要消掉的格子的集合

Set cSet = new HashSet(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 set = new HashSet();

// 为该格子相邻的格子迭代扩张,并从cSet中移除掉

this.nearAdd(x, y, maps[x][y].color, set, cSet);

if (!set.isEmpty()) {

List list = new ArrayList();

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() {

@Override

public int compare(Cell o1, Cell o2) {

if (o1.Y == o2.Y) {

return 0;

} else if (o1.Y > o2.Y) {

return -1;

} else {

return 1;

}

}

});

removeCellList.add(list);

}

}

}

}

/**

* 消除要消除的格子跟并且地图格子下降

*/

private void removeCellAndDown() {

Set set = new HashSet();

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] = null;

if (!set.contains(x)) {

set.add(x);

}

}

for (Integer x : set) {

List list = new ArrayList();

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] = null;

}

}

int j = this.ySize - 1;

for (Cell cell : list) {

cell.setX(x);

maps[x][j] = cell;

j--;

}

}

}

/**

* 获取空的节点

*

* @return

*/

private Set getNonePoint() {

Set set = new HashSet();

for (int i = 0; i < this.xSize; i++) {

for (int j = 0; j < this.ySize; j++) {

if (maps[i][j] == null) {

Cell cell = new Cell();

cell.setX(i);

cell.setY(j);

set.add(cell);

}

}

}

return set;

}

/**

* 是否为死图

*

* @return

*/

private boolean isDieMap() {

for (int i = 0; i < this.xSize; i++) {

for (int j = 0; j < this.ySize; j++) {

maps[i][j].X = i;

maps[i][j].Y = j;

if (isDie(i, j) == false) {

return false;

}

}

}

return true;

}

/**

* 判断该格子是否为死格子

*

* @param x

* 格子的x坐标

* @param y

* 格子的y坐标

* @return

*/

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.xSize;

boolean bx2 = x + 2 < this.xSize;

boolean bx3 = x + 3 < this.xSize;

boolean ly1 = y - 1 > -1;

boolean ly2 = y - 2 > -1;

boolean ly3 = y - 3 > -1;

boolean by1 = y + 1 < this.ySize;

boolean by2 = y + 2 < this.ySize;

boolean by3 = y + 3 < this.ySize;

Color color = maps[x][y].color;

if (bx1) {

if (maps[x + 1][y].color == color) {

if (bx3) {

if (maps[x + 3][y].color == color) {

return false;

}

}

if (bx2 && by1) {

if (maps[x + 2][y + 1].color == color) {

return false;

}

}

if (bx2 && ly1) {

if (maps[x + 2][y - 1].color == color) {

return false;

}

}

if (lx2) {

if (maps[x - 2][y].color == color) {

return false;

}

}

if (lx1 && ly1) {

if (maps[x - 1][y - 1].color == color) {

return false;

}

}

if (lx1 && by1) {

if (maps[x - 1][y + 1].color == color) {

return false;

}

}

}

if (ly1 && by1) {

if (maps[x + 1][y - 1].color == color && maps[x + 1][y + 1].color == color) {

return false;

}

}

}

if (lx1) {

if (maps[x - 1][y].color == color) {

if (lx3) {

if (maps[x - 3][y].color == color) {

return false;

}

}

if (lx2 && by1) {

if (maps[x - 2][y + 1].color == color) {

return false;

}

}

if (lx2 && ly1) {

if (maps[x - 2][y - 1].color == color) {

return false;

}

}

if (bx2) {

if (maps[x + 2][y].color == color) {

return false;

}

}

if (bx1 && ly1) {

if (maps[x + 1][y - 1].color == color) {

return false;

}

}

if (bx1 && by1) {

if (maps[x + 1][y + 1].color == color) {

return false;

}

}

}

if (ly1 && by1) {

if (maps[x - 1][y - 1].color == color && maps[x - 1][y + 1].color == color) {

return false;

}

}

}

if (by1) {

if (maps[x][y + 1].color == color) {

if (by3) {

if (maps[x][y + 3].color == color) {

return false;

}

}

if (lx1 && by2) {

if (maps[x - 1][y + 2].color == color) {

return false;

}

}

if (bx1 && by2) {

if (maps[x + 1][y + 2].color == color) {

return false;

}

}

if (ly2) {

if (maps[x][y - 2].color == color) {

return false;

}

}

if (bx1 && ly1) {

if (maps[x + 1][y - 1].color == color) {

return false;

}

}

if (lx1 && ly1) {

if (maps[x - 1][y - 1].color == color) {

return false;

}

}

}

if (lx1 && bx1) {

if (maps[x - 1][y + 1].color == color && maps[x + 1][y + 1].color == color) {

return false;

}

}

}

if (ly1) {

if (maps[x][y - 1].color == color) {

if (ly3) {

if (maps[x][y - 3].color == color) {

return false;

}

}

if (lx1 && ly2) {

if (maps[x - 1][y - 2].color == color) {

return false;

}

}

if (bx1 && ly2) {

if (maps[x + 1][y - 2].color == color) {

return false;

}

}

if (by2) {

if (maps[x][y + 2].color == color) {

return false;

}

}

if (bx1 && by1) {

if (maps[x + 1][y + 1].color == color) {

return false;

}

}

if (lx1 && by1) {

if (maps[x - 1][y + 1].color == color) {

return false;

}

}

}

if (lx1 && bx1) {

if (maps[x - 1][y - 1].color == color && maps[x + 1][y - 1].color == color) {

return false;

}

}

}

return true;

}

public Cell[][] getMaps() {

return maps;

}

public void setMaps(Cell[][] maps) {

this.maps = maps;

}

public int getxSize() {

return xSize;

}

public void setxSize(int xSize) {

this.xSize = xSize;

}

public int getySize() {

return ySize;

}

public void setySize(int ySize) {

this.ySize = ySize;

}

}

package com.eyugame.tade.module.glops.model;

import com.eyugame.tade.module.glops.constant.Color;

/**

* 单元格

*

* @author k60

*/

public class Cell {

/**

* x坐标

*/

public int X;

/**

* y坐标

*/

public int Y;

/**

* 颜色

*/

public Color color;

public Cell() {

super();

}

public Cell(int x, int y) {

super();

X = x;

Y = y;

}

public int getX() {

return X;

}

public void setX(int x) {

X = x;

}

public int getY() {

return Y;

}

public void setY(int y) {

Y = y;

}

public Color getColor() {

return color;

}

public void setColor(Color color) {

this.color = color;

}

public boolean nearCell(Cell cell) {

if (cell != null) {

if (this.X == cell.X && this.Y == (cell.Y + 1)) {

return true;

} else if (this.X == cell.X && this.Y == (cell.Y - 1)) {

return true;

} else if (this.X == (cell.X + 1) && this.Y == cell.Y) {

return true;

} else if (this.X == (cell.X - 1) && this.Y == cell.Y) {

return true;

}

}

return false;

}

@Override

public String toString() {

return this.X+"_"+this.Y+":"+this.color;

}

@Override

public int hashCode() {

final int prime = 31;

int result = 1;

result = prime * result + X;

result = prime * result + Y;

return result;

}

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

Cell other = (Cell) obj;

if (X != other.X)

return false;

if (Y != other.Y)

return false;

return true;

}

public Cell clone(){

Cell cell=new Cell();

cell.setX(this.X);

cell.setY(this.Y);

cell.setColor(this.color);

return cell;

}

}

package com.eyugame.tade.module.glops.model;

import java.util.List;

/**

* 消除刻度结果

*

* @author k60

*/

public class RemoveScaleResult {

/**

* 消除的单元格

*/

private List> removeCellList;

/**

* 新产生的单元格颜色列表

*

* 产生规则:

* X轴,由左至右补

* Y轴,由下至上补

*/

private List newCellList;

public List> getRemoveCellList() {

return removeCellList;

}

public void setRemoveCellList(List> removeCellList) {

this.removeCellList = removeCellList;

}

public List getNewCellList() {

return newCellList;

}

public void setNewCellList(List newCellList) {

this.newCellList = newCellList;

}

}

package com.eyugame.tade.module.glops.exception;

/**

*

* 当起点向目标移动,目标跟起点不是相邻时异常

*

*/

public class NearCellException extends RuntimeException {

private static final long serialVersionUID = -5973332015600566849L;

public NearCellException(String message){

super(message);

}

}

package com.eyugame.tade.module.glops.exception;

/**

*

* 当起点向目标移动,但是不能3消异常

*

*/

public class NoSpoilageException extends RuntimeException {

private static final long serialVersionUID = 3129338536664414593L;

public NoSpoilageException(String message) {

super(message);

}

}

消消乐实现下坠_消消乐游戏算法实现相关推荐

  1. 消消乐实现下坠_手把手教你如何实现iOS消消乐小游戏Demo

    引言 做消消乐Demo属于一个意外,本想借助学习iOS游戏开发把CoreAnimation学好,并完成第一个游戏Demo:俄罗斯方块.却在这过程中发现了一些实现消消乐的小技巧,于是兴起完成了这个小De ...

  2. 消消乐实现下坠_教你用Vue写一个开心消消乐

    之前做过一个算法题,算法要求就是写一个开心消消乐的逻辑算法,当时也是考虑了一段时间才做出来.后来想了想,既然核心算法都有了,能不能实现一个开心消消乐的小游戏呢,于是花了两天时间做了一个小游戏出来. 效 ...

  3. 消消乐实现下坠_消消乐.cpp

    #include #include #include #define High 600//定义画布长度与高度 #define Width 600 #define step 50//定义方块大小 str ...

  4. 消消乐实现下坠_JavaScript有多强大,实现消消乐小游戏

    简易JS消消乐-jq22.com html,body { margin:0px; padding:0px; } .bgs0 { background:linear-gradient(to left,# ...

  5. 酷家乐 java面经_酷家乐内部教练案例分享

    素材中台主营两部分业务:模型.材质,模型材质数据是酷家乐的关键资源,对内承载着对业务团队的数据支持,对外负责了酷家乐渲染图的表现效果. 所以团队成员承接的工作除了中台能力建设之外,还有很多日常很多前台 ...

  6. python生成一笔画_一笔画小游戏-算法-python+autojs

    一笔画小游戏,好玩的很 就是到了后面比较麻烦,手动找路径太慢了,作为程序员,这又是一个锻炼的好机会是不是!于是乎,了解了一下dfs和bfs算法(都是路径搜索算法),然后就开撸: #pointArr=[ ...

  7. 开心消消乐java下载_开心消消乐原版下载安装

    开心消消乐原版最新版是非常受欢迎的手机消除游戏,在这里你可以随时随地体验正版消除游戏带来的乐趣,还有海量关卡等你来挑战,游戏操作简单,感兴趣的玩家赶快来下载体验吧! 开心消消乐原版游戏介绍 开心消消乐 ...

  8. java开心消消乐代码_Vue实现开心消消乐游戏算法

    摘要:这篇Vue栏目下的"Vue实现开心消消乐游戏算法",介绍的技术点是"开心消消乐.Vue.开心.游戏.算法.实现",希望对大家开发技术学习和问题解决有帮助. ...

  9. 消消乐 游戏算法html,小游戏版消消乐

    概述:最近看了点算法,为了对其有深刻的体会,利用周末时间撸了一个简易版的三消游戏,采用JS+Canvas实现,没有使用额外的游戏引擎,对于初学者来说,也比较容易入门的.下面是小游戏效果展示: 效果展示 ...

最新文章

  1. java mqtt 断开连接,可以将MQTT Paho客户端断开连接吗?
  2. 洛谷 P2574 XOR的艺术
  3. manjaro笔记本显卡驱动_从入门到高端!AMD Radeon RX 500系列移动显卡全解析
  4. 写一个ajax程序就是如此简单
  5. android 处理http状态码,OkHttp(Retrofit)对于http状态码202的处理
  6. 单E1光端机分类及技术指标详解
  7. android uri db,Android ContentProvider封装数据库和文件读写总结
  8. 在Windows上编译MongoDB C Driver
  9. 程序设计基础——c语言篇,C语言程序设计基础篇.ppt
  10. linux mysql 5.0.45_linux 下安装mysql-5.0.45.tar.gz
  11. 强大的Qtstylesheet
  12. Fun with Opterons, SATA, and INNODB
  13. [2018.10.13 T2] 工作计划
  14. 基于汽车运动学模型的LQR控制
  15. 我的世界服务器怎么无限附魔,我的世界无限附魔书指令
  16. 五到十分钟java演讲_10分钟励志演讲稿5篇最新
  17. 苹果公司的电脑产品及其历史
  18. SpringBosent框架
  19. HTML5 Canvas编写五彩连珠(4):动画
  20. 中建普联:大数据在工程造价中的应用

热门文章

  1. C语言字符加法原理,这个加法原理,在小学阶段一定要弄明白!
  2. 炸了!没有任何HTML/CSS ! 纯Python打造一个网站!
  3. android图片处理的工具代码
  4. 2023认证杯数学建模挑战赛C题心脏危险完整原创论文讲解
  5. 微信搜索不到小程序名字?微信小程序搜索不到应用怎么办?微信小程序怎么搜索?
  6. 全国计算机b级试题及答案,全国计算机等级考试一级b模拟试题及答案
  7. 《鱿鱼游戏》中的 AI 是绝对公平的吗?
  8. 用java计算学生绩点并排序_JS代码计算GPA平均学分绩点(适合新版正方教务系统)...
  9. 深入场景痛点,制造业数据应用思考与实践
  10. 手机C语言代码,C语言(示例代码)