gpt4 book ai didi

JavaFX:使用 Permanin 扭曲创建板网格

转载 作者:行者123 更新时间:2023-12-02 10:51:53 25 4
gpt4 key购买 nike

我正在创建一个棋盘游戏(首先移植到 JavaFX),其中玩家必须通过循环杀死对手的棋子。

CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=138535, Permanin game board

以上内容是在 Surakurta(Permanin 的另一个名称)的维基百科页面上提供的。但是,我只能构建这种类型的网格:

JavaFX Permanin app by Silcos (SHUKANT PAL)

如何在拐角处创建这些环形交叉口?

已构建网格的实现细节:GridPane 填充了 36 个 BoardInput 扩展 javafx.scene.control.Button 对象。这些对象很特殊,因为它们自动创建一个带有三个 BackgroundFill 对象的 Background - 水平线、垂直线和卵石圆形填充。

最佳答案

使用路径ArcTo 元素允许您创建圆形零件。 HLineToVLineToClosePath 可用于直线部分:

此外,我不建议使用BackgroundFill。我更喜欢在面板视觉效果上覆盖不可见按钮或为 GridPane 本身处理 MouseEvent

示例

private static ArcTo createArc(double radius, double dx, double dy) {
ArcTo result = new ArcTo(radius, radius, 0, dx, dy, true, true);
result.setAbsolute(false);
return result;
}

private static HLineTo createHLine(double length) {
HLineTo result = new HLineTo(length);
result.setAbsolute(false);
return result;
}

private static VLineTo createVLine(double length) {
VLineTo result = new VLineTo(length);
result.setAbsolute(false);
return result;
}

private static Path createPath(double radius, double midSize, Color storke) {
final double lineLength = 2 * radius + midSize;

Path result = new Path(
new MoveTo(radius, 2 * radius), // start at left end of top horizontal line
createArc(radius, radius, -radius), // top left loop
createVLine(lineLength), // down
createArc(radius, -radius, -radius), // bottom left loop
createHLine(lineLength), // right
createArc(radius, -radius, radius), // bottom right loop
createVLine(-lineLength), // up
createArc(radius, radius, radius),
new ClosePath() // left
);
result.setStroke(storke);
result.setStrokeWidth(10);
return result;
}

@Override
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(new StackPane(
createPath(100, 50, Color.GREEN),
createPath(50, 150, Color.AQUA)
));
primaryStage.setScene(scene);
primaryStage.show();
}

输出

Screenshot of result

关于JavaFX:使用 Permanin 扭曲创建板网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52113774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com