Kenneth van Ewijk 10 年之前
父节点
当前提交
d02e697197

+ 8 - 11
other/generics/Generics.java

@@ -1,16 +1,13 @@
 package generics;
 
 public class Generics {
-	
+
 	public enum Test {
-		COMPARE,
-		ARRAY
+		COMPARE, ARRAY
 	}
-	
-	public Generics(Test t)
-	{
-		switch(t)
-		{
+
+	public Generics(Test t) {
+		switch (t) {
 		case COMPARE:
 			runCompareTest();
 			break;
@@ -24,16 +21,16 @@ public class Generics {
 		JKArray<JKElement> jk = new JKArray<JKElement>();
 		jk.add(new JKElement("hoi", 1));
 		jk.add(new JKElement("doei", 2));
-		
+
 		System.out.println("Elements: " + jk.size());
 		System.out.println("Sum num: " + jk.numsize());
 		System.out.println("String size: " + jk.stringsize());
 		System.out.println("String: " + jk.getStrings());
-		
+
 	}
 
 	private void runCompareTest() {
 		// TODO Auto-generated method stub
-		
+
 	}
 }

+ 21 - 29
other/generics/JKArray.java

@@ -6,54 +6,46 @@ import java.util.List;
 public class JKArray<E extends JKElement> {
 
 	List<E> elements;
-	
-	public JKArray(){
+
+	public JKArray() {
 		elements = new ArrayList<E>();
 	}
-	
-	public void add(E e)
-	{
+
+	public void add(E e) {
 		elements.add(e);
 	}
-	
-	public int size()
-	{
+
+	public int size() {
 		return elements.size();
 	}
-	
-	public int numsize()
-	{
+
+	public int numsize() {
 		int sum = 0;
-		
-		for(E e : elements)
-		{
+
+		for (E e : elements) {
 			sum += e.getNum();
 		}
-		
+
 		return sum;
 	}
-	
-	public int stringsize()
-	{
+
+	public int stringsize() {
 		int sum = 0;
-		
-		for(E e : elements)
-		{
+
+		for (E e : elements) {
 			sum += e.getString().length();
 		}
-		
+
 		return sum;
 	}
-	
-	public String getStrings()
-	{
+
+	public String getStrings() {
 		String str = "";
-		
-		for(E e : elements)
-		{
+
+		for (E e : elements) {
 			str += e.getString();
 		}
-		
+
 		return str;
 	}
 }

+ 6 - 9
other/generics/JKElement.java

@@ -1,23 +1,20 @@
 package generics;
 
 public class JKElement {
-	
+
 	String string;
 	int num;
-	
-	public JKElement(String string, int num)
-	{
+
+	public JKElement(String string, int num) {
 		this.string = string;
 		this.num = num;
 	}
-	
-	public int getNum()
-	{
+
+	public int getNum() {
 		return num;
 	}
 
-	public String getString()
-	{
+	public String getString() {
 		return string;
 	}
 }

+ 9 - 7
other/other/Main.java

@@ -7,12 +7,14 @@ public class Main {
 
 	public static void main(String[] args) {
 
-		//We hebben in de game geen Generics of Recursive function verwerkt, dus hebben we deze code erbij geleverd.
-		//Roep de methode aan van de code die je wi runnen. We starten geen GUI, dus alles gebeurt in de console.
-		
-		//runGenerics();
-		
-		//runRecursive();
+		// We hebben in de game geen Generics of Recursive function verwerkt,
+		// dus hebben we deze code erbij geleverd.
+		// Roep de methode aan van de code die je wi runnen. We starten geen
+		// GUI, dus alles gebeurt in de console.
+
+		// runGenerics();
+
+		// runRecursive();
 
 	}
 
@@ -21,7 +23,7 @@ public class Main {
 	}
 
 	private static void runGenerics() {
-		Generics g = new Generics(Generics.Test.ARRAY);		
+		Generics g = new Generics(Generics.Test.ARRAY);
 	}
 
 }

+ 17 - 22
other/recursive/Recursive.java

@@ -3,16 +3,13 @@ package recursive;
 import java.io.File;
 
 public class Recursive {
-	
+
 	public enum Test {
-		FILE,
-		FIBONACCI
+		FILE, FIBONACCI
 	}
-	
-	public Recursive(Test t)
-	{
-		switch(t)
-		{
+
+	public Recursive(Test t) {
+		switch (t) {
 		case FILE:
 			runFileTest();
 			break;
@@ -27,29 +24,27 @@ public class Recursive {
 		System.out.println(calcFibonacci(20));
 	}
 
-	public int calcFibonacci(int n)  {
-	    if(n == 0)
-	        return 0;
-	    else if(n == 1)
-	    	return 1;
-	   else
-	      return calcFibonacci(n - 1) + calcFibonacci(n - 2);
+	public int calcFibonacci(int n) {
+		if (n == 0)
+			return 0;
+		else if (n == 1)
+			return 1;
+		else
+			return calcFibonacci(n - 1) + calcFibonacci(n - 2);
 	}
 
 	private void runFileTest() {
 		System.err.println("Running recursive file test...");
 		System.out.println(viewFiles("."));
 	}
-	
-	private String viewFiles(String path)
-	{
+
+	private String viewFiles(String path) {
 		String str = "\n";
 		File folder = new File(path);
 		File[] files = folder.listFiles();
-		
-		for(File f : files)
-		{
-			if(f.isDirectory())
+
+		for (File f : files) {
+			if (f.isDirectory())
 				str += "\n" + f.getName() + "\t" + viewFiles(f.getAbsolutePath());
 			else
 				str += "\n\t" + f.getName();

+ 1 - 1
server/server/LevelReader.java

@@ -35,7 +35,7 @@ public class LevelReader {
 		if (levelfile.size() == 3) {
 			int levelnum = Integer.parseInt(levelfile.get(0));
 			level.setNum(levelnum);
-			
+
 			String[] ballsstrings = levelfile.get(1).split("\\|"); // split all
 																	// the balls
 			for (String ball : ballsstrings) {

+ 1 - 1
server/server/Main.java

@@ -3,7 +3,7 @@ package server;
 public class Main {
 
 	public static void main(String[] args) {
-		//Start a server on port
+		// Start a server on port
 		new Server(1234);
 	}
 

+ 4 - 4
server/server/NetworkUser.java

@@ -16,7 +16,7 @@ public class NetworkUser {
 	private Match match;
 	private int pid;
 
-	//A thread which handles the server communication to a client
+	// A thread which handles the server communication to a client
 	public NetworkUser(Socket client) {
 		this.client = client;
 		try {
@@ -67,7 +67,7 @@ public class NetworkUser {
 	public void sendUpdateMessage(String m) {
 		sendMessage("2|" + m);
 	}
-	
+
 	public void sendChatMessage(String m) {
 		sendMessage("4|" + m);
 	}
@@ -102,8 +102,8 @@ public class NetworkUser {
 			match.stopMatch();
 		}
 	}
-	
-	public void close() throws IOException{
+
+	public void close() throws IOException {
 		receivethread.stop();
 		din.close();
 		dout.close();

+ 5 - 5
server/server/Server.java

@@ -11,11 +11,11 @@ public class Server {
 	private ArrayList<NetworkUser> matchMakingUsers;
 
 	public Server(final int port) {
-		
-		//Users waiting to play
+
+		// Users waiting to play
 		matchMakingUsers = new ArrayList<NetworkUser>();
 
-		//Server Thread
+		// Server Thread
 		Thread clientconnect = new Thread(new Runnable() {
 			@Override
 			public void run() {
@@ -25,10 +25,10 @@ public class Server {
 						try {
 							Socket client = server.accept();
 
-							//User connects and is added to wait list
+							// User connects and is added to wait list
 							matchMakingUsers.add(new NetworkUser(client));
 
-							//Match first two users
+							// Match first two users
 							if (matchMakingUsers.size() >= 2) {
 								new Thread(new Match(matchMakingUsers.get(0), matchMakingUsers.get(1)));
 								matchMakingUsers.remove(1);

+ 23 - 24
server/server/match/Match.java

@@ -33,10 +33,9 @@ public class Match implements Runnable {
 	private int timeleft;
 	private long lasttime;
 
-	
-	//Contains all the server game logic.
-	//The server decides when collision occurs or a player is allowed to move.
-	//Also manages health, time and chat
+	// Contains all the server game logic.
+	// The server decides when collision occurs or a player is allowed to move.
+	// Also manages health, time and chat
 	public Match(NetworkUser nwuser1, NetworkUser nwuser2) {
 		nwuser1.startMatch(nwuser1.getName(), nwuser2.getName(), 1, this);
 		nwuser2.startMatch(nwuser2.getName(), nwuser1.getName(), 2, this);
@@ -49,7 +48,7 @@ public class Match implements Runnable {
 		levels = LevelReader.readLevelsFromFiles();
 		Collections.sort(levels, new LevelSorter());
 		playLevel(getCurrentLevel());
-		
+
 		timer = new Timer();
 		timer.schedule(new TimerTask() {
 			@Override
@@ -59,14 +58,14 @@ public class Match implements Runnable {
 		}, 0, 1000 / 30);
 	}
 
-	//Play a selected level
+	// Play a selected level
 	public void playLevel(Level level) {
 		balls.clear();
-		if(level == null){
+		if (level == null) {
 			timer.cancel();
 			setOverlayMessage("No more levels to play!");
-		}else{
-			setOverlayMessage("Level "+(currentlevel+1));
+		} else {
+			setOverlayMessage("Level " + (currentlevel + 1));
 			player1.reset();
 			player2.reset();
 			line1 = null;
@@ -80,7 +79,7 @@ public class Match implements Runnable {
 				balls.add(b.clone());
 			}
 			timeleft = level.getTime();
-			lasttime = System.currentTimeMillis();	
+			lasttime = System.currentTimeMillis();
 			setOverlayMessage("");
 		}
 	}
@@ -88,9 +87,7 @@ public class Match implements Runnable {
 	public Level getCurrentLevel() {
 		if (currentlevel >= 0 && currentlevel < levels.size()) {
 			return levels.get(currentlevel);
-		}
-		else
-		{
+		} else {
 			stopMatch();
 		}
 		return null;
@@ -98,25 +95,25 @@ public class Match implements Runnable {
 
 	/* UPDATE */
 	public void update() {
-		if(player1.getHealth()  == 0 && player2.getHealth() == 0){
+		if (player1.getHealth() == 0 && player2.getHealth() == 0) {
 			return;
 		}
-		if(player1.getHealth() > 0){
+		if (player1.getHealth() > 0) {
 			if (p1direction == 1)
 				player1.walkRight();
 			else if (p1direction == -1)
 				player1.walkLeft();
 			player1.update();
-		}else{
+		} else {
 			player1.setY(-100);
 		}
-		if(player2.getHealth() > 0){
+		if (player2.getHealth() > 0) {
 			if (p2direction == 1)
 				player2.walkRight();
 			else if (p2direction == -1)
 				player2.walkLeft();
 			player2.update();
-		}else{
+		} else {
 			player2.setY(-100);
 		}
 
@@ -169,7 +166,8 @@ public class Match implements Runnable {
 					bal.update();
 				}
 			}
-		} catch (ConcurrentModificationException e) {}
+		} catch (ConcurrentModificationException e) {
+		}
 		timeleft -= (System.currentTimeMillis() - lasttime);
 		if (balls.size() == 0) {
 			if (player1.getHealth() > 0)
@@ -213,7 +211,7 @@ public class Match implements Runnable {
 			linesinfo += "0|0|0|";
 
 		String timeleft = ",0";
-		if(getCurrentLevel() != null){
+		if (getCurrentLevel() != null) {
 			timeleft = "," + (int) (this.timeleft / (double) getCurrentLevel().getTime() * 100);
 		}
 
@@ -223,10 +221,11 @@ public class Match implements Runnable {
 	}
 
 	/* GETTERS AND SETTERS */
-	public void setOverlayMessage(String m){
+	public void setOverlayMessage(String m) {
 		nwuser1.sendOverlayText(m);
 		nwuser2.sendOverlayText(m);
 	}
+
 	public void setPlayerDirection(int pid, int dir) {
 		if (pid == 1)
 			p1direction = dir;
@@ -236,15 +235,15 @@ public class Match implements Runnable {
 
 	public void playerShoot(int pid) {
 		if (pid == 1 && player1.getHealth() > 0)
-			if(line1 == null)
+			if (line1 == null)
 				line1 = new ShootingLine(player1.getX() + player1.getWidth() / 2, player1.getY() + player1.getHeigth());
 		if (pid == 2 && player2.getHealth() > 0)
-			if(line2 == null)
+			if (line2 == null)
 				line2 = new ShootingLine(player2.getX() + player2.getWidth() / 2, player2.getY() + player2.getHeigth());
 	}
 
 	public void stopMatch() {
-		if(timer != null)
+		if (timer != null)
 			timer.cancel();
 		try {
 			nwuser1.close();

+ 9 - 11
server/server/match/levels/Level.java

@@ -5,23 +5,21 @@ import java.util.List;
 
 import server.match.objects.Ball;
 
-public class Level implements Comparable<Level>{
+public class Level implements Comparable<Level> {
 	private List<Ball> startballs;
 	private int time;
 	private int num;
-	
-	//Contains all the info to start a level
+
+	// Contains all the info to start a level
 	public Level() {
 		this.startballs = new ArrayList<Ball>();
 	}
-	
-	public void setNum(int num)
-	{
+
+	public void setNum(int num) {
 		this.num = num;
 	}
-	
-	public int getNum()
-	{
+
+	public int getNum() {
 		return num;
 	}
 
@@ -44,9 +42,9 @@ public class Level implements Comparable<Level>{
 	@Override
 	public int compareTo(Level l) {
 		int rt = 0;
-		if(num < l.getNum())
+		if (num < l.getNum())
 			rt = -1;
-		else if(num > l.getNum())
+		else if (num > l.getNum())
 			rt = 1;
 		return rt;
 	}

+ 5 - 5
server/server/match/levels/LevelSorter.java

@@ -7,13 +7,13 @@ public class LevelSorter implements Comparator<Level> {
 	@Override
 	public int compare(Level l1, Level l2) {
 		int comp = 0;
-		
-		if(l1.getNum() < l2.getNum())
+
+		if (l1.getNum() < l2.getNum())
 			comp = -1;
-		else if(l1.getNum() > l2.getNum())
+		else if (l1.getNum() > l2.getNum())
 			comp = 1;
-		
+
 		return comp;
 	}
-	
+
 }

+ 5 - 5
server/server/match/levels/ReverseLevelSorter.java

@@ -7,13 +7,13 @@ public class ReverseLevelSorter implements Comparator<Level> {
 	@Override
 	public int compare(Level l1, Level l2) {
 		int comp = 0;
-		
-		if(l1.getNum() > l2.getNum())
+
+		if (l1.getNum() > l2.getNum())
 			comp = -1;
-		else if(l1.getNum() < l2.getNum())
+		else if (l1.getNum() < l2.getNum())
 			comp = 1;
-		
+
 		return comp;
 	}
-	
+
 }

+ 2 - 2
server/server/match/objects/Ball.java

@@ -13,7 +13,7 @@ public class Ball {
 	double rx, ry; // position
 	double vx, vy; // velocity
 
-	//Contains the logic of a ball
+	// Contains the logic of a ball
 	public Ball(int size, int bounceheight, Color color, int x, int y, int direction, double velocity) {
 		this.color = color;
 		this.size = size * 20;
@@ -27,7 +27,7 @@ public class Ball {
 		bal = new Ellipse2D.Double(x, y, this.size, this.size);
 	}
 
-	//Collision
+	// Collision
 	public boolean hitLine(ShootingLine l) {
 		return bal.intersects(l.getX(), l.getY() - l.getHeight(), l.getWidth(), l.getHeight());
 	}

+ 1 - 1
server/server/match/objects/DrawObject.java

@@ -8,7 +8,7 @@ public class DrawObject {
 	protected Point2D position;
 	protected BufferedImage image;
 
-	//Contains the logic for offline DrawObjects
+	// Contains the logic for offline DrawObjects
 	public DrawObject(BufferedImage image) {
 		this.image = image;
 

+ 4 - 4
server/server/match/objects/Player.java

@@ -11,7 +11,7 @@ public class Player extends DrawObject {
 	private int score, health, speed = 10;
 	private Double beginlocation;
 
-	//Contains the logic for players
+	// Contains the logic for players
 	public Player(BufferedImage image, int x, int y) {
 		super(image.getSubimage(38, 0, 40, 54));
 		super.setPosition(x, y);
@@ -19,21 +19,21 @@ public class Player extends DrawObject {
 		health = 5;
 	}
 
-	//Walk left when key is pressed
+	// Walk left when key is pressed
 	public void walkLeft() {
 		if (getX() - speed > 10) {
 			setX(getX() - speed);
 		}
 	}
 
-	//Walk right when key is pressed
+	// Walk right when key is pressed
 	public void walkRight() {
 		if (getX() + getWidth() + speed < Window.WIDTH - 10) {
 			setX(getX() + speed);
 		}
 	}
 
-	//Reset player to start location
+	// Reset player to start location
 	public void reset() {
 		setPosition(beginlocation);
 		speed = 10;

+ 1 - 1
server/server/match/objects/ShootingLine.java

@@ -3,7 +3,7 @@ package server.match.objects;
 public class ShootingLine {
 	private int startx, starty, length;
 
-	//Contains logic of a line
+	// Contains logic of a line
 	public ShootingLine(int startx, int starty) {
 		this.startx = startx;
 		this.starty = starty;

+ 2 - 2
src/main/Main.java

@@ -2,8 +2,8 @@ package main;
 
 public class Main {
 	public static void main(String[] args) {
-		
-		//Start new game
+
+		// Start new game
 		new Window();
 	}
 }

+ 15 - 16
src/main/Window.java

@@ -17,52 +17,51 @@ import control.GameControl;
 @SuppressWarnings("serial")
 public class Window extends JFrame {
 
-	//Window width and height
+	// Window width and height
 	public static final int WIDTH = 800;
 	public static final int HEIGHT = 800;
 
-	//Update and draw speed
+	// Update and draw speed
 	public static final int UPDATES_PER_SECOND = 30;
 	public static final int FRAMES_PER_SECOND = 30;
 
 	public Window() {
-		//Open new window
+		// Open new window
 		super("Bubble Trouble");
 		setSize(WIDTH, HEIGHT);
 		setResizable(false);
 		setDefaultCloseOperation(3);
 
-		//Start gamestate manager and MVC model
+		// Start gamestate manager and MVC model
 		GameStateManager gsm = new GameStateManager();
 		GameModel model = new GameModel(gsm);
 		GameView view = new GameView(model, gsm);
 		GameControl control = new GameControl(view, model, gsm);
 
-		//Keyboard
+		// Keyboard
 		addKeyListener(control);
 
 		setContentPane(view);
 
 		setVisible(true);
-		
-		//Start playing the theme song
+
+		// Start playing the theme song
 		playAudio();
 	}
-	
-	private void playAudio()
-	{
-		//Load theme song from resources and play
+
+	private void playAudio() {
+		// Load theme song from resources and play
 		Clip clip = null;
 		try {
 			clip = AudioSystem.getClip();
 			AudioInputStream inputStream = AudioSystem.getAudioInputStream(Main.class.getResource("/resources/audio/soundtrack.wav"));
-		    clip.open(inputStream);
+			clip.open(inputStream);
 		} catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) {
 			clip.close();
 		}
-	    
-		//Loop the theme song
-	    clip.loop(Clip.LOOP_CONTINUOUSLY);
+
+		// Loop the theme song
+		clip.loop(Clip.LOOP_CONTINUOUSLY);
 	}
-	
+
 }

+ 1 - 1
src/model/GameModel.java

@@ -15,7 +15,7 @@ public class GameModel implements ActionListener {
 	public GameModel(GameStateManager gsm) {
 		this.gsm = gsm;
 
-		//Start the update timer
+		// Start the update timer
 		t = new Timer(1000 / Window.UPDATES_PER_SECOND, this);
 		t.start();
 	}

+ 8 - 8
src/model/GameStateManager.java

@@ -14,7 +14,7 @@ public class GameStateManager {
 	private List<State> gamestates;
 	private State currentState;
 
-	//Manage all the states and allow to switch between them
+	// Manage all the states and allow to switch between them
 	public GameStateManager() {
 		gamestates = new ArrayList<State>();
 
@@ -24,7 +24,7 @@ public class GameStateManager {
 		currentState = gamestates.get(0);
 	}
 
-	//Change the current state
+	// Change the current state
 	public void setState(String name) {
 		for (State s : gamestates) {
 			if (s.getName() == name) {
@@ -33,8 +33,8 @@ public class GameStateManager {
 			}
 		}
 	}
-	
-	//Get the current state
+
+	// Get the current state
 	public State getState(String name) {
 		for (State s : gamestates) {
 			if (s.getName() == name) {
@@ -44,7 +44,7 @@ public class GameStateManager {
 		return null;
 	}
 
-	//Private method to change the state
+	// Private method to change the state
 	private void changeState(State st) {
 		if (!currentState.equals(st)) {
 			currentState.exit();
@@ -53,12 +53,12 @@ public class GameStateManager {
 		}
 	}
 
-	//Update the current state
+	// Update the current state
 	public void update() {
 		currentState.update();
 	}
 
-	//Paint the current state
+	// Paint the current state
 	public void paint(Graphics2D g2d) {
 		currentState.paint(g2d);
 	}
@@ -66,7 +66,7 @@ public class GameStateManager {
 	/*
 	 * Send keypresses to the current state
 	 */
-	
+
 	public void keyPressed(KeyEvent e) {
 		currentState.keyPressed(e);
 	}

+ 18 - 19
src/model/InfoPanel.java

@@ -17,7 +17,7 @@ public class InfoPanel {
 	private int OFFSET = 610;
 	private List<String> chat;
 
-	//Draw the game hud
+	// Draw the game hud
 	public InfoPanel(PlayState play) {
 		this.play = play;
 		chat = new ArrayList<String>();
@@ -25,7 +25,7 @@ public class InfoPanel {
 
 	public void paint(Graphics2D g2d) {
 		g2d.setColor(Color.red);
-		//TIME
+		// TIME
 		g2d.fillRect(200, OFFSET, 400 / 100 * play.getTimeleftpercent(), 20);
 
 		g2d.setColor(Color.black);
@@ -34,11 +34,11 @@ public class InfoPanel {
 
 		// Player 1
 		g2d.drawLine(35, OFFSET, 35, Window.HEIGHT);
-		//P1 Name
+		// P1 Name
 		g2d.drawString(play.getPlayer1().getName(), 40, OFFSET + 5 + g2d.getFont().getSize());
-		//P1 Score
+		// P1 Score
 		g2d.drawString(play.getPlayer1().getScore() + " xp", 40, OFFSET + 5 + g2d.getFont().getSize() * 2 + 5);
-		//P1 Health
+		// P1 Health
 		for (int i = 0; i < play.getPlayer1().getHealth(); i++) {
 			g2d.drawImage(Images.getImage(ImageType.HEARTH), null, 5, OFFSET + (30 * i));
 		}
@@ -46,37 +46,36 @@ public class InfoPanel {
 
 		// Chat
 		g2d.drawLine(200, OFFSET, 200, Window.HEIGHT);
-		//Chat
-		for(int i=0; i<chat.size(); i++)
-		{
-			g2d.drawString(chat.get(i), 210, OFFSET + 50  + g2d.getFont().getSize()*i);
+		// Chat
+		for (int i = 0; i < chat.size(); i++) {
+			g2d.drawString(chat.get(i), 210, OFFSET + 50 + g2d.getFont().getSize() * i);
 		}
 		g2d.drawLine(600, OFFSET, 600, Window.HEIGHT);
-		g2d.drawLine(200, OFFSET + 60  + g2d.getFont().getSize()*3, 600, OFFSET + 60  + g2d.getFont().getSize()*3);
-		//Current message being typed
+		g2d.drawLine(200, OFFSET + 60 + g2d.getFont().getSize() * 3, 600, OFFSET + 60 + g2d.getFont().getSize() * 3);
+		// Current message being typed
 		g2d.drawString(play.chatMessage, 270, Window.HEIGHT - 20 - g2d.getFont().getSize());
 
 		g2d.drawLine(Window.WIDTH - 35, OFFSET, Window.WIDTH - 35, Window.HEIGHT);
-		//P2 Name
+		// P2 Name
 		g2d.drawString(play.getPlayer2().getName(), Window.WIDTH - 40 - play.getPlayer2().getName().length() * 15, OFFSET + 5 + g2d.getFont().getSize());
-		//P2 Score
+		// P2 Score
 		g2d.drawString(play.getPlayer2().getScore() + " xp", Window.WIDTH - 40 - ((play.getPlayer1().getScore() + " ").length() + 3) * 15, OFFSET + 5 + g2d.getFont().getSize() * 2 + 5);
-		//P2 Health
+		// P2 Health
 		for (int i = 0; i < play.getPlayer2().getHealth(); i++) {
 			g2d.drawImage(Images.getImage(ImageType.HEARTH), null, Window.WIDTH - 30, OFFSET + (30 * i));
 		}
 		g2d.drawLine(Window.WIDTH - 35, OFFSET + g2d.getFont().getSize() * 3, Window.WIDTH - 200, OFFSET + g2d.getFont().getSize() * 3);
-		
-		if(play.typing)
+
+		if (play.typing)
 			g2d.setColor(Color.RED);
 		g2d.drawString("Chat: ", 210, Window.HEIGHT - 20 - g2d.getFont().getSize());
 	}
 
-	//Add a chat message
+	// Add a chat message
 	public void addChatMessage(String msg) {
 		chat.add(msg);
-		
-		if(chat.size() > 4)
+
+		if (chat.size() > 4)
 			chat.remove(0);
 	}
 

+ 21 - 22
src/model/NetworkConnection.java

@@ -19,23 +19,23 @@ public class NetworkConnection {
 	private PlayState play;
 	private Socket server;
 
-	//Connection to the server
+	// Connection to the server
 	public NetworkConnection(PlayState play) {
 		this.play = play;
 		play.setOverlayText("Waiting for other players..");
 	}
 
-	//Try to connect to the server
+	// Try to connect to the server
 	public void connect(String name) throws UnknownHostException, IOException {
 		if (checkConnection()) {
 			throw new IOException("Already connected!");
 		}
-		try{
+		try {
 			server = new Socket(address, port);
 			dout = new DataOutputStream(server.getOutputStream());
 			din = new DataInputStream(server.getInputStream());
 			dout.writeUTF(name);
-		}catch (ConnectException e){
+		} catch (ConnectException e) {
 			play.setOverlayText("Can't connect to the server \n Press ESC to return to the mainmenu");
 			System.err.println("Can't connect to the server");
 			throw new IOException("Can't connect to the server");
@@ -51,7 +51,7 @@ public class NetworkConnection {
 		receivethread.start();
 	}
 
-	//Check if the connection already exists
+	// Check if the connection already exists
 	public boolean checkConnection() {
 		if (dout == null)
 			return false;
@@ -63,7 +63,7 @@ public class NetworkConnection {
 		return true;
 	}
 
-	//Receive a message from the server and decode it
+	// Receive a message from the server and decode it
 	private void receiveMessage() {
 		try {
 			String message = din.readUTF();
@@ -75,12 +75,12 @@ public class NetworkConnection {
 			case "2": // Update message
 				messagesplit = message.split(",");
 
-				//Update players
+				// Update players
 				String[] playersplit = messagesplit[0].split("\\|");
 				play.updatePlayerInfo(Integer.parseInt(playersplit[1]), Integer.parseInt(playersplit[2]), Integer.parseInt(playersplit[3]), Integer.parseInt(playersplit[4]), play.getPlayer1());
 				play.updatePlayerInfo(Integer.parseInt(playersplit[5]), Integer.parseInt(playersplit[6]), Integer.parseInt(playersplit[7]), Integer.parseInt(playersplit[8]), play.getPlayer2());
 
-				//Update Balls
+				// Update Balls
 				String[] ballsplit = messagesplit[1].split("\\|");
 				if (ballsplit.length / 4 != play.getBalls().size()) {
 					play.getBalls().clear();
@@ -89,21 +89,21 @@ public class NetworkConnection {
 					play.getBall(i).updateInfo(Integer.parseInt(ballsplit[(i * 4) + 0]), Integer.parseInt(ballsplit[(i * 4) + 1]), Color.decode(ballsplit[(i * 4) + 3]), Integer.parseInt(ballsplit[(i * 4) + 2]));
 				}
 
-				//Update lines
+				// Update lines
 				String[] linesplit = messagesplit[2].split("\\|");
 				play.updateLines(Integer.parseInt(linesplit[0]), Integer.parseInt(linesplit[1]), Integer.parseInt(linesplit[2]), Integer.parseInt(linesplit[3]), Integer.parseInt(linesplit[4]), Integer.parseInt(linesplit[5]));
-				
-				//Update time
+
+				// Update time
 				play.setTimeleftpercent(Integer.parseInt(messagesplit[3]));
 				break;
-			case "3": //Overlay text
+			case "3": // Overlay text
 				play.setOverlayText(messagesplit[1]);
 				break;
-			case "4": //Chat Message
+			case "4": // Chat Message
 				play.addChatMessage(messagesplit[1]);
 				break;
 			}
-			
+
 		} catch (IOException e) {
 			play.setOverlayText("Connection to the server closed \n Press ESC to return to the mainmenu");
 			play.stopMatch();
@@ -113,26 +113,25 @@ public class NetworkConnection {
 
 	}
 
-	//Send control request to server
+	// Send control request to server
 	public void sendInput(int direction, int shoot) {
 		sendMessage("1|" + direction + "|" + shoot);
 	}
 
-	//Send chat message to server
-	public void sendChatMessage(String str)
-	{
+	// Send chat message to server
+	public void sendChatMessage(String str) {
 		sendMessage("2|" + str);
 	}
-	
-	//Close connection to server and stop the thread
-	public void close() throws IOException{
+
+	// Close connection to server and stop the thread
+	public void close() throws IOException {
 		receivethread.stop();
 		din.close();
 		dout.close();
 		server.close();
 	}
 
-	//Send a message
+	// Send a message
 	private void sendMessage(String m) {
 		try {
 			dout.writeUTF(m);

+ 1 - 2
src/model/objects/Ball.java

@@ -64,8 +64,7 @@ public class Ball {
 		bal.setFrame(getX(), getY(), size, size);
 	}
 
-	
-	//Update info based on network data
+	// Update info based on network data
 	public void updateInfo(int x, int y, Color color, int size) {
 		setX(x);
 		setY(y);

+ 2 - 2
src/model/objects/ShootingLine.java

@@ -18,8 +18,8 @@ public class ShootingLine {
 		line = new Path2D.Double();
 		line.moveTo(startx, starty);
 		int tempy = starty;
-		
-		//Create curve
+
+		// Create curve
 		for (int i = 0; i < length; i++) {
 			line.curveTo(startx + 10, tempy - 10, startx - 10, tempy - 20, startx, tempy - 30);
 			tempy -= 30;

+ 23 - 24
src/model/state/MenuState.java

@@ -11,14 +11,14 @@ import resources.image.Images;
 import resources.image.Images.ImageType;
 
 public class MenuState extends State {
-	
-	//Create random username on start
-	public static String name = "Guest" + Math.round((Math.random()*1000));
-	
-	//Disallow certain characters in name
-	private static int[] not_allowed = {KeyEvent.VK_COMMA, KeyEvent.VK_SEMICOLON, KeyEvent.VK_PERIOD, KeyEvent.VK_QUOTE, KeyEvent.VK_QUOTEDBL, KeyEvent.VK_SHIFT};
-
-	//This is the menu state, it is the default state when the game starts
+
+	// Create random username on start
+	public static String name = "Guest" + Math.round((Math.random() * 1000));
+
+	// Disallow certain characters in name
+	private static int[] not_allowed = { KeyEvent.VK_COMMA, KeyEvent.VK_SEMICOLON, KeyEvent.VK_PERIOD, KeyEvent.VK_QUOTE, KeyEvent.VK_QUOTEDBL, KeyEvent.VK_SHIFT };
+
+	// This is the menu state, it is the default state when the game starts
 	public MenuState(GameStateManager gsm) {
 		super("menu", gsm);
 	}
@@ -26,7 +26,7 @@ public class MenuState extends State {
 	/* INIT AND EXIT */
 	@Override
 	public void init() {
-		
+
 	}
 
 	@Override
@@ -41,19 +41,19 @@ public class MenuState extends State {
 
 	@Override
 	public void paint(Graphics2D g2) {
-		g2.drawImage(Images.getImage(ImageType.BACKGROUND_MENU), 0,0,null);
+		g2.drawImage(Images.getImage(ImageType.BACKGROUND_MENU), 0, 0, null);
 		g2.drawImage(Images.getImage(ImageType.PLAYER1).getSubimage(38, 0, 40, 54), 610, 550, null);
 		g2.drawImage(Images.getImage(ImageType.PLAYER2).getSubimage(38, 0, 40, 54), 670, 550, null);
-		
+
 		g2.setColor(Color.WHITE);
-		
+
 		g2.setFont(new Font("Segoe UI", Font.PLAIN, 20));
 		g2.drawString("Type your name and press ENTER to start the game", 20, 690);
-		
+
 		g2.setFont(new Font("Segoe UI", Font.BOLD, 30));
 		g2.drawString(name.toString(), 20, 730);
 		g2.drawRect(15, 702, 380, 36);
-		
+
 		g2.setFont(new Font("Segoe UI", Font.BOLD, 80));
 		g2.drawString("Bubble Trouble", 100, 150);
 	}
@@ -62,26 +62,25 @@ public class MenuState extends State {
 	@Override
 	public void keyPressed(KeyEvent e) {
 		if (e.getKeyCode() == KeyEvent.VK_ENTER) {
-			//Start the game
+			// Start the game
 			gsm.setState("play");
 		}
-		
-		if(e.getKeyCode() == KeyEvent.VK_BACK_SPACE && name.length() > 0)
-		{
-			//Remove last letter from name when BACKSPACE is pressed
-			name = name.substring(0, name.length()-1);
+
+		if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE && name.length() > 0) {
+			// Remove last letter from name when BACKSPACE is pressed
+			name = name.substring(0, name.length() - 1);
 		}
 	}
 
 	@Override
 	public void keyReleased(KeyEvent e) {
-		if(name.length() <= 15 && e.getKeyCode() != KeyEvent.VK_BACK_SPACE && !Arrays.asList(not_allowed).contains(e.getKeyCode()))
-		{
-			//Add allowed characters to name
+		if (name.length() <= 15 && e.getKeyCode() != KeyEvent.VK_BACK_SPACE && !Arrays.asList(not_allowed).contains(e.getKeyCode())) {
+			// Add allowed characters to name
 			name += e.getKeyChar();
 		}
 	}
 
 	@Override
-	public void keyTyped(KeyEvent e) {}
+	public void keyTyped(KeyEvent e) {
+	}
 }

+ 16 - 23
src/model/state/PlayState.java

@@ -31,7 +31,7 @@ public class PlayState extends State {
 	public String chatMessage = "";
 	public boolean typing = false;
 
-	//The state in which the game runs
+	// The state in which the game runs
 	public PlayState(GameStateManager gsm) {
 		super("play", gsm);
 		player1 = null;
@@ -39,7 +39,7 @@ public class PlayState extends State {
 	}
 
 	/* NETWORK CONTROL */
-	//This is called when a match has been made by the server
+	// This is called when a match has been made by the server
 	public void newMatch(String p1, String p2) {
 		player1 = new Player(Images.getImage(ImageType.PLAYER1), 40, 550, p1);
 		player2 = new Player(Images.getImage(ImageType.PLAYER2), 90, 550, p2);
@@ -52,8 +52,8 @@ public class PlayState extends State {
 	}
 
 	/* INIT AND EXIT */
-	
-	//This is called when this state loads
+
+	// This is called when this state loads
 	@Override
 	public void init() {
 		matchStarted = false;
@@ -64,7 +64,7 @@ public class PlayState extends State {
 		}
 	}
 
-	//Close the match and connection
+	// Close the match and connection
 	@Override
 	public void exit() {
 		try {
@@ -97,9 +97,8 @@ public class PlayState extends State {
 
 	@Override
 	public void update() {
-		if(player1 != null && player2 != null)
-		{
-			if(player1.getHealth()  == 0 && player2.getHealth() == 0){
+		if (player1 != null && player2 != null) {
+			if (player1.getHealth() == 0 && player2.getHealth() == 0) {
 				setOverlayText("Game over");
 			}
 			player1.update();
@@ -113,7 +112,7 @@ public class PlayState extends State {
 		g2d.setColor(Color.RED);
 		g2d.drawString(overlayText, 100, 300);
 		g2d.setColor(Color.black);
-		if(!matchStarted)
+		if (!matchStarted)
 			return;
 		if (line1 != null) {
 			line1.paint(g2d);
@@ -164,7 +163,7 @@ public class PlayState extends State {
 		this.overlayText = text;
 	}
 
-	public void stopMatch(){
+	public void stopMatch() {
 		try {
 			nwc.close();
 		} catch (IOException e) {
@@ -192,7 +191,7 @@ public class PlayState extends State {
 			case KeyEvent.VK_ENTER:
 				if (typing) {
 					typing = false;
-					if(chatMessage.length()>0)
+					if (chatMessage.length() > 0)
 						nwc.sendChatMessage(chatMessage);
 					chatMessage = "";
 				}
@@ -203,8 +202,7 @@ public class PlayState extends State {
 
 	@Override
 	public void keyReleased(KeyEvent e) {
-		if (!typing)
-		{
+		if (!typing) {
 			switch (e.getKeyCode()) {
 			case KeyEvent.VK_RIGHT:
 				direction = 0;
@@ -221,16 +219,11 @@ public class PlayState extends State {
 				typing = true;
 				break;
 			}
-		}
-		else
-		{
-			if(e.getKeyCode() != KeyEvent.VK_BACK_SPACE)
-			{
+		} else {
+			if (e.getKeyCode() != KeyEvent.VK_BACK_SPACE) {
 				chatMessage += e.getKeyChar();
-			}
-			else if(e.getKeyCode() == KeyEvent.VK_BACK_SPACE && chatMessage.length() > 0)
-			{
-				chatMessage = chatMessage.substring(0, chatMessage.length()-1);
+			} else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE && chatMessage.length() > 0) {
+				chatMessage = chatMessage.substring(0, chatMessage.length() - 1);
 			}
 		}
 		nwc.sendInput(direction, shoot);
@@ -240,7 +233,7 @@ public class PlayState extends State {
 	public void keyTyped(KeyEvent e) {
 	};
 
-	//Add a chatmessage to this match
+	// Add a chatmessage to this match
 	public void addChatMessage(String msg) {
 		infopanel.addChatMessage(msg);
 	}

+ 1 - 1
src/model/state/State.java

@@ -11,7 +11,7 @@ public abstract class State {
 
 	protected String name;
 
-	//Super class of all the implemented states
+	// Super class of all the implemented states
 	public State(String name, GameStateManager gsm) {
 		this.name = name;
 		this.gsm = gsm;

+ 2 - 3
src/resources/image/Images.java

@@ -12,11 +12,10 @@ public class Images {
 
 	private static ArrayList<BufferedImage> images = new ArrayList<BufferedImage>();
 
-	
 	public Images() {
 	}
-	
-	//Load all images on start
+
+	// Load all images on start
 	static {
 		try {
 			images.add(ImageIO.read(Main.class.getResource("/resources/image/player1_sprite.png")));

+ 2 - 2
src/view/GameView.java

@@ -28,12 +28,12 @@ public class GameView extends JPanel implements ActionListener {
 
 		setBackground(Color.WHITE);
 
-		//Start paint timer
+		// Start paint timer
 		t = new Timer(1000 / Window.FRAMES_PER_SECOND, this);
 		t.start();
 	}
 
-	//Paint the game
+	// Paint the game
 	@Override
 	public void paintComponent(Graphics g) {
 		super.paintComponent(g);