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 * A class that contains all constant values to configure the game
* *
* @author dmlux, modified by I. Schumacher * @author dmlux, modified by I. Schumacher
*
*/ */
public class Constants { public class Constants {

View File

@ -6,15 +6,14 @@ import break_out.view.View;
/** /**
* The entry point of the program. The game get started here and all components * The entry point of the program. The game get started here and all components
* are initialized here. * are initialized here.
* *
* @author dmlux, modified by I. Schumacher * @author dmlux, modified by I. Schumacher
*
*/ */
public class Main { public class Main {
/** /**
* The main method * The main method
* *
* @param args The arguments that were passed by the command line. * @param args The arguments that were passed by the command line.
*/ */
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -13,9 +13,8 @@ import break_out.view.View;
/** /**
* The controller takes care of the input events and reacts on those events by * The controller takes care of the input events and reacts on those events by
* manipulating the view and updates the model. * 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 { public class Controller implements ActionListener, KeyListener {
@ -31,9 +30,8 @@ public class Controller implements ActionListener, KeyListener {
/** /**
* The constructor expects a view to construct itself. * The constructor expects a view to construct itself.
* *
* @param view * @param view The view that is connected to this controller
* The view that is connected to this controller
*/ */
public Controller(View view) { public Controller(View view) {
this.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 * This method will be called, after a key was typed. This means, that the key
* was pressed and released, before this method get called. * was pressed and released, before this method get called.
*
* @param e The key event * @param e The key event
*/ */
@Override @Override
@ -110,20 +109,22 @@ public class Controller implements ActionListener, KeyListener {
/** /**
* This method will be called, after a key was pressed down. * This method will be called, after a key was pressed down.
*
* @param e The key event * @param e The key event
*/ */
@Override @Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
} }
/** /**
* This method will be called, after a key was released. * This method will be called, after a key was released.
*
* @param e The key event * @param e The key event
*/ */
@Override @Override
public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) {
} }
/** /**

View File

@ -4,91 +4,92 @@ import break_out.Constants;
/** /**
* This class contains the information about the balls characteristics and behavior * This class contains the information about the balls characteristics and behavior
* *
* @author iSchumacher * @author iSchumacher
* @author modified by Gruppe 175: Moritz Henseleit, Ruben Meyer * @author modified by Gruppe 175: Moritz Henseleit, Ruben Meyer
*
*/ */
public class Ball implements IBall{ public class Ball implements IBall {
/** /**
* The balls position on the playground * The balls position on the playground
*/ */
private Position position; private Position position;
/** /**
* The balls direction * The balls direction
*/ */
private Vector2D direction; private Vector2D direction;
/** /**
* The constructor of a ball * The constructor of a ball
* The balls position and direction are initialized here. * The balls position and direction are initialized here.
*/ */
public Ball() { public Ball() {
this.position = new Position(0, 0); this.position = new Position(0, 0);
this.direction = new Vector2D(Constants.BALL_SPEED,Constants.BALL_SPEED); this.direction = new Vector2D(Constants.BALL_SPEED, Constants.BALL_SPEED);
this.direction.rescale(); this.direction.rescale();
// start at bottom-center // start at bottom-center
this.position.setX((Constants.SCREEN_WIDTH - Constants.BALL_DIAMETER)/2); this.position.setX((Constants.SCREEN_WIDTH - Constants.BALL_DIAMETER) / 2.0);
this.position.setY(Constants.SCREEN_HEIGHT-Constants.BALL_DIAMETER); this.position.setY(Constants.SCREEN_HEIGHT - Constants.BALL_DIAMETER - Constants.PADDLE_HEIGHT);
} }
/** /**
* The getter for the balls position * The getter for the balls position
*
* @return position The balls current position * @return position The balls current position
*/ */
public Position getPosition() { public Position getPosition() {
return this.position; return this.position;
} }
/** /**
* The getter for the balls direction * The getter for the balls direction
*
* @return direction The balls current direction * @return direction The balls current direction
*/ */
public Vector2D getDirection() { public Vector2D getDirection() {
return this.direction; return this.direction;
} }
/** /**
* updates ball position * updates ball position
*/ */
public void updatePosition() { public void updatePosition() {
// sets X position // sets X position
this.position.setX(this.position.getX()+this.direction.getDx()); this.position.setX(this.position.getX() + this.direction.getDx());
// sets Y position // sets Y position
this.position.setY(this.position.getY()+this.direction.getDy()); this.position.setY(this.position.getY() + this.direction.getDy());
} }
/** /**
* Ball reacts to contact with the borders * Ball reacts to contact with the borders
*/ */
public void reactOnBorder() { public void reactOnBorder() {
// reacts on left border // reacts on left border
if(this.position.getX() <= 0) { if (this.position.getX() <= 0) {
this.position.setX(0); this.position.setX(0);
this.direction.setDx(-(this.direction.getDx())); this.direction.setDx(-(this.direction.getDx()));
} }
// reacts on right border (-Diameter because of hitbox) // reacts on right border (-Diameter because of hitbox)
if(this.position.getX() >= Constants.SCREEN_WIDTH - Constants.BALL_DIAMETER) { if (this.position.getX() >= Constants.SCREEN_WIDTH - Constants.BALL_DIAMETER) {
this.position.setX(Constants.SCREEN_WIDTH - Constants.BALL_DIAMETER); this.position.setX(Constants.SCREEN_WIDTH - Constants.BALL_DIAMETER);
this.direction.setDx(-(this.direction.getDx())); this.direction.setDx(-(this.direction.getDx()));
} }
// reacts on top border // reacts on top border
if(this.position.getY() <= 0) { if (this.position.getY() <= 0) {
this.position.setY(0); this.position.setY(0);
this.direction.setDy(-(this.direction.getDy())); this.direction.setDy(-(this.direction.getDy()));
} }
// reacts on bottom border (+Diameter because of hitbox) // reacts on bottom border (+Diameter because of hitbox)
if(this.position.getY() >= Constants.SCREEN_HEIGHT - Constants.BALL_DIAMETER) { if (this.position.getY() >= Constants.SCREEN_HEIGHT - Constants.BALL_DIAMETER) {
this.position.setY(Constants.SCREEN_HEIGHT - Constants.BALL_DIAMETER); this.position.setY(Constants.SCREEN_HEIGHT - Constants.BALL_DIAMETER);
this.direction.setDy(-(this.direction.getDy())); this.direction.setDy(-(this.direction.getDy()));
} }
} }
} }

View File

@ -8,9 +8,8 @@ import break_out.view.View;
/** /**
* This class contains information about the game (the model in MVC) * 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 { public class Game {
@ -46,9 +45,8 @@ public class Game {
/** /**
* The constructor creates a new game instance with the given Controller * The constructor creates a new game instance with the given Controller
* *
* @param controller * @param controller The controller to manage this instance (MVC-patter)
* The controller to manage this instance (MVC-patter)
*/ */
public Game(Controller controller) { public Game(Controller controller) {
this.controller = controller; this.controller = controller;
@ -72,7 +70,7 @@ public class Game {
/** /**
* Getter for the Controller * Getter for the Controller
* *
* @return controller The controller of this game * @return controller The controller of this game
*/ */
public Controller getController() { public Controller getController() {
@ -81,7 +79,7 @@ public class Game {
/** /**
* Getter for the current Level * Getter for the current Level
* *
* @return level The current level of the game * @return level The current level of the game
*/ */
public Level getLevel() { public Level getLevel() {
@ -90,7 +88,7 @@ public class Game {
/** /**
* Getter for the total score * Getter for the total score
* *
* @return score The current score of the game * @return score The current score of the game
*/ */
public int getScore() { public int getScore() {
@ -101,11 +99,9 @@ public class Game {
* Creates the first or the next level, if the level number is less or equal * Creates the first or the next level, if the level number is less or equal
* maxLevel. If the current level is higher than maxLevel the view will be * maxLevel. If the current level is higher than maxLevel the view will be
* switched to the startScreen. * switched to the startScreen.
* *
* @param levelnr * @param levelnr The number for the next level
* The number for the next level * @param score The current players score after finishing the previous level.
* @param score
* The current players score after finishing the previous level.
*/ */
public void createLevel(int levelnr, int score) { public void createLevel(int levelnr, int score) {
this.score = score; this.score = score;

View File

@ -1,125 +1,162 @@
package break_out.model; package break_out.model;
import break_out.Constants;
/** /**
* This class contains information about the running game * This class contains information about the running game
* *
* @author dmlux * @author dmlux
* @author I. Schumacher * @author I. Schumacher
* @author modified by Gruppe 175: Moritz Henseleit, Ruben Meyer * @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 * The game to which the level belongs
*/ */
private Game game; private Game game;
/** /**
* The number of the level * The number of the level
*/ */
private int levelnr; private int levelnr;
/** /**
* The score of the level * The score of the level
*/ */
private int score; private int score;
/**
* The ball of the level
*/
private Ball ball;
/**
* Flag that shows if the ball was started
*/
private boolean ballWasStarted = true;
/**
* 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
*/
public Level(Game game, int levelnr, int score) {
this.game = game;
this.levelnr = levelnr;
this.score = score;
this.ball = new Ball();
loadLevelData(levelnr);
}
/** /**
* The getter for the ball object * The ball of the level
* @return ball The ball of the level */
*/ private Ball ball;
public Ball getBall() {
return this.ball;
}
/**
* Sets ballWasStarted to true, the ball is moving
*/
public void startBall() {
ballWasStarted = true;
}
/** /**
* Sets ballWasStarted to false, the ball is stopped * Flag that shows if the ball was started
*/ */
public void stopBall() { private boolean ballWasStarted = true;
ballWasStarted = false;
} /**
* The paddles of the level
/** */
* Returns if the ball is moving or stopped private Paddle paddleTop, paddleBottom;
* @return ballWasStarted True: the ball is moving; false: the ball is stopped
*/ /**
public boolean ballWasStarted() { * The constructor creates a new level object and needs the current game object,
return ballWasStarted; * 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
*/
public Level(Game game, int levelnr, int score) {
this.game = game;
this.levelnr = levelnr;
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() {
return this.ball;
}
/**
* Sets ballWasStarted to true, the ball is moving
*/
public void startBall() {
ballWasStarted = true;
}
/**
* Sets ballWasStarted to false, the ball is stopped
*/
public void stopBall() {
ballWasStarted = false;
}
/**
* Returns if the ball is moving or stopped
*
* @return ballWasStarted True: the ball is moving; false: the ball is stopped
*/
public boolean ballWasStarted() {
return ballWasStarted;
}
/**
* The method of the level thread
*/
public void run() {
game.notifyObservers();
// endless loop
while (true) {
// if ballWasStarted is true, the ball is moving
if (ballWasStarted) {
// Call here the balls method for updating his position on the playground
this.ball.updatePosition();
// Call here the balls method for reacting on the borders of the playground
this.ball.reactOnBorder();
// Tells the observer to repaint the components on the playground
game.notifyObservers();
}
// The thread pauses for a short time
try {
Thread.sleep(4);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
/**
* 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;
}
/**
* The method of the level thread
*/
public void run() {
game.notifyObservers();
// endless loop
while (true) {
// if ballWasStarted is true, the ball is moving
if (ballWasStarted) {
// Call here the balls method for updating his position on the playground
this.ball.updatePosition();
// Call here the balls method for reacting on the borders of the playground
this.ball.reactOnBorder();
// Tells the observer to repaint the components on the playground
game.notifyObservers();
}
// The thread pauses for a short time
try {
Thread.sleep(4);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
/**
* 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) {
}
} }

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

@ -3,9 +3,8 @@ package break_out.model;
/** /**
* This class represents a position within the board in pixel coordinates * This class represents a position within the board in pixel coordinates
* *
* @author dmlux * @author dmlux
*
*/ */
public class Position { public class Position {
@ -18,10 +17,10 @@ public class Position {
* Y coordinate * Y coordinate
*/ */
private double y; private double y;
/** /**
* The constructor needs a x and y coordinate to be called * The constructor needs a x and y coordinate to be called
* *
* @param x The x position of the object on the board * @param x The x position of the object on the board
* @param y The y position of the object on the board * @param y The y position of the object on the board
*/ */
@ -32,7 +31,7 @@ public class Position {
/** /**
* Getter for the x-coordinate * Getter for the x-coordinate
* *
* @return x The x value of this position * @return x The x value of this position
*/ */
public double getX() { public double getX() {
@ -41,6 +40,7 @@ public class Position {
/** /**
* Setter for the x-coordinate * Setter for the x-coordinate
*
* @param x The new x-coordinate * @param x The new x-coordinate
*/ */
public void setX(double x) { public void setX(double x) {
@ -49,7 +49,7 @@ public class Position {
/** /**
* Getter for y-coordinate * Getter for y-coordinate
* *
* @return y The y value of the position * @return y The y value of the position
*/ */
public double getY() { public double getY() {
@ -58,10 +58,11 @@ public class Position {
/** /**
* Setter for the y-coordinate * Setter for the y-coordinate
*
* @param y The new y-coordinate * @param y The new y-coordinate
*/ */
public void setY(double y) { public void setY(double y) {
this.y = y; this.y = y;
} }
} }

View File

@ -5,7 +5,7 @@ import break_out.model.Position;
/** /**
* This class represent a two dimensional vector. * This class represent a two dimensional vector.
* *
* @author I. Schumacher * @author I. Schumacher
* @author modified by Gruppe 175: Moritz Henseleit, Ruben Meyer * @author modified by Gruppe 175: Moritz Henseleit, Ruben Meyer
*/ */
@ -23,7 +23,7 @@ public class Vector2D implements IVector2D {
/** /**
* This constructor creates a new vector with the given x and y parts. * This constructor creates a new vector with the given x and y parts.
* *
* @param dx the delta x part for the new vector * @param dx the delta x part for the new vector
* @param dy the delty y part for the new vector * @param dy the delty y part for the new vector
*/ */
@ -34,7 +34,7 @@ public class Vector2D implements IVector2D {
/** /**
* Getter for the dx-part * Getter for the dx-part
* *
* @return dx The dx part of this vector * @return dx The dx part of this vector
*/ */
public double getDx() { public double getDx() {
@ -43,7 +43,7 @@ public class Vector2D implements IVector2D {
/** /**
* Setter for the dx-part * Setter for the dx-part
* *
* @param dx The new dx part of this vector * @param dx The new dx part of this vector
*/ */
public void setDx(double dx) { public void setDx(double dx) {
@ -52,7 +52,7 @@ public class Vector2D implements IVector2D {
/** /**
* Getter for the dy-part * Getter for the dy-part
* *
* @return dy The dy part of this vector * @return dy The dy part of this vector
*/ */
public double getDy() { public double getDy() {
@ -61,7 +61,7 @@ public class Vector2D implements IVector2D {
/** /**
* Setter for the dy-part * Setter for the dy-part
* *
* @param dy The new dy part of this vector * @param dy The new dy part of this vector
*/ */
public void setDy(double dy) { public void setDy(double dy) {
@ -74,7 +74,7 @@ public class Vector2D implements IVector2D {
public void rescale() { public void rescale() {
// calc unit vector and set it // calc unit vector and set it
double vectorLength = Math.sqrt(Math.pow(getDx(), 2) + Math.pow(getDy(), 2)); //using the square root of x and y double vectorLength = Math.sqrt(Math.pow(getDx(), 2) + Math.pow(getDy(), 2)); //using the square root of x and y
setDx((1/vectorLength) * getDx() * Constants.BALL_SPEED); setDx((1 / vectorLength) * getDx() * Constants.BALL_SPEED);
setDy((1/vectorLength) * getDy() * Constants.BALL_SPEED); setDy((1 / vectorLength) * getDy() * Constants.BALL_SPEED);
} }
} }

View File

@ -13,7 +13,7 @@ import net.miginfocom.swing.MigLayout;
/** /**
* The field represents the board of the game. All components are on the board * The field represents the board of the game. All components are on the board
* *
* @author dmlux, modified by iSchumacher * @author dmlux, modified by iSchumacher
* @author modified by Gruppe 175: Moritz Henseleit, Ruben Meyer * @author modified by Gruppe 175: Moritz Henseleit, Ruben Meyer
*/ */
@ -36,7 +36,7 @@ public class Field extends JPanel {
/** /**
* The constructor needs a view * The constructor needs a view
* *
* @param view The view of this board * @param view The view of this board
*/ */
public Field(View view) { public Field(View view) {
@ -61,15 +61,17 @@ public class Field extends JPanel {
/** /**
* Change the background color * Change the background color
*
* @param color The new color * @param color The new color
*/ */
public void changeBackground(Color color) { public void changeBackground(Color color) {
background = color; background = color;
repaint(); repaint();
} }
/** /**
* This method is called when painting/repainting the playground * This method is called when painting/repainting the playground
*
* @param g the graphics object * @param g the graphics object
*/ */
@Override @Override
@ -91,20 +93,27 @@ public class Field extends JPanel {
// Setting the background color // Setting the background color
g2.setColor(background); g2.setColor(background);
g2.fillRect(0, 0, getWidth(), getHeight()); g2.fillRect(0, 0, getWidth(), getHeight());
// Setting the color for the following components // Setting the color for the following components
g2.setColor(new Color(200, 200, 200)); g2.setColor(new Color(200, 200, 200));
// Calls the method for drawing the ball // Calls the method for drawing the ball
drawBall(g2); drawBall(g2);
// Calls the method for drawing the grid // Calls the method for drawing the grid
drawGrid(g2); 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 * Draws the ball
*
* @param g2 The graphics object * @param g2 The graphics object
*/ */
private void drawBall(Graphics2D g2) { private void drawBall(Graphics2D g2) {
@ -116,6 +125,7 @@ public class Field extends JPanel {
/** /**
* Draws the grid * Draws the grid
*
* @param g2 The graphics object * @param g2 The graphics object
*/ */
private void drawGrid(Graphics2D g2) { private void drawGrid(Graphics2D g2) {
@ -125,14 +135,44 @@ public class Field extends JPanel {
int blockHeight = Constants.SCREEN_HEIGHT / Constants.SQUARES_Y; int blockHeight = Constants.SCREEN_HEIGHT / Constants.SQUARES_Y;
// draw vertical lines // draw vertical lines
for(int i = 1 ; i < Constants.SQUARES_X; i++) { for (int i = 1; i < Constants.SQUARES_X; i++) {
g2.drawLine(i*blockWidth, 0, i*blockWidth, Constants.SCREEN_HEIGHT); g2.drawLine(i * blockWidth, 0, i * blockWidth, Constants.SCREEN_HEIGHT);
} }
// draw horizontal lines // draw horizontal lines
for(int i = 1 ; i < Constants.SQUARES_Y; i++) { for (int i = 1; i < Constants.SQUARES_Y; i++) {
g2.drawLine(0, i*blockHeight, Constants.SCREEN_WIDTH, i*blockHeight); g2.drawLine(0, i * blockHeight, Constants.SCREEN_WIDTH, i * blockHeight);
} }
} }
/**
* 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 * This panel represents the background for special divisions in this application
* *
* @author dmlux * @author dmlux
*
*/ */
public class SectionPanel extends JPanel { public class SectionPanel extends JPanel {

View File

@ -16,9 +16,8 @@ import net.miginfocom.swing.MigLayout;
/** /**
* This screen serves the configuration of the game. * This screen serves the configuration of the game.
* *
* @author dmlux, modified by I. Schumacher * @author dmlux, modified by I. Schumacher
*
*/ */
public class StartScreen extends JPanel { public class StartScreen extends JPanel {
@ -52,10 +51,10 @@ public class StartScreen extends JPanel {
*/ */
private JLabel error; private JLabel error;
/** /**
* The constructor needs a view * The constructor needs a view
* *
* @param view The view of this board * @param view The view of this board
*/ */
public StartScreen(View view) { public StartScreen(View view) {
@ -71,7 +70,7 @@ public class StartScreen extends JPanel {
initialize(); initialize();
} }
/** /**
* Initializes the settings for this screen * Initializes the settings for this screen
*/ */
@ -136,12 +135,13 @@ public class StartScreen extends JPanel {
headline.setFont(new Font("Sans-serif", Font.PLAIN, 16)); headline.setFont(new Font("Sans-serif", Font.PLAIN, 16));
headline.setHorizontalAlignment(SwingConstants.CENTER); headline.setHorizontalAlignment(SwingConstants.CENTER);
scoreMenu.add(headline, "cell 0 0, gaptop 5"); scoreMenu.add(headline, "cell 0 0, gaptop 5");
add(scoreMenu, "cell 1 0, gapleft 5"); add(scoreMenu, "cell 1 0, gapleft 5");
} }
/** /**
* Adds an action listener to the start button * Adds an action listener to the start button
*
* @param l The actionListener * @param l The actionListener
*/ */
public void addActionListenerToStartButton(ActionListener l) { public void addActionListenerToStartButton(ActionListener l) {
@ -150,6 +150,7 @@ public class StartScreen extends JPanel {
/** /**
* Returns the start button * Returns the start button
*
* @return startGame The button for starting the game * @return startGame The button for starting the game
*/ */
public JButton getStartButton() { public JButton getStartButton() {
@ -158,6 +159,7 @@ public class StartScreen extends JPanel {
/** /**
* Adds an action listener to the quit button * Adds an action listener to the quit button
*
* @param l The actionListener * @param l The actionListener
*/ */
public void addActionListenerToQuitButton(ActionListener l) { public void addActionListenerToQuitButton(ActionListener l) {
@ -166,6 +168,7 @@ public class StartScreen extends JPanel {
/** /**
* Returns the quit button * Returns the quit button
*
* @return quitGame The button for ending the game * @return quitGame The button for ending the game
*/ */
public JButton getQuitButton() { public JButton getQuitButton() {
@ -174,6 +177,7 @@ public class StartScreen extends JPanel {
/** /**
* Returns the players name * Returns the players name
*
* @return The name of the player in the JTextField playersName * @return The name of the player in the JTextField playersName
*/ */
public String getPlayersName() { public String getPlayersName() {
@ -182,6 +186,7 @@ public class StartScreen extends JPanel {
/** /**
* Shows an error in the menu * Shows an error in the menu
*
* @param message The String to be shown * @param message The String to be shown
*/ */
public void showError(String message) { public void showError(String message) {

View File

@ -10,12 +10,11 @@ import break_out.model.Game;
/** /**
* The view class manages the depiction of the components inside the JFrames. It * The view class manages the depiction of the components inside the JFrames. It
* gets the components from the game which is connected to this class * gets the components from the game which is connected to this class
* *
* @author dmlux * @author dmlux
* @author modified by Gruppe 175: Moritz Henseleit, Ruben Meyer * @author modified by Gruppe 175: Moritz Henseleit, Ruben Meyer
*
*/ */
public class View extends JFrame { public class View extends JFrame {
/** /**
* Automatic generated serial version UID * Automatic generated serial version UID
@ -42,7 +41,7 @@ public class View extends JFrame {
*/ */
private Field field; private Field field;
/** /**
* The constructor of the view * The constructor of the view
*/ */
@ -78,6 +77,7 @@ public class View extends JFrame {
/** /**
* Getter for the start screen * Getter for the start screen
*
* @return startScreen * @return startScreen
*/ */
public StartScreen getStartScreen() { public StartScreen getStartScreen() {
@ -86,6 +86,7 @@ public class View extends JFrame {
/** /**
* Getter for the playground * Getter for the playground
*
* @return field * @return field
*/ */
public Field getField() { public Field getField() {
@ -94,14 +95,16 @@ public class View extends JFrame {
/** /**
* Getter for the game * Getter for the game
*
* @return game * @return game
*/ */
public Game getGame() { public Game getGame() {
return game; return game;
} }
/** /**
* Setter for the game * Setter for the game
*
* @param game The current game * @param game The current game
*/ */
public void setGame(Game game) { public void setGame(Game game) {
@ -109,9 +112,10 @@ public class View extends JFrame {
this.game = game; this.game = game;
game.addObserver(this); game.addObserver(this);
} }
/** /**
* Shows a given screen if the card layout contains this screen * Shows a given screen if the card layout contains this screen
*
* @param screenName The screen to be shown * @param screenName The screen to be shown
*/ */
public void showScreen(String screenName) { 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 * Called by game.notifyObservers() in the run()-method of Level class
* to repaint the playground * to repaint the playground
*
* @param game The game to observe * @param game The game to observe
*/ */
public void modelChanged(Game game) { public void modelChanged(Game game) {