diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Block.java b/Arctic_Nigthmare/src/arctic_nightmare/Block.java index 762ed76e3668e2cb14103066db3d0316b5dca793..3b6d2c9d683e43f27a46e43d1e231b3cf05cf814 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Block.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Block.java @@ -62,7 +62,12 @@ public class Block extends JLabel{ else if (field.snow == 3) images.add(new ScaledImagePanel(window, MediaAssociation.getImage("snowpile3"),x, y, width, height)); else if (field.snow >= 4) images.add(new ScaledImagePanel(window, MediaAssociation.getImage("snowpile4"),x, y, width, height)); } - else images.add(new ScaledImagePanel(window, MediaAssociation.getImage("water"),x, y, width, height)); + else + { + if (field.bear != null) images.add(new ScaledImagePanel(window, MediaAssociation.getImage("bear_half"), x + (int)(width*0.33), y +(int)(2 * height*0.3), (int)(width*0.33), (int)(height*0.33))); + for(int i = 0; field.persons.size() > i; i ++) images.add(new ScaledImagePanel(window, MediaAssociation.getImage(field.persons.get(i) instanceof Eskimo ? "eskimo_half" : "explorer_half"), x + (int)(width*(0.1 + 0.1 * i)), y +(int)(height*0.1), (int)(width*0.33), (int)(height*0.33))); + images.add(new ScaledImagePanel(window, MediaAssociation.getImage("water"),x, y, width, height)); + } if (field.isCapacityVisible()) this.setText(" " + field.capacity); else this.setText(""); //this.setText("<html>" + field.snow + "|" + field.capacity + "|" + field.itemPickable + "|" + field.hasIgloo + "<br>" + field.persons.size() +"|" + field.bear + "</html>" ); diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Field.java b/Arctic_Nigthmare/src/arctic_nightmare/Field.java index 7551c768ea22f7e373e02fa2f41f2c67420c3069..c7ef496733acf9e25e725beaf5c06cf862c81d4f 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Field.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Field.java @@ -3,169 +3,257 @@ package arctic_nightmare; import java.util.ArrayList; import java.util.List; +/** + * A jegmezo absztrakt osztalya, ebbol szarmazik a stabil es az instabil jegmezo is. + */ public abstract class Field { + + /** A mezon levo ho mennyisege */ protected int snow; + /** A jegtablaba faszott targy. Amennyiben nem talalhato a jegtablan targy az erteke null. */ protected Item item; + /** A jegtabla kapacitasa. */ protected int capacity; + /** Megmutatja, hogy van-e a mezore igloo epitve. */ protected boolean hasIgloo; + /** Megmutatja, hogy a tablan talalhato targy felveheto-e. */ protected boolean itemPickable; + /** A jegtablan talalhato jatekosok listaja. */ protected ArrayList<Person> persons; + /** * A mezovel szomszedos jegtablak listaja. */ private ArrayList<Field> neighbors; + /** Megmutatja, hogy lathato-e a jegtabla kapacitasa. */ private boolean visibleCapacity; + /** Jeloli, hogy talalhato-e a mezon jegesmedve. */ protected IceBear bear; + /** Jeloli, hogy talalhato-e a mezon sator. */ protected 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) - { + /** + * Altalanos konstruktor az Field osztalyhoz. + * @param snow a mezon levo ho mennyisege. + * @param capacity a jegmezo felfordulasa nelkul a mezon egyszerre tartozkodhato jatekosok maximalis szama. + * @param item a jegmezobe fagyott targy. Amennyiben nem talalhato targy a jegmezon, a null ertek megadasa reprezentalja. + */ + Field(int capacity, int snow, Item item) { persons = new ArrayList<Person>(); this.capacity = capacity; - this. snow = snow; + this.snow = snow; this.item = item; visibleCapacity = false; - neighbors = new ArrayList<Field>(); - id = idcounter++; + neighbors = new ArrayList<Field>(); } - + + /** + * A jegesmedve mezore valo lepeset kezelo osztaly. + * @param b a mezore lepo jegesmedve. + * @throws PlayerDiedException amennyiben a mezon mar tartozkodik jatekos, annak a jegesmedvevel valo talalkozasa a jatekos halalat okozza. Ennek hatasara dobodik ez a kivetel. + */ public void accept(IceBear b) throws PlayerDiedException { - bear = b; - if(persons.size() != 0 && !hasIgloo) - persons.get(0).die(); + bear = b; + if (persons.size() != 0 && !hasIgloo) { + persons.get(0).die(); + } } - + + /** + * A jatekosok mezore valo lepeset kezelo fuggveny. + * @param p a mezore lepo jatekos + * @throws PlayerDiedException a mezore valo lepes hirtelen halalt okozhat a mezon tartozkodo jegesmedve vagy felfordulo jegtabla altal. Ha ez bekovetkezik, akkor dobodik ez az exception. + */ public abstract void accept(Person p) throws PlayerDiedException; - + + /** + * A jegmezon talalhato targyat beallito/modosito fuggveny. + * @param it a jegmezohoz hozzaadott targy. + */ public void addItem(Item it) { - item = it; + item = it; } - + + /** + * A jegmezon talalhato targyat beallito/modosito fuggveny. Az egyszeru hasznalat erdekeben a megadott stringnek megfelelo nevu item jon letre. + * @param it a jegmezohoz hozzaadott targy neve. + */ public void addItem(String it) { - item = new Item(it); - } - + item = new Item(it); + } + + /** + * A mezovel szomszedos jegtablak koze egy ujat beszurni kepes fuggveny. + * @param f az ujjonnan hozzaadott jegmezo. + */ public void addNeighbor(Field f) { - neighbors.add(f); + neighbors.add(f); } - //For initializing components - public abstract boolean canAddPlayer(); - //For initializing components - public void addPlayer(Person p) { - persons.add(p); + //For initializing components + + /** + * A terkepgeneralashoz hasznalt fuggveny absztrakt modellje. Amennyiben meg egy jatekos a mezon valo elhelyezese nem jar egyutt a mezo felfordulasaval illetve a mezon nem tartozkodik jegesmedve, igaz erteket kapunk, egyebkent hamisat. + * @return biztonsagos-e jatekos elhelyezese a mezon? + */ + public abstract boolean canAddPlayer(); + //For initializing components + + /** + * Egy jatekost hozzaad a mezon talalhato jatekosok listajahoz. + * @param p a hozzaadott jatekos. + */ + public void addPlayer(Person p) { + persons.add(p); } - + //A Fieldet ero hovihar hatasat kozvetiti a rajta allok fele - public void blizzard(int quant) throws PlayerDiedException{ - this.snow += quant; + + /** + * A jegeso esemenynek a mezohoz tartozo fuggvenye. Amennyiben a mezon nincsen sem igloo sem sator, a jatekosok hitByBlizzard fuggvenye hivodik meg. Ezen kivul a megadott mennyisegu ho hozzaadodik a mezon talalhato ho mennyisegehez. + * @param quant a jegeso altal hozzaadott ho mennyisege. + * @throws PlayerDiedException amennyiben csokken a jatekosok testhoje, ugy elkepzelheto, hogy eleri a nullat. Amennyiben ez bekovetkezik, ugy a jatekos meghal, ekkor dobodik ez a kivetel. + */ + public void blizzard(int quant) throws PlayerDiedException { + this.snow += quant; if(this.snow> 4) this.snow = 4; - if(!(hasIgloo || tent != null)) { - for(Person p : persons) - p.hitByBlizzard(); - } + if (!(hasIgloo || tent != null)) { + for (Person p : persons) { + p.hitByBlizzard(); + } + } } - - public boolean clearSnow(int layers) - { - if (snow > 0) - { + + /** + * A jegmezorol havat eltavolito fuggveny. + * @param layers ennyi reteg havet szandekozunk eltavolitani a jegmezorol. + * @return sikeres volt-e a tevekenyseg. + */ + public boolean clearSnow(int layers) { + if (snow > 0) { snow -= layers; - if (snow < 0) - snow = 0; + if (snow < 0) { + snow = 0; + } return true; } return false; } - - public boolean emitItem(){ - if(snow ==0 && !itemPickable) - { - this.itemPickable= true; // ha nincs mar a mezon ho, az item lathatova valik + + /** + * Beallitja az itemPickable valtozo erteket. Ha a targy mar felveheto volt vagy ho boritja a mezot, akkor false-val ter vissza, egyebkent true-val. + * @return megtortent-e a tevekenyseg. + */ + public boolean emitItem() { + if (snow == 0 && !itemPickable) { + itemPickable = true; // ha nincs mar a mezon ho, az item lathatova valik return true; } - return false; + return false; } - - public boolean isNeighbor(Field f) - { - return neighbors.contains(f); + + /** + * Megmondja, hogy egy adott jegmezo szomszedos-e ezzel a mezovel. + * @param f a kerdeses mezo. + * @return a szomszedsagi viszony. + */ + public boolean isNeighbor(Field f) { + return neighbors.contains(f); } - - public int getCapacity(){ - return capacity; + + /** + * Visszaadja a mezo kapacitasat. + * @return a mezo kapacitasa. + */ + public int getCapacity() { + return capacity; } - - public boolean isCapacityVisible() - { + + /** + * Megmutatja, hogy a mezonek lathato-e a kapacitasa. + * @return a kapacitas lathatosaga. + */ + public boolean isCapacityVisible() { return this.visibleCapacity; - } - - public Item getItem() - { - if(snow == 0 && itemPickable) { - Item return_item = item; - item = null; - return return_item; - } - return null; - } - - public List<Field> getNeighbors() - { - return neighbors; - } - - public List<Person> getPersons() - { - return persons; - } - - public void removeBear() - { - bear = null; - } - - - public void remove(Person p) - { - persons.remove(p); - } - - public boolean revealCapacity() - { - if(visibleCapacity) return false; - visibleCapacity = true; - return true; - } - - public boolean setIgloo(){ - if(hasIgloo) return false; - hasIgloo = true; - return true; - } - + } + + /** + * Visszaadja a mezon talalhato targyat, ugyanakkor el is tavolitja azt a mezorol. Ezzel a fuggvennyel tudja a jatekos felvenni a targyat. + * @return a mezon talalhato targy. + */ + public Item getItem() { + if (snow == 0 && itemPickable) { + Item return_item = item; + item = null; + return return_item; + } + return null; + } + + /** + * Visszaadja a mezovel szomszedos jegmezok listajat. + * @return a szomszedos jegmezok listaja. + */ + public List<Field> getNeighbors() { + return neighbors; + } + + /** + * Visszaadja a mezon talalhato jatekosok listajat. + * @return a mezon talalhato jatekosok listaja. + */ + public List<Person> getPersons() { + return persons; + } + + /** + * Eltavolitja a jegesmedvet a megadott mezorol. + */ + public void removeBear() { + bear = null; + } + + /** + * Eltavolitja a megadott jatekost a mezon talalhato jatekosok listajabol. + * @param p az eltavolitando jatekos + */ + public void remove(Person p) { + persons.remove(p); + } + + /** + * Beallittja a mezo kapacitasanak lathatosagat. Amennyiben a kapacitas mar lathato volt, ugy a tevekenyseg nem tortenik meg. + * @return jelzi, hogy a tevekenyseg sikeres volt-e. + */ + public boolean revealCapacity() { + if (visibleCapacity) { + return false; + } + visibleCapacity = true; + return true; + } + + /** + * A mezohoz igloot hozzaado fuggveny. Amennyiben a jegmezon mar volt igloo, ugy a hozzaadas nem tortenik meg. + * @return jelzi, hogy a tevekenyseg sikeres volt-e. + */ + public boolean setIgloo() { + if (hasIgloo) { + return false; + } + hasIgloo = true; + return true; + } + + /** + * A mezohoz satrat hozzaado fuggveny. Amennyiben a mezon mar allt egy sator, ugy a hozzaadas nem tortenik semmi. + * @param t az ujonnan hozzaadott sator. + * @return jelzi, hogy a tevekenyseg sikeres volt-e. + */ public boolean setTent(Tent t) { if(tent != null) { if(t == null) tent = null; return false; } - tent = t; - return true; + tent = t; + return true; } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Field.java.orig b/Arctic_Nigthmare/src/arctic_nightmare/Field.java.orig new file mode 100644 index 0000000000000000000000000000000000000000..e3b5da759a54be965baa109ae5fe376751f5a35b --- /dev/null +++ b/Arctic_Nigthmare/src/arctic_nightmare/Field.java.orig @@ -0,0 +1,282 @@ +package arctic_nightmare; + +import java.util.ArrayList; +import java.util.List; + +/** + * A jegmezo absztrakt osztalya, ebbol szarmazik a stabil es az instabil jegmezo is. + */ +public abstract class Field { + + /** A mezon levo ho mennyisege */ + protected int snow; + /** A jegtablaba faszott targy. Amennyiben nem talalhato a jegtablan targy az erteke null. */ + protected Item item; + /** A jegtabla kapacitasa. */ + protected int capacity; + /** Megmutatja, hogy van-e a mezore igloo epitve. */ + protected boolean hasIgloo; + /** Megmutatja, hogy a tablan talalhato targy felveheto-e. */ + protected boolean itemPickable; + /** A jegtablan talalhato jatekosok listaja. */ + protected ArrayList<Person> persons; + /** * A mezovel szomszedos jegtablak listaja. */ + private ArrayList<Field> neighbors; + /** Megmutatja, hogy lathato-e a jegtabla kapacitasa. */ + private boolean visibleCapacity; + /** Jeloli, hogy talalhato-e a mezon jegesmedve. */ + protected IceBear bear; + /** Jeloli, hogy talalhato-e a mezon sator. */ + protected Tent tent; + + /** + * Altalanos konstruktor az Field osztalyhoz. + * @param snow a mezon levo ho mennyisege. + * @param capacity a jegmezo felfordulasa nelkul a mezon egyszerre tartozkodhato jatekosok maximalis szama. + * @param item a jegmezobe fagyott targy. Amennyiben nem talalhato targy a jegmezon, a null ertek megadasa reprezentalja. + */ + Field(int capacity, int snow, Item item) { + persons = new ArrayList<Person>(); + this.capacity = capacity; + this.snow = snow; + this.item = item; + visibleCapacity = false; + neighbors = new ArrayList<Field>(); + } + + /** + * A jegesmedve mezore valo lepeset kezelo osztaly. + * @param b a mezore lepo jegesmedve. + * @throws PlayerDiedException amennyiben a mezon mar tartozkodik jatekos, annak a jegesmedvevel valo talalkozasa a jatekos halalat okozza. Ennek hatasara dobodik ez a kivetel. + */ + public void accept(IceBear b) throws PlayerDiedException { + bear = b; + if (persons.size() != 0 && !hasIgloo) { + persons.get(0).die(); + } + } + + /** + * A jatekosok mezore valo lepeset kezelo fuggveny. + * @param p a mezore lepo jatekos + * @throws PlayerDiedException a mezore valo lepes hirtelen halalt okozhat a mezon tartozkodo jegesmedve vagy felfordulo jegtabla altal. Ha ez bekovetkezik, akkor dobodik ez az exception. + */ + public abstract void accept(Person p) throws PlayerDiedException; + + /** + * A jegmezon talalhato targyat beallito/modosito fuggveny. + * @param it a jegmezohoz hozzaadott targy. + */ + public void addItem(Item it) { + item = it; + } + + /** + * A jegmezon talalhato targyat beallito/modosito fuggveny. Az egyszeru hasznalat erdekeben a megadott stringnek megfelelo nevu item jon letre. + * @param it a jegmezohoz hozzaadott targy neve. + */ + public void addItem(String it) { + item = new Item(it); + } + + /** + * A mezovel szomszedos jegtablak koze egy ujat beszurni kepes fuggveny. + * @param f az ujjonnan hozzaadott jegmezo. + */ + public void addNeighbor(Field f) { + neighbors.add(f); + } + //For initializing components + + /** + * A terkepgeneralashoz hasznalt fuggveny absztrakt modellje. Amennyiben meg egy jatekos a mezon valo elhelyezese nem jar egyutt a mezo felfordulasaval illetve a mezon nem tartozkodik jegesmedve, igaz erteket kapunk, egyebkent hamisat. + * @return biztonsagos-e jatekos elhelyezese a mezon? + */ + public abstract boolean canAddPlayer(); + //For initializing components + + /** + * Egy jatekost hozzaad a mezon talalhato jatekosok listajahoz. + * @param p a hozzaadott jatekos. + */ + public void addPlayer(Person p) { + persons.add(p); + } + + //A Fieldet ero hovihar hatasat kozvetiti a rajta allok fele +<<<<<<< origin/master + public void blizzard(int quant) throws PlayerDiedException{ + this.snow += quant; + if(this.snow> 4) + this.snow = 4; + if(!(hasIgloo || tent != null)) { + for(Person p : persons) + p.hitByBlizzard(); + } + } + + public boolean clearSnow(int layers) + { + if (snow > 0) + { +======= + + /** + * A jegeso esemenynek a mezohoz tartozo fuggvenye. Amennyiben a mezon nincsen sem igloo sem sator, a jatekosok hitByBlizzard fuggvenye hivodik meg. Ezen kivul a megadott mennyisegu ho hozzaadodik a mezon talalhato ho mennyisegehez. + * @param quant a jegeso altal hozzaadott ho mennyisege. + * @throws PlayerDiedException amennyiben csokken a jatekosok testhoje, ugy elkepzelheto, hogy eleri a nullat. Amennyiben ez bekovetkezik, ugy a jatekos meghal, ekkor dobodik ez a kivetel. + */ + public void blizzard(int quant) throws PlayerDiedException { + this.snow += quant; + if (!(hasIgloo || tent != null)) { + for (Person p : persons) { + p.hitByBlizzard(); + } + } + } + + /** + * A jegmezorol havat eltavolito fuggveny. + * @param layers ennyi reteg havet szandekozunk eltavolitani a jegmezorol. + * @return sikeres volt-e a tevekenyseg. + */ + public boolean clearSnow(int layers) { + if (snow > 0) { +>>>>>>> local + snow -= layers; + if (snow < 0) { + snow = 0; + } + return true; + } + return false; + } + + /** + * Beallitja az itemPickable valtozo erteket. Ha a targy mar felveheto volt vagy ho boritja a mezot, akkor false-val ter vissza, egyebkent true-val. + * @return megtortent-e a tevekenyseg. + */ + public boolean emitItem() { + if (snow == 0 && !itemPickable) { + itemPickable = true; // ha nincs mar a mezon ho, az item lathatova valik + return true; + } + return false; + } + + /** + * Megmondja, hogy egy adott jegmezo szomszedos-e ezzel a mezovel. + * @param f a kerdeses mezo. + * @return a szomszedsagi viszony. + */ + public boolean isNeighbor(Field f) { + return neighbors.contains(f); + } + + /** + * Visszaadja a mezo kapacitasat. + * @return a mezo kapacitasa. + */ + public int getCapacity() { + return capacity; + } + + /** + * Megmutatja, hogy a mezonek lathato-e a kapacitasa. + * @return a kapacitas lathatosaga. + */ + public boolean isCapacityVisible() { + return this.visibleCapacity; + } + + /** + * Visszaadja a mezon talalhato targyat, ugyanakkor el is tavolitja azt a mezorol. Ezzel a fuggvennyel tudja a jatekos felvenni a targyat. + * @return a mezon talalhato targy. + */ + public Item getItem() { + if (snow == 0 && itemPickable) { + Item return_item = item; + item = null; + return return_item; + } + return null; + } + + /** + * Visszaadja a mezovel szomszedos jegmezok listajat. + * @return a szomszedos jegmezok listaja. + */ + public List<Field> getNeighbors() { + return neighbors; + } + + /** + * Visszaadja a mezon talalhato jatekosok listajat. + * @return a mezon talalhato jatekosok listaja. + */ + public List<Person> getPersons() { + return persons; + } + + /** + * Eltavolitja a jegesmedvet a megadott mezorol. + */ + public void removeBear() { + bear = null; + } + + /** + * Eltavolitja a megadott jatekost a mezon talalhato jatekosok listajabol. + * @param p az eltavolitando jatekos + */ + public void remove(Person p) { + persons.remove(p); + } + + /** + * Beallittja a mezo kapacitasanak lathatosagat. Amennyiben a kapacitas mar lathato volt, ugy a tevekenyseg nem tortenik meg. + * @return jelzi, hogy a tevekenyseg sikeres volt-e. + */ + public boolean revealCapacity() { + if (visibleCapacity) { + return false; + } + visibleCapacity = true; + return true; + } + + /** + * A mezohoz igloot hozzaado fuggveny. Amennyiben a jegmezon mar volt igloo, ugy a hozzaadas nem tortenik meg. + * @return jelzi, hogy a tevekenyseg sikeres volt-e. + */ + public boolean setIgloo() { + if (hasIgloo) { + return false; + } + hasIgloo = true; + return true; + } + + /** + * A mezohoz satrat hozzaado fuggveny. Amennyiben a mezon mar allt egy sator, ugy a hozzaadas nem tortenik semmi. + * @param t az ujonnan hozzaadott sator. + * @return jelzi, hogy a tevekenyseg sikeres volt-e. + */ + public boolean setTent(Tent t) { +<<<<<<< origin/master + if(tent != null) { + if(t == null) + tent = null; + return false; + } + tent = t; + return true; +======= + if (tent != null) { + return false; + } + tent = t; + return true; +>>>>>>> local + } +} diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Logger.java b/Arctic_Nigthmare/src/arctic_nightmare/Logger.java deleted file mode 100644 index d2084b0af361fad155a5ef7e782ada9c9e140749..0000000000000000000000000000000000000000 --- a/Arctic_Nigthmare/src/arctic_nightmare/Logger.java +++ /dev/null @@ -1,136 +0,0 @@ -package arctic_nightmare; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Scanner; - - -final public class Logger { - private final static String library = "src/arctic_nightmare/logs/", extension = ".log"; - private static int tabs; - private static String logfile; - static private FileOutputStream fileoutput; - private static Scanner scanner = new Scanner(System.in); - - static - { - File directory = new File(library); - if (! directory.exists())directory.mkdir(); - logfile = DateTimeFormatter.ofPattern("yyyy_MM_dd-HH_mm_ss").format(LocalDateTime.now()).toString() + extension; - File file = new File(library + logfile); - try { - fileoutput = new FileOutputStream(file); - } catch (FileNotFoundException ex) { - Log(ex.toString(), false);} - tabs = 0; - } - - static FileOutputStream getFileStream() - { - return fileoutput; - } - - static int getNumericInput(int lowerConstraint, int upperConstraint) { - int c = scanner.nextInt(); - while(c < lowerConstraint || c > upperConstraint) { - Log("A megadott érték érvénytelen."); - c = scanner.nextInt(); - } - return c; - } - - static void setTabs(int newtabs) - { - tabs = newtabs; - } - - static void increaseTabs() - { - tabs ++; - } - - static void decreaseTabs() - { - tabs --; - if (1 > tabs) tabs =0; - } - - public static void Log(String message) - { - try { - if (tabs != 0) - { - String output = String.format("%0" + tabs + "d", 0).replace("0", "\t") + message; - System.out.println(output); - fileoutput.write((output + "\n").getBytes()); - } - else - { - System.out.println(message); - fileoutput.write((message + "\n").getBytes()); - } - } catch (IOException ex) { - Log(ex.toString(), false); - } - } - - public static void LogNoNewLine(String message) - { - try { - if (tabs != 0) - { - String output = String.format("%0" + tabs + "d", 0).replace("0", "\t") + message; - System.out.print(output); - fileoutput.write(output.getBytes()); - } - else - { - System.out.print(message); - fileoutput.write(message.getBytes()); - } - } catch (IOException ex) { - Log(ex.toString(), false); - } - } - - public static void Log(String message, boolean tabulated) { - if(!tabulated) - { - System.out.println(message); - try { - fileoutput.write((message + "\n").getBytes()); - } catch (IOException ex) { - Log(ex.toString(), false); - } - } - else Log(message); - } - - public static void LogNoNewLine(String message, boolean tabulated) { - if(!tabulated) - { - System.out.print(message); - try { - fileoutput.write(message.getBytes()); - } catch (IOException ex) { - Log(ex.toString(), false); - } - } - else Log(message); - } - - static void LogAndIncreaseTabs(String message) - { - Log(message); - increaseTabs(); - } - - static void LogAndDecreaseTabs(String message) - { - LogAndDecreaseTabs(message); - } -} diff --git a/Arctic_Nigthmare/src/arctic_nightmare/PlayerDiedException.java b/Arctic_Nigthmare/src/arctic_nightmare/PlayerDiedException.java index 8d0f2977747df3261ed237d6b6a2770ad056e6dd..851157d4975640423218cd12b9722f762b6b33c1 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/PlayerDiedException.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/PlayerDiedException.java @@ -1,5 +1,8 @@ package arctic_nightmare; +/** + * A jatekos halala eseten dobott kivetel. + */ public class PlayerDiedException extends Exception{ private static final long serialVersionUID = 1L; PlayerDiedException(String error) {super(error);} diff --git a/Arctic_Nigthmare/src/arctic_nightmare/PlayersWinException.java b/Arctic_Nigthmare/src/arctic_nightmare/PlayersWinException.java index b3b2f9dca0d6af32924358f815bbd41fb88ff98e..0dd8f6040cf8c744ee8fcc0bb90557fe40c569b6 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/PlayersWinException.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/PlayersWinException.java @@ -1,5 +1,8 @@ package arctic_nightmare; +/** + * A jatek megnyerese eseten dobott kivetel. + */ public class PlayersWinException extends Exception{ private static final long serialVersionUID = 1L; PlayersWinException(String error) {super(error);} diff --git a/Arctic_Nigthmare/src/arctic_nightmare/ScaledImagePanel.java b/Arctic_Nigthmare/src/arctic_nightmare/ScaledImagePanel.java index dd35d769d843508595205b4ef5a568ca737758f7..5cd674eb95e921be4413f01307f609ebb37929cc 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/ScaledImagePanel.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/ScaledImagePanel.java @@ -11,7 +11,7 @@ import javax.swing.JLabel; public class ScaledImagePanel extends JLabel{ - + public ScaledImagePanel(JFrame window, String file, int x, int y, int width, int height) { super(new ImageIcon(GameWindow.getScaledImage((new ImageIcon(file)).getImage(), width, height))); diff --git a/Arctic_Nigthmare/src/arctic_nightmare/StableField.java b/Arctic_Nigthmare/src/arctic_nightmare/StableField.java index a741f409463489f6ea066881d0124234e812637e..c2ee5918895d025b18ba168b9d8bb86acb4c2872 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/StableField.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/StableField.java @@ -1,20 +1,33 @@ package arctic_nightmare; +/** + * Az stabil jegmezot reprezentalo osztaly. A stabil jegmezovel ellentetben ennek a típusnak végtelen a kapacitása. + */ public class StableField extends Field { + /** + * Altalanos konstruktor az StableField osztalyhoz. + * @param snow a mezon levo ho mennyisege. + * @param item a jegmezobe fagyott targy. Amennyiben nem talalhato targy a jegmezon, a null ertek megadasa reprezentalja. + */ public StableField(int snow, Item item) { super(10, snow, item); } - + + /** + * Altalanos konstruktor az StableField osztalyhoz. A konnyebb hasznalat erdekeben stringkent fogadja az itemet es letrehozza a hozza tartozo objektumot. + * @param snow a mezon levo ho mennyisege. + * @param item a jegmezobe fagyott targy neve. Amennyiben nem talalhato targy a jegmezon, a null ertek megadasa reprezentalja. + */ public StableField(int snow, String item) { super(10, snow, new Item(item)); } - - public StableField() { - super(); - capacity = 10; - } + /** + * A jatekosok mezore valo lepeset kezelo fuggveny. + * @param person a mezore lepo jatekos + * @throws PlayerDiedException a mezore valo lepes hirtelen halalt okozhat a mezon tartozkodo jegesmedve vagy felfordulo jegtabla altal. Ha ez bekovetkezik, akkor dobodik ez az exception. + */ public void accept(Person person) throws PlayerDiedException { person.field = this; @@ -24,7 +37,11 @@ public class StableField extends Field { } persons.add(person); } - + + /** + * A terkepgeneralashoz hasznalt fuggveny. Amennyiben meg egy jatekos a mezon valo elhelyezese nem jar egyutt a mezo felfordulasaval illetve a mezon nem tartozkodik jegesmedve, igaz erteket kapunk, egyebkent hamisat. + * @return biztonsagos-e jatekos elhelyezese a mezon? + */ public boolean canAddPlayer() { if(bear != null) return false; return true; diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Tent.java b/Arctic_Nigthmare/src/arctic_nightmare/Tent.java index c623f187eda32033f0c442913e5c25cb1aedf999..c0eb400eed962b9dcff188c1ab311de187d96543 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Tent.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Tent.java @@ -1,22 +1,38 @@ package arctic_nightmare; +/** + * A jatekos altal felveheto satort reprezentalo osztaly + */ 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); - } - + + private Field field; + + /** + * A sator altalanos konstruktora. + */ + public Tent() { + super("Tent"); + field = null; + } + + /** + * A sator felallitasat kezelo fuggveny. Amennyiben parameterkent olyan mezot adunk meg, amelyiken mar van sator, ugy a tevekenyseg ne mtortenik meg. + * @param f a mezo, amelyiken a satrat fel kivanjuk allitani. + * @return a tevekenyseg sikeres volt-e. + */ + public boolean use(Field f) { + if (f.setTent(this)) { + field = f; + return true; + } + return false; + } + + /** + * A satrat eltavolitja a mezorol. + */ + 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 a0fa4e5be3f72a022933397b51a24e97b5489e75..47c616af6d89a22c94cb1eed4fd88da64f11a450 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/UnstableField.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/UnstableField.java @@ -1,49 +1,70 @@ package arctic_nightmare; +/** + * Az instabil jegmezot reprezentalo osztaly. A stabil jegmezovel ellentetben ennek a típusnak van maximalis kapacitasa. + */ +public class UnstableField extends Field { -public class UnstableField extends Field{ - public UnstableField() { - super(); - capacity = 0; - } - + /** + * Altalanos konstruktor az UnstableField osztalyhoz. + * @param snow a mezon levo ho mennyisege. + * @param capacity a jegmezo felfordulasa nelkul a mezon egyszerre tartozkodhato jatekosok maximalis szama. + * @param item a jegmezobe fagyott targy. Amennyiben nem talalhato targy a jegmezon, a null ertek megadasa reprezentalja. + */ public UnstableField(int snow, int capacity, Item item) { super(capacity, snow, item); } - + + /** + * Altalanos konstruktor az UnstableField osztalyhoz. A konnyebb hasznalat erdekeben stringkent fogadja az itemet es letrehozza a hozza tartozo objektumot. + * @param snow a mezon levo ho mennyisege. + * @param capacity a jegmezo felfordulasa nelkul a mezon egyszerre tartozkodhato jatekosok maximalis szama. + * @param item a jegmezobe fagyott targy neve. Amennyiben nem talalhato targy a jegmezon, a null ertek megadasa reprezentalja. + */ public UnstableField(int snow, int capacity, String item) { super(capacity, snow, new Item(item)); } - - - public void accept(Person person) throws PlayerDiedException - { + + /** + * A jatekosok mezore valo lepeset kezelo fuggveny. + * @param person a mezore lepo jatekos + * @throws PlayerDiedException a mezore valo lepes hirtelen halalt okozhat a mezon tartozkodo jegesmedve vagy felfordulo jegtabla altal. Ha ez bekovetkezik, akkor dobodik ez az exception. + */ + public void accept(Person person) throws PlayerDiedException { persons.add(person); person.field = this; - if(bear != null && !hasIgloo) - { + if (bear != null && !hasIgloo) { MediaAssociation.play("bear"); - person.die(); + person.die(); } - if (persons.size() > capacity) + if (persons.size() > capacity) { overturn(); + } } - - public void overturn() throws PlayerDiedException - { - capacity = 0; - snow = 0; - hasIgloo = false; - item = null; - tent = null; - for (Person person : persons) - { + + /** + * A jegmezo felfordulasat kezelo fuggveny. + * @throws PlayerDiedException a mezo felfordulasa okozhatja a rajta levok halalat. Ha ez bekovetkezik, akkor dobodik ez az exception. + */ + public void overturn() throws PlayerDiedException { + capacity = 0; + snow = 0; + hasIgloo = false; + item = null; + tent = null; + for (Person person : persons) { person.fall(); } } + + /** + * A terkepgeneralashoz hasznalt fuggveny. Amennyiben meg egy jatekos a mezon valo elhelyezese nem jar egyutt a mezo felfordulasaval illetve a mezon nem tartozkodik jegesmedve, igaz erteket kapunk, egyebkent hamisat. + * @return biztonsagos-e jatekos elhelyezese a mezon? + */ public boolean canAddPlayer() { - if(bear != null || (persons.size() + 1) > capacity) - return false; - return true; + if (bear != null || (persons.size() + 1) > capacity) { + return false; + } + return true; } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/eskimo_half.png b/Arctic_Nigthmare/src/arctic_nightmare/resources/eskimo_half.png new file mode 100644 index 0000000000000000000000000000000000000000..b5701d6e43bfbc676434ced1257ec4e549205e67 Binary files /dev/null and b/Arctic_Nigthmare/src/arctic_nightmare/resources/eskimo_half.png differ diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/explorer_half.png b/Arctic_Nigthmare/src/arctic_nightmare/resources/explorer_half.png new file mode 100644 index 0000000000000000000000000000000000000000..5ffdb92ce35babc3069bcbb1ff3524746ea5d6ef Binary files /dev/null and b/Arctic_Nigthmare/src/arctic_nightmare/resources/explorer_half.png differ diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/icebear_half.png b/Arctic_Nigthmare/src/arctic_nightmare/resources/icebear_half.png new file mode 100644 index 0000000000000000000000000000000000000000..8ed994c5ffd3586da3bea6f2fed315dbf02136d4 Binary files /dev/null and b/Arctic_Nigthmare/src/arctic_nightmare/resources/icebear_half.png differ