-1
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);
}
}
如何手動平移多邊形?我需要做它來創建一個遊戲板。到目前爲止,我只完成了多邊形的自動翻譯,這絕對是我不需要的。手動平移多邊形
請勿在截圖中發佈代碼。將其作爲文本發佈。 – khelwood
這個問題還不清楚。更具體一些。 –
它怎麼可能更清楚?我正在嘗試翻譯多邊形,並且我已經評論了自動翻譯多邊形的位置,這不是我正在嘗試執行的操作。 –