日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

消消乐实现下坠_消消乐游戏算法实现

發布時間:2024/1/1 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 消消乐实现下坠_消消乐游戏算法实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

先上前端效果圖

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);

}

}

總結

以上是生活随笔為你收集整理的消消乐实现下坠_消消乐游戏算法实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。