Zum Inhalt springen

kleines spiel als java app... geht irgendwie nicht?


Empfohlene Beiträge

Geschrieben

Hallo zusammen,

ich programmier grad das Spiel Breakout (Arkanoid) und bleib bei einer Fehlermeldung stecken. Kann mir jemand helfen? Wäre total nett. Hier sind die Codes:

import java.awt.event.*;

import javax.swing.*;

import java.awt.*;

public class Notarkanoid{

/**

* @param args

*/

private Ball ball;

public Notarkanoid() {

ball = new Ball(this);

}

public static void main(String[] args){

Notarkanoid notarkanoid = new Notarkanoid();

}

}

///////////////////////////UND:

import java.awt.event.*;

import javax.swing.*;

import java.awt.*;

public class Ball extends JPanel implements Runnable

{

private Thread t;

private int d;

private int x;

private int y;

private int dx;

private int dy;

private int size = 10;

private Block[] block= new Block;

private Bat bat;

public Ball()

{

super();

bat = new Bat();

this.x = bat.x+bat.w+10; // control the start point of x

this.y = bat.y+(bat.l/2); // control the start point of y

this.d = 20; // control the size of the ball

this.dx = 5; // control the speed of x

this.dy = 5; // control the speed of y

for (int i = 0; i < size; i++) {

block = new Block(400, 50+i*50, 49);

}

this.setOpaque(false);

this.setDoubleBuffered(true);

t = new Thread(this);

t.start();

}

protected void paintComponent(Graphics g)

{

g.setColor(Color.green);

g.fillRect(bat.x, bat.y, bat.w, bat.l);

for (int i = 0; i < size; i++) {

if (!block.i****()){

g.setColor(Color.green);

g.fillRect(block.x, block.y, block.w, block.w);

}

}

g.setColor(Color.red);

g.fillOval(this.x, this.y, this.d, this.d);

}

public void animate()

{

addMouseListener(new MouseAdapter() {

public void mousePressed(MouseEvent event){

bat=new Bat();

}

});

addMouseMotionListener(new MouseMotionAdapter(){

public void mouseMoved(MouseEvent event){

bat.y=event.getY();

}

});

Rectangle bounds = this.getBounds();

for (int i = 0; i < size; i++) {

if (!block.i****()){

if ((this.x > block.x)&&(this.x+this.d<block.x+block.w)){

if ((this.y + this.d+dy > block.y)&&(this.y +dy <block.y+block.w)){

dy = -dy;

block.setI****(true);

}

}

if((this.y > block.y)&&(this.y +this.d <block.y+block.w)){

if ((this.x +this.d+dx > block.x)&&(this.x+dx <block.x+block.w)) {

dx = -dx;

block.setI****(true);

}

}

}

}

if(((this.y > bat.y)&&(this.y+this.d<bat.y+bat.l)) &&(this.x<bat.x+bat.w))dx= -dx;

if((this.x + this.d + dx > bounds.width))

dx = -dx;

if((this.y + dy < 0) || (this.y + this.d + dy > bounds.height))

dy = -dy;

if((this.x<10)) return;

this.x += dx;

this.y += dy;

this.repaint();

}

public void run()

{

while(true)

{

this.animate();

try

{

Thread.sleep(10);

}

catch (InterruptedException e) { }

}

}

}

class Block {

int w;

int x;

int y;

boolean hit;

public boolean i****(){

return hit;

}

public void setI****(boolean hit){

this.hit=hit;

}

public Block(int x, int y, int w) {

hit = false;

this.x = x;

this.y = y;

this.w = w;

}

}

class Bat {

int x;

int y;

int w;

int l;

public Bat() {

x = 10;

y = 200;

w = 20;

l = 100;

}

}

Danke schonmal! :)

Geschrieben

Die Fehlermeldung wäre mal interessant - dann bekommt man u.U. auch raus was das Problem ist, ohne dass man deinen Code compilieren muss. Da in der Fehlermeldung wahrscheinlich auch die Zeile der Fehlerquelle angegeben ist solltest du die auch gleich weiterreichen. Hast du dir mal den Exception-Stack angeschaut ?

Geschrieben

sorry.

das ist die fehlermeldung:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:

The constructor Ball(Notarkanoid) is undefined

at Notarkanoid.<init>(Notarkanoid.java:12)

at Notarkanoid.main(Notarkanoid.java:16)

Geschrieben

Hmm die Fehlermeldung sagt doch schon alles ;)

Du rufst in Zeile 12 einen Konstruktor für die Klasse Ball mit einem Parameter der Klasse Notarkanoid auf. Allerdings existiert so ein Konstruktor nicht. In der Klasse Ball ist nur ein Standardkonstruktor ohne Parameter definiert. Du könntest zum Beispiel den Konstruktor anpassen.

public Ball(Notarkanoid notarkanoid)

{

super();

this.notarkanoid = notarkanoid;

[...]

}

Erstelle ein Benutzerkonto oder melde Dich an, um zu kommentieren

Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können

Benutzerkonto erstellen

Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!

Neues Benutzerkonto erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde Dich hier an.

Jetzt anmelden

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...