reformatted code

This commit is contained in:
Bokros Bálint 2016-04-24 23:01:34 +02:00
parent d0d656452c
commit 1ab13398bb
19 changed files with 365 additions and 382 deletions

View File

@ -1,11 +1,10 @@
package cicaprojekt;
public class Box implements Pickable, Destroyable
{
public class Box implements Pickable, Destroyable {
private int weight = 5;
public Box(){
public Box() {
}
public void destroy() {

View File

@ -3,12 +3,10 @@ package cicaprojekt;
import java.io.*;
public class Dungeon {
cicaprojekt.Tile buildDungeon(File input) throws IOException
{
cicaprojekt.Tile buildDungeon(File input) throws IOException {
Tile oneilllocation = null;
Tile jaffalocation = null;
try(BufferedReader reader = new BufferedReader(new FileReader(input)))
{
try (BufferedReader reader = new BufferedReader(new FileReader(input))) {
String[] sizedata = reader.readLine().split("x"); // read size data at beginning of file
reader.readLine(); // throw empty line away
int width = Integer.parseInt(sizedata[0]);
@ -19,11 +17,9 @@ public class Dungeon {
String line = null;
Gate gate = new Gate();
Gate lastgate = gate;
for (int y = 0; y < height; ++y)
{
line = reader.readLine().replaceAll("\\s",""); // read line and remove whitespaces
for (int x = 0; x < width; ++x)
{
for (int y = 0; y < height; ++y) {
line = reader.readLine().replaceAll("\\s", ""); // read line and remove whitespaces
for (int x = 0; x < width; ++x) {
switch (line.charAt(x)) // set the dungeon up
{
case 'W':
@ -74,27 +70,25 @@ public class Dungeon {
// NOTE: code seems to be correct till this point based on a debugger run-through
/* setting up Tile cross references */
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
if (x-1 >= 0) // leftwards Tile reference
dungeon[y][x].setAdajacentTile(dungeon[y][x-1], Direction.WEST);
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
if (x - 1 >= 0) // leftwards Tile reference
dungeon[y][x].setAdajacentTile(dungeon[y][x - 1], Direction.WEST);
else
dungeon[y][x].setAdajacentTile(null, Direction.WEST);
if (x+1 < width) // rightwards Tile reference
dungeon[y][x].setAdajacentTile(dungeon[y][x+1], Direction.EAST);
if (x + 1 < width) // rightwards Tile reference
dungeon[y][x].setAdajacentTile(dungeon[y][x + 1], Direction.EAST);
else
dungeon[y][x].setAdajacentTile(null, Direction.EAST);
if (y+1 < height) // upwards Tile reference
dungeon[y][x].setAdajacentTile(dungeon[y+1][x], Direction.NORTH);
if (y + 1 < height) // upwards Tile reference
dungeon[y][x].setAdajacentTile(dungeon[y + 1][x], Direction.NORTH);
else
dungeon[y][x].setAdajacentTile(null, Direction.NORTH);
if (y-1 >= 0) // downwards Tile reference
dungeon[y][x].setAdajacentTile(dungeon[y-1][x], Direction.SOUTH);
if (y - 1 >= 0) // downwards Tile reference
dungeon[y][x].setAdajacentTile(dungeon[y - 1][x], Direction.SOUTH);
else
dungeon[y][x].setAdajacentTile(null, Direction.SOUTH);
}

View File

@ -3,8 +3,7 @@ package cicaprojekt;
import java.util.HashMap;
import java.util.Map;
public class Field extends cicaprojekt.Tile
{
public class Field extends cicaprojekt.Tile {
private static int recursionLimit = 0;
@ -21,10 +20,10 @@ public class Field extends cicaprojekt.Tile
}
public void onEntry(PlayerBase playerBase) {
if(boxStack.size() > 0)
if (boxStack.size() > 0)
return;
playerBase.setCurrentTile(this);
if(zpmOnTile != null)
if (zpmOnTile != null)
playerBase.pickZPM(this);
}

View File

@ -3,12 +3,11 @@ package cicaprojekt;
import java.util.Timer;
import java.util.TimerTask;
public class FlowOfTime extends Timer{
public class FlowOfTime extends Timer {
private TimerTask timeup;
private long gametime;
public void start()
{
public void start() {
}
}

View File

@ -2,9 +2,12 @@ package cicaprojekt;
public class Game {
private Player oneill;
private Dungeon dungeon;
private FlowOfTime flowoftime;
public static void main(String[] args) {
}
public void allZPMsCollected() {
this.stopGame();
@ -15,6 +18,4 @@ public class Game {
public void stopGame() {
}
public static void main(String[] args) {}
}

View File

@ -1,8 +1,7 @@
package cicaprojekt;
public class Gap extends cicaprojekt.Tile
{
public Gap(){
public class Gap extends cicaprojekt.Tile {
public Gap() {
super();
}

View File

@ -1,27 +1,25 @@
package cicaprojekt;
public class Gate extends Tile
{
public class Gate extends Tile {
private boolean open = false;
public Gate(){
public Gate() {
super();
}
public void spawnStargate(Stargate stargate, Direction direction) {
if(this.open) adjacentTile.get(direction).spawnStargate(stargate, direction);
if (this.open) adjacentTile.get(direction).spawnStargate(stargate, direction);
}
public void onEntry(PlayerBase playerBase) {
if(open){
if (open) {
playerBase.setCurrentTile(this);
}
else
} else
return;
}
public void onExit(PlayerBase playerBase) throws IllegalStateException {
if(!open){
if (!open) {
throw new IllegalStateException("Hiba! Te hogy kerültél a csukott ajtóba?");
}
}

View File

@ -7,22 +7,20 @@ public class Menu {
public static String tabulator = "\t";
public static void addTab()
{
public static void addTab() {
tabulator += '\t';
}
public static void removeTab()
{
tabulator = tabulator.substring(0, tabulator.length()-1);
public static void removeTab() {
tabulator = tabulator.substring(0, tabulator.length() - 1);
}
public static void main (String[] args) throws IOException{
public static void main(String[] args) throws IOException {
System.out.println("Continuously Integrated Cica Projekt - Skeleton");
System.out.println("Üdvözöllek a Babylon Simulator 2000 játékban! Kérlek válassz egy menüpontot!");
boolean isExiting = false;
while(!isExiting) {
while (!isExiting) {
System.out.println("1. Lépés");
System.out.println("2. Doboz felvétele");
System.out.println("3. Doboz lerakása");
@ -36,90 +34,90 @@ public class Menu {
Scanner sc = new Scanner(System.in);
switch (sc.nextLine().charAt(0)) {
case '1' :
case '1':
System.out.println("ONeill [északi|nyugati|déli|keleti] irányba lép egyet,");
System.out.println("Elfogadott bemenet: W, A, S, D");
switch (sc.nextLine().charAt(0)) {
case 'W' :
case 'W':
oNeill.move(Direction.NORTH);
break;
case 'A' :
case 'A':
oNeill.move(Direction.WEST);
break;
case 'S' :
case 'S':
oNeill.move(Direction.SOUTH);
break;
case 'D' :
case 'D':
oNeill.move(Direction.EAST);
break;
case 'X' :
case 'X':
break;
}
break;
case '2' :
case '2':
System.out.println("Doboz felvétele");
System.out.println("Elfogadott bemenet: L");
switch (sc.nextLine().charAt(0)) {
case 'L' :
case 'L':
oNeill.boxLift();
break;
case 'X' :
case 'X':
break;
}
break;
case '3' :
case '3':
System.out.println("Doboz lerakása");
System.out.println("Elfogadott bemenet: D");
switch (sc.nextLine().charAt(0)) {
case 'D':
oNeill.boxDrop();
break;
case 'X' :
case 'X':
break;
}
break;
case '4' :
case '4':
System.out.println("Elforgás");
System.out.println("Elfogadott bemenet: L, R");
switch (sc.nextLine().charAt(0)) {
case 'L' :
case 'L':
oNeill.rotateLeft();
break;
case 'D' :
case 'D':
oNeill.rotateRight();
break;
case 'X' :
case 'X':
break;
}
break;
case '5' :
case '5':
System.out.println("Nézés");
System.out.println("Elfogadott bemenet: W");
switch (sc.nextLine().charAt(0)) {
case 'W' :
case 'W':
Tile t = oNeill.getCurrentTile().getAdjacentTile(oNeill.getFacingDirection());
System.out.println("O'Neill előtt egy " + t.toString() + "mező található");
break;
case 'X' :
case 'X':
break;
}
break;
case '6' :
case '6':
System.out.println("Csillagkapu lövés");
System.out.println("Elfogadott bemenet: Y, B");
Tile t = oNeill.getCurrentTile();
switch (sc.nextLine().charAt(0)) {
case 'Y' :
case 'Y':
t.spawnStargate(Stargate.yellowStargate, oNeill.getFacingDirection());
break;
case 'B' :
case 'B':
t.spawnStargate(Stargate.blueStargate, oNeill.getFacingDirection());
break;
case 'X' :
case 'X':
break;
}
break;
case 'X' :
case 'X':
System.out.println("Kilépés");
isExiting = true;
break;

View File

@ -3,12 +3,12 @@ package cicaprojekt;
import java.util.ArrayList;
import java.util.List;
public class Player extends PlayerBase{
public class Player extends PlayerBase {
private List<ZPM> zpmContainer;
private Box boxLifted;
public Player(Tile startTile, Direction startDirection){
public Player(Tile startTile, Direction startDirection) {
zpmContainer = new ArrayList<>();
currentTile = startTile;
facingDirection = startDirection; /* Be lehetne állítani egy defaultot is, nem tudom, mennyire kéne */
@ -24,8 +24,7 @@ public class Player extends PlayerBase{
}
@Override
public void pickZPM(Tile tile)
{
public void pickZPM(Tile tile) {
zpmContainer.add(tile.getZPMFromTile());
}

View File

@ -1,12 +1,13 @@
package cicaprojekt;
public class PlayerBase implements Destroyable{
public class PlayerBase implements Destroyable {
protected Game game;
protected Tile currentTile;
protected Direction facingDirection;
public void destroy() {}
public void destroy() {
}
public Tile getCurrentTile() {
return currentTile;

View File

@ -8,7 +8,7 @@ public class Scale extends Field {
private int weight;
public Scale(Gate gate, int threshold){
public Scale(Gate gate, int threshold) {
gateConnected = gate;
this.threshold = threshold;
boxStack = new Stack<Box>();
@ -26,7 +26,7 @@ public class Scale extends Field {
@Override
public Box getABox() {
if(boxStack.isEmpty())
if (boxStack.isEmpty())
return null;
weight -= boxStack.peek().weight();
stackChanged();
@ -35,7 +35,7 @@ public class Scale extends Field {
@Override
public void putABox(Box box) {
if(box == null)
if (box == null)
return;
boxStack.push(box);
weight += box.weight();
@ -47,7 +47,7 @@ public class Scale extends Field {
}
private void stackChanged() {
if(weight > threshold)
if (weight > threshold)
gateConnected.setOpen(true);
else
gateConnected.setOpen(false);

View File

@ -1,14 +1,12 @@
package cicaprojekt;
public class Stargate {
private boolean isSpawned;
public static final Stargate yellowStargate = new Stargate();
public static final Stargate blueStargate = new Stargate();
public static final Stargate redStargate = new Stargate();
public static final Stargate greenStargate = new Stargate();
public /*final*/ Stargate other; //TODO find better ways to do this
private boolean isSpawned;
private Wall currentWall;

View File

@ -10,7 +10,7 @@ public abstract class Tile {
protected Stack<Box> boxStack;
public Tile(){
public Tile() {
adjacentTile = new HashMap<Direction, Tile>();
}
@ -39,13 +39,13 @@ public abstract class Tile {
}
public void putABox(Box box) {
if(box == null)
if (box == null)
return;
boxStack.push(box);
}
public Box getABox(){
if(boxStack.isEmpty())
public Box getABox() {
if (boxStack.isEmpty())
return null;
return boxStack.pop();
}

View File

@ -3,12 +3,12 @@ package cicaprojekt;
public class Wall extends Tile {
private Stargate sg;
public Wall(){
public Wall() {
super();
}
public void spawnStargate(Stargate stargate, Direction direction) {
if(sg == null)
if (sg == null)
sg = stargate;
else
return;
@ -19,10 +19,9 @@ public class Wall extends Tile {
}
public void onEntry(PlayerBase playerBase) {
if(sg == null) {
if (sg == null) {
return;
}
else {
} else {
sg.teleport(playerBase.facingDirection);
}
}

View File

@ -1,12 +1,11 @@
package cicaprojekt;
public class ZPM implements Pickable
{
public void pick(){
public class ZPM implements Pickable {
public void pick() {
}
@Override
public void destroy(){
public void destroy() {
}
@Override