diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Board.java b/Arctic_Nigthmare/src/arctic_nightmare/Board.java index 714e215349898492fd4ca632217315c4d80375e7..85d6f0facc0542b9ea849a0771cc581f2333dbb7 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Board.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Board.java @@ -7,60 +7,38 @@ import java.util.List; public class Board { private List<Field> fields; - /*Only when the fields lay in grid, and board1s size is rows*column*/ + /*Only when the fields lay in grid, and board's size is rows*column*/ private int columns = -1; /*Only for proto*/ private int id; private int idcounter = 1; - public Board() { + public Board(int field_num , int column_num) { fields = new ArrayList<Field>(); - for(int i = 0; i < 9; ++i) { + for(int i = 0; i < field_num; ++i) { if(i % 2 == 0) fields.add(new StableField()); else fields.add(new UnstableField()); } - columns = 3; + columns = column_num; setNeighbors(); id = idcounter++; } - - //A hovihar tesztesethez, letrehoz egy mezobol allo jatektablat - //a jatektablara raallitja a parameterul kapott persont - public Board(Person p) { - Field f = new StableField(); + + public Board() { fields = new ArrayList<Field>(); - f.accept(p); - fields.add(f); id = idcounter++; } - public Board(int tesztesetSzama,List<Person> persons) - { - id = idcounter++; - switch(tesztesetSzama) - { - case 5:{ //5. tesztesetben csak 1 field es egy eszkimo szukseges - StableField f1 = new StableField(1, new Item("Rope")); - fields= new ArrayList<Field>(); - fields.add(f1); - for (Person p: persons) - { - f1.accept(p); - } - } - - } - + public void addField(Field f) { + fields.add(f); } - public void makeBlizzard(){ - Logger.LogAndIncreaseTabs("Board makeBlizzard"); - /* Csak a teszteleshez minden fielden vihart hoz létre*/ + public void makeBlizzard() throws PlayerDiedException{ for(Field f : fields) f.blizzard(1); - Logger.decreaseTabs(); + } /*Only for proto*/ diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Direction.java b/Arctic_Nigthmare/src/arctic_nightmare/Direction.java deleted file mode 100644 index a8f9a051865b32659d27d57987dda84934ad7708..0000000000000000000000000000000000000000 --- a/Arctic_Nigthmare/src/arctic_nightmare/Direction.java +++ /dev/null @@ -1,8 +0,0 @@ -package arctic_nightmare; - -public enum Direction { - LEFT, - RIGHT, - UP, - DOWN -} diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Eskimo.java b/Arctic_Nigthmare/src/arctic_nightmare/Eskimo.java index 44793dbf18267654c9b14a02fbd520bf4910d27d..21db5fbe50cac09f4e2693d2d071ffacaa28e2d5 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Eskimo.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Eskimo.java @@ -6,18 +6,23 @@ public class Eskimo extends Person { maxTemp = 5; bodyTemp = 5; } + + public Eskimo(Game g) { + super(g); + maxTemp = 5; + bodyTemp = 5; + } - public Eskimo(String name) { - super(name);} + //public Eskimo(String name) { + //super(name);} - public Eskimo(String name, Field field) { + /*public Eskimo(String name, Field field) { super(name, field); - } + }*/ public void buildIgloo(){ - Logger.LogAndIncreaseTabs("Eskimo: buildIgloo"); - this.field.setIgloo(); - Logger.decreaseTabs(); + if(this.field.setIgloo()) + work--; } /*Only for proto*/ diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Event.java b/Arctic_Nigthmare/src/arctic_nightmare/Event.java new file mode 100644 index 0000000000000000000000000000000000000000..387e1af6c4bb35cb453f1b4de8d7819304d395e8 --- /dev/null +++ b/Arctic_Nigthmare/src/arctic_nightmare/Event.java @@ -0,0 +1,9 @@ +package arctic_nightmare; + +public class Event { + private int code; + private Object[] params; + public Event(int c, Object[] o) { + } + +} diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Explorer.java b/Arctic_Nigthmare/src/arctic_nightmare/Explorer.java index 5fe1f899217f973626821f35c936f42c1f05352a..3d8c2f12f026dd400d5e5428fc2fdeef48f282eb 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Explorer.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Explorer.java @@ -9,16 +9,23 @@ public class Explorer extends Person { bodyTemp = 4; } - public Explorer(String name) { - super(name); - } - public Explorer(String name, Field field) { + public Explorer(Game g) { + super(g); + maxTemp = 4; + bodyTemp = 4; + } + + //public Explorer(String name) { + // super(name); + //} + /*public Explorer(String name, Field field) { super(name, field); - } + }*/ public void checkCapacity(Field f) { if(field.isNeighbor(f)) - f.revealCapacity(); + if(f.revealCapacity()) + work--; } /*Only for proto*/ diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Field.java b/Arctic_Nigthmare/src/arctic_nightmare/Field.java index 7f0c35a35f1a3c62ace082a31aa0cec4f89c0d60..fe9642af0463f3c1cdb6a69307cbc1dff12e87e2 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Field.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Field.java @@ -45,13 +45,13 @@ public abstract class Field { id = idcounter++; } - public void accept(IceBear b) { + public void accept(IceBear b) throws PlayerDiedException { bear = b; if(persons.size() != 0 && !hasIgloo) persons.get(0).die(); } - public abstract void accept(Person p); + public abstract void accept(Person p) throws PlayerDiedException; public void addItem(Item it) { item = it; @@ -61,8 +61,15 @@ public abstract class Field { neighbors.add(f); } + //For initializing components + public abstract boolean canAddPlayer(); + //For initializing components + public void addPlayer(Person p) { + persons.add(p); + } + //A Fieldet ero hovihar hatasat kozvetiti a rajta allok fele - public void blizzard(int quant){ + public void blizzard(int quant) throws PlayerDiedException{ this.snow += quant; if(!(hasIgloo || tent != null)) { for(Person p : persons) @@ -131,9 +138,12 @@ public abstract class Field { persons.remove(p); } - public void revealCapacity() + public boolean revealCapacity() { + if(visibleCapacity) + return false; visibleCapacity = true; + return true; } public boolean setIgloo(){ diff --git a/Arctic_Nigthmare/src/arctic_nightmare/FragileShovel.java b/Arctic_Nigthmare/src/arctic_nightmare/FragileShovel.java index 6987c0f63eaaf9f71bca1b71d35ffafb15b09007..b5e9f31c1629755684d03879d7387e5903547c63 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/FragileShovel.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/FragileShovel.java @@ -12,7 +12,10 @@ public class FragileShovel extends Item{ } public boolean use(Field f) { - return (--remainingUse >= 0); + remainingUse--; + if(remainingUse == 0) + return false; + return true; } @Override diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Game.java b/Arctic_Nigthmare/src/arctic_nightmare/Game.java index 4ca6c2e1c89c0420f7ddbca0695f2ad9f9e23dde..0673ba0b6109cb68d2f0cd1d61c72f072e770658 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Game.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Game.java @@ -43,232 +43,61 @@ public class Game{ void gameOver(){} - void nextPlayer(){} - - - void newGame(){ - board = new Board(); - bear = new IceBear(board.getfield(0)); - board.getfield(0).bear = bear; - for(int i = 0; i < 4; ++i) { - if(i % 2 == 0) { - players.add(new Eskimo(board.getfield((i + 1) * 2), this)); - board.getfield((i + 1) * 2).accept(players.get(i)); - } - else { - players.add(new Explorer(board.getfield((i + 1) * 2), this)); - board.getfield((i + 1) * 2).accept(players.get(i)); - } - } - actualPlayer = players.get(0); - String names[] = {"Cartridge", "Flare", "Pistol", "Rope", "Food"}; - for(int i = 0; i < 5; ++i) { - Item it = new Item(names[i]); - items.add(it); - if(i < 4) - players.get(0).addItem(it); - else - board.getfield(0).addItem(it); - } - Item fs = new FragileShovel(); - items.add(fs); - board.getfield(2).addItem(fs); - - } - - void setActualPerson(Person P){ - actualPlayer = P; - } - - void win(){ - Logger.LogAndIncreaseTabs("Game win"); - Logger.Log(">> A játék véget ért a játékosok nyertek.", false); - Logger.decreaseTabs(); - } - - /************************************************* - * Test functions * - *************************************************/ - - void test() throws IOException - { - boolean exit = false; - String in; - BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - while (!exit){ - Logger.setTabs(0); - Logger.Log("Kérlek válassz tesztesetet!\n" - + "1: A sarkkutató megvizsgálja a mezőt\n" - + "2: A sarkkutató instabil jégmezőre lép (automatikusan futtatja a 3-ast is)\n" - + "3: A sarkkutató vízbe esik\n" - + "4: A sarkkutató kiássa és elfogyasztja az élelmet\n" - + "5: Az eszkimó letakarítja, kiássa és felveszi a kötelet\n" - + "6: Az eszkimó iglut épít\n" - + "7: A sarkkutató hóviharba kerül\n" - + "8: Az eszkimó összeszereli és elsüti a jelzőfényt\n" - + "exit"); - in = reader.readLine(); - switch (in) - { - case "1": - explorerChecksCapacity(); - break; - case "2": - personStepsToUnstable(); - break; - case "3": - personFalls(); - break; - case "4": - personEatsFood(); - break; - case "5": - personDigsRope(); - break; - case "6": - eskimoBuildsIgloo(); - break; - case "7": - explorerGetsHitByBlizzard(); - break; - case "8": - eskimoAssemblesandShootsFlare(); - break; - case "exit": - exit = true; - break; - } - } - } - - private void explorerChecksCapacity() - { - Logger.LogAndIncreaseTabs("Game: a játéklogika meghívja az explorer checkCapacity függvényét."); - Field field1 = new StableField(0, null); - Field field2 = new StableField(0, null); - field1.addNeighbor(field2); - field2.addNeighbor(field1); - Explorer explorer = new Explorer("Explorer", field2); - Logger.Log("Melyik mezőt vizsgálja a sarkkutató?(0 = Alsó, 1 = Felső, 2 = Jobb, 3 = Bal)", false); - Direction d; - switch(Logger.getNumericInput(0, 3)) { - case 0: d = Direction.DOWN; break; - case 1: d = Direction.UP; break; - case 2: d = Direction.RIGHT; break; - default:d = Direction.LEFT; break; - } - explorer.checkCapacity(field1); - Logger.decreaseTabs(); + public int getPlayerNumber() { + return players.size(); } - private void personStepsToUnstable() - { - Logger.LogAndIncreaseTabs("Game: a játéklogika meghívja az adott karakter step(Direction.RIGHT) függvényét."); - Field unstablefield = new UnstableField(); - Field stablefield = new StableField(0, null); - unstablefield.addNeighbor(stablefield); - stablefield.addNeighbor(unstablefield); - Explorer ex1 = new Explorer("ex1", stablefield); - Explorer ex2 = new Explorer("ex2", unstablefield); - stablefield.accept(ex1); //A stabil mezore inicializaljuk ex1-t - unstablefield.accept(ex2); //Az instabil mezore inicializaljuk ex2-t - //ex1.step(Direction.RIGHT); // no directional step anymore - Logger.decreaseTabs(); - } - - private void personFalls() { - Logger.increaseTabs(); - Field unstablefield = new UnstableField(0, 0, null); - Field stablefield = new StableField(0,null); - unstablefield.addNeighbor(stablefield); - stablefield.addNeighbor(unstablefield); - Explorer ex1 = new Explorer("ex1", unstablefield); - Explorer ex2 = new Explorer("ex2", stablefield); - Logger.Log("Van búvárruha a sarkkutatónál? (0 = nem, 1 = igen)", false); - if(Logger.getNumericInput(0,1)==1) ex1.addItem(new Item("DivingSuit")); - Logger.Log("Van kötél a szomszédos mezőn álló eszkimónál? (0 = nem, 1 = igen)", false); - if(Logger.getNumericInput(0,1)==1) ex2.addItem(new Item("Rope")); - ex1.fall(); - Logger.decreaseTabs(); - } - - private void personEatsFood() throws IOException - { - Logger.Log("Mennyi a sarkkutató testhője?( 1-4ig)\n", false); - int bodytemp = Logger.getNumericInput(1,4); - Person ex1 = new Explorer("ExplorerAboutToEatFood"); - ex1.setBodyTemp(bodytemp); - StableField f1 = new StableField(0, new Item("Food")); - f1.accept(ex1); - Logger.LogAndIncreaseTabs("Game: a játéklogika meghívja az adott karakter pickUpItem függvényét."); - ex1.pickUpItem(); // hozzaadjuk a mezon felszedett itemet az Explroerhez + void nextPlayer(){ + int actualPlayerIdx = players.indexOf(actualPlayer); + int nextPlayerIdx = actualPlayerIdx + 1; + if(nextPlayerIdx >= players.size()) + nextPlayerIdx = 0; + setActualPerson(nextPlayerIdx); } - private void personDigsRope() - - { - Person es1 = new Eskimo("EskimoAboutToPickupRope"); - List<Person> persons= new ArrayList<Person>(); - persons.add(es1); - - this.board = new Board(5,persons); // listaba kerül az explorer, hogy at lehessen adni a board konstruktoranak - - Logger.Log("Explorernek van ásója?( 0 = nem vagy 1 = igen)\n", false); - int aso = Logger.getNumericInput(0,1); - Logger.Log("Hány réteg hó borítja a fieldet? 1 vagy 2?)\n", false); - Logger.getNumericInput(1,2); - Logger.LogAndIncreaseTabs("Game: a játéklogika meghívja az adott karakter shovel függvényét."); - if(aso == 1) - { - es1.addItem(new Item("Shovel")); // Aso hozzaadasa az eszkimohoz - } - es1.shovel(); - Logger.decreaseTabs(); - Logger.LogAndIncreaseTabs("Game: a játéklogika meghívja az adott karakter dig függvényét."); - es1.dig();// kiassa a kotelet - Logger.decreaseTabs(); - Logger.LogAndIncreaseTabs("Game: a játéklogika meghívja az adott karakter pickUpItemfüggvényét."); - es1.pickUpItem(); // felveszi a targyat, ami jelen esetben egy kotel - Logger.decreaseTabs(); + public void play() { + try { + while(true) { + actualPlayer.enablePlayer(); + nextPlayer(); + } + } + catch(PlayerDiedException e) { + gameOver(); + } + catch(PlayersWinException e) { + win = true; + } + finally { + + } } - //a testeset az Iglu epitest szimulalja - //felhasznalo donti el, hogy van-e mar a mezon Iglu - void eskimoBuildsIgloo() - { - Logger.LogAndIncreaseTabs("Game: a játéklogika meghívja az eskimo buildIgloo() függvényét."); - StableField f = new StableField(2, null); - Eskimo es = new Eskimo("IglooBuilder",f); - es.buildIgloo(); - Logger.decreaseTabs(); + void newGame(int fieldsnum, int boardcolumns, int playernum){ + board = new Board(fieldsnum, boardcolumns); + bear = new IceBear(board.getfield(0)); + board.getfield(0).bear = bear; + for(int i = 0; i < playernum; ++i) { + Person newperson = null; + if(i % 2 == 0) + newperson = new Eskimo(this); + else + newperson = new Explorer(board.getfield((i + 1) * 2), this); + players.add(newperson); + if(board.getfield((i + 1) * 2).canAddPlayer()) + board.getfield((i + 1) * 2).addPlayer(newperson); + newperson.addField(board.getfield((i + 1) * 2)); + } + actualPlayer = players.get(0); } - //a testeset a Vihart szimulalja - //a felhasznalo donti el, hogy van-e Iglu a mezon, amin a sarkkutato tartozkodik - //ha van Iglu, nem tortenik sebzes - //a felhasznalo allitja be a sarkkutato testhojet is - //ha 1 a testho, a sarkkutato meghal - void explorerGetsHitByBlizzard() { - Logger.LogAndIncreaseTabs("Game: a játéklogika meghívja az explorer hitByBlizzard függvényét."); - Explorer ex = new Explorer("ex"); - Board b = new Board(ex); - b.makeBlizzard(); - Logger.decreaseTabs(); + void setActualPerson(int idx){ + actualPlayer = players.get(idx); } - - //a testeset a pisztoly összeszerelését és elsuteset szimulalja - //a felhasznalo donti el, hogy a jatekosok osszegyujtottek-e az osszes alkatreszt - //ha igen, megnyerik a jatekot - void eskimoAssemblesandShootsFlare() { - Logger.LogAndIncreaseTabs("Game: a játéklogika meghívja az eskimo AssembleFlare függvényét."); - StableField f1 = new StableField(2,null); - Eskimo es1 = new Eskimo("es1",f1); - Eskimo es2 = new Eskimo("es2",f1); - f1.accept(es1); - f1.accept(es2); - es1.assembleFlare(); - Logger.decreaseTabs(); + + void win() throws PlayersWinException{ + throw new PlayersWinException(); } /*Only for proto*/ diff --git a/Arctic_Nigthmare/src/arctic_nightmare/IceBear.java b/Arctic_Nigthmare/src/arctic_nightmare/IceBear.java index 379028d6e49b996f53ff3767ff177482d3846186..a73a0ac074f65abe0dd5de2fafb451721937b563 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/IceBear.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/IceBear.java @@ -2,6 +2,8 @@ package arctic_nightmare; import java.io.OutputStream; import java.io.PrintWriter; +import java.util.List; +import java.util.Random; public class IceBear { private Field field; @@ -15,8 +17,14 @@ public class IceBear { field = f; id = idcounter++; } - public void step() { - + public void step() throws PlayerDiedException { + Random rand = new Random(); + List<Field> neighborList = field.getNeighbors(); + int rand_idx = rand.nextInt(neighborList.size()); + Field nextField = field.getNeighbors().get(rand_idx); + field.removeBear(); + field = nextField; + nextField.accept(this); } /*Only for proto*/ diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Main.java b/Arctic_Nigthmare/src/arctic_nightmare/Main.java index 0f3b3a871dd27712bd736c800cc8b8e9778fcc28..5ba201dac41ff9ec7f4c8af4066e134a15137023 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Main.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Main.java @@ -1,10 +1,5 @@ package arctic_nightmare; -import java.util.TreeMap; import java.io.IOException; -import java.io.PrintWriter; -import java.util.Set; -import java.util.Iterator; -import java.util.Map; public class Main { @@ -14,8 +9,7 @@ public class Main { */ public static void main(String[] args) throws IOException { Game game = new Game(); - game.newGame(); + game.newGame(9, 3, 4); game.save(); game.draw_minimap(); - } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Person.java b/Arctic_Nigthmare/src/arctic_nightmare/Person.java index 034c220759e25c1dc1575888ac05c65871f7331a..1103351ca6e85f2653d6dd808c9d8cc5b4651f2c 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Person.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Person.java @@ -6,10 +6,12 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.Vector; +import org.w3c.dom.events.Event; + public abstract class Person { protected int bodyTemp; protected int maxTemp; - private int work; + protected int work; private String name; //Teszt kiiratashoz protected Field field; private Vector<Item> items; @@ -20,17 +22,31 @@ public abstract class Person { private int id; private static int idcounter = 1; + + + ///Person konstruktorba kell Game mindenképpen + public Person(Field f, Game g) { work = 0; name = new String(); - field =f; + field = f; + items = new Vector<Item>(); + game = g; + builtTent = null; + id = idcounter++; + } + + public Person(Game g) { + work = 0; + name = new String(); + field = null; items = new Vector<Item>(); game = g; builtTent = null; id = idcounter++; } - Person(String name, Field field) + /*Person(String name, Field field) { items = new Vector<>(); this.field = field; @@ -38,7 +54,7 @@ public abstract class Person { this.name = name; work = 4; id = idcounter++; - } + }*/ Person(String name) { @@ -48,18 +64,12 @@ public abstract class Person { id = idcounter++; } - /*public void addItem(Item item) - { - items.add(item); - }*/ - /*Only for proto*/ public int getid() {return id;} - public void assembleFlare(){ - Logger.LogAndIncreaseTabs("Person assembleFlare"); + public void assembleFlare() throws PlayersWinException{ List<Person> persons = field.getPersons(); - Item parts[] = {new Item("Pistol"), new Item("Cartridge"), new Item("Flare")}; + String parts[] = {"Pistol", "Cartridge", "Flare"}; boolean b[] = {false, false, false}; for(int i = 0; i <3; ++i) { for(Person p : persons) { @@ -69,127 +79,96 @@ public abstract class Person { } } } - if(b[0] && b[1] && b[2]) { + if(b[0] && b[1] && b[2] && persons.size() == game.getPlayerNumber()) { game.win(); } - else - Logger.Log(">> Nincs meg minden darab", false); - Logger.decreaseTabs(); + } - public void die() + public void die() throws PlayerDiedException { - Logger.LogAndIncreaseTabs("Person(" + name + ") die"); - Logger.decreaseTabs(); + throw new PlayerDiedException(); } public void dig(){ - Logger.LogAndIncreaseTabs("Person(" + name + ") dig"); if(this.field.emitItem()) work--; - Logger.decreaseTabs(); } - //Kiegeszitve a teszthez szükseges sorokkal - public void fall() + public void fall() throws PlayerDiedException { - Logger.LogAndIncreaseTabs("Person(" + name + ") fall"); //teszthez - if(items.contains(new Item("DivingSuit"))) { - Logger.Log(">>" + this.getName() + "-nek van búvárruhája, túléli", false); + if(hasItem("DivingSuit")) { step(field.getNeighbors().get(0)); } else { - Logger.Log(">>" + this.getName() + "-nek nincs búvárruhája, segítők keresése", false); ArrayList<Person> potentialhelpers = findHelpers(); boolean saved = false; if(!potentialhelpers.isEmpty()) { for (Person person : potentialhelpers) { saved = person.pullOut(this); - if(saved) break; - } - if(!saved) { - Logger.Log(">> " + name +"-t egyik szomszédja sem tudta kimenteni.", false); - die(); + if(saved) return; } } - else die(); + die(); } - Logger.decreaseTabs(); } - //Teszt kiiratashoz public String getName() { return name; } - public int getWork(){return 0;} + public int getWork(){ + return work; + } - public boolean hasItem(Item item){ - Logger.LogAndIncreaseTabs("Person hasItem : " + item ); - Logger.Log("Van " + item + " a karakternél(" + name + - ")?(0 = I, 1 = N)", false); - boolean b = Logger.getNumericInput(0, 1) == 0; - Logger.decreaseTabs(); - return b; + public boolean hasItem(String itemname){ + for(Item it : items) + if(it.getName().equals(itemname)) + return true; + return false; } - public void hitByBlizzard(){ - Logger.LogAndIncreaseTabs("Person: hitByBlizzard"); + public void hitByBlizzard() throws PlayerDiedException{ this.bodyTemp--; - if(this.bodyTemp==0) die(); - Logger.decreaseTabs(); + if(this.bodyTemp==0) + die(); } public ArrayList<Person> findHelpers(){ - Logger.LogAndIncreaseTabs("Person(" + name + ") findHelpers"); ArrayList<Person> potentialhelpers = new ArrayList<Person>(); - Direction dirs[] = Direction.values(); - List<Field> neighbors = field.getNeighbors(); + List<Field> neighbors = field.getNeighbors(); for(Field neighbor: neighbors) { //iteralas az osszes iranyt tartalmazo tombon potentialhelpers.addAll(neighbor.getPersons()); } - Logger.decreaseTabs(); - if(potentialhelpers.isEmpty()) Logger.Log(">>" + name + " nem talált segítőket.", false); return potentialhelpers; } public void pickUpItem() { - Logger.LogAndIncreaseTabs("Person(" + name + ") pickUpItem"); Item item = field.getItem(); if (item != null) { - if(item.equals(new Item("food"))) + if(item.getName().equals("Food")) { - if(this.bodyTemp < 4) { - this.bodyTemp++; // ha elelmet talalt a person azt nem tarolja el, hanem megeszi es noveli vele a bodyTempjét - Logger.Log(">> Élelem efogyasztása és bodyTemp növelése", false); - } - else Logger.Log(">> A testhő maximális: 4 ", false); + if(bodyTemp < maxTemp) + bodyTemp++; // ha elelmet talalt a person azt nem tarolja el, hanem megeszi es noveli vele a bodyTempjét } else { if(!items.contains(item)) { - items.add(item); - Logger.Log(">> Person(" + name + ") felvette: " + item, false); - work --; + items.add(item); + work --; } } } - else - { - Logger.Log(">> Person(" + name + ") nem tudta felvenni a tárgyat", false); - } - Logger.decreaseTabs(); } - public boolean pullOut(Person p){ - Logger.LogAndIncreaseTabs("Person(" + name + ") pullOut("+p.name+ ")"); - if(items.contains(new Item("Rope"))) { + public boolean pullOut(Person p) throws PlayerDiedException{ + if(hasItem("Rope")) { p.step(field); + return true; } - Logger.decreaseTabs(); - return items.contains(new Item("Rope")); + return false; } public void setWork(int i) @@ -199,17 +178,30 @@ public abstract class Person { public void shovel() { - Logger.LogAndIncreaseTabs("Person(" + name + ") shovel"); - if (field.clearSnow(items.contains(new Item("Shovel")) ? 2 : 1)) work --; // ellenorizzuk hogy van e asoja - Logger.decreaseTabs(); // ha van asoja, akkor 2 reteg havat tud letakaritani ha nincs akkor 1-t + int snow_layers = 1; + if(hasItem("Shovel") || hasItem("FragileShovel")) + snow_layers = 2; + if(field.clearSnow(snow_layers)){ + work--; + for(int i = 0; i < items.size(); ++i) { + Item it = items.get(i); + if(it.getName() == "FragileShovel") + if(!it.use(null)) { + items.remove(it); + return; + } + } + } } - public void step(Field field) + public void step(Field f) throws PlayerDiedException { - Logger.LogAndIncreaseTabs("Person(" + name + ") step(Field)"); - field.accept(this); - Logger.decreaseTabs(); + if(field.isNeighbor(f)) { + this.field.remove(this); + work--; + f.accept(this); + } } public void setBodyTemp(int bodyTemp) { @@ -222,16 +214,26 @@ public abstract class Person { items.add(item); } - public void enablePlayer() { + //For initializing components + public void addField(Field f) { + field = f; + } + + public void enablePlayer() throws PlayerDiedException, PlayersWinException { setWork(4); if(builtTent != null) builtTent.removeFromField(); + return; + //switch(Event.code) { + //case 1: step((Field) event.params[0]); + //case 2: func2((Field) event.params[0], (Item) event.params[1]); + //} } - + public void buildTent() { if(work > 0) { for(Item it : items) { - if(it.getName().contentEquals("Tent")) { + if(it.getName().equals("Tent")) { if(it.use(field)) { items.remove(it); work--; diff --git a/Arctic_Nigthmare/src/arctic_nightmare/PlayerDiedException.java b/Arctic_Nigthmare/src/arctic_nightmare/PlayerDiedException.java new file mode 100644 index 0000000000000000000000000000000000000000..314d58d2378a7ac835a3dc8217a7539f0f0b6f98 --- /dev/null +++ b/Arctic_Nigthmare/src/arctic_nightmare/PlayerDiedException.java @@ -0,0 +1,10 @@ +package arctic_nightmare; + +public class PlayerDiedException extends Exception{ + + /** + * + */ + private static final long serialVersionUID = 1L; + +} diff --git a/Arctic_Nigthmare/src/arctic_nightmare/PlayersWinException.java b/Arctic_Nigthmare/src/arctic_nightmare/PlayersWinException.java new file mode 100644 index 0000000000000000000000000000000000000000..3769ef7ab3ee546940ab8400584ae2ec54333b98 --- /dev/null +++ b/Arctic_Nigthmare/src/arctic_nightmare/PlayersWinException.java @@ -0,0 +1,8 @@ +package arctic_nightmare; + +public class PlayersWinException extends Exception{ + /** + * + */ + private static final long serialVersionUID = 1L; +} diff --git a/Arctic_Nigthmare/src/arctic_nightmare/StableField.java b/Arctic_Nigthmare/src/arctic_nightmare/StableField.java index b01a5c9c19b1ff5b140c149811732e0a8d0c725b..b729e90d7dc09ee0162153e33ecd9fccda119f33 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/StableField.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/StableField.java @@ -13,7 +13,7 @@ public class StableField extends Field { } - public void accept(Person person) + public void accept(Person person) throws PlayerDiedException { if(bear != null && !hasIgloo) person.die(); @@ -23,4 +23,10 @@ public class StableField extends Field { /*Only for proto*/ public String get_type_name() {return "StableField";} + + public boolean canAddPlayer() { + if(bear != null) + return false; + return true; + } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/UnstableField.java b/Arctic_Nigthmare/src/arctic_nightmare/UnstableField.java index 3b0438dc93d822fa8cf33a860973c52011c56f56..c3c8a8487d4ad286ee4ce3f27845d538465ac4fb 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/UnstableField.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/UnstableField.java @@ -12,16 +12,17 @@ public class UnstableField extends Field{ } - public void accept(Person person) + public void accept(Person person) throws PlayerDiedException { persons.add(person); if(bear != null && !hasIgloo) person.die(); if (persons.size() > capacity) overturn(); + person.field = this; } - public void overturn() + public void overturn() throws PlayerDiedException { capacity = 0; snow = 0; @@ -36,4 +37,10 @@ public class UnstableField extends Field{ /*Only for proto*/ public String get_type_name() {return "UnstableField";} + + public boolean canAddPlayer() { + if(bear != null || (persons.size() + 1) > capacity) + return false; + return true; + } }