JAVA アプレットでプログラムを作成しました。プログラムは、A
ランダムに生成された 4 つの点で多角形を描画し、次にランダムに生成された 4 つの点で別の多角形を描画しB
ます。この後、各ポリゴンの各ポイントを比較して、それらが同じかどうかを確認します。A[0] > B[0]
そうでない場合は、と言いましょうA[0]--
。古いポリゴンのすべてのポイントがA
新しいポリゴンになるまでB
。その後、繰り返します。
だから私が抱えている問題は、何らかの理由でポリゴンがどんどん薄くなっていくということです.
ここに私のコードがあります:
package some.package.games;
import java.applet.Applet;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.Polygon;
import java.awt.geom.GeneralPath;
import java.awt.image.BufferedImage;
import java.awt.image.ImageProducer;
import java.util.Random;
public class graphics extends Applet implements Runnable
{
public boolean isRunning = false;
protected BufferedImage mBuffer;
protected boolean comparaisonFinni = false;
protected Polygon polygonCourant = createNewPolygon();
protected Graphics2D mGraphics;
protected Dimension mDimension;
protected int mFPS = (1000 / 9);
public void start()
{
isRunning = true;
new Thread(this).start();
}
public void stop()
{
isRunning = false;
}
public void init()
{
mDimension = getSize();
mBuffer = (BufferedImage)createImage(mDimension.width, mDimension.height);
mGraphics = (Graphics2D)mBuffer.createGraphics();
}
public void paint(Graphics pGraphics)
{
pGraphics.clearRect(0, 0, mDimension.width, mDimension.height);
Polygon polygonTmp = new Polygon();
if (!comparaisonFinni)
polygonTmp = createNewPolygon();
for (int i = 0; i < 4; i++)
{
if (polygonTmp.xpoints[i] < polygonCourant.xpoints[i])
{
polygonCourant.xpoints[i]--;
}
if (polygonTmp.xpoints[i] > polygonCourant.xpoints[i])
{
polygonCourant.xpoints[i]++;
}
if ( polygonTmp.ypoints[i] < polygonCourant.ypoints[i])
{
polygonCourant.ypoints[i]--;
}
if ( polygonTmp.ypoints[i] > polygonCourant.ypoints[i])
{
polygonCourant.ypoints[i]++;
}
if ((polygonCourant.xpoints[0] == polygonTmp.xpoints[0]) && (polygonCourant.xpoints[1] == polygonTmp.xpoints[1]) &&
(polygonCourant.xpoints[2] == polygonTmp.xpoints[2]) && (polygonCourant.xpoints[3] == polygonTmp.xpoints[3]) &&
(polygonCourant.ypoints[0] == polygonTmp.ypoints[0]) && (polygonCourant.ypoints[1] == polygonTmp.ypoints[1]) &&
(polygonCourant.ypoints[2] == polygonTmp.ypoints[2]) && (polygonCourant.ypoints[3] == polygonTmp.ypoints[3]))
{
comparaisonFinni = true;
}
}
pGraphics.drawPolygon(polygonCourant);
}
public Polygon createNewPolygon()
{
Random aNumber = new Random();
int x1Points[] = new int [4];
int y1Points[] = new int [4];
for (int i = 0; i < 4; i++)
{
x1Points[i] = aNumber.nextInt(200);
y1Points[i] = aNumber.nextInt(300);
}
Polygon lePolygon = new Polygon(x1Points, y1Points, 4);
if (comparaisonFinni)
{
comparaisonFinni = false;
polygonCourant = lePolygon;
}
return lePolygon;
}
public void update(Graphics pGraphics)
{
paint(pGraphics);
}
public void run()
{
while (isRunning)
{
repaint();
try
{ Thread.sleep(mFPS); }
catch (InterruptedException pException)
{ pException.printStackTrace(); }
}
}
}