first commit

This commit is contained in:
2025-02-02 21:34:39 +01:00
commit 94ff96e056
11 changed files with 1962 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
package me.zacharias.star.map;
import org.json.JSONObject;
import javax.swing.*;
import java.awt.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main extends JPanel {
public static void main(String[] args) throws IOException {
new Main();
}
String word;
JSONObject starMap;
public Main() throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Input word:");
//word = in.readLine();
word = "ABCD";
BufferedReader starMapIn = new BufferedReader(new FileReader("./map.json"));
String tmp = "";
StringBuilder builder = new StringBuilder();
while((tmp = starMapIn.readLine()) != null){
builder.append(tmp);
}
starMap = new JSONObject(builder.toString());
JFrame frame = new JFrame();
frame.add(this);
frame.setSize(600,400);
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
Stroke big = new BasicStroke(2);
Stroke normal = new BasicStroke(1);
int starSize = 6;
int starOffset = starSize/2;
int size = 20;
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
int x = 40, y = 40;
for(char c : word.toCharArray()){
JSONObject constellation = starMap.getJSONObject(String.valueOf(Character.toUpperCase(c)));
for(Object part : constellation.getJSONArray("parts")){
if(part instanceof JSONObject jsonObject){
g2d.fillOval(x+size*jsonObject.getInt("x")-starOffset, y+size*jsonObject.getInt("y")-starOffset,starSize,starSize);
for(Object lineObj : jsonObject.getJSONArray("links")){
if(lineObj instanceof JSONObject line){
g2d.setStroke(big);
g2d.drawLine(x+size*jsonObject.getInt("x"), y+size*jsonObject.getInt("y"), x+size*line.getInt("x"), y+size*line.getInt("y"));
g2d.setStroke(normal);
}
}
}
g2d.setColor(new Color(178, 164, 0));
g2d.fillOval((x+size*constellation.getJSONObject("start").getInt("x"))-starOffset, (y+size*constellation.getJSONObject("start").getInt("y"))-starOffset,starSize,starSize);
g2d.fillOval((x+size*constellation.getJSONObject("end").getInt("x"))-starOffset, (y+size*constellation.getJSONObject("end").getInt("y"))-starOffset,starSize,starSize);
g2d.setColor(new Color(0,0,0));
x = x+size*constellation.getJSONObject("end").getInt("x");
y = y+size*constellation.getJSONObject("end").getInt("y");
}
}
}
}