迷雾开格
parent
cc1ab75c18
commit
ba247b4161
|
|
@ -10,6 +10,7 @@ import com.ljsd.jieling.network.session.ISession;
|
|||
import com.ljsd.jieling.protocols.CommonProto;
|
||||
import com.ljsd.jieling.protocols.MapInfoProto;
|
||||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||
import com.ljsd.jieling.util.CellUtil;
|
||||
import com.ljsd.jieling.util.MessageUtil;
|
||||
import com.ljsd.jieling.util.ToolsUtil;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -105,7 +106,7 @@ public class MapLogic {
|
|||
int randomIndex = random.nextInt(scMap1.getGroups().length);
|
||||
int x = scMap1.getGroups()[randomIndex][0];
|
||||
int y = scMap1.getGroups()[randomIndex][1];
|
||||
int xy = ToolsUtil.xy2Pos(x, y);
|
||||
int xy = CellUtil.xy2Pos(x, y);
|
||||
SCMapEventsConfig scMapEvent = SCMapEventsConfig.scMapEventMap.get(scMap1.getEvent());
|
||||
if (scMapEvent.getStyle() == EventType.enter) {
|
||||
mapManager.setCurXY(xy);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,92 @@
|
|||
package com.ljsd.jieling.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class CellUtil {
|
||||
|
||||
|
||||
public static int xy2Pos(int x, int y) {
|
||||
if (x < 0 || y < 0){
|
||||
return 0;
|
||||
}
|
||||
return (x << 8) | y;
|
||||
}
|
||||
|
||||
public static int[] pos2XY(int pos) {
|
||||
int[] xy = new int[2];
|
||||
xy[0] = (pos >> 8) & 0xff;
|
||||
xy[1] = pos & 0xff;
|
||||
return xy;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
int xx = 19;
|
||||
int yy = 14;
|
||||
int pos = xy2Pos(xx,yy);
|
||||
System.out.println("======> pos : "+pos);
|
||||
int[] xy = pos2XY(pos);
|
||||
System.out.println("=======> nX : "+xy[0]+" , nY : "+xy[1]);
|
||||
System.out.println("=====================================");
|
||||
Set<Integer> cells = getOneOpenCell(21,18, pos);
|
||||
for(Integer i : cells){
|
||||
int[] new_xy = pos2XY(i);
|
||||
System.out.println("=======> nX : "+new_xy[0]+" , nY : "+new_xy[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Set<Integer> getOneOpenCell(int width, int height, int pos){
|
||||
int[] xy = pos2XY(pos);
|
||||
int x = xy[0];
|
||||
int y = xy[1];
|
||||
Set<Integer> openCells = new HashSet<>();
|
||||
for (int i = -2; i <= 2; i++) {
|
||||
if (0 <= x+i && x+i < width && i!=0){
|
||||
openCells.add(xy2Pos(x+i,y));
|
||||
// System.out.println("=======> nX : "+(x+i)+" , nY : "+y);
|
||||
}
|
||||
if (0 <= y+i && y+i < height && i!=0){
|
||||
openCells.add(xy2Pos(x,y+i));
|
||||
// System.out.println("=======> nX : "+x+" , nY : "+(y+i));
|
||||
}
|
||||
}
|
||||
if (x+1 < width && y+1 < height){
|
||||
openCells.add(xy2Pos(x+1,y+1));
|
||||
// System.out.println("===============> nX : "+(x+1)+" , nY : "+(y+1));
|
||||
}
|
||||
if (x+1 < width && y-1 >= 0){
|
||||
openCells.add(xy2Pos(x+1,y-1));
|
||||
// System.out.println("===============> nX : "+(x+1)+" , nY : "+(y-1));
|
||||
}
|
||||
if (x-1 >= 0 && y+1 < height){
|
||||
openCells.add(xy2Pos(x-1,y+1));
|
||||
// System.out.println("===============> nX : "+(x-1)+" , nY : "+(y+1));
|
||||
}
|
||||
if (x-1 >= 0 && y-1 >= 0){
|
||||
openCells.add(xy2Pos(x-1,y-1));
|
||||
// System.out.println("===============> nX : "+(x-1)+" , nY : "+(y-1));
|
||||
}
|
||||
System.out.println("=====================================");
|
||||
return openCells;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 做归并-将较小集合归并到较大集合
|
||||
* @param s1 较大集合
|
||||
* @param s2 较小集合
|
||||
* @return
|
||||
*/
|
||||
public static Set<Integer> union(Set<Integer> s1 , Set<Integer> s2){
|
||||
for(Integer s : s2){
|
||||
if(!s1.contains(s))
|
||||
s1.add(s);
|
||||
}
|
||||
return s1 ;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,26 +3,6 @@ package com.ljsd.jieling.util;
|
|||
public class ToolsUtil {
|
||||
|
||||
|
||||
public static int xy2Pos(int x, int y) {
|
||||
return (x << 8) | y;
|
||||
}
|
||||
|
||||
public static int[] pos2XY(int pos) {
|
||||
int[] xy = new int[2];
|
||||
xy[0] = (pos >> 8) & 0xff;
|
||||
xy[1] = pos & 0xff;
|
||||
return xy;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
int xx = 12;
|
||||
int yy = 5;
|
||||
int pos = xy2Pos(xx,yy);
|
||||
System.out.println("======> pos : "+pos);
|
||||
int[] xy = pos2XY(pos);
|
||||
System.out.println("=======> nX : "+xy[0]+" , nY : "+xy[1]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue