【发布时间】:2016-06-01 11:17:06
【问题描述】:
public class Hexagon extends JPanel {
// Team that controls the hexagon
public int controller; // 0 neutral // 1 is team 1 // 2 is team 2
// Color of the hexagon
// /* All attributes of the board, used for size an boarder etc... */ Board board
// /* Determines where the hexagon sits on the game board */ int position
public static void main(String args[])
{
JFrame j = new JFrame();
j.setSize(350, 250);
for(int i = 0; i < 121; i++)
{
Hexagon hex = new Hexagon();
j.add(hex);
}
j.setVisible(true);
}
@Override
public void paintComponent(Graphics shape)
{
super.paintComponent(shape);
Polygon hexagon = new Polygon();
// x, y coordinate centers, r is radius from center
Double x, y;
// Define sides of polygon for hexagon
for(int i = 0; i < 6; i++)
{
x = 25 + 22 * Math.cos(i * 2 * Math.PI / 6);
y = 25 + 22 * Math.sin(i * 2 * Math.PI / 6);
hexagon.addPoint(x.intValue(), y.intValue());
}
// Automatic translate
hexagon.translate(10, 10);
// How do I manually control translate?
shape.drawPolygon(hexagon);
}
}
如何手动平移多边形?我需要这样做来创建一个游戏板。到目前为止,我只完成了多边形的自动翻译,这绝对是我不需要的。
【问题讨论】:
-
不要在屏幕截图中发布代码。以文本形式发布。
-
问题不清楚。更具体。
-
怎么可能更清楚?我正在尝试翻译多边形,我已经评论了我在哪里自动翻译了多边形,这不是我想要做的。
-
So far I've only accomplished automatic translation of polygons which is definitely what I don't need.为什么?如果它自动工作,为什么要浪费时间尝试手动做某事?我不明白问题的重点。 -
如果你熟悉游戏的十六进制,那么所有的棋盘都已经移动了多边形,所以我不能让它自动。