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.

Results 1 to 3 of 3

Thread: help me to create Block Breaker (using OOP method)

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    2
    My Mood
    Worried
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb help me to create Block Breaker (using OOP method)

    hi everyone can you help me to create Block Breaker using OOP code?


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: help me to create Block Breaker (using OOP method)

    Post your code and ask specific questions.

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    2
    My Mood
    Worried
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help me to create Block Breaker (using OOP method)

    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);
    }
    }


    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);





    }
    }
    how can i move this paddle and ball?
    and hit the blocks.?

Similar Threads

  1. HELP! Can you teach me how to do the constructor method in OOP(JAVA)
    By BALLISLIFE in forum Object Oriented Programming
    Replies: 1
    Last Post: July 26th, 2013, 12:23 AM
  2. Brick Breaker
    By jan4185 in forum Object Oriented Programming
    Replies: 19
    Last Post: February 8th, 2013, 02:32 PM
  3. where to put list of objects method OOP
    By stanlj in forum Object Oriented Programming
    Replies: 3
    Last Post: January 14th, 2013, 02:08 PM
  4. [SOLVED] How to create a Java generic method, similar to a C++ template method?
    By Sharmeen in forum Object Oriented Programming
    Replies: 3
    Last Post: October 18th, 2012, 02:33 AM
  5. Replies: 4
    Last Post: June 15th, 2012, 01:50 PM