Skip to content
Snippets Groups Projects
Commit bde96e98 authored by Dennis Eisold's avatar Dennis Eisold
Browse files

Code cleanup

parent 337dba8d
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ package de.itstall;
public class EmptyTile extends GameTile {
EmptyTile(Position position) {
this.pos = new Position(0, 0);
this.pos = position;
}
@Override
......
package de.itstall;
public class GameField {
public int width, height;
int width, height;
private GameTile[][] field;
GameField(int width, String stringField) {
......@@ -26,12 +26,8 @@ public class GameField {
}
}
public boolean checkField(int x, int y) {
if(this.field[x][y].getClass().getSimpleName().equals("EmptyTile")) {
return true;
} else {
return false;
}
boolean checkField(int x, int y) {
return this.field[x][y].getClass().getSimpleName().equals("EmptyTile");
}
@Override
......@@ -40,8 +36,8 @@ public class GameField {
StringBuilder sb = new StringBuilder();
for (int y = 0; y < this.field[0].length; y++) {
for (int x = 0; x < this.field.length; x++) {
sb.append(this.field[x][y]);
for (GameTile[] gameTiles : this.field) {
sb.append(gameTiles[y]);
}
}
......
package de.itstall;
import java.io.*;
public class GameMain {
public static void main(String[] args) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
World w = new World();
w.setLineBreaks(7);
char key;
......
......@@ -3,7 +3,7 @@ package de.itstall;
public abstract class GameTile {
Position pos;
public GameTile() {
GameTile() {
pos = new Position(0, 0);
}
......
......@@ -6,7 +6,7 @@ public class Player extends GameTile {
this.pos = position;
}
public String draw(String s, int worldLength) {
String draw(String s, int worldLength) {
int index = pos.toIndex( worldLength );
char[] chars = s.toCharArray();
chars[index] = this.toString().charAt(0);
......
package de.itstall;
public class Position {
private int x = 0;
private int y = 0;
private int x;
private int y;
public Position(int x, int y) {
Position(int x, int y) {
this.x = x;
this.y = y;
}
public boolean equals(Position obj, Position obj2) {
if (obj.getX() == obj2.getX() && obj.getY() == obj2.getY()) {
return true;
} else {
return false;
}
return obj.getX() == obj2.getX() && obj.getY() == obj2.getY();
}
void setPosition(int x, int y) {
......@@ -22,15 +18,15 @@ public class Position {
this.y = y;
}
public int getX() {
int getX() {
return x;
}
public int getY() {
int getY() {
return y;
}
public int toIndex(int width) {
int toIndex(int width) {
return x + y * width;
}
}
......@@ -3,7 +3,7 @@ package de.itstall;
public class WallTile extends GameTile {
WallTile(Position position) {
this.pos = new Position(0, 0);
this.pos = position;
}
@Override
......
package de.itstall;
public class World {
GameField field;
Player player;
class World {
private GameField field;
private Player player;
private int lineBreaks = 0;
private boolean tempLineBreaks = false;
public World() {
World() {
String canvas = "######### ## #### ## #########";
this.field = new GameField(8, canvas);
this.player = new Player(new Position(1, 1));
}
public String draw() {
String draw() {
StringBuilder sb = new StringBuilder();
String s = this.player.draw(this.field.toString(), this.field.width);
......@@ -22,9 +22,7 @@ public class World {
breaks--;
}
for(int i = 0; i < breaks; i++) {
sb.append("\n");
}
sb.append("\n".repeat(Math.max(0, breaks)));
for (int y = 0; y < this.field.height; y++) {
sb.append(s.substring(y * this.field.width, (y + 1) * this.field.width));
......@@ -34,7 +32,7 @@ public class World {
return sb.toString();
}
public void keyPressed(String s) {
void keyPressed(String s) {
if( s.isEmpty() ) {
return;
}
......@@ -72,7 +70,7 @@ public class World {
}
}
public void setLineBreaks(int lineBreaks) {
void setLineBreaks(int lineBreaks) {
this.lineBreaks = lineBreaks;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment