简体   繁体   English

如何制作以下物品?

[英]How can I make the following object?

I am new in java. 我是Java新手。 So , I am trying to make asteroid game project.I have this point class 因此,我正在尝试制作小行星游戏项目。

  class Point implements Cloneable {
     double x,y;
     public Point(double inX, double inY) { x = inX; y = inY; }

  public Point clone() {
      return new Point(x, y);
   }
   }

and the polygon class which takes an array of points,point and integer. 以及一个包含点,点和整数数组的面类。 class Polygon { private Point[] shape; 类Polygon {private Point [] shape; // An array of points. //点数组。 public Point position; 公共点位置; // The offset mentioned above. //上面提到的偏移量。 public double rotation; 公众双重轮换; // Zero degrees is due east. //零度应归东。

       public Polygon(Point[] inShape, Point inPosition, double inRotation) {
           shape = inShape;
           position = inPosition;
           rotation = inRotation;

    // First, we find the shape's top-most left-most boundary, its origin.
    Point origin = shape[0].clone();
        for (Point p : shape) {
        if (p.x < origin.x) origin.x = p.x;
        if (p.y < origin.y) origin.y = p.y;
    }

      // Then, we orient all of its points relative to the real origin.
    for (Point p : shape) {
       p.x -= origin.x;
      p.y -= origin.y;
    }
    }

..... ..... .... in the main asteroid class . 在小行星的主要类中........... I want to make a polygon which is my ship. 我想制作一个多边形,这就是我的船。 How can i put the parameter here? 我如何在这里放置参数?

public static void main (String[] args) {
        Asteroids a = new Asteroids();
        a.repaint();

I want to create an object of polygon I tried like this 我想创建一个我尝试过的多边形对象

       Polygon p=new polygon({(0,2),(2,3),(3,1)},(2,3),3);

           p.repaint();

I am not taking the parameter correctly. 我没有正确使用参数。 Any help will be appreciated. 任何帮助将不胜感激。

In your constructor, you need to create an array of type Point that initializes new Point objects, like so: 在构造函数中,您需要创建一个Point类型的数组来初始化新的Point对象,如下所示:

new Point[] {new Point(0,2),new Point(2,3),new Point(3,1)}

And then define a new Point : 然后定义一个新的Point

new Point(2,3)

So your constructor call would look like this: 因此,您的构造函数调用将如下所示:

Polygon p = new Polygon(
    new Point[] {new Point(0,2),new Point(2,3),new Point(3,1)},
    new Point(2,3),
    3);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM