添加当前棋子标识

main
dai_48k 2024-01-23 10:54:32 +08:00
parent 5fb38f50ed
commit 50ced7a834
5 changed files with 32 additions and 35 deletions

View File

@ -4,26 +4,10 @@ import top.dreamcenter.go.msg.Cross;
public class DataUtil {
public static String parseData(Cross[][] map){
StringBuilder sb = new StringBuilder();
for (int i = 0; i < map.length; i++) {
for (int j = 0; j < map.length; j++) {
sb.append(i).append(j);
if (map[i][j] == Cross.NONE) {
sb.append(0);
} else if (map[i][j] == Cross.BLACK) {
sb.append(1);
} else {
sb.append(2);
}
}
}
return sb.toString();
}
public static Cross[][] rawData(String data){
Cross[][] cross = new Cross[9][9];
Cross[] colors = new Cross[]{Cross.NONE, Cross.BLACK, Cross.WHITE};
Cross[] colors = new Cross[]{Cross.NONE, Cross.BLACK, Cross.WHITE, Cross.BLACK_CUR, Cross.WHITE_CUR};
for (int i = 0; i < data.length(); ) {
int row = data.charAt(i) - '0';
int col = data.charAt(i + 1) - '0';

View File

@ -139,7 +139,23 @@ public class MainFrame extends JFrame {
drawOval(g, col * BASE_FROM , row * BASE_FROM + BASE_HEIGHT, BASE_FROM / 2 - 1);
drawOval(g, col * BASE_FROM , row * BASE_FROM + BASE_HEIGHT, BASE_FROM / 2 - 2);
}
if (cross == Cross.BLACK_CUR) {
fillOval(g, col * BASE_FROM , row * BASE_FROM + BASE_HEIGHT, BASE_FROM / 2);
drawPlus(g, col * BASE_FROM , row * BASE_FROM + BASE_HEIGHT, BASE_FROM>>2, Color.WHITE);
}
if (cross == Cross.WHITE_CUR) {
drawOval(g, col * BASE_FROM , row * BASE_FROM + BASE_HEIGHT, BASE_FROM / 2 - 1);
drawOval(g, col * BASE_FROM , row * BASE_FROM + BASE_HEIGHT, BASE_FROM / 2 - 2);
drawPlus(g, col * BASE_FROM , row * BASE_FROM + BASE_HEIGHT, BASE_FROM>>2, Color.BLACK);
}
}
private void drawPlus(Graphics g, int cx, int cy, int r, Color color){
g.setColor(color);
g.fillRect(cx- r, cy - 1, r * 2 + 1, 3);
g.fillRect(cx - 1, cy - r, 3, r * 2 + 1);
g.setColor(Color.BLACK);
}
}

View File

@ -1,5 +1,7 @@
package top.dreamcenter.go.msg;
public enum Cross {
NONE, BLACK, WHITE
NONE, BLACK, WHITE,
BLACK_CUR, WHITE_CUR
}

View File

@ -1,37 +1,32 @@
package top.dreamcenter.go.server;
import top.dreamcenter.go.msg.Cross;
import top.dreamcenter.go.msg.NewClick;
public class DataUtil {
public static String parseData(Cross[][] map){
public static String parseData(Cross[][] map, NewClick newClick){
StringBuilder sb = new StringBuilder();
for (int i = 0; i < map.length; i++) {
for (int j = 0; j < map.length; j++) {
int magnification = 1;
if (i == newClick.pos.k - 1 && j == newClick.pos.v - 1) magnification = 3;
sb.append(i).append(j);
if (map[i][j] == Cross.NONE) {
sb.append(0);
} else if (map[i][j] == Cross.BLACK) {
sb.append(1);
sb.append(magnification); // 1 3
} else {
sb.append(2);
sb.append(magnification+1); // 2 4
}
}
}
return sb.toString();
}
public static Cross[][] rawData(String data){
Cross[][] cross = new Cross[9][9];
Cross[] colors = new Cross[]{Cross.NONE, Cross.BLACK, Cross.WHITE};
for (int i = 0; i < data.length();) {
int row = data.charAt(i) - '0';
int col = data.charAt(i + 1) - '0';
Cross color = colors[data.charAt(i + 2) - '0'];
cross[row][col] = color;
i += 3;
}
return cross;
}
}

View File

@ -67,7 +67,7 @@ public class UserThread extends Thread{
users.forEach(u -> {
try {
if (u.isAlive) u.sendMsg(DataUtil.parseData(map));
if (u.isAlive) u.sendMsg(DataUtil.parseData(map, newClick));
} catch (IOException e) {
e.printStackTrace();
}