Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MovablePoint implements Movable {
- int x;
- int y;
- int xSpeed;
- int ySpeed;
- //Constructors
- public MovablePoint(int x, int y, int xSpeed, int ySpeed) {
- this.x = x;
- this.y = y;
- this.xSpeed = xSpeed;
- this.ySpeed = ySpeed;
- }
- //Movement Methods
- public void moveUp() {
- y -= ySpeed;
- }
- public void moveDown() {
- y += ySpeed;
- }
- public void moveLeft() {
- x -= xSpeed;
- }
- public void moveRight() {
- x += xSpeed;
- }
- //toString()
- public String toString() {
- return "(" + x + "," + y + ")";
- }
- }
- class MovableRectangle implements Movable {
- private MovablePoint topLeft;
- private MovablePoint bottomRight;
- MovableRectangle(int x1, int y1, int x2, int y2, int xSpeed, int ySpeed) {
- topLeft = new MovablePoint(x1, y1, xSpeed, ySpeed);
- bottomRight = new MovablePoint(x2, y2, xSpeed, ySpeed);
- }
- public String toString() {
- return "(" + topLeft.x + "," + topLeft.y + "), (" + bottomRight.x + "," + bottomRight.y + ")";
- }
- //Movement Methods
- public void moveUp() {
- topLeft.moveUp();
- bottomRight.moveUp();
- }
- public void moveDown() {
- topLeft.moveDown();
- bottomRight.moveDown();
- }
- public void moveLeft() {
- topLeft.moveLeft();
- bottomRight.moveLeft();
- }
- public void moveRight() {
- topLeft.moveRight();
- bottomRight.moveRight();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement