Skip to content
Snippets Groups Projects
Commit 60fbb966 authored by sfphoton's avatar sfphoton
Browse files

Dead worker won't participate in the game

parent dd5cab54
No related branches found
No related tags found
No related merge requests found
...@@ -46,15 +46,17 @@ public class Main extends Application { ...@@ -46,15 +46,17 @@ public class Main extends Application {
} }
//swapping active worker //swapping active worker
if (aliveWorkers.size() != 0) {
boolean activeFound = false; boolean activeFound = false;
int i; int i;
for(i=0; i<workers.size() && !activeFound; i++) { for(i=0; i<aliveWorkers.size() && !activeFound; i++) {
if(workers.values().toArray()[i] == activeWorker) { if(aliveWorkers.values().toArray()[i] == activeWorker) {
activeFound = true; activeFound = true;
} }
} }
if(i==workers.size()) activeWorker = (Worker)workers.values().toArray()[0]; if(i==aliveWorkers.size()) activeWorker = (Worker)aliveWorkers.values().toArray()[0];
else activeWorker = (Worker)workers.values().toArray()[i]; else activeWorker = (Worker)aliveWorkers.values().toArray()[i];
}
//checking if game should end //checking if game should end
checkGameEnded(); checkGameEnded();
...@@ -68,6 +70,8 @@ public class Main extends Application { ...@@ -68,6 +70,8 @@ public class Main extends Application {
private static HashMap<String, Worker> workers = new HashMap<>(); //a munkások private static HashMap<String, Worker> workers = new HashMap<>(); //a munkások
private static HashMap<String, Crate> crates = new HashMap<>(); //a ládák - azért szedtem így külön mindent, hogy a játék vége detektálásánál végig lehessen kérdezgetni csak a ládákat - comment by SF private static HashMap<String, Crate> crates = new HashMap<>(); //a ládák - azért szedtem így külön mindent, hogy a játék vége detektálásánál végig lehessen kérdezgetni csak a ládákat - comment by SF
private static HashMap<String, Worker> aliveWorkers = new HashMap<>();
private static Worker activeWorker; private static Worker activeWorker;
private static boolean gameRunning; private static boolean gameRunning;
...@@ -158,20 +162,9 @@ public class Main extends Application { ...@@ -158,20 +162,9 @@ public class Main extends Application {
af.shouldDraw(view); af.shouldDraw(view);
} }
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
launch(args); launch(args);
// while (true) {
// String line;
// line = br.readLine();
//
// if (line == null) break;
//
// runCommand(line);
// }
} }
public static String getFieldName(AbstractField field) public static String getFieldName(AbstractField field)
{ {
return getKeyByValue(map, field); return getKeyByValue(map, field);
...@@ -189,7 +182,7 @@ public class Main extends Application { ...@@ -189,7 +182,7 @@ public class Main extends Application {
public static void deleteWorker(Worker w) public static void deleteWorker(Worker w)
{ {
workers.remove(getKeyByValue(workers, w)); aliveWorkers.remove(getKeyByValue(workers, w));
} }
public static void deleteCrate(Crate c) public static void deleteCrate(Crate c)
...@@ -198,6 +191,11 @@ public class Main extends Application { ...@@ -198,6 +191,11 @@ public class Main extends Application {
} }
private static void checkGameEnded() { private static void checkGameEnded() {
if (aliveWorkers.size() == 0) {
endGame();
return;
}
boolean ended = true; boolean ended = true;
for(Crate c : crates.values()) { for(Crate c : crates.values()) {
if(!c.couldGameFinish()) ended = false; if(!c.couldGameFinish()) ended = false;
...@@ -208,12 +206,7 @@ public class Main extends Application { ...@@ -208,12 +206,7 @@ public class Main extends Application {
} }
} }
private static void endGame() private static void endGame() {
{
for (Entry<String, Worker> e : workers.entrySet())
{
System.out.println(e.getKey() + ": " + e.getValue());
}
gameRunning=false; gameRunning=false;
} }
...@@ -335,6 +328,7 @@ public class Main extends Application { ...@@ -335,6 +328,7 @@ public class Main extends Application {
{ {
Worker w=new Worker(force); Worker w=new Worker(force);
workers.put(name, w); workers.put(name, w);
aliveWorkers.put(name, w);
AbstractField f=map.get(field); AbstractField f=map.get(field);
f.accept(Direction.RIGHT, w, w); f.accept(Direction.RIGHT, w, w);
} }
......
...@@ -75,6 +75,7 @@ public class Worker extends Moveable { ...@@ -75,6 +75,7 @@ public class Worker extends Moveable {
public void kill() { public void kill() {
force=0; force=0;
alive=false; alive=false;
Main.deleteWorker(this);
super.kill(); super.kill();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment