From 19531824c78cd2edf8a6b1a8da665728692d1a9a Mon Sep 17 00:00:00 2001 From: S Date: Tue, 6 Jun 2017 14:42:27 +0100 Subject: [PATCH 01/31] {"types":"A","runs":0} --- Breakout.java | 132 +++++++++++++++++++++++++------------------------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/Breakout.java b/Breakout.java index 3f7c84d..21afe9e 100755 --- a/Breakout.java +++ b/Breakout.java @@ -1,66 +1,66 @@ -/* - * File: Breakout.java - * ------------------- - * Name: - * Section Leader: - * - * This file will eventually implement the game of Breakout. - */ - -import acm.graphics.*; -import acm.program.*; -import acm.util.*; - -import java.applet.*; -import java.awt.*; -import java.awt.event.*; - -public class Breakout extends GraphicsProgram { - -/** Width and height of application window in pixels */ - public static final int APPLICATION_WIDTH = 400; - public static final int APPLICATION_HEIGHT = 600; - -/** Dimensions of game board (usually the same) */ - private static final int WIDTH = APPLICATION_WIDTH; - private static final int HEIGHT = APPLICATION_HEIGHT; - -/** Dimensions of the paddle */ - private static final int PADDLE_WIDTH = 60; - private static final int PADDLE_HEIGHT = 10; - -/** Offset of the paddle up from the bottom */ - private static final int PADDLE_Y_OFFSET = 30; - -/** Number of bricks per row */ - private static final int NBRICKS_PER_ROW = 10; - -/** Number of rows of bricks */ - private static final int NBRICK_ROWS = 10; - -/** Separation between bricks */ - private static final int BRICK_SEP = 4; - -/** Width of a brick */ - private static final int BRICK_WIDTH = - (WIDTH - (NBRICKS_PER_ROW - 1) * BRICK_SEP) / NBRICKS_PER_ROW; - -/** Height of a brick */ - private static final int BRICK_HEIGHT = 8; - -/** Radius of the ball in pixels */ - private static final int BALL_RADIUS = 10; - -/** Offset of the top brick row from the top */ - private static final int BRICK_Y_OFFSET = 70; - -/** Number of turns */ - private static final int NTURNS = 3; - -/* Method: run() */ -/** Runs the Breakout program. */ - public void run() { - /* You fill this in, along with any subsidiary methods */ - } - -} +/* + * File: Breakout.java + * ------------------- + * Name: + * Section Leader: + * + * This file will eventually implement the game of Breakout. + */ + +import acm.graphics.*; +import acm.program.*; +import acm.util.*; + +import java.applet.*; +import java.awt.*; +import java.awt.event.*; + +public class Breakout extends GraphicsProgram { + +/** Width and height of application window in pixels */ + public static final int APPLICATION_WIDTH = 400; + public static final int APPLICATION_HEIGHT = 600; + +/** Dimensions of game board (usually the same) */ + private static final int WIDTH = APPLICATION_WIDTH; + private static final int HEIGHT = APPLICATION_HEIGHT; + +/** Dimensions of the paddle */ + private static final int PADDLE_WIDTH = 60; + private static final int PADDLE_HEIGHT = 10; + +/** Offset of the paddle up from the bottom */ + private static final int PADDLE_Y_OFFSET = 30; + +/** Number of bricks per row */ + private static final int NBRICKS_PER_ROW = 10; + +/** Number of rows of bricks */ + private static final int NBRICK_ROWS = 10; + +/** Separation between bricks */ + private static final int BRICK_SEP = 4; + +/** Width of a brick */ + private static final int BRICK_WIDTH = + (WIDTH - (NBRICKS_PER_ROW - 1) * BRICK_SEP) / NBRICKS_PER_ROW; + +/** Height of a brick */ + private static final int BRICK_HEIGHT = 8; + +/** Radius of the ball in pixels */ + private static final int BALL_RADIUS = 10; + +/** Offset of the top brick row from the top */ + private static final int BRICK_Y_OFFSET = 70; + +/** Number of turns */ + private static final int NTURNS = 3; + +/* Method: run() */ +/** Runs the Breakout program. */ + public void run() { + /* You fill this in, along with any subsidiary methods */ + } + +} From 415d0d0c74f73129a08a0fde0bf179dc50e320c8 Mon Sep 17 00:00:00 2001 From: S Date: Wed, 7 Jun 2017 14:51:55 +0100 Subject: [PATCH 02/31] {"types":"C","runs":1} From f020ab55e0d8b8db403e0207baf55e0351d0106f Mon Sep 17 00:00:00 2001 From: S Date: Fri, 9 Jun 2017 16:42:14 +0100 Subject: [PATCH 03/31] {"types":"C","runs":1} --- Breakout.java | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Breakout.java b/Breakout.java index 21afe9e..def3900 100755 --- a/Breakout.java +++ b/Breakout.java @@ -1,5 +1,5 @@ /* - * File: Breakout.java + * File: Breakout.java * ------------------- * Name: * Section Leader: @@ -59,7 +59,33 @@ public class Breakout extends GraphicsProgram { /* Method: run() */ /** Runs the Breakout program. */ + + public void run() { + buildGame(); + + } + private void buildGame(){ + setSize(WIDTH,HEIGHT); + createBrick(0,BRICK_Y_OFFSET); + //createBall(); + //createPaddle(); + } + private void createBrick(double bry, double brx){ + for(int row = 0;row < NBRICK_ROWS; row++){ + for(int column = 0; column < NBRICKS_PER_ROW; column++){ + double y = bry +(BRICK_HEIGHT + BRICK_SEP)*row; + double x = brx +(BRICK_WIDTH + BRICK_SEP)*column; + GRect brick = new GRect(x,y,BRICK_WIDTH,BRICK_HEIGHT); + add(brick); + + + + + + } + } + } /* You fill this in, along with any subsidiary methods */ } From 60f37f1fb83d17858995dc4cb1ca18098c3cb0a0 Mon Sep 17 00:00:00 2001 From: S Date: Fri, 9 Jun 2017 16:43:01 +0100 Subject: [PATCH 04/31] {"types":"C","runs":2} --- Breakout.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Breakout.java b/Breakout.java index def3900..249c1a0 100755 --- a/Breakout.java +++ b/Breakout.java @@ -89,4 +89,4 @@ private void createBrick(double bry, double brx){ /* You fill this in, along with any subsidiary methods */ } -} + From 8f32a86d5089bbb345d1176cc243e822b3bbfeb7 Mon Sep 17 00:00:00 2001 From: S Date: Fri, 9 Jun 2017 16:43:59 +0100 Subject: [PATCH 05/31] {"types":"C","runs":2} From 5aa17d4a32dab5c95f0af7537e2a0aaa9aaae3f8 Mon Sep 17 00:00:00 2001 From: S Date: Fri, 9 Jun 2017 16:52:39 +0100 Subject: [PATCH 06/31] {"types":"C","runs":5} --- Breakout.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Breakout.java b/Breakout.java index 249c1a0..ce1b128 100755 --- a/Breakout.java +++ b/Breakout.java @@ -71,7 +71,7 @@ private void buildGame(){ //createBall(); //createPaddle(); } - private void createBrick(double bry, double brx){ + private void createBrick(double brx, double bry){ for(int row = 0;row < NBRICK_ROWS; row++){ for(int column = 0; column < NBRICKS_PER_ROW; column++){ double y = bry +(BRICK_HEIGHT + BRICK_SEP)*row; From 8051272c091781ca356a1f3b6411ccd21068155b Mon Sep 17 00:00:00 2001 From: S Date: Sat, 10 Jun 2017 15:16:00 +0100 Subject: [PATCH 07/31] {"types":"C","runs":14} --- Breakout.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Breakout.java b/Breakout.java index ce1b128..116671b 100755 --- a/Breakout.java +++ b/Breakout.java @@ -78,7 +78,18 @@ private void createBrick(double brx, double bry){ double x = brx +(BRICK_WIDTH + BRICK_SEP)*column; GRect brick = new GRect(x,y,BRICK_WIDTH,BRICK_HEIGHT); add(brick); + + + + switch (row){ + case 1:brick.setColor(Color.RED);break; + case 2:brick.setColor(Color.RED);break; + case 3:brick.setColor(Color.RED);break; + case 4:brick.setColor(Color.RED);break; + case 5:brick.setColor(Color.RED);break; + default: brick.setColor(Color.ORANGE);break; + } From fcbbe43f0579ff360d8ffa6176fddd59be55b000 Mon Sep 17 00:00:00 2001 From: S Date: Sat, 10 Jun 2017 15:20:50 +0100 Subject: [PATCH 08/31] {"types":"C","runs":15} --- Breakout.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Breakout.java b/Breakout.java index 116671b..6ea5ea4 100755 --- a/Breakout.java +++ b/Breakout.java @@ -80,7 +80,8 @@ private void createBrick(double brx, double bry){ add(brick); - + brick.setFillColor(Color.RED); + brick.setFilled(true); switch (row){ case 1:brick.setColor(Color.RED);break; case 2:brick.setColor(Color.RED);break; From 4e14068a59dedd972e5941b6f0bf31280f07feca Mon Sep 17 00:00:00 2001 From: S Date: Sat, 10 Jun 2017 15:32:13 +0100 Subject: [PATCH 09/31] {"types":"C","runs":16} --- Breakout.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Breakout.java b/Breakout.java index 6ea5ea4..fd2f734 100755 --- a/Breakout.java +++ b/Breakout.java @@ -85,10 +85,14 @@ private void createBrick(double brx, double bry){ switch (row){ case 1:brick.setColor(Color.RED);break; case 2:brick.setColor(Color.RED);break; - case 3:brick.setColor(Color.RED);break; - case 4:brick.setColor(Color.RED);break; - case 5:brick.setColor(Color.RED);break; - default: brick.setColor(Color.ORANGE);break; + case 3:brick.setColor(Color.ORANGE);break; + case 4:brick.setColor(Color.ORANGE);break; + case 5:brick.setColor(Color.YELLOW);break; + case 6:brick.setColor(Color.YELLOW);break; + case 7:brick.setColor(Color.GREEN);break; + case 8:brick.setColor(Color.GREEN);break; + case 9:brick.setColor(Color.CYAN);break; + default: brick.setColor(Color.CYAN);break; } From ea78857b778b434a285cb640251e9ee194ba3334 Mon Sep 17 00:00:00 2001 From: S Date: Sat, 10 Jun 2017 15:39:49 +0100 Subject: [PATCH 10/31] {"types":"C","runs":17} --- Breakout.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Breakout.java b/Breakout.java index fd2f734..00b6556 100755 --- a/Breakout.java +++ b/Breakout.java @@ -77,11 +77,8 @@ private void createBrick(double brx, double bry){ double y = bry +(BRICK_HEIGHT + BRICK_SEP)*row; double x = brx +(BRICK_WIDTH + BRICK_SEP)*column; GRect brick = new GRect(x,y,BRICK_WIDTH,BRICK_HEIGHT); - add(brick); - - - brick.setFillColor(Color.RED); brick.setFilled(true); + switch (row){ case 1:brick.setColor(Color.RED);break; case 2:brick.setColor(Color.RED);break; @@ -93,10 +90,10 @@ private void createBrick(double brx, double bry){ case 8:brick.setColor(Color.GREEN);break; case 9:brick.setColor(Color.CYAN);break; default: brick.setColor(Color.CYAN);break; - } - + add(brick); + } From 9cddf749d8087a51b6bcb775a6affb3df51d6514 Mon Sep 17 00:00:00 2001 From: S Date: Sat, 10 Jun 2017 15:43:10 +0100 Subject: [PATCH 11/31] {"types":"C","runs":18} --- Breakout.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Breakout.java b/Breakout.java index 00b6556..f38bbec 100755 --- a/Breakout.java +++ b/Breakout.java @@ -89,7 +89,8 @@ private void createBrick(double brx, double bry){ case 7:brick.setColor(Color.GREEN);break; case 8:brick.setColor(Color.GREEN);break; case 9:brick.setColor(Color.CYAN);break; - default: brick.setColor(Color.CYAN);break; + case 10:brick.setColor(Color.CYAN);break; + default:;break; } add(brick); From 9c287b50a4dc3f0d6fb7c442f3eb941506741ae2 Mon Sep 17 00:00:00 2001 From: S Date: Sat, 10 Jun 2017 15:44:46 +0100 Subject: [PATCH 12/31] {"types":"C","runs":19} --- Breakout.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Breakout.java b/Breakout.java index f38bbec..47e73c7 100755 --- a/Breakout.java +++ b/Breakout.java @@ -77,7 +77,7 @@ private void createBrick(double brx, double bry){ double y = bry +(BRICK_HEIGHT + BRICK_SEP)*row; double x = brx +(BRICK_WIDTH + BRICK_SEP)*column; GRect brick = new GRect(x,y,BRICK_WIDTH,BRICK_HEIGHT); - brick.setFilled(true); + switch (row){ case 1:brick.setColor(Color.RED);break; @@ -92,7 +92,7 @@ private void createBrick(double brx, double bry){ case 10:brick.setColor(Color.CYAN);break; default:;break; } - + brick.setFilled(true); add(brick); From 70fa0ada73f9570c6068e2addd105bffae74c024 Mon Sep 17 00:00:00 2001 From: S Date: Sat, 10 Jun 2017 15:48:00 +0100 Subject: [PATCH 13/31] {"types":"C","runs":20} --- Breakout.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Breakout.java b/Breakout.java index 47e73c7..65b2b31 100755 --- a/Breakout.java +++ b/Breakout.java @@ -80,16 +80,16 @@ private void createBrick(double brx, double bry){ switch (row){ + case 0:brick.setColor(Color.RED);break; case 1:brick.setColor(Color.RED);break; - case 2:brick.setColor(Color.RED);break; + case 2:brick.setColor(Color.ORANGE);break; case 3:brick.setColor(Color.ORANGE);break; - case 4:brick.setColor(Color.ORANGE);break; + case 4:brick.setColor(Color.YELLOW);break; case 5:brick.setColor(Color.YELLOW);break; - case 6:brick.setColor(Color.YELLOW);break; + case 6:brick.setColor(Color.GREEN);break; case 7:brick.setColor(Color.GREEN);break; - case 8:brick.setColor(Color.GREEN);break; + case 8:brick.setColor(Color.CYAN);break; case 9:brick.setColor(Color.CYAN);break; - case 10:brick.setColor(Color.CYAN);break; default:;break; } brick.setFilled(true); From efef0b019308f0cbedafabde9d320a2b200580bc Mon Sep 17 00:00:00 2001 From: S Date: Sat, 10 Jun 2017 15:53:16 +0100 Subject: [PATCH 14/31] {"types":"C","runs":20} --- Breakout.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Breakout.java b/Breakout.java index 65b2b31..2df1643 100755 --- a/Breakout.java +++ b/Breakout.java @@ -96,7 +96,6 @@ private void createBrick(double brx, double bry){ add(brick); - } } } From f0a4a67ad7e7989d0e9c0e75b7b9400f65705658 Mon Sep 17 00:00:00 2001 From: S Date: Sat, 10 Jun 2017 22:05:59 +0100 Subject: [PATCH 15/31] {"types":"C","runs":1} --- Breakout.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Breakout.java b/Breakout.java index 2df1643..ef074f8 100755 --- a/Breakout.java +++ b/Breakout.java @@ -68,7 +68,7 @@ public void run() { private void buildGame(){ setSize(WIDTH,HEIGHT); createBrick(0,BRICK_Y_OFFSET); - //createBall(); + createBall(); //createPaddle(); } private void createBrick(double brx, double bry){ @@ -95,11 +95,19 @@ private void createBrick(double brx, double bry){ brick.setFilled(true); add(brick); - - } - } + + } } + } + /* You fill this in, along with any subsidiary methods */ - } + private void createBall(){ + GOval ball = new GOval(WIDTH/2-BALL_RADIUS,HEIGHT/2-BALL_RADIUS,BALL_RADIUS,BALL_RADIUS); + ball.setColor(Color.BLACK); + ball.setFilled(true); + add(ball); + + } +} From 2da0aaa531eb33a033360d2086fc60387f593075 Mon Sep 17 00:00:00 2001 From: S Date: Sat, 10 Jun 2017 22:39:38 +0100 Subject: [PATCH 16/31] {"types":"C","runs":2} --- Breakout.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Breakout.java b/Breakout.java index ef074f8..f446c11 100755 --- a/Breakout.java +++ b/Breakout.java @@ -94,8 +94,6 @@ private void createBrick(double brx, double bry){ } brick.setFilled(true); add(brick); - - } } } @@ -107,7 +105,13 @@ private void createBall(){ ball.setColor(Color.BLACK); ball.setFilled(true); add(ball); - } + private void createPaddle(){ + GRect paddle = new GRect(PADDLE_WIDTH,PADDLE_HEIGHT); + paddle.setColor(Color.BLACK); + paddle.setFilled(true); + add(paddle); + } + } From b62300e11fcd90c32b3adee7a979f6a42dc5c944 Mon Sep 17 00:00:00 2001 From: S Date: Sat, 10 Jun 2017 22:41:39 +0100 Subject: [PATCH 17/31] {"types":"C","runs":3} --- Breakout.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Breakout.java b/Breakout.java index f446c11..6e320ab 100755 --- a/Breakout.java +++ b/Breakout.java @@ -109,6 +109,7 @@ private void createBall(){ private void createPaddle(){ GRect paddle = new GRect(PADDLE_WIDTH,PADDLE_HEIGHT); paddle.setColor(Color.BLACK); + paddle.setFillColor(Color.BLACK); paddle.setFilled(true); add(paddle); } From d49bbb3670907f3b235741661d2dbd11e6b24b7f Mon Sep 17 00:00:00 2001 From: S Date: Sat, 10 Jun 2017 23:31:08 +0100 Subject: [PATCH 18/31] {"types":"C","runs":4} --- Breakout.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Breakout.java b/Breakout.java index 6e320ab..e24b5bd 100755 --- a/Breakout.java +++ b/Breakout.java @@ -107,11 +107,13 @@ private void createBall(){ add(ball); } private void createPaddle(){ - GRect paddle = new GRect(PADDLE_WIDTH,PADDLE_HEIGHT); + GRect paddle = new GRect((getWidth()-PADDLE_WIDTH)/2,(getHeight()-PADDLE_Y_OFFSET-PADDLE_HEIGHT),PADDLE_WIDTH,PADDLE_HEIGHT); paddle.setColor(Color.BLACK); paddle.setFillColor(Color.BLACK); paddle.setFilled(true); add(paddle); + + } } From 8cadff61b2131e12a1c5281b9b31445965e8d4c0 Mon Sep 17 00:00:00 2001 From: S Date: Sat, 10 Jun 2017 23:38:34 +0100 Subject: [PATCH 19/31] {"types":"C","runs":5} --- Breakout.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Breakout.java b/Breakout.java index e24b5bd..f641a83 100755 --- a/Breakout.java +++ b/Breakout.java @@ -110,7 +110,7 @@ private void createPaddle(){ GRect paddle = new GRect((getWidth()-PADDLE_WIDTH)/2,(getHeight()-PADDLE_Y_OFFSET-PADDLE_HEIGHT),PADDLE_WIDTH,PADDLE_HEIGHT); paddle.setColor(Color.BLACK); paddle.setFillColor(Color.BLACK); - paddle.setFilled(true); + add(paddle); From 5aed9c4de81c66203ef7b2c9b8813c820dea4c08 Mon Sep 17 00:00:00 2001 From: S Date: Sun, 11 Jun 2017 05:21:36 +0100 Subject: [PATCH 20/31] {"types":"C","runs":6} --- Breakout.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Breakout.java b/Breakout.java index f641a83..e24b5bd 100755 --- a/Breakout.java +++ b/Breakout.java @@ -110,7 +110,7 @@ private void createPaddle(){ GRect paddle = new GRect((getWidth()-PADDLE_WIDTH)/2,(getHeight()-PADDLE_Y_OFFSET-PADDLE_HEIGHT),PADDLE_WIDTH,PADDLE_HEIGHT); paddle.setColor(Color.BLACK); paddle.setFillColor(Color.BLACK); - + paddle.setFilled(true); add(paddle); From 039d7ec11e1e9a21a27ebcc404b4602dd47502d5 Mon Sep 17 00:00:00 2001 From: S Date: Sun, 11 Jun 2017 15:45:03 +0100 Subject: [PATCH 21/31] {"types":"C","runs":1} --- Breakout.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Breakout.java b/Breakout.java index e24b5bd..1c213ff 100755 --- a/Breakout.java +++ b/Breakout.java @@ -69,7 +69,7 @@ private void buildGame(){ setSize(WIDTH,HEIGHT); createBrick(0,BRICK_Y_OFFSET); createBall(); - //createPaddle(); + createPaddle(); } private void createBrick(double brx, double bry){ for(int row = 0;row < NBRICK_ROWS; row++){ From 723443bb4585e3f607a69b91f30a6d3efa2875d2 Mon Sep 17 00:00:00 2001 From: S Date: Mon, 12 Jun 2017 08:55:52 +0100 Subject: [PATCH 22/31] {"types":"C","runs":3} --- Breakout.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Breakout.java b/Breakout.java index 1c213ff..60338d3 100755 --- a/Breakout.java +++ b/Breakout.java @@ -57,6 +57,7 @@ public class Breakout extends GraphicsProgram { /** Number of turns */ private static final int NTURNS = 3; + private GRect paddle; /* Method: run() */ /** Runs the Breakout program. */ @@ -70,6 +71,8 @@ private void buildGame(){ createBrick(0,BRICK_Y_OFFSET); createBall(); createPaddle(); + + } private void createBrick(double brx, double bry){ for(int row = 0;row < NBRICK_ROWS; row++){ @@ -107,14 +110,18 @@ private void createBall(){ add(ball); } private void createPaddle(){ - GRect paddle = new GRect((getWidth()-PADDLE_WIDTH)/2,(getHeight()-PADDLE_Y_OFFSET-PADDLE_HEIGHT),PADDLE_WIDTH,PADDLE_HEIGHT); + paddle = new GRect((getWidth()-PADDLE_WIDTH)/2,(getHeight()-PADDLE_Y_OFFSET-PADDLE_HEIGHT),PADDLE_WIDTH,PADDLE_HEIGHT); paddle.setColor(Color.BLACK); paddle.setFillColor(Color.BLACK); paddle.setFilled(true); add(paddle); - - - } - + } + +// makes paddle move +public void paddleMovement(MouseEvent e){ + paddle.setLocation(e.getX() - PADDLE_WIDTH/2, paddle.getY()); + if (paddle.getX() <= 0) paddle.setLocation(0, paddle.getY()); + if (paddle.getX() + PADDLE_WIDTH >= getWidth()) paddle.setLocation(getWidth() - PADDLE_WIDTH, paddle.getY()); +} } From f7a53f1f9da54cd5d6f44526bc9cbf8099201b4f Mon Sep 17 00:00:00 2001 From: S Date: Mon, 12 Jun 2017 09:40:20 +0100 Subject: [PATCH 23/31] {"types":"C","runs":3} --- Breakout.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Breakout.java b/Breakout.java index 60338d3..c9e5238 100755 --- a/Breakout.java +++ b/Breakout.java @@ -63,6 +63,7 @@ public class Breakout extends GraphicsProgram { public void run() { + addMouseListeners(); buildGame(); } @@ -115,6 +116,7 @@ private void createPaddle(){ paddle.setFillColor(Color.BLACK); paddle.setFilled(true); add(paddle); + } // makes paddle move From 8a62787ac9cad0c6824d4019450fd88f62e0e474 Mon Sep 17 00:00:00 2001 From: S Date: Mon, 12 Jun 2017 09:45:43 +0100 Subject: [PATCH 24/31] {"types":"C","runs":4} --- Breakout.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Breakout.java b/Breakout.java index c9e5238..6254cbd 100755 --- a/Breakout.java +++ b/Breakout.java @@ -120,7 +120,7 @@ private void createPaddle(){ } // makes paddle move -public void paddleMovement(MouseEvent e){ +public void mouseMoved(MouseEvent e){ paddle.setLocation(e.getX() - PADDLE_WIDTH/2, paddle.getY()); if (paddle.getX() <= 0) paddle.setLocation(0, paddle.getY()); if (paddle.getX() + PADDLE_WIDTH >= getWidth()) paddle.setLocation(getWidth() - PADDLE_WIDTH, paddle.getY()); From 14878c83c7dc80f9f955f3332e0d0738b5cf4529 Mon Sep 17 00:00:00 2001 From: S Date: Tue, 13 Jun 2017 16:19:26 +0100 Subject: [PATCH 25/31] {"types":"C","runs":0} --- .settings/org.eclipse.jdt.core.prefs | 12 +++++++++++- java.policy.applet | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 java.policy.applet diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 21ed01f..90cc2ec 100755 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,12 +1,21 @@ -#Mon Oct 15 10:34:35 PDT 2007 eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore org.eclipse.jdt.core.compiler.problem.deprecation=warning org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled org.eclipse.jdt.core.compiler.problem.discouragedReference=warning org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning @@ -50,3 +59,4 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=di org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/java.policy.applet b/java.policy.applet new file mode 100644 index 0000000..ba9f51d --- /dev/null +++ b/java.policy.applet @@ -0,0 +1,7 @@ +/* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/ +/* DO NOT EDIT */ + +grant { + permission java.security.AllPermission; +}; + From 312da0564de196b3b0a187e1c2e494b883c365a3 Mon Sep 17 00:00:00 2001 From: S Date: Tue, 13 Jun 2017 16:20:11 +0100 Subject: [PATCH 26/31] {"types":"C","runs":2} --- Breakout.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Breakout.java b/Breakout.java index 6254cbd..36a2b5c 100755 --- a/Breakout.java +++ b/Breakout.java @@ -125,5 +125,6 @@ public void mouseMoved(MouseEvent e){ if (paddle.getX() <= 0) paddle.setLocation(0, paddle.getY()); if (paddle.getX() + PADDLE_WIDTH >= getWidth()) paddle.setLocation(getWidth() - PADDLE_WIDTH, paddle.getY()); } + } From 12dc17b0a0e9016c389b11701e76ec173310fe24 Mon Sep 17 00:00:00 2001 From: S Date: Tue, 13 Jun 2017 16:32:37 +0100 Subject: [PATCH 27/31] {"types":"C","runs":4} --- Breakout.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Breakout.java b/Breakout.java index 36a2b5c..714a88f 100755 --- a/Breakout.java +++ b/Breakout.java @@ -63,9 +63,8 @@ public class Breakout extends GraphicsProgram { public void run() { - addMouseListeners(); buildGame(); - + //playGame(); } private void buildGame(){ setSize(WIDTH,HEIGHT); @@ -116,7 +115,7 @@ private void createPaddle(){ paddle.setFillColor(Color.BLACK); paddle.setFilled(true); add(paddle); - + addMouseListeners(); } // makes paddle move From 8d1a7a40223e6fc12a6c9ed789a38ce50dc9cb88 Mon Sep 17 00:00:00 2001 From: S Date: Tue, 13 Jun 2017 17:46:22 +0100 Subject: [PATCH 28/31] {"types":"C","runs":4} --- Breakout.java | 109 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 4 deletions(-) diff --git a/Breakout.java b/Breakout.java index 714a88f..5efbe19 100755 --- a/Breakout.java +++ b/Breakout.java @@ -56,16 +56,33 @@ public class Breakout extends GraphicsProgram { /** Number of turns */ private static final int NTURNS = 3; - + private int brickCounter = 100; private GRect paddle; + private double vx, vy; + private GOval ball; + private static final int DELAY = 20; + private RandomGenerator rgen = RandomGenerator.getInstance(); /* Method: run() */ /** Runs the Breakout program. */ public void run() { + for (int i = 0; i < NTURNS; i++){ buildGame(); - //playGame(); - } + playGame(); + if (brickCounter == 0){ + ball.setVisible(false); + printWinner(); + break; + } + if(brickCounter > 0){ + removeAll(); + } + } + if(brickCounter > 0){ + printGameOver(); + } + } private void buildGame(){ setSize(WIDTH,HEIGHT); createBrick(0,BRICK_Y_OFFSET); @@ -104,7 +121,7 @@ private void createBrick(double brx, double bry){ /* You fill this in, along with any subsidiary methods */ private void createBall(){ - GOval ball = new GOval(WIDTH/2-BALL_RADIUS,HEIGHT/2-BALL_RADIUS,BALL_RADIUS,BALL_RADIUS); + ball = new GOval(WIDTH/2-BALL_RADIUS,HEIGHT/2-BALL_RADIUS,BALL_RADIUS,BALL_RADIUS); ball.setColor(Color.BLACK); ball.setFilled(true); add(ball); @@ -124,6 +141,90 @@ public void mouseMoved(MouseEvent e){ if (paddle.getX() <= 0) paddle.setLocation(0, paddle.getY()); if (paddle.getX() + PADDLE_WIDTH >= getWidth()) paddle.setLocation(getWidth() - PADDLE_WIDTH, paddle.getY()); } +private void playGame(){ + waitForClick(); + getBallVelocity(); + while (true){ + moveBall(); + if (ball.getY() >= getHeight()){ + break; + } + if (brickCounter == 0){ + break; + } + } + } + + private void getBallVelocity(){ + vy = 4.0; + vx = rgen.nextDouble(1.0, 3.0); + if (rgen.nextBoolean(0.5)){ + vx = -vx; + } + } + + private void moveBall(){ + ball.move(vx, vy); + + //To check for collision. + if ((ball.getX() - vx <= 0 && vx < 0) || (ball.getX() + vx >= (getWidth() - BALL_RADIUS * 2) && vx > 0)){ + vx = -vx; + } + + if ((ball.getY() - vy <= 0 && vy < 0)){ + vy = -vy; + } + //Checking for other objects + GObject collider = getCollidingObject(); + if (collider == paddle){ + if (ball.getY() >= getHeight() - PADDLE_Y_OFFSET - PADDLE_HEIGHT - BALL_RADIUS * 2 && ball.getY() < getHeight() -PADDLE_Y_OFFSET - PADDLE_HEIGHT - BALL_RADIUS * 2 + 4){ + vy = -vy; + } + } + else if (collider != null){ + remove(collider); + brickCounter--; + vy = -vy; + } + pause(DELAY); +} + private GObject getCollidingObject(){ + if ((getElementAt(ball.getX(), ball.getY())) != null){ + return getElementAt(ball.getX(), ball.getY()); + } + else if ((getElementAt((ball.getX() + BALL_RADIUS * 2), ball.getY()) != null)){ + return (getElementAt((ball.getX() + BALL_RADIUS * 2), ball.getY())); + } + else if ((getElementAt((ball.getX() + BALL_RADIUS * 2), (ball.getY() + BALL_RADIUS * 2)) != null)){ + return (getElementAt((ball.getX() + BALL_RADIUS * 2), ball.getY() + BALL_RADIUS * 2)); + } + else if ((getElementAt((ball.getX()), (ball.getY() + BALL_RADIUS * 2)) != null)){ + return (getElementAt((ball.getX()), ball.getY() + BALL_RADIUS * 2)); + } + else{ + return null; + } + } + +/* */ + private void printGameOver(){ + GLabel label = new GLabel(" GAME OVER ", getWidth() / 2, getHeight() / 2); + label.move(-label.getWidth()/2, -label.getHeight()); + label.setColor(Color.RED); + add(label); + + } + + /* */ + private void printWinner(){ + GLabel label = new GLabel(" YOU WON!!! ", getWidth() / 2, getHeight() / 2); + label.move(-label.getWidth() / 2, label.getHeight()); + label.setColor(Color.RED); + add(label); + + } + + } From f0d6e3f38f80edc0234d48bc174235f564c3b26b Mon Sep 17 00:00:00 2001 From: S Date: Tue, 13 Jun 2017 23:54:31 +0100 Subject: [PATCH 29/31] {"types":"C","runs":10} --- Breakout.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Breakout.java b/Breakout.java index 5efbe19..3779c39 100755 --- a/Breakout.java +++ b/Breakout.java @@ -60,7 +60,7 @@ public class Breakout extends GraphicsProgram { private GRect paddle; private double vx, vy; private GOval ball; - private static final int DELAY = 20; + private static final int DELAY = 17; private RandomGenerator rgen = RandomGenerator.getInstance(); /* Method: run() */ /** Runs the Breakout program. */ From 2e989ef076b01e6f57c97ca488e2ce43c1ea05ea Mon Sep 17 00:00:00 2001 From: S Date: Wed, 14 Jun 2017 00:07:06 +0100 Subject: [PATCH 30/31] {"types":"C","runs":10} --- Breakout.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Breakout.java b/Breakout.java index 3779c39..8849a79 100755 --- a/Breakout.java +++ b/Breakout.java @@ -205,26 +205,22 @@ else if ((getElementAt((ball.getX()), (ball.getY() + BALL_RADIUS * 2)) != null)) return null; } } - + //This method display the Game Over message once the turn has elapse /* */ private void printGameOver(){ GLabel label = new GLabel(" GAME OVER ", getWidth() / 2, getHeight() / 2); label.move(-label.getWidth()/2, -label.getHeight()); - label.setColor(Color.RED); + label.setColor(Color.CYAN); add(label); } - + //this method display you win message once all the bricks had been broken /* */ private void printWinner(){ GLabel label = new GLabel(" YOU WON!!! ", getWidth() / 2, getHeight() / 2); label.move(-label.getWidth() / 2, label.getHeight()); label.setColor(Color.RED); - add(label); - + add(label); } - - - } From 83b16c481add7223f40af25f9fa33b9319dd8671 Mon Sep 17 00:00:00 2001 From: S Date: Wed, 14 Jun 2017 00:09:54 +0100 Subject: [PATCH 31/31] {"types":"C","runs":10} --- Breakout.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/Breakout.java b/Breakout.java index 8849a79..c1ef725 100755 --- a/Breakout.java +++ b/Breakout.java @@ -64,8 +64,6 @@ public class Breakout extends GraphicsProgram { private RandomGenerator rgen = RandomGenerator.getInstance(); /* Method: run() */ /** Runs the Breakout program. */ - - public void run() { for (int i = 0; i < NTURNS; i++){ buildGame();