-2
我的比赛是有3个目标和一个球。用户将输入一个移动球的程度,以便击中其中一个目标。我所希望的是有一个新的屏幕弹出“你赢了!”如果用户击中其中一个目标。如何在用户赢得游戏时弹出新屏幕?
这里是我的屏幕类哪里会得出(有没有3所示的其他类):
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
public class Screen extends JPanel
{
private BufferedImage buffered;
private Ball b1;
private Target t1;
private Target t2;
private Target t3;
public Screen()
{
b1 = new Ball(130,340);
t1 = new Target(300,120);
t2 = new Target(600,300);
t3 = new Target(400,400);
}
public Dimension getPreferredSize()
{
//Sets the size of the panel
return new Dimension(800,600);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Color rough = new Color(0,130,33);
Color green = new Color(107,204,4);
//Create Buffered
if(buffered == null)
{
buffered = (BufferedImage)(createImage(getWidth(), getHeight()));
}
//Create a temporary graphics buffered to draw
Graphics gBuff = buffered.createGraphics();
//Clear everything
//This draws the white box
gBuff.setColor(rough);
gBuff.fillRect(0, 0, 800, 600);
gBuff.setColor(green);
gBuff.fillOval(20,20,650,560);
gBuff.fillOval(240,50,530,540);
b1.drawMe(gBuff);
t1.drawMe(gBuff);
t2.drawMe(gBuff);
t3.drawMe(gBuff);
//draw the buffered image
g.drawImage(buffered, 0, 0, null);
}
public void setVariables(int degreeInput)
{
b1.setDegrees(degreeInput);
}
public void animate()
{
int count = 0;
while(count < 100000)
{
//wait for .01 second
try {
Thread.sleep(10);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
b1.move();
if(t1.checkCollision(b1.getX(), b1.getY(), b1.getWidth(), b1.getHeight()))
{
break;
}
if(t2.checkCollision(b1.getX(), b1.getY(), b1.getWidth(), b1.getHeight()))
{
break;
}
if(t3.checkCollision(b1.getX(), b1.getY(), b1.getWidth(), b1.getHeight()))
{
break;
}
count++;
repaint();
}
}
}
而且因为我是一个初学者,如果答案可能是简单的形式来会是大!
问题在哪里,您到目前为止尝试了什么? – mattias 2014-11-08 23:10:19
没有问题,我只是不确定如何制作一个新窗口 – pman 2014-11-09 09:16:34