diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Board.java b/Arctic_Nigthmare/src/arctic_nightmare/Board.java index 31e182b564f02a43f51745d31e875875d42d18fb..b0e77c2d68a300491a441fdfc538405108c15aa9 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Board.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Board.java @@ -1,9 +1,30 @@ package arctic_nightmare; +import java.io.OutputStream; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; public class Board { private List<Field> fields; + /*Only when the fields lay in grid, and board1s size is rows*column*/ + private int columns = -1; + + /*Only for proto*/ + private int id; + private int idcounter = 1; + + public Board() { + fields = new ArrayList<Field>(); + for(int i = 0; i < 9; ++i) { + if(i % 2 == 0) + fields.add(new StableField()); + else + fields.add(new UnstableField()); + } + columns = 3; + setNeighbors(); + id = idcounter++; + } //A hovihar tesztesethez, letrehoz egy mezobol allo jatektablat //a jatektablara raallitja a parameterul kapott persont @@ -12,13 +33,15 @@ public class Board { fields = new ArrayList<Field>(); f.addPerson(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,Item.rope); + StableField f1 = new StableField(1, new Item("Rope")); fields= new ArrayList<Field>(); fields.add(f1); for (Person p: persons) @@ -38,4 +61,73 @@ public class Board { f.blizzard(1); Logger.decreaseTabs(); } + + /*Only for proto*/ + public int getid() {return id;} + + /*Only for proto*/ + public void save(OutputStream os) { + PrintWriter pw = new PrintWriter(os); + String s = new String("Board("); + s += getid() + "): fields:"; + if(fields != null && fields.size() != 0) + for(int i = 0; i < fields.size(); ++i) { + s += fields.get(i).getid(); + if(i == fields.size() - 1) + s += ";"; + s += " "; + } + else + s += "null"; + s += "\n"; + pw.write(s); + pw.flush(); + pw = null; + for(Field f : fields) + f.save(os); + } + + public Field getfield(int i) { + if(i < 0 || i > fields.size()) + throw new ArrayIndexOutOfBoundsException(); + return fields.get(i); + } + + /*Use only when the fields lay in grid, and board1s size is rows*column*/ + public void setNeighbors() { + int n = fields.size(); + for(int i = 0; i < n; ++i) { + Field f = fields.get(i); + if(i >= columns) + f.addNeighbor(fields.get(i - columns)); + if(i % columns > 0) + f.addNeighbor(fields.get(i - 1)); + if(i % columns < columns - 1) + f.addNeighbor(fields.get(i + 1)); + if(i < n - columns) + f.addNeighbor(fields.get(i + columns)); + } + } + + /*Only for proto*/ + /*Use only when the fields lay in grid, and board1s size is rows*colomn*/ + public void draw_minimap(OutputStream os) { + PrintWriter pw = new PrintWriter(os); + for(int i = 0; i < fields.size() / columns; ++i) { + for(int j = 0; j < columns; ++j) { + pw.format("%03d", fields.get(i * columns + j).getid()); + if(j != columns - 1) + pw.write("|"); + } + pw.write("\n"); + if(i != fields.size() / columns -1) + for(int j = 0; j < columns; ++j) { + if(j != columns - 1) + pw.write("---|"); + else + pw.write("---\n"); + } + } + pw.flush(); + } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Eskimo.java b/Arctic_Nigthmare/src/arctic_nightmare/Eskimo.java index 6f5d4f3c08b446c6de3ca9f3c1f06817028f30cd..44793dbf18267654c9b14a02fbd520bf4910d27d 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Eskimo.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Eskimo.java @@ -1,6 +1,11 @@ package arctic_nightmare; public class Eskimo extends Person { + public Eskimo(Field f, Game g) { + super(f, g); + maxTemp = 5; + bodyTemp = 5; + } public Eskimo(String name) { @@ -14,4 +19,9 @@ public class Eskimo extends Person { this.field.setIgloo(); Logger.decreaseTabs(); } + + /*Only for proto*/ + public String get_type_name() { + return "Eskimo"; + } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Explorer.java b/Arctic_Nigthmare/src/arctic_nightmare/Explorer.java index 44fc96273f61613272b26621560efa71859473ee..0ffdb897dc099cbb5bb93a94f0ba478bb68703d1 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Explorer.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Explorer.java @@ -11,6 +11,11 @@ package arctic_nightmare; */ public class Explorer extends Person { + public Explorer(Field f, Game g) { + super(f, g); + maxTemp = 4; + bodyTemp = 4; + } public Explorer(String name) { super(name); @@ -25,4 +30,9 @@ public class Explorer extends Person { f.revealCapacity(); Logger.decreaseTabs(); } + + /*Only for proto*/ + public String get_type_name() { + return "Explorer"; + } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Field.java b/Arctic_Nigthmare/src/arctic_nightmare/Field.java index 5102b5c956808567dc78da68d9309e7a2f36fe4c..40cd1f35fb248a1b04e8b4bb3307b12497553d02 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Field.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Field.java @@ -1,5 +1,7 @@ package arctic_nightmare; +import java.io.OutputStream; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; @@ -7,16 +9,29 @@ public abstract class Field { private int snow; private Item item; protected int capacity; - private boolean hasIgloo; + protected boolean hasIgloo; private boolean itemPickable; protected ArrayList<Person> persons; private ArrayList<Field> neighbors; // left right up down private boolean visibleCapacity; - + protected IceBear bear; + private Tent tent; + + /*Only for proto*/ + private int id; + private static int idcounter = 1; public Field() { + snow = 0; + item = null; + hasIgloo = false; + itemPickable = false; neighbors = new ArrayList<Field>(); persons = new ArrayList<Person>(); + visibleCapacity = false; + bear = null; + tent = null; + id = idcounter++; } Field(int capacity, int snow, Item item) @@ -26,7 +41,8 @@ public abstract class Field { this. snow = snow; this.item = item; visibleCapacity = false; - neighbors = new ArrayList<Field>(); + neighbors = new ArrayList<Field>(); + id = idcounter++; } //Teszthez: a Field minden szomszedjat a kapott Field-re allitja az egyszeruseg kedveert. Nem valos funkció. @@ -45,6 +61,8 @@ public abstract class Field { neighbors.set(idx, field); } + public void addNeighbor(Field f) {neighbors.add(f);} + public abstract void accept(Person p); //A Fieldet ero hovihar hatasat kozvetiti a rajta allok fele @@ -90,7 +108,7 @@ public abstract class Field { return false; } - public int getCapacity(){return 0;} + public int getCapacity(){return capacity;} public Item getItem() { @@ -158,5 +176,77 @@ public abstract class Field { persons.add(p); p.field = this; } + + public boolean setTent(Tent t) { + if(tent != null) + return false; + tent = t; + return true; + } + + public void accept(IceBear b) { + bear = b; + if(persons.size() != 0 && !hasIgloo) + persons.get(0).die(); + } + + public void removeBear() {bear = null;} + + /*Only for proto*/ + public int getid() {return id;} + + /*Only for proto*/ + public void save(OutputStream os) { + PrintWriter pw = new PrintWriter(os); + String s = new String(get_type_name() + "("); + s += getid() + "): "; + s += "snow:" + snow + "; "; + s += "capacity:" + capacity + "; "; + s += "hasIgloo:" + hasIgloo + "; "; + s += "itemPickable:" + itemPickable + "; "; + s += "neighbors:"; + if(neighbors != null && neighbors.size() != 0) + for(int i = 0; i < neighbors.size(); ++i) { + s += neighbors.get(i).getid(); + if(i == neighbors.size() -1) + s += ";"; + s += " "; + } + else + s += "null; "; + s += "persons:"; + if(persons != null && persons.size() != 0) + for(int i = 0; i < persons.size(); ++i) { + s += persons.get(i).getid(); + if(i == persons.size() - 1) + s += ";"; + s += " "; + } + else + s += "null; "; + s += "bear:"; + if(bear != null) + s += bear.getid() + "; "; + else + s += "null; "; + s += "item:"; + if(item != null) + s += item.getName() + "; "; + else + s += "null; "; + s += "tent: "; + if(tent != null) + s += tent.getid() + "\n"; + else + s += "null\n"; + pw.write(s); + pw.flush(); + } + /*Only for proto*/ + public abstract String get_type_name(); + + public void addItem(Item it) { + item = it; + } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/FragileShovel.java b/Arctic_Nigthmare/src/arctic_nightmare/FragileShovel.java new file mode 100644 index 0000000000000000000000000000000000000000..6987c0f63eaaf9f71bca1b71d35ffafb15b09007 --- /dev/null +++ b/Arctic_Nigthmare/src/arctic_nightmare/FragileShovel.java @@ -0,0 +1,27 @@ +package arctic_nightmare; + +import java.io.OutputStream; +import java.io.PrintWriter; + +public class FragileShovel extends Item{ + private int remainingUse; + + public FragileShovel() { + super("FragileShovel"); + remainingUse = 3; + } + + public boolean use(Field f) { + return (--remainingUse >= 0); + } + + @Override + public void save(OutputStream os) { + PrintWriter pw = new PrintWriter(os); + String s = new String("Item(" + getid() + "): name:"); + s += getName() + "; "; + s += "remainingUse:" + remainingUse + "\n"; + pw.write(s);; + pw.flush(); + } +} diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Game.java b/Arctic_Nigthmare/src/arctic_nightmare/Game.java index dbc4da69072cfe351fbc1db7bdf35d2b6cba82fb..85f4732d9a67996d522a5a192c4049462b72c05b 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Game.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Game.java @@ -7,6 +7,10 @@ import java.awt.event.KeyListener; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.nio.charset.Charset; + import static java.lang.System.in; import java.util.ArrayList; import java.util.List; @@ -18,16 +22,58 @@ public class Game{ private Person actualPlayer; private List<Person> players; private Board board; + private IceBear bear; + private boolean win; + + /*Only for proto*/ + private int id; + private static int idcounter = 1; + private List<Item> items; - Game(){} + Game(){ + actualPlayer = null; + players = new ArrayList<Person>(); + board = null; + bear = null; + win = false; + id = idcounter++; + items = new ArrayList<Item> (); + } void gameOver(){} void nextPlayer(){} - void newGame() - { + + 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){ @@ -119,7 +165,7 @@ public class Game{ { 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, Item.nothing); + Field stablefield = new StableField(0, null); unstablefield.setAllNeighbor(stablefield); stablefield.setAllNeighbor(unstablefield); Explorer ex1 = new Explorer("ex1", stablefield); @@ -132,16 +178,16 @@ public class Game{ private void personFalls() { Logger.increaseTabs(); - Field unstablefield = new UnstableField(0, 0, Item.nothing); - Field stablefield = new StableField(0,Item.nothing); + Field unstablefield = new UnstableField(0, 0, null); + Field stablefield = new StableField(0,null); unstablefield.setAllNeighbor(stablefield); stablefield.setAllNeighbor(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(Item.divingSuit); + 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(Item.rope); + if(Logger.getNumericInput(0,1)==1) ex2.addItem(new Item("Rope")); ex1.fall(); Logger.decreaseTabs(); } @@ -152,7 +198,7 @@ public class Game{ int bodytemp = Logger.getNumericInput(1,4); Person ex1 = new Explorer("ExplorerAboutToEatFood"); ex1.setBodyTemp(bodytemp); - StableField f1 = new StableField(0,Item.food); + StableField f1 = new StableField(0, new Item("Food")); f1.addPerson(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 @@ -174,7 +220,7 @@ public class Game{ Logger.LogAndIncreaseTabs("Game: a játéklogika meghívja az adott karakter shovel függvényét."); if(aso == 1) { - es1.addItem(Item.shovel); // Aso hozzaadasa az eszkimohoz + es1.addItem(new Item("Shovel")); // Aso hozzaadasa az eszkimohoz } es1.shovel(); Logger.decreaseTabs(); @@ -192,7 +238,7 @@ public class Game{ void eskimoBuildsIgloo() { Logger.LogAndIncreaseTabs("Game: a játéklogika meghívja az eskimo buildIgloo() függvényét."); - StableField f = new StableField(2,Item.nothing); + StableField f = new StableField(2, null); Eskimo es = new Eskimo("IglooBuilder",f); es.buildIgloo(); Logger.decreaseTabs(); @@ -216,7 +262,7 @@ public class Game{ //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,Item.nothing); + StableField f1 = new StableField(2,null); Eskimo es1 = new Eskimo("es1",f1); Eskimo es2 = new Eskimo("es2",f1); f1.addPerson(es1); @@ -225,4 +271,55 @@ public class Game{ Logger.decreaseTabs(); } + /*Only for proto*/ + public void save(OutputStream os) throws IOException { + String string = new String("Game(" + id + "): players:"); + if(players != null && players.size() != 0) + for(int i = 0; i < players.size(); ++i) { + string += players.get(i).getid(); + if( i == players.size() - 1) + string += ";"; + string += " "; + } + else + string += "null; "; + string += "actualPlayer:"; + if(actualPlayer != null) + string += actualPlayer.getid() + "; "; + else + string += "null; "; + string += "bear:"; + if(bear != null) + string += bear.getid() + "; "; + else + string += "null; "; + string += "board:"; + if(board != null) + string += board.getid() + "; "; + else + string += "null; "; + string += "win:" + win + "\n"; + PrintWriter pw = new PrintWriter(os); + pw.write(string); + pw.flush(); + pw = null; + if(bear != null) + bear.save(os); + if(board != null) + board.save(os); + if(players != null && players.size() != 0) + for(Person p : players) + p.save(os); + if(items != null && items.size() != 0) + for(Item i : items) + i.save(os); + } + + /*Only for proto*/ + public int getid() {return id;} + + /*Pnly for proto*/ + public void draw_minimap(OutputStream os) { + board.draw_minimap(os); + } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/IceBear.java b/Arctic_Nigthmare/src/arctic_nightmare/IceBear.java new file mode 100644 index 0000000000000000000000000000000000000000..cb3287151ad6a1e326c2ba2e8a020fba1805f5a4 --- /dev/null +++ b/Arctic_Nigthmare/src/arctic_nightmare/IceBear.java @@ -0,0 +1,38 @@ +package arctic_nightmare; + +import java.io.OutputStream; +import java.io.PrintWriter; + +public class IceBear { + private Field field; + + /*Only for proto*/ + private int id; + private static int idcounter = 1; + + + public IceBear(Field f) { + field = f; + id = idcounter++; + } + public void step() { + + } + + /*Only for proto*/ + public int getid() {return id;} + + /*Only for proto*/ + public void save(OutputStream os) { + PrintWriter pw = new PrintWriter(os); + String s = new String("IceBear("); + s += id + "): field:"; + if(field != null) + s += field.getid(); + else + s += "null"; + s += "\n"; + pw.write(s); + pw.flush(); + } +} diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Item.java b/Arctic_Nigthmare/src/arctic_nightmare/Item.java index b8d1b428e17e0dd10903dab295553d6b2a83fab8..8e88c8d48506cf758d53f80691e30ce494fbe4be 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Item.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Item.java @@ -1,12 +1,33 @@ package arctic_nightmare; -public enum Item { - nothing, - food, - rope, - shovel, - divingSuit, - pistol, - flare, - cartridge +import java.io.OutputStream; +import java.io.PrintWriter; + +public class Item { + private String name; + + /*Only for proto*/ + private int id; + private static int idcounter = 1; + + public Item(String s) { + name = new String(s); + id = idcounter++; + } + + /*Only for proto*/ + public int getid() {return id;} + + public String getName() { return name;} + + public boolean use(Field f) {return true;} + + /*Only for proto*/ + public void save(OutputStream os) { + PrintWriter pw = new PrintWriter(os); + String s = new String("Item(" + id + "): name:"); + s += name + "\n"; + pw.write(s);; + pw.flush(); + } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Main.java b/Arctic_Nigthmare/src/arctic_nightmare/Main.java index 78c3b73dc4ec8b3328011e1f89ee1b94787d93cc..c16fba613f1c9ed4e65a3ea603dced888c2bbd95 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Main.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Main.java @@ -6,6 +6,7 @@ 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; @@ -24,10 +25,10 @@ public class Main { Game game = new Game(); game.newGame(); + game.save(System.out); + game.draw_minimap(System.out); - - - game.test(); + //game.test(); } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Person.java b/Arctic_Nigthmare/src/arctic_nightmare/Person.java index 31c09526dbd9374ff9153f4e6dfca65042ff3386..5bfb7eb6f596747e2fa109a55898111723068207 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Person.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Person.java @@ -1,18 +1,34 @@ package arctic_nightmare; import java.util.List; +import java.io.OutputStream; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.Vector; -public class Person { - private int bodyTemp; - private int maxTemp; +public abstract class Person { + protected int bodyTemp; + protected int maxTemp; private int work; private String name; //Teszt kiiratashoz protected Field field; private Vector<Item> items; private Game game; + private Tent builtTent; + + /*Only for proto*/ + private int id; + private static int idcounter = 1; + public Person(Field f, Game g) { + work = 0; + name = new String(); + field =f; + items = new Vector<Item>(); + game = g; + builtTent = null; + id = idcounter++; + } Person(String name, Field field) { @@ -21,6 +37,7 @@ public class Person { field.addPerson(this); this.name = name; work = 4; + id = idcounter++; } Person(String name) @@ -28,6 +45,7 @@ public class Person { items = new Vector<>(); this.name = name; work = 4; + id = idcounter++; } /*public void addItem(Item item) @@ -35,10 +53,13 @@ public class Person { items.add(item); }*/ + /*Only for proto*/ + public int getid() {return id;} + public void assembleFlare(){ Logger.LogAndIncreaseTabs("Person assembleFlare"); List<Person> persons = field.getPersons(); - Item parts[] = {Item.pistol, Item.cartridge, Item.flare}; + Item parts[] = {new Item("Pistol"), new Item("Cartridge"), new Item("Flare")}; boolean b[] = {false, false, false}; for(int i = 0; i <3; ++i) { for(Person p : persons) { @@ -72,7 +93,7 @@ public class Person { public void fall() { Logger.LogAndIncreaseTabs("Person(" + name + ") fall"); //teszthez - if(items.contains(Item.divingSuit)) { + if(items.contains(new Item("DivingSuit"))) { Logger.Log(">>" + this.getName() + "-nek van búvárruhája, túléli", false); step(Direction.RIGHT); } @@ -138,7 +159,7 @@ public class Person { Item item = field.getItem(); if (item != null) { - if(item.equals(Item.food)) + if(item.equals(new Item("food"))) { if(this.bodyTemp < 4) { this.bodyTemp++; // ha elelmet talalt a person azt nem tarolja el, hanem megeszi es noveli vele a bodyTempjét @@ -164,22 +185,22 @@ public class Person { public boolean pullOut(Person p){ Logger.LogAndIncreaseTabs("Person(" + name + ") pullOut("+p.name+ ")"); - if(items.contains(Item.rope)) { + if(items.contains(new Item("Rope"))) { p.step(field); } Logger.decreaseTabs(); - return items.contains(Item.rope); + return items.contains(new Item("Rope")); } public void setWork(int i) { - + work = i; } public void shovel() { Logger.LogAndIncreaseTabs("Person(" + name + ") shovel"); - if (field.clearSnow(items.contains(Item.shovel) ? 2 : 1)) work --; // ellenorizzuk hogy van e asoja + 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 } @@ -214,4 +235,62 @@ public class Person { if(!items.contains(item)) items.add(item); } + + public void enablePlayer() { + setWork(4); + if(builtTent != null) + builtTent.removeFromField(); + } + + public void buildTent() { + if(work > 0) { + for(Item it : items) { + if(it.getName().contentEquals("Tent")) { + if(it.use(field)) { + items.remove(it); + work--; + } + break; + } + } + } + } + /*Only for proto*/ + public void save(OutputStream os) { + PrintWriter pw = new PrintWriter(os); + String s = new String(get_type_name() + "(" + id + "): "); + s += "bodyTemp:" + bodyTemp + "; "; + s += "maxTemp:" + maxTemp + "; "; + s += "work:" + work + "; "; + s += "game:"; + if(game != null) + s += game.getid() + "; "; + else + s += "null; "; + s += "field:"; + if(field != null) + s += field.getid() + "; "; + else + s += "null; "; + s += "items:"; + if(items != null && items.size() != 0) + for(int i = 0; i < items.size(); ++i) { + s += items.get(i).getid(); + if(i == items.size() - 1) + s += ";"; + s += " "; + } + else + s += "null; "; + s += "builtTent:"; + if(builtTent != null) + s += builtTent.getid() + "\n"; + else + s += "null\n"; + pw.write(s); + pw.flush(); + } + + /*Only for proto*/ + public abstract String get_type_name(); } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/StableField.java b/Arctic_Nigthmare/src/arctic_nightmare/StableField.java index 6503147ef0daab33d8a17cbab72abb1b4584933e..2f2e810ddc5f4350068e0720675f2564c4accba2 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/StableField.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/StableField.java @@ -9,15 +9,21 @@ public class StableField extends Field { public StableField() { super(); + capacity = 10; } public void accept(Person person) { Logger.LogAndIncreaseTabs("StableField accept : " + person.getName()); + if(bear != null && !hasIgloo) + person.die(); person.field = this; persons.add(person); Logger.Log(">>"+ person.getName() +" sikeresen átlépett stablefield-re.", false); Logger.decreaseTabs(); } + + /*Only for proto*/ + public String get_type_name() {return "StableField";} } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Tent.java b/Arctic_Nigthmare/src/arctic_nightmare/Tent.java new file mode 100644 index 0000000000000000000000000000000000000000..c623f187eda32033f0c442913e5c25cb1aedf999 --- /dev/null +++ b/Arctic_Nigthmare/src/arctic_nightmare/Tent.java @@ -0,0 +1,22 @@ +package arctic_nightmare; + +public class Tent extends Item { + private Field field; + + public Tent() { + super("Tent"); + field = null; + } + public boolean use(Field f) { + if(f.setTent(this)) { + field = f; + return true; + } + return false; + } + + public void removeFromField() { + field.setTent(null); + } + +} diff --git a/Arctic_Nigthmare/src/arctic_nightmare/UnstableField.java b/Arctic_Nigthmare/src/arctic_nightmare/UnstableField.java index 7c9f301c125a1c0f7d7e727d87d30816f38d2eba..d15bf1094669ab97d8a82122e3984108019cb2f0 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/UnstableField.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/UnstableField.java @@ -3,7 +3,10 @@ package arctic_nightmare; import java.util.ArrayList; public class UnstableField extends Field{ - public UnstableField() {super();} + public UnstableField() { + super(); + capacity = 0; + } public UnstableField(int capacity, int snow, Item item) { super(capacity, snow, item); @@ -15,6 +18,9 @@ public class UnstableField extends Field{ Logger.LogAndIncreaseTabs("UnstableField accept : " + person.getName()); persons.add(person); Logger.Log("Mennyi a jégtábla kapacitása? (1-2)", false); + + if(bear != null && !hasIgloo) + person.die(); capacity = Logger.getNumericInput(0, 3); if (persons.size() > capacity) { @@ -39,4 +45,7 @@ public class UnstableField extends Field{ } Logger.decreaseTabs(); } + + /*Only for proto*/ + public String get_type_name() {return "UnstableField";} }