hi everyone can you help me to create Block Breaker using OOP code?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
hi everyone can you help me to create Block Breaker using OOP code?
Post your code and ask specific questions.
here are my codes:
MAIN
package blockbreak;
import java.awt.Point;
import javax.swing.JFrame;
public class main {
public static void main(String[] args) {
JFrame frame = new JFrame ("Block Bricker");
frame.setSize(620,600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
paddle pad = new paddle((short)50, new Point(20,20));
frame.add(pad);
Thread t = new Thread(pad);
t.start();
frame.setVisible(true);
}
}
how can i move this paddle and ball?PADDLE:
package blockbreak;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
public class paddle extends Canvas implements Runnable {
private short speed;
@Override
public void run() {
}
private enum Direction {
FORWARD, BACKWARD
};
private Direction direction;
private Point position;
private Point position1;
private boolean isMoving;
public paddle(short speed, Point position) {
this.speed = speed;
this.position = position;
this.direction = direction.FORWARD;
this.isMoving = false;
}
public void paint(Graphics graphics) {
//paddle
graphics.setColor(Color.BLACK);
graphics.fillRect(position.x + 250, position.y + 500, 100, 15);
//ball
graphics.setColor(Color.RED);
graphics.fillRoundRect(310, 500, 20, 20, 20,20);
//line 1 blocks
graphics.setColor(Color.RED);
graphics.fillRect(position.x + 50, position.y + 30, 50, 20);
graphics.setColor(Color.RED);
graphics.fillRect(position.x + 130, position.y + 30, 50, 20);
graphics.setColor(Color.RED);
graphics.fillRect(position.x + 210, position.y + 30, 50, 20);
graphics.setColor(Color.RED);
graphics.fillRect(position.x + 290, position.y + 30, 50, 20);
graphics.setColor(Color.RED);
graphics.fillRect(position.x + 370, position.y + 30, 50, 20);
graphics.setColor(Color.RED);
graphics.fillRect(position.x + 450, position.y + 30, 50, 20);
// line 2 block
graphics.setColor(Color.BLUE);
graphics.fillRect(position.x + 90, position.y + 60, 50, 20);
graphics.setColor(Color.BLUE);
graphics.fillRect(position.x + 170, position.y + 60, 50, 20);
graphics.setColor(Color.BLUE);
graphics.fillRect(position.x + 250, position.y + 60, 50, 20);
graphics.setColor(Color.BLUE);
graphics.fillRect(position.x + 330, position.y + 60, 50, 20);
graphics.setColor(Color.BLUE);
graphics.fillRect(position.x + 410, position.y + 60, 50, 20);
// line 3 block
graphics.setColor(Color.YELLOW);
graphics.fillRect(position.x + 130, position.y + 90, 50, 20);
graphics.setColor(Color.YELLOW);
graphics.fillRect(position.x + 210, position.y + 90, 50, 20);
graphics.setColor(Color.YELLOW);
graphics.fillRect(position.x + 290, position.y + 90, 50, 20);
graphics.setColor(Color.YELLOW);
graphics.fillRect(position.x + 370, position.y + 90, 50, 20);
// line 4 block
graphics.setColor(Color.ORANGE);
graphics.fillRect(position.x + 170, position.y + 120, 50, 20);
graphics.setColor(Color.ORANGE);
graphics.fillRect(position.x + 250, position.y + 120, 50, 20);
graphics.setColor(Color.ORANGE);
graphics.fillRect(position.x + 330, position.y + 120, 50, 20);
// line 5 block
graphics.setColor(Color.GREEN);
graphics.fillRect(position.x + 210, position.y + 150, 50, 20);
graphics.setColor(Color.GREEN);
graphics.fillRect(position.x + 290, position.y + 150, 50, 20);
// line 6 block
graphics.setColor(Color.pink);
graphics.fillRect(position.x+250, position.y+180, 50, 20);
}
}
and hit the blocks.?