1
0
Fork 0

Aufgabe 2.1 + reindent project

This commit is contained in:
rxbn 2019-12-01 18:31:50 +01:00
parent 1f5c6edd03
commit c9f87ace17
13 changed files with 399 additions and 201 deletions

View File

@ -6,7 +6,6 @@ import java.awt.Color;
* A class that contains all constant values to configure the game
*
* @author dmlux, modified by I. Schumacher
*
*/
public class Constants {

View File

@ -8,7 +8,6 @@ import break_out.view.View;
* are initialized here.
*
* @author dmlux, modified by I. Schumacher
*
*/
public class Main {

View File

@ -14,8 +14,7 @@ import break_out.view.View;
* The controller takes care of the input events and reacts on those events by
* manipulating the view and updates the model.
*
* @author dmlux, modified by I. Schumacher and I. Traupe
*
* @author dmlux, modified by I. Schumacher and I. Traupe, modified by Gruppe 175
*/
public class Controller implements ActionListener, KeyListener {
@ -32,8 +31,7 @@ public class Controller implements ActionListener, KeyListener {
/**
* The constructor expects a view to construct itself.
*
* @param view
* The view that is connected to this controller
* @param view The view that is connected to this controller
*/
public Controller(View view) {
this.view = view;
@ -101,6 +99,7 @@ public class Controller implements ActionListener, KeyListener {
/**
* This method will be called, after a key was typed. This means, that the key
* was pressed and released, before this method get called.
*
* @param e The key event
*/
@Override
@ -110,6 +109,7 @@ public class Controller implements ActionListener, KeyListener {
/**
* This method will be called, after a key was pressed down.
*
* @param e The key event
*/
@Override
@ -119,6 +119,7 @@ public class Controller implements ActionListener, KeyListener {
/**
* This method will be called, after a key was released.
*
* @param e The key event
*/
@Override

View File

@ -7,7 +7,6 @@ import break_out.Constants;
*
* @author iSchumacher
* @author modified by Gruppe 175: Moritz Henseleit, Ruben Meyer
*
*/
public class Ball implements IBall {
@ -31,12 +30,13 @@ public class Ball implements IBall{
this.direction.rescale();
// start at bottom-center
this.position.setX((Constants.SCREEN_WIDTH - Constants.BALL_DIAMETER)/2);
this.position.setY(Constants.SCREEN_HEIGHT-Constants.BALL_DIAMETER);
this.position.setX((Constants.SCREEN_WIDTH - Constants.BALL_DIAMETER) / 2.0);
this.position.setY(Constants.SCREEN_HEIGHT - Constants.BALL_DIAMETER - Constants.PADDLE_HEIGHT);
}
/**
* The getter for the balls position
*
* @return position The balls current position
*/
public Position getPosition() {
@ -45,6 +45,7 @@ public class Ball implements IBall{
/**
* The getter for the balls direction
*
* @return direction The balls current direction
*/
public Vector2D getDirection() {

View File

@ -9,8 +9,7 @@ import break_out.view.View;
/**
* This class contains information about the game (the model in MVC)
*
* @author dmlux, modified by I. Schumacher
*
* @author dmlux, modified by I. Schumacher, modified by Gruppe 175
*/
public class Game {
@ -47,8 +46,7 @@ public class Game {
/**
* The constructor creates a new game instance with the given Controller
*
* @param controller
* The controller to manage this instance (MVC-patter)
* @param controller The controller to manage this instance (MVC-patter)
*/
public Game(Controller controller) {
this.controller = controller;
@ -102,10 +100,8 @@ public class Game {
* maxLevel. If the current level is higher than maxLevel the view will be
* switched to the startScreen.
*
* @param levelnr
* The number for the next level
* @param score
* The current players score after finishing the previous level.
* @param levelnr The number for the next level
* @param score The current players score after finishing the previous level.
*/
public void createLevel(int levelnr, int score) {
this.score = score;

View File

@ -1,6 +1,8 @@
package break_out.model;
import break_out.Constants;
/**
* This class contains information about the running game
*
@ -8,7 +10,7 @@ package break_out.model;
* @author I. Schumacher
* @author modified by Gruppe 175: Moritz Henseleit, Ruben Meyer
*/
public class Level extends Thread {
public class Level extends Thread implements ILevel {
/**
* The game to which the level belongs
@ -35,9 +37,15 @@ public class Level extends Thread {
*/
private boolean ballWasStarted = true;
/**
* The paddles of the level
*/
private Paddle paddleTop, paddleBottom;
/**
* The constructor creates a new level object and needs the current game object,
* the number of the level to be created and the current score
*
* @param game The game object
* @param levelnr The number of the new level object
* @param score The score
@ -48,11 +56,20 @@ public class Level extends Thread {
this.score = score;
this.ball = new Ball();
// calc paddle positions
Position posPaddleTop = new Position((Constants.SCREEN_WIDTH - Constants.PADDLE_WIDTH) / 2.0, 0);
Position posPaddleBottom = new Position((Constants.SCREEN_WIDTH - Constants.PADDLE_WIDTH) / 2.0, Constants.SCREEN_HEIGHT - Constants.PADDLE_HEIGHT);
// set paddles
this.paddleTop = new Paddle(posPaddleTop);
this.paddleBottom = new Paddle(posPaddleBottom);
loadLevelData(levelnr);
}
/**
* The getter for the ball object
*
* @return ball The ball of the level
*/
public Ball getBall() {
@ -75,6 +92,7 @@ public class Level extends Thread {
/**
* Returns if the ball is moving or stopped
*
* @return ballWasStarted True: the ball is moving; false: the ball is stopped
*/
public boolean ballWasStarted() {
@ -114,12 +132,31 @@ public class Level extends Thread {
/**
* Loads the information for the level from a json-file located in the folder /res of the project
*
* @param levelnr The number X for the LevelX.json file
*/
private void loadLevelData(int levelnr) {
}
/**
* The getter for the top paddle object
*
* @return paddleTop The top paddle of the level
*/
public Paddle getPaddleTop() {
return paddleTop;
}
/**
* The getter for the bottom paddle object
*
* @return paddleBottom The bottom paddle of the level
*/
public Paddle getPaddleBottom() {
return paddleBottom;
}
}

View File

@ -0,0 +1,115 @@
package break_out.model;
import break_out.Constants;
import java.awt.*;
/**
* This class contains the information about the paddles characteristics and behavior
*
* @author Gruppe 175: Moritz Henseleit, Ruben Meyer
*/
public class Paddle implements IPaddle {
/**
* The paddles position on the playground
*/
private Position position;
/**
* The paddles sizing
*/
private double width;
private double height;
/**
* The paddles color
*/
private Color color;
/**
* The constructor of a paddle
*/
public Paddle(Position position) {
this.position = position;
// set sizing
width = Constants.PADDLE_WIDTH;
height = Constants.PADDLE_HEIGHT;
// set color
color = Color.CYAN;
}
/**
* The getter for the paddles position
*
* @return position The paddles current position
*/
public Position getPosition() {
return position;
}
/**
* The setter for the paddles position
*
* @param position The paddles new position
*/
public void setPosition(Position position) {
this.position = position;
}
/**
* The getter for the paddles color
*
* @return color The paddles current color
*/
public Color getColor() {
return color;
}
/**
* The setter for the paddles color
*
* @param color The paddles new color
*/
public void setColor(Color color) {
this.color = color;
}
/**
* The getter for the paddles width
*
* @return width The paddles current width
*/
public double getWidth() {
return width;
}
/**
* The setter for the paddles width
*
* @param width The paddles new width
*/
public void setWidth(double width) {
this.width = width;
}
/**
* The getter for the paddles height
*
* @return height The paddles current height
*/
public double getHeight() {
return height;
}
/**
* The setter for the paddles height
*
* @param height The paddles new height
*/
public void setHeight(double height) {
this.height = height;
}
}

View File

@ -5,7 +5,6 @@ package break_out.model;
* This class represents a position within the board in pixel coordinates
*
* @author dmlux
*
*/
public class Position {
@ -41,6 +40,7 @@ public class Position {
/**
* Setter for the x-coordinate
*
* @param x The new x-coordinate
*/
public void setX(double x) {
@ -58,6 +58,7 @@ public class Position {
/**
* Setter for the y-coordinate
*
* @param y The new y-coordinate
*/
public void setY(double y) {

View File

@ -61,6 +61,7 @@ public class Field extends JPanel {
/**
* Change the background color
*
* @param color The new color
*/
public void changeBackground(Color color) {
@ -70,6 +71,7 @@ public class Field extends JPanel {
/**
* This method is called when painting/repainting the playground
*
* @param g the graphics object
*/
@Override
@ -101,10 +103,17 @@ public class Field extends JPanel {
// Calls the method for drawing the grid
drawGrid(g2);
// Calls the method for drawing the bottom paddle
drawPaddleBottom(g2);
// Calls the method for drawing the top paddle
drawPaddleTop(g2);
}
/**
* Draws the ball
*
* @param g2 The graphics object
*/
private void drawBall(Graphics2D g2) {
@ -116,6 +125,7 @@ public class Field extends JPanel {
/**
* Draws the grid
*
* @param g2 The graphics object
*/
private void drawGrid(Graphics2D g2) {
@ -135,4 +145,34 @@ public class Field extends JPanel {
}
}
/**
* Draws the bottom paddle
*
* @param g2 The graphics object
*/
private void drawPaddleBottom(Graphics2D g2) {
// fillRoundRect(x, y, width, height, arcWidth, arcHeight)
g2.fillRoundRect((int) view.getGame().getLevel().getPaddleBottom().getPosition().getX(),
(int) view.getGame().getLevel().getPaddleBottom().getPosition().getY(),
(int) view.getGame().getLevel().getPaddleBottom().getWidth(),
(int) view.getGame().getLevel().getPaddleBottom().getHeight(),
10,
10);
}
/**
* Draws the top paddle
*
* @param g2 The graphics object
*/
private void drawPaddleTop(Graphics2D g2) {
// fillRoundRect(x, y, width, height, arcWidth, arcHeight)
g2.fillRoundRect((int) view.getGame().getLevel().getPaddleTop().getPosition().getX(),
(int) view.getGame().getLevel().getPaddleTop().getPosition().getY(),
(int) view.getGame().getLevel().getPaddleTop().getWidth(),
(int) view.getGame().getLevel().getPaddleTop().getHeight(),
10,
10);
}
}

View File

@ -14,7 +14,6 @@ import javax.swing.JPanel;
* This panel represents the background for special divisions in this application
*
* @author dmlux
*
*/
public class SectionPanel extends JPanel {

View File

@ -18,7 +18,6 @@ import net.miginfocom.swing.MigLayout;
* This screen serves the configuration of the game.
*
* @author dmlux, modified by I. Schumacher
*
*/
public class StartScreen extends JPanel {
@ -142,6 +141,7 @@ public class StartScreen extends JPanel {
/**
* Adds an action listener to the start button
*
* @param l The actionListener
*/
public void addActionListenerToStartButton(ActionListener l) {
@ -150,6 +150,7 @@ public class StartScreen extends JPanel {
/**
* Returns the start button
*
* @return startGame The button for starting the game
*/
public JButton getStartButton() {
@ -158,6 +159,7 @@ public class StartScreen extends JPanel {
/**
* Adds an action listener to the quit button
*
* @param l The actionListener
*/
public void addActionListenerToQuitButton(ActionListener l) {
@ -166,6 +168,7 @@ public class StartScreen extends JPanel {
/**
* Returns the quit button
*
* @return quitGame The button for ending the game
*/
public JButton getQuitButton() {
@ -174,6 +177,7 @@ public class StartScreen extends JPanel {
/**
* Returns the players name
*
* @return The name of the player in the JTextField playersName
*/
public String getPlayersName() {
@ -182,6 +186,7 @@ public class StartScreen extends JPanel {
/**
* Shows an error in the menu
*
* @param message The String to be shown
*/
public void showError(String message) {

View File

@ -13,7 +13,6 @@ import break_out.model.Game;
*
* @author dmlux
* @author modified by Gruppe 175: Moritz Henseleit, Ruben Meyer
*
*/
public class View extends JFrame {
@ -78,6 +77,7 @@ public class View extends JFrame {
/**
* Getter for the start screen
*
* @return startScreen
*/
public StartScreen getStartScreen() {
@ -86,6 +86,7 @@ public class View extends JFrame {
/**
* Getter for the playground
*
* @return field
*/
public Field getField() {
@ -94,6 +95,7 @@ public class View extends JFrame {
/**
* Getter for the game
*
* @return game
*/
public Game getGame() {
@ -102,6 +104,7 @@ public class View extends JFrame {
/**
* Setter for the game
*
* @param game The current game
*/
public void setGame(Game game) {
@ -112,6 +115,7 @@ public class View extends JFrame {
/**
* Shows a given screen if the card layout contains this screen
*
* @param screenName The screen to be shown
*/
public void showScreen(String screenName) {
@ -121,6 +125,7 @@ public class View extends JFrame {
/**
* Called by game.notifyObservers() in the run()-method of Level class
* to repaint the playground
*
* @param game The game to observe
*/
public void modelChanged(Game game) {