diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Audio.java b/Arctic_Nigthmare/src/arctic_nightmare/Audio.java index 6a28f35548dbb933ca2174163d544c66212cfbf9..3d4beaf579f3c5ab3cc1162b4499b3ec98ee2773 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Audio.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Audio.java @@ -1,7 +1,5 @@ - package arctic_nightmare; -import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; @@ -12,22 +10,26 @@ import javax.sound.sampled.FloatControl; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.UnsupportedAudioFileException; - +/** + * Az audiofajlok kezelesere letrehozott osztaly. Egyetlen funkcioja, hogy a jatek soran a megfelelo pillanatokban bejatssza a benne tarolt audiofajl tartalmat. + */ public class Audio { - Clip clip; - Audio(String filename) - { + + /** A tarolt audio */ + private Clip clip; + + /** + * Altalanos konstruktor. + * @param filename a lejatszani kivant hangfajl neve. Wav formatum tamogatott. + */ + Audio(String filename) { AudioInputStream sound = null; try { - sound = AudioSystem.getAudioInputStream(new File(filename)); - clip = AudioSystem.getClip(); - clip.open(sound); - } catch (UnsupportedAudioFileException ex) { + sound = AudioSystem.getAudioInputStream(Audio.class.getResource(filename)); + clip = AudioSystem.getClip(); + clip.open(sound); + } catch (UnsupportedAudioFileException | IOException | LineUnavailableException ex) { Logger.getLogger(Audio.class.getName()).log(Level.SEVERE, null, ex); - } catch (IOException ex) { - Logger.getLogger(Audio.class.getName()).log(Level.SEVERE, null, ex); - }catch (LineUnavailableException ex) { - Logger.getLogger(Audio.class.getName()).log(Level.SEVERE, null, ex); } finally { try { sound.close(); @@ -36,20 +38,25 @@ public class Audio { } } } - - public void play() - { + + /** + * A tarolt audio tartalom lejatszasara szolgalo fuggveny. + */ + public void play() { clip.setFramePosition(0); - clip.start(); + clip.start(); } - public void play(float newvolume) - { + /** + * A tarolt audio tartalom lejatszasara szolgalo fuggveny. A hangot a parameterkent megadott hangerovel jatssza le. Sajnos a mukodese bugos, a hangero nem teljesen ugy koveti a megadott erteket, mint ahogy az elvart lenne. + * @param newvolume a hangerot merteke. Egy es nulla kozotti erteket kell felvennie, egyes a maximum, nulla a csend. + */ + public void play(float newvolume) { clip.setFramePosition(0); - clip.start(); + clip.start(); FloatControl volume = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); - double gain = 0.1; + double gain = 0.1; float dB = (float) (Math.log(gain) / Math.log(10.0) * 20.0); - volume.setValue(dB); + volume.setValue(dB); } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Block.java b/Arctic_Nigthmare/src/arctic_nightmare/Block.java index ff505748ad030a997d61f2cde272e01d49aa9324..27bd697ee375aaf9e74f74ed9d3baaef88abfb75 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Block.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Block.java @@ -8,17 +8,34 @@ import java.util.List; import java.util.Random; import javax.swing.JLabel; -public class Block extends JLabel{ +/** + * A jegmezok aktualis allapotanak kirajzolasaert felelos osztaly. A JLabel osztaly leszarmazotta, tulajdonkeppen egy letrehozott labelen keresztul kepes kattintas eventeket fogadni, amik hatasara az ot tartalmazo ablak event fuggvenyet hivja meg egy onmagara mutato referenciaval parameterezve. + */ +public class Block extends JLabel { + + /** A generalas soran hasznalt peldanyositott random osztaly. */ Random rnd = new Random(); + /** A jatek ablakara mutato referencia. */ private GameWindow window; + /** A jatekmezo. */ private Field field; + /** A jegmezo a jatek ablakan elfoglalt pozicioja illetve a merete. Azert van szukseg a valtozoban valo tarolasara, mert az ezeket lekero fuggvenyek nem mindig mukodnek stabilan layout hianyaban. */ int x, y, width, height; + /** A jegmezo aktualis allasanak megjelenitesehez hasznalt osszes kep. Kulon tarolasukra azert van szukseg, mert minden egyes esemenynel az allapot valtozhat, ehhez a korabban tarolt kepek eltavolitasra kerulnek es ujak generalodnak. */ private List<ScaledImagePanel> images; - - Block(GameWindow window, Field field, int x, int y, int width, int height) - { + + /** + * Altalanos konstruktor a Block osztalyhoz. + * @param window a tartalmazo ablakra mutato referencia. + * @param field a jateklogikaban talalhato field osztalyra mutato referencia, ennek a mezonek az aktualis allapotat fogjuk kirajzolni. + * @param x az ablakon beluli x koordinata. + * @param y az ablakon beluli y koordinata. + * @param width a mezo szelessege. + * @param height a mezo magassaga. + */ + Block(GameWindow window, Field field, int x, int y, int width, int height) { this.window = window; - this.field = field; + this.field = field; this.x = x; this.y = y; this.width = width; @@ -28,33 +45,24 @@ public class Block extends JLabel{ window.add(this); setOpaque(false); setBackground(Color.pink); - addMouseListener(new MouseAdapter() - { - public void mouseClicked(MouseEvent e) - { + addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { window.event(field); - } - }); + } + }); } - private void removeImages() - { - while (images.size() > 0) - { - images.get(0).remove(); - images.remove(0); - } - } - - + /** + * Ujrarajzolja a jegtombot. Eloszor eltavolitja az osszes tarolt kepet, utana az aktualis jatekallasnak megfeleloen ujakat hoz letre. + */ void drawBlock() { removeImages(); if (window.fields_hit_by_blizzard != null && window.fields_hit_by_blizzard.contains(field)) images.add(new ScaledImagePanel(window, MediaAssociation.getImage(3>rnd.nextInt(100)? "storm_cat" : rnd.nextBoolean() ? "storm1" : "storm2"),x + width/10, y-height/10, 8 * width / 10, 8 * height / 10)); if (field.snow > 0 || field.capacity > 0) { - if (field.item != null) images.add(new ScaledImagePanel(window, field.itemPickable ? MediaAssociation.getImage(field.item.getName()) : MediaAssociation.getImageCovered(field.item.getName()), x + (int)(width*0.5)-10, y +(int)(height*0.5)-10, 20, 20)); - //if (field.item != null && field.snow == 0) images.add(new ScaledImagePanel(window, field.itemPickable ? MediaAssociation.getImage(field.item.getName()) : MediaAssociation.getImageCovered(field.item.getName()), x + (int)(width*0.5)-10, y +(int)(height*0.5)-10, 20, 20)); + if (field.item != null) images.add(new ScaledImagePanel(window, field.itemPickable ? MediaAssociation.getImage(field.item.getName()) : MediaAssociation.getImageCovered(field.item.getName()), x + (int)(width*0.5)-10, y +(int)(height*0.5)-10, 20, 20)); + //if (field.item != null && field.snow == 0) images.add(new ScaledImagePanel(window, field.itemPickable ? MediaAssociation.getImage(field.item.getName()) : MediaAssociation.getImageCovered(field.item.getName()), x + (int)(width*0.5)-10, y +(int)(height*0.5)-10, 20, 20)); if (field.bear != null) images.add(new ScaledImagePanel(window, MediaAssociation.getImage("bear"), 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" : "explorer"), x + (int)(width*(0.1 + 0.1 * i)), y +(int)(height*0.1), (int)(width*0.33), (int)(height*0.33))); if (field.hasIgloo) images.add(new ScaledImagePanel(window, MediaAssociation.getImage("igloo"), x + (int)(2 *width*0.33), y +(int)(height*0.33), (int)(width*0.33), (int)(height*0.33))); @@ -75,10 +83,22 @@ public class Block extends JLabel{ else this.setText(""); //this.setText("<html>" + field.snow + "|" + field.capacity + "|" + field.itemPickable + "|" + field.hasIgloo + "<br>" + field.persons.size() +"|" + field.bear + "</html>" ); } - - void remove() - { - removeImages(); + + /** + * Eltavolitja az osszes tarolt kepet + */ + private void removeImages() { + while (images.size() > 0) { + images.get(0).remove(); + images.remove(0); + } + } + + /** + * Eltavolitja az objektumot.a szuloosztalybol + */ + void remove() { + removeImages(); this.getParent().remove(this); } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Board.java b/Arctic_Nigthmare/src/arctic_nightmare/Board.java index 9da4dfc88f64aecd2c0306d821a56e09940c62e2..fe68135500aee77af6686ddccce96d66296da111 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Board.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Board.java @@ -84,10 +84,8 @@ public class Board { Random rand = new Random(); ArrayList<Field> fields_hit_by_blizzard = new ArrayList<>(); if (rand.nextInt() % 2 == 0) { - for (Field f : fields) - { - if (rand.nextInt() % 5 == 0) - { + for (Field f : fields) { + if (rand.nextInt() % 5 == 0) { fields_hit_by_blizzard.add(f); f.blizzard(1); } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/Dramatic-sound.wav b/Arctic_Nigthmare/src/arctic_nightmare/Dramatic-sound.wav similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/Dramatic-sound.wav rename to Arctic_Nigthmare/src/arctic_nightmare/Dramatic-sound.wav diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Eskimo.java b/Arctic_Nigthmare/src/arctic_nightmare/Eskimo.java index 1ac1f388da83061b07be990f21e2412687fe3156..da5be411e77695383214be6b6b3dc8c687d37245 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Eskimo.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Eskimo.java @@ -1,6 +1,7 @@ package arctic_nightmare; public class Eskimo extends Person { + public Eskimo(String name, Field f, Game g) { super(name, f, g); maxTemp = 5; @@ -19,20 +20,19 @@ public class Eskimo extends Person { bodyTemp = 5; } - - //public Eskimo(String name) { - //super(name);} - + //public Eskimo(String name) { + //super(name);} /*public Eskimo(String name, Field field) { super(name, field); }*/ - public void buildIgloo(){ - if(this.field.setIgloo()) - work--; + public void buildIgloo() { + if (this.field.setIgloo()) { + work--; + } } - public void useSpecialAbility(Field f) { - buildIgloo(); - - } + public void useSpecialAbility(Field f) { + buildIgloo(); + + } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Event.java b/Arctic_Nigthmare/src/arctic_nightmare/Event.java index 8efcef03f36686a697b1d9cfd95d5eb7291a5be4..9dd238375bee03f73ff41ecba585919976ca143e 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Event.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Event.java @@ -1,20 +1,38 @@ package arctic_nightmare; -// - +/** + * A kepernyon torteno kattintasok altal kivaltott esemenyeket tarolo osztaly. A kod tulajdonkeppen az esemeny hatasara fefuttatott fuggvenyt jeloli, a parameter pedig annak parameterekent hasznalt mezot (amennyiben ilyenre nincs szukseg, null). + */ public class Event { + + /** Az esemeny kodja. */ private int code; + /** A mezo, amit az esemeny erint. */ private Field param; + + /** + * Altalanos konstruktor. + * @param c az esemeny kodja. + * @param f az esemenyhez kotheto mezo (amennyiben nem szukseges, null). + */ public Event(int c, Field f) { - code = c; - param = f; + code = c; + param = f; } - + + /** + * Az esemeny kodjanak getter fuggvenye. + * @return az esemeny kodja. + */ public int getCode() { - return code; + return code; } - + + /** + * Az esemeny mezojenek getter fuggvenye. + * @return az esemeny mezoje. + */ public Field getParam() { - return param; + return param; } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/EventButton.java b/Arctic_Nigthmare/src/arctic_nightmare/EventButton.java index e11cb6cfe3a3b00dc2469666981bf32b99114ec5..1aa772da68d58f6a2cb67206b673753ab69b1c83 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/EventButton.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/EventButton.java @@ -4,28 +4,30 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JButton; +/** + * Az iranyitogombokat reprezentalo osztaly, a sima JButton kiterjesztese. Kattintas eseten a letrehozasanal megadott koddal hivja meg az ablak event fuggvenyet. + */ public class EventButton extends JButton { + + /** Az ablakra mutato referencia */ private GameWindow window; + /** A kivaltando esemeny kodja */ private int code; - - EventButton(GameWindow window, int code, String text, int x, int y, int width, int height) - { + + EventButton(GameWindow window, int code, String text, int x, int y, int width, int height) { this.window = window; this.code = code; this.setText(text); setBounds(x, y, width, height); window.add(this); - addMouseListener(new MouseAdapter() - { - public void mouseClicked(MouseEvent e) - { + addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { window.event(code); - } - }); + } + }); } - void remove() - { + void remove() { this.getParent().remove(this); } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Explorer.java b/Arctic_Nigthmare/src/arctic_nightmare/Explorer.java index ce7e2279d408a80c456d3ce8bdcc2fbab0922bd5..2fe02a56da1988f963297418ad790923ff609ba8 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Explorer.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Explorer.java @@ -1,6 +1,5 @@ package arctic_nightmare; - public class Explorer extends Person { public Explorer(String name, Field f, Game g) { @@ -19,24 +18,25 @@ public class Explorer extends Person { super(name, f); maxTemp = 5; bodyTemp = 5; - } - - //public Explorer(String name) { + } + + //public Explorer(String name) { // super(name); //} /*public Explorer(String name, Field field) { super(name, field); }*/ - public void checkCapacity(Field f) - { - if(field.isNeighbor(f)) - if(f.revealCapacity()) - work--; + public void checkCapacity(Field f) { + if (field.isNeighbor(f)) { + if (f.revealCapacity()) { + work--; + } + } } - @Override - public void useSpecialAbility(Field f) { - checkCapacity(f); - - } + @Override + public void useSpecialAbility(Field f) { + checkCapacity(f); + + } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Field.java.orig b/Arctic_Nigthmare/src/arctic_nightmare/Field.java.orig deleted file mode 100644 index e3b5da759a54be965baa109ae5fe376751f5a35b..0000000000000000000000000000000000000000 --- a/Arctic_Nigthmare/src/arctic_nightmare/Field.java.orig +++ /dev/null @@ -1,282 +0,0 @@ -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/FragileShovel.java b/Arctic_Nigthmare/src/arctic_nightmare/FragileShovel.java index 60516721a1bdadaa195d67878bb9189fe2e2bbd6..9659b61e517d4627d897bc43ab81df91f89a6f8f 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/FragileShovel.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/FragileShovel.java @@ -1,16 +1,30 @@ package arctic_nightmare; -public class FragileShovel extends Item{ +/** + * A torekeny asot reprezentalo osztaly. + */ +public class FragileShovel extends Item { + + /** Az aso hatralevo hasznalatainak szama. */ private int remainingUse; + /** + * Altalanos konstruktor az osztalyhoz. + */ public FragileShovel() { super("FragileShovel"); remainingUse = 3; } - + /** + * Az aso hasznalata soran meghivott fuggveny, ami az aso tervezett elhasznalodasaert felelos. + * @param f a mezon, amelyiken az asot hasznalni fogjuk. + * @return visszaadja, hogy a tevekenyseg soran az aso elhasznalodott-e. + */ public boolean use(Field f) { remainingUse--; - if(remainingUse == 0) return false; + if (remainingUse == 0) { + return false; + } return true; } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Game.java b/Arctic_Nigthmare/src/arctic_nightmare/Game.java index c348c9a064d6d8ca433660fd88f70ae18e696b01..dad9a5e90072f9e0c2c44e4898c2602239223335 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Game.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Game.java @@ -6,115 +6,127 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; -public class Game{ +/** + * A jateklogika + */ +public class Game { + private Person actualPlayer; private List<Person> players; private Board board; private IceBear bear; private boolean win; private GameWindow window; - - - Game(){ - actualPlayer = null; - players = new ArrayList<Person>(); - board = null; - bear = null; - Object[] options = GameWindow.getMapOptions(); + + Game() { + actualPlayer = null; + players = new ArrayList<Person>(); + board = null; + bear = null; + int[] options = GameWindow.getMapOptions(); window = new GameWindow(this); - newGame((int) pow(Integer.parseInt((String)options[0]), 2), Integer.parseInt((String)options[0]), Integer.parseInt((String)options[1])); + newGame((int) pow(options[0], 2), options[0], options[1]); } - - void gameOver(String text){ - if (GameWindow.playAgain(text + " Sucker ....")) - { - Object[] options = GameWindow.getMapOptions(); - newGame((int) pow(Integer.parseInt((String)options[0]), 2), Integer.parseInt((String)options[0]), Integer.parseInt((String)options[1])); + + void gameOver(String text) { + if (GameWindow.playAgain(text + " Sucker ....")) { + int[] options = GameWindow.getMapOptions(); + newGame((int) pow(options[0], 2), options[0], options[1]); window.setBoard(board); - window.drawBoard(); + } else { + window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING)); } - else window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING)); } - + + /** + * + * @return + */ public int getPlayerNumber() { - return players.size(); + return players.size(); } - + + /** + * + * @return + */ public Person getActualPlayer() { - return actualPlayer; - } - - void nextPlayer() throws PlayerDiedException{ - int actualPlayerIdx = players.indexOf(actualPlayer); - int nextPlayerIdx = actualPlayerIdx + 1; - if(nextPlayerIdx >= players.size()) { - nextPlayerIdx = 0; - ArrayList<Field> fields_hit_by_blizzard = board.makeBlizzard(); - if(fields_hit_by_blizzard.size() != 0) - { - window.drawBlizzard(fields_hit_by_blizzard); - - MediaAssociation.play(new String[]{"thunder1", "thunder2", "thunder3", "thunder4", "thunder5"}[new Random().nextInt(4)]); - } - bear.step(); - } - setActualPerson(nextPlayerIdx); + return actualPlayer; } - + + void nextPlayer() throws PlayerDiedException { + int actualPlayerIdx = players.indexOf(actualPlayer); + int nextPlayerIdx = actualPlayerIdx + 1; + if (nextPlayerIdx >= players.size()) { + nextPlayerIdx = 0; + ArrayList<Field> fields_hit_by_blizzard = board.makeBlizzard(); + if (fields_hit_by_blizzard.size() != 0) { + window.drawBlizzard(fields_hit_by_blizzard); + + MediaAssociation.play(new String[]{"thunder1", "thunder2", "thunder3", "thunder4", "thunder5"}[new Random().nextInt(4)]); + } + bear.step(); + } + setActualPerson(nextPlayerIdx); + } + + /** + * + * @param ev + */ public void play(Event ev) { - try { - actualPlayer.event(ev); - if(actualPlayer.getWork() <= 0) { - nextPlayer(); - actualPlayer.enablePlayer(); - } - window.drawBoard(); - } - catch(PlayerDiedException e) { + try { + actualPlayer.event(ev); + if (actualPlayer.getWork() <= 0) { + nextPlayer(); + actualPlayer.enablePlayer(); + } + window.drawBoard(); + } catch (PlayerDiedException e) { gameOver(e.getMessage()); - } - catch(PlayersWinException e) { + } catch (PlayersWinException e) { win(e.getMessage()); - } - finally {} + } finally { + } } - - - void newGame(int fieldsnum, int boardcolumns, int playernum){ - board = new Board(fieldsnum, boardcolumns, playernum); - bear = new IceBear(board.getfield(0)); + + void newGame(int fieldsnum, int boardcolumns, int playernum) { + board = new Board(fieldsnum, boardcolumns, playernum); + bear = new IceBear(board.getfield(0)); players = new ArrayList<Person>(); - board.getfield(0).bear = bear; - for(int i = 1; i < playernum + 1; i++) { + board.getfield(0).bear = bear; + for (int i = 1; i < playernum + 1; i++) { boolean playertype = false; Person newperson = null; String name = GameWindow.getPlayerOptions(i); - if(i % 2 == 0) + if (i % 2 == 0) { newperson = new Eskimo(name, this); - else + } else { newperson = new Explorer(name, 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); - window.setBoard(board); - window.drawBoard(); - actualPlayer.enablePlayer(); + 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); + window.setBoard(board); + actualPlayer.enablePlayer(); } - - void setActualPerson(int idx){ + + void setActualPerson(int idx) { actualPlayer = players.get(idx); } - void win(String text){ - if (GameWindow.playAgain(text + " The lucky one ....")) - { - Object[] options = GameWindow.getMapOptions(); - newGame((int) pow(Integer.parseInt((String)options[0]), 2), Integer.parseInt((String)options[0]), Integer.parseInt((String)options[1])); + void win(String text) { + if (GameWindow.playAgain(text + " The lucky one ....")) { + int[] options = GameWindow.getMapOptions(); + newGame((int) pow(options[0], 2), options[0], options[1]); window.setBoard(board); window.drawBoard(); + } else { + window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING)); } - else window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING)); } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/GameWindow.java b/Arctic_Nigthmare/src/arctic_nightmare/GameWindow.java index 3baa00c1726e5f688f57ee313ba1256174d7fdfd..0ff7306b22ae1b7f1fddd1c15bc42a712676b833 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/GameWindow.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/GameWindow.java @@ -21,184 +21,240 @@ import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.UIManager; +/** + * A jatek ablakait vezerlo osztaly. Benne talalhato a jatek fo terekent + * talalhato ablak ami megjeleniti a jegmezoket, de statikus metoduskent a + * dialogusablakok is. + */ +public class GameWindow extends JFrame { -public class GameWindow extends JFrame{ + /** + * Referencia a jateklogikara. + */ private Game game; + /** + * Az aktualis jatekosra mutato referencia. + */ private Person actualplayer; + /** + * A jegmezok listaja. + */ private List<Block> fields; + /** + * Azon mezok listaja, amelyeket utoljara hovihar sulytott. + */ ArrayList<Field> fields_hit_by_blizzard; + /** + * Az ablakon levo kepobjektumok listaja. + */ private List<ScaledImagePanel> playeritems; + /** + * Az ablakon levo gombok listaja. + */ private List<EventButton> buttons; - private int lastclick; + /** + * Az utolso klikkelest rogzito valtozo. Abban az esetben van ra szukseg, ha + * olyan tevekenyseget akarunk vegezni, amit ket klikkeles hataroz meg. + */ + private int lastclick; + /** + * A jatek nevet mutato cimke. + */ private JLabel actualstats, logo; - - GameWindow(Game game) - { + + /** + * Az ablak altalanos konstruktora. + * + * @param game a jateklogika. + */ + GameWindow(Game game) { this.game = game; actualstats = new JLabel(); actualstats.setVisible(true); actualstats.setOpaque(true); - actualstats.setBackground(Color.white); + actualstats.setBackground(Color.white); add(actualstats); - logo = new JLabel(new ImageIcon("src/arctic_nightmare/resources/logo.gif"), SwingConstants.CENTER); + logo = new JLabel(new ImageIcon(GameWindow.class.getResource("logo.gif")), SwingConstants.CENTER); add(logo); setSize(600, 600); setTitle("Arctic Nightmare"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setResizable(true); - setVisible(true); + setVisible(true); setLayout(null); fields = null; } - - public void drawBoard() - { + + /** + * Az ablakot ujrarajzolo fuggveny. Eloszor torol minden olyan objektumot, + * ami a korabbi jatekallashoz kotheto, utana az uj allas alapjan ujakat + * helyez fel. + */ + public void drawBoard() { actualplayer = game.getActualPlayer(); removePlayerItems(); getPlayerItems(); - actualstats.setText("<html>" + actualplayer.getName() + "<br>Bodyheat : " + actualplayer.bodyTemp + "<br>Work : " + actualplayer.work + "</html>" ); - for (Block block : fields) - { - block.drawBlock(); + actualstats.setText("<html>" + actualplayer.getName() + "<br>Bodyheat : " + actualplayer.bodyTemp + "<br>Work : " + actualplayer.work + "</html>"); + for (Block block : fields) { + block.drawBlock(); } this.fields_hit_by_blizzard = null; repaint(); } - - + /** + * A jegeso eseten hivott fuggveny. Eltarolja az ablakban a jegeso altal + * sulytott mezok listajat a kovetkezo kirajzolashoz. + * + * @param fields_hit_by_blizzard a jegeso altal sulytott mezok listaja. + */ public void drawBlizzard(ArrayList<Field> fields_hit_by_blizzard) { - this.fields_hit_by_blizzard = fields_hit_by_blizzard; - } + this.fields_hit_by_blizzard = fields_hit_by_blizzard; + } - private void removePlayerItems() - { - if (playeritems != null){ - for(int i =0; playeritems.size()>i; i++) - { + /** + * Az aktiv jatekos targyait torlo fuggveny. + */ + private void removePlayerItems() { + if (playeritems != null) { + for (int i = 0; playeritems.size() > i; i++) { playeritems.get(0).remove(); playeritems.remove(0); } } } - - private void getPlayerItems() - { + + /** + * Az aktiv jatekos targyait kirajzolo fuggveny. + */ + private void getPlayerItems() { Dimension windowsize = this.getSize(); int itemiconsize = 20; Vector<Item> items = actualplayer.getItems(); - for (int i= 0; items.size() > i; i++) - { - ScaledImagePanel item = new ScaledImagePanel(this, MediaAssociation.getImage(items.get(i).getName()), windowsize.width - 40 - i * itemiconsize, windowsize.height -60, itemiconsize, itemiconsize); + for (int i = 0; items.size() > i; i++) { + ScaledImagePanel item = new ScaledImagePanel(this, MediaAssociation.getImage(items.get(i).getName()), windowsize.width - 40 - i * itemiconsize, windowsize.height - 60, itemiconsize, itemiconsize); this.add(item); playeritems.add(item); } } - - private void removeControls() - { + + /** + * A gombokat és a mezoket eltavolito fuggveny. + */ + private void removeControls() { removePlayerItems(); - if (fields != null){ - for (Block b :fields) - { + if (fields != null) { + for (Block b : fields) { b.remove(); } fields = null; } - if (buttons != null){ - for (EventButton b :buttons) - { + if (buttons != null) { + for (EventButton b : buttons) { b.remove(); } buttons = null; - } - //IMPORTANT + } this.revalidate(); this.repaint(); } - - public void setBoard(Board board) - { + + /** + * Egy megadott Board objektum alapjan ez a fuggveny krealja meg a + * foablakban a jatekteret. Fo funkcioja a gombok es a jegmezok hozzaadasa, + * illetve az ehhez szukseges adatok szamitasa. + * + * @param board a bemeneti jatektabla. + */ + public void setBoard(Board board) { MediaAssociation.play("storm", 0.1f); removeControls(); playeritems = new ArrayList<>(); fields = new ArrayList<>(); - buttons = new ArrayList<>(); + buttons = new ArrayList<>(); int columns = board.columns(); int fieldwidth = 120; int fildheight = 120; int fielddistancehorizontal = 130; int fielddistancevertical = 130; int buttonwidth = 100; - int windowwidth = 20 + (columns -1) * fielddistancehorizontal + fielddistancehorizontal + 20 + buttonwidth; - int windowhight = 200 +(columns -1) * fielddistancevertical + fielddistancevertical; - + int windowwidth = 20 + (columns - 1) * fielddistancehorizontal + fielddistancehorizontal + 20 + buttonwidth; + int windowhight = 200 + (columns - 1) * fielddistancevertical + fielddistancevertical; setSize(windowwidth, windowhight); - System.out.println(windowwidth + " " + windowhight); - logo.setBounds(windowwidth /2 - 270, 0, 527, 102); - actualstats.setBounds(windowwidth-100, windowhight-150, 100, 50); - for (int i = 0;board.size() > i; i++) - { - Block block = new Block(this, board.getfield(i), 20 + fielddistancehorizontal * (i - (i / columns) * columns ), 150 + fielddistancevertical * (i / columns), fieldwidth, fildheight); + logo.setBounds(windowwidth / 2 - 270, 0, 527, 102); + actualstats.setBounds(windowwidth - 100, windowhight - 150, 100, 50); + for (int i = 0; board.size() > i; i++) { + Block block = new Block(this, board.getfield(i), 20 + fielddistancehorizontal * (i - (i / columns) * columns), 150 + fielddistancevertical * (i / columns), fieldwidth, fildheight); this.add(block); fields.add(block); } buttons.add(new EventButton(this, 0, "Step", windowwidth - buttonwidth, 110, buttonwidth, 30)); - buttons.add(new EventButton(this, 1, "Shovel", windowwidth - buttonwidth, 150, buttonwidth, 30 )); - buttons.add(new EventButton(this, 2, "Dig", windowwidth - buttonwidth, 190, buttonwidth, 30 )); - buttons.add(new EventButton(this, 3, "Pickup",windowwidth - buttonwidth, 230, buttonwidth, 30 )); - buttons.add(new EventButton(this, 4, "Tent", windowwidth - buttonwidth, 270, buttonwidth, 30 )); - buttons.add(new EventButton(this, 5, "Pistol", windowwidth - buttonwidth, 310, buttonwidth, 30 )); - buttons.add(new EventButton(this, 6, "Igluu",windowwidth - buttonwidth, 350, buttonwidth, 30 )); - buttons.add(new EventButton(this, 7, "Inspect",windowwidth - buttonwidth, 390, buttonwidth, 30 )); + buttons.add(new EventButton(this, 1, "Shovel", windowwidth - buttonwidth, 150, buttonwidth, 30)); + buttons.add(new EventButton(this, 2, "Dig", windowwidth - buttonwidth, 190, buttonwidth, 30)); + buttons.add(new EventButton(this, 3, "Pickup", windowwidth - buttonwidth, 230, buttonwidth, 30)); + buttons.add(new EventButton(this, 4, "Tent", windowwidth - buttonwidth, 270, buttonwidth, 30)); + buttons.add(new EventButton(this, 5, "Pistol", windowwidth - buttonwidth, 310, buttonwidth, 30)); + buttons.add(new EventButton(this, 6, "Igluu", windowwidth - buttonwidth, 350, buttonwidth, 30)); + buttons.add(new EventButton(this, 7, "Inspect", windowwidth - buttonwidth, 390, buttonwidth, 30)); drawBoard(); } - - public void event(Field field) - { - if (lastclick != -1){ + + /** + * A Block objektumokon torteno kattintasokat kezelo fuggveny. Amennyiben a jatekos szandeka egyertelmu, meghivja a Game szukseges metodusat. Az esemenyek tipusanak feldolgozasa a Person osztaly event metodusaban talalhato. + * @param field az a mezo, amin a kattintas tortent. + */ + public void event(Field field) { + if (lastclick != -1) { game.play(new Event(lastclick, field)); lastclick = -1; - } - else - { - if (actualplayer.field.isNeighbor(field)) game.play(new Event(0, field)); - else if (actualplayer.field == field) - { - if (field.snow > 0) game.play(new Event(1, field)); - else if (0 >= field.snow && !field.itemPickable) game.play(new Event(2, field)); - else if (0 >= field.snow && field.itemPickable) game.play(new Event(3, field)); + } else { + if (actualplayer.field.isNeighbor(field)) { + game.play(new Event(0, field)); + } else if (actualplayer.field == field) { + if (field.snow > 0) { + game.play(new Event(1, field)); + } else if (0 >= field.snow && !field.itemPickable) { + game.play(new Event(2, field)); + } else if (0 >= field.snow && field.itemPickable) { + game.play(new Event(3, field)); + } } } } - - public void event(int event) - { - if (event == 1 || event == 2 || event == 3 || event == 4 || event == 5 || event == 6) - { + + /** + * Az EventButton objektumokon tortent kattintasokat kezelo fuggveny. Amennyiben tovabbi kattintasra van szukseg a jatekos szandekanak eldontesere, eltarolja a mostani esemenyt, amennyiben viszont az egyertelmu, meghivja a Game szukseges metodusat. Az esemenyek tipusanak feldolgozasa a Person osztaly event metodusaban talalhato. + * @param event az esemeny tipusa. + */ + public void event(int event) { + if (event >= 1 && 6 >= event) { game.play(new Event(event, null)); - lastclick = -1; + lastclick = -1; + } else { + lastclick = event; } - else lastclick = event; } - + /////////////////// // Dialogwindows // /////////////////// - static public Object[] getMapOptions() - { + /** + * A terkep generalasa soran hasznalt dialogusablak. A terkep meretet illetve a jatekosok szamat lehet rajta beallitani. + * @return egy int tomb formajaban visszakapjuk a kivant palya meretet valamint a jatekosok szamat. + */ + static public int[] getMapOptions() { MediaAssociation.play("dramaticsound"); - UIManager UI=new UIManager(); + UIManager UI = new UIManager(); UI.put("OptionPane.background", new Color(255, 255, 255)); - UI.put("Panel.background", Color.white); + UI.put("Panel.background", Color.white); String[] size = {"4", "5", "6", "7"}; String[] players = {"3", "4", "5", "6"}; JComboBox<String> combo = new JComboBox<>(size); JComboBox<String> combo1 = new JComboBox<>(players); JPanel panel0 = new JPanel(new FlowLayout()); JPanel panel = new JPanel(new GridLayout(0, 1)); - JLabel bear = new JLabel(new ImageIcon("src/arctic_nightmare/resources/icebear.gif")); - panel.add(bear); + JLabel bear = new JLabel(new ImageIcon(GameWindow.class.getResource("icebear.gif"))); + panel.add(bear); panel.add(new JLabel("Map size :")); panel.add(combo); panel.add(new JLabel("Players :")); @@ -206,11 +262,15 @@ public class GameWindow extends JFrame{ panel0.add(panel); panel0.add(bear); int result = JOptionPane.showConfirmDialog(null, panel0, "Game options", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE); - return new Object[]{combo.getSelectedItem(), combo1.getSelectedItem()}; - } - - static public String getPlayerOptions(int count) - { + return new int[]{Integer.parseInt((String)combo.getSelectedItem()), Integer.parseInt((String)combo1.getSelectedItem())}; + } + + /** + * A jatekosok generalasa soran hasznalt dialogusablak. A jatekosok nevet lehet rajta beadni. + * @param count ezaltal tudja az ablak, hogy hanyadikkent generalt jatekosrol van szo. Az automatikusan generalt jatekosnevhez illetve a generalt jatekos ikonjanak megjelenitesehez van ra szukseg. + * @return a jatekos neve. + */ + static public String getPlayerOptions(int count) { JTextField field1 = new JTextField("Player " + count); JPanel panel0 = new JPanel(new FlowLayout()); JPanel panel = new JPanel(new GridLayout(0, 1)); @@ -222,26 +282,21 @@ public class GameWindow extends JFrame{ int result = JOptionPane.showConfirmDialog(null, panel0, "Set player " + count, JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE); return field1.getText(); } - - static public boolean playAgain(String text) - { + + /** + * A jatek megnyerese illetve elvesztese eseten lehetoseg van kozvetlenul uj jatek inditasara. Az erre valo igenyt meri fel ez a dialogusablak. + * @param text a dialogusablakban megjelenitett szoveg. + * @return logikai ertek mely azt fejezi ki, hogy a jatekos(ok) szeretnenek-e uj jatekot. + */ + static public boolean playAgain(String text) { JPanel panel = new JPanel(new GridLayout(0, 1)); panel.add(new JLabel(text)); panel.add(new JLabel("Do you want another game?")); int result = JOptionPane.showConfirmDialog(null, panel, "", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE); - if (result == JOptionPane.OK_OPTION) return true; - else return false; - } - - - static public Image getScaledImage(Image srcImg, int w, int h){ - BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); - Graphics2D g2 = resizedImg.createGraphics(); - - g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); - g2.drawImage(srcImg, 0, 0, w, h, null); - g2.dispose(); - - return resizedImg; + if (result == JOptionPane.OK_OPTION) { + return true; + } else { + return false; + } } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/IceBear.java b/Arctic_Nigthmare/src/arctic_nightmare/IceBear.java index fd48afc586a2e7779649b9779e169b5412e7da36..9078d12ecf03841697a67241adcc094ac0c371f7 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/IceBear.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/IceBear.java @@ -3,12 +3,26 @@ package arctic_nightmare; import java.util.List; import java.util.Random; +/** + * Az eszakisark csendes gyilkosat reprezentalo osztaly. + */ public class IceBear { + + /** A mezo, ahol a maci talalhato. */ private Field field; + /** + * Altalanos konstruktor az osztalyhoz. + * @param f a mezo, ahol a rettegett gyilkologepet el szeretnenk helyezni. + */ public IceBear(Field f) { field = f; } + + /** + * A jegesmedve lepteteseert felelos fuggveny. + * @throws PlayerDiedException amennyiben a medve egy olyan mezore lep, ahol jatekos talalhato, ugy azt menthetetlenul szetszaggatja. Ebben az esetben dobodik ez a kivetel. + */ public void step() throws PlayerDiedException { Random rand = new Random(); List<Field> neighborList = field.getNeighbors(); diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Item.java b/Arctic_Nigthmare/src/arctic_nightmare/Item.java index 9e3074c78f8bcb1ca81febda9a898ae2d885dbd7..286492d410545ca552211cf01e6609817b3a2bc3 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Item.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Item.java @@ -1,13 +1,35 @@ package arctic_nightmare; +/** + * A jatekban talalhato targyakat reprezentalo osztaly. + */ public class Item { - private String name; - + + /** A targy neve. */ + private String name; + + /** + * Altalanos konstruktor az osztalyhoz. + * @param s a letrehozott targy neve. + */ public Item(String s) { - name = new String(s); + name = new String(s); + } + + /** + * A targy nevet visszaado fuggveny. + * @return a targy neve. + */ + public String getName() { + return name; + } + + /** + * Ez nem tudom, micsoda :) + * @param f egy field + * @return igaz + */ + public boolean use(Field f) { + return true; } - - public String getName() { return name;} - - public boolean use(Field f) {return true;} } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Main.java b/Arctic_Nigthmare/src/arctic_nightmare/Main.java index fb5e3a2890be266fc55df4e42feda26fd4f5bc98..5d58be35031f9eed2d017f6491349d1c3cf25482 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Main.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Main.java @@ -1,13 +1,16 @@ package arctic_nightmare; import java.io.IOException; - +/** + * A jatek belepesi pontjakent szolgalo Main osztaly es main fuggveny. + */ public class Main { /** - * @param args the command line arguments + * A jatek belepesi pontjakent szolgalo main fuggveny. + * @throws java.io.IOException */ - public static void main(String[] args) throws IOException { + public static void main() throws IOException { Game game = new Game(); } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/MediaAssociation.java b/Arctic_Nigthmare/src/arctic_nightmare/MediaAssociation.java index e5efa09b33eef070c47fdc392c771c0e0836e31f..841556db669535ec104a7c68539c8c198826670e 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/MediaAssociation.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/MediaAssociation.java @@ -4,84 +4,106 @@ import java.util.HashMap; import java.util.Map; import javax.swing.ImageIcon; - +/** + * A kepek es a hangok kozos tarolasara hasznalt osztaly. Segitsegevel ezek a nagy meretu adatok egy helyen tarolodnak, hasznalat eseten innen hivodnak meg. + */ public class MediaAssociation { - + + /** A kepek tarolasara szolgalo map. */ static private Map<String, ImageIcon> items; + /** Az hangok tarolasara szolgalo map */ static private Map<String, Audio> audios; - - static - { + + + /** + * Az osztaly statikus konstruktora. Minden egyes adathoz egy egyszeru kulcsot rendel. + */ + static { items = new HashMap<>(); - items.put("bear", new ImageIcon( "src/arctic_nightmare/resources/icebear.png")); - items.put("bear_half", new ImageIcon( "src/arctic_nightmare/resources/icebear_half.png")); - items.put("Cartridge", new ImageIcon( "src/arctic_nightmare/resources/cartridge_visible.png")); - items.put("Cartridge_COVERED", new ImageIcon( "src/arctic_nightmare/resources/cartridge_covered.png")); - items.put("DivingSuit", new ImageIcon( "src/arctic_nightmare/resources/divingsuit_visible.png")); - items.put("DivingSuit_COVERED", new ImageIcon( "src/arctic_nightmare/resources/divingsuit_covered.png")); - items.put("eskimo", new ImageIcon( "src/arctic_nightmare/resources/eskimo.png")); - items.put("eskimo_half", new ImageIcon( "src/arctic_nightmare/resources/eskimo_half.png")); - items.put("explorer", new ImageIcon( "src/arctic_nightmare/resources/explorer.png")); - items.put("explorer_half", new ImageIcon( "src/arctic_nightmare/resources/explorer_half.png")); - items.put("Flare", new ImageIcon( "src/arctic_nightmare/resources/signalflare_visible.png")); - items.put("Flare_COVERED", new ImageIcon( "src/arctic_nightmare/resources/signalflare_covered.png")); - items.put("Food", new ImageIcon( "src/arctic_nightmare/resources/food_visible.png")); - items.put("Food_COVERED", new ImageIcon( "src/arctic_nightmare/resources/food_covered.png")); - items.put("FragileShovel", new ImageIcon( "src/arctic_nightmare/resources/fragile_shovel_visible.png")); - items.put("FragileShovel_COVERED", new ImageIcon( "src/arctic_nightmare/resources/fragile_shovel_covered.png")); - items.put("igloo", new ImageIcon( "src/arctic_nightmare/resources/igloo_set.png")); - items.put("Pistol", new ImageIcon( "src/arctic_nightmare/resources/pistol_visible.png")); - items.put("Pistol_COVERED", new ImageIcon( "src/arctic_nightmare/resources/pistol_covered.png")); - items.put("Rope", new ImageIcon( "src/arctic_nightmare/resources/rope_visible.png")); - items.put("Rope_COVERED", new ImageIcon( "src/arctic_nightmare/resources/rope_covered.png")); - items.put("Shovel", new ImageIcon( "src/arctic_nightmare/resources/shovel_visible.png")); - items.put("Shovel_COVERED", new ImageIcon( "src/arctic_nightmare/resources/shovel_covered.png")); - items.put("snowpile0", new ImageIcon( "src/arctic_nightmare/resources/field_0snow.png")); - items.put("snowpile1", new ImageIcon( "src/arctic_nightmare/resources/field_1snow.png")); - items.put("snowpile2", new ImageIcon( "src/arctic_nightmare/resources/field_2snow.png")); - items.put("snowpile3", new ImageIcon( "src/arctic_nightmare/resources/field_3snow.png")); - items.put("snowpile4", new ImageIcon( "src/arctic_nightmare/resources/field_4snow.png")); - items.put("storm1", new ImageIcon( "src/arctic_nightmare/resources/storm1.png")); - items.put("storm2", new ImageIcon( "src/arctic_nightmare/resources/storm2.png")); - items.put("storm_cat", new ImageIcon( "src/arctic_nightmare/resources/storm_cat.png")); - items.put("tent", new ImageIcon( "src/arctic_nightmare/resources/tent_set.png")); - items.put("Tent", new ImageIcon( "src/arctic_nightmare/resources/tent_visible.png")); - items.put("Tent_COVERED", new ImageIcon( "src/arctic_nightmare/resources/tent_covered.png")); - items.put("water", new ImageIcon( "src/arctic_nightmare/resources/field_water.png")); - + items.put("bear", new ImageIcon(MediaAssociation.class.getResource("icebear.png"))); + items.put("bear_half", new ImageIcon(MediaAssociation.class.getResource("icebear_half.png"))); + items.put("Cartridge", new ImageIcon(MediaAssociation.class.getResource("cartridge_visible.png"))); + items.put("Cartridge_COVERED", new ImageIcon(MediaAssociation.class.getResource("cartridge_covered.png"))); + items.put("DivingSuit", new ImageIcon(MediaAssociation.class.getResource("divingsuit_visible.png"))); + items.put("DivingSuit_COVERED", new ImageIcon(MediaAssociation.class.getResource("divingsuit_covered.png"))); + items.put("eskimo", new ImageIcon(MediaAssociation.class.getResource("eskimo.png"))); + items.put("eskimo_half", new ImageIcon(MediaAssociation.class.getResource("eskimo_half.png"))); + items.put("explorer", new ImageIcon(MediaAssociation.class.getResource("explorer.png"))); + items.put("explorer_half", new ImageIcon(MediaAssociation.class.getResource("explorer_half.png"))); + items.put("Flare", new ImageIcon(MediaAssociation.class.getResource("signalflare_visible.png"))); + items.put("Flare_COVERED", new ImageIcon(MediaAssociation.class.getResource("signalflare_covered.png"))); + items.put("Food", new ImageIcon(MediaAssociation.class.getResource("food_visible.png"))); + items.put("Food_COVERED", new ImageIcon(MediaAssociation.class.getResource("food_covered.png"))); + items.put("FragileShovel", new ImageIcon(MediaAssociation.class.getResource("fragile_shovel_visible.png"))); + items.put("FragileShovel_COVERED", new ImageIcon(MediaAssociation.class.getResource("fragile_shovel_covered.png"))); + items.put("igloo", new ImageIcon(MediaAssociation.class.getResource("igloo_set.png"))); + items.put("Pistol", new ImageIcon(MediaAssociation.class.getResource("pistol_visible.png"))); + items.put("Pistol_COVERED", new ImageIcon(MediaAssociation.class.getResource("pistol_covered.png"))); + items.put("Rope", new ImageIcon(MediaAssociation.class.getResource("rope_visible.png"))); + items.put("Rope_COVERED", new ImageIcon(MediaAssociation.class.getResource("rope_covered.png"))); + items.put("Shovel", new ImageIcon(MediaAssociation.class.getResource("shovel_visible.png"))); + items.put("Shovel_COVERED", new ImageIcon(MediaAssociation.class.getResource("shovel_covered.png"))); + items.put("snowpile0", new ImageIcon(MediaAssociation.class.getResource("field_0snow.png"))); + items.put("snowpile1", new ImageIcon(MediaAssociation.class.getResource("field_1snow.png"))); + items.put("snowpile2", new ImageIcon(MediaAssociation.class.getResource("field_2snow.png"))); + items.put("snowpile3", new ImageIcon(MediaAssociation.class.getResource("field_3snow.png"))); + items.put("snowpile4", new ImageIcon(MediaAssociation.class.getResource("field_4snow.png"))); + items.put("storm1", new ImageIcon(MediaAssociation.class.getResource("storm1.png"))); + items.put("storm2", new ImageIcon(MediaAssociation.class.getResource("storm2.png"))); + items.put("storm_cat", new ImageIcon(MediaAssociation.class.getResource("storm_cat.png"))); + items.put("tent", new ImageIcon(MediaAssociation.class.getResource("tent_set.png"))); + items.put("Tent", new ImageIcon(MediaAssociation.class.getResource("tent_visible.png"))); + items.put("Tent_COVERED", new ImageIcon(MediaAssociation.class.getResource("tent_covered.png"))); + items.put("water", new ImageIcon(MediaAssociation.class.getResource("field_water.png"))); + audios = new HashMap<String, Audio>(); - audios.put("bear", new Audio( "src/arctic_nightmare/resources/bear.wav")); - audios.put("dig", new Audio( "src/arctic_nightmare/resources/dig.wav")); - audios.put("pickup", new Audio( "src/arctic_nightmare/resources/wow.wav")); - audios.put("dramaticsound", new Audio( "src/arctic_nightmare/resources/Dramatic-sound.wav")); - audios.put("shovel", new Audio( "src/arctic_nightmare/resources/shovel.wav")); - audios.put("storm", new Audio( "src/arctic_nightmare/resources/storm.wav")); - audios.put("thunder1", new Audio( "src/arctic_nightmare/resources/thunder1.wav")); - audios.put("thunder2", new Audio( "src/arctic_nightmare/resources/thunder2.wav")); - audios.put("thunder3", new Audio( "src/arctic_nightmare/resources/thunder3.wav")); - audios.put("thunder4", new Audio( "src/arctic_nightmare/resources/thunder4.wav")); - audios.put("thunder5", new Audio( "src/arctic_nightmare/resources/thunder5.wav")); - audios.put("water", new Audio( "src/arctic_nightmare/resources/water.wav")); - audios.put("water", new Audio( "src/arctic_nightmare/resources/win.wav")); + audios.put("bear", new Audio("bear.wav")); + audios.put("dig", new Audio("dig.wav")); + audios.put("pickup", new Audio("wow.wav")); + audios.put("dramaticsound", new Audio("Dramatic-sound.wav")); + audios.put("shovel", new Audio("shovel.wav")); + audios.put("storm", new Audio("storm.wav")); + audios.put("thunder1", new Audio("thunder1.wav")); + audios.put("thunder2", new Audio("thunder2.wav")); + audios.put("thunder3", new Audio("thunder3.wav")); + audios.put("thunder4", new Audio("thunder4.wav")); + audios.put("thunder5", new Audio("thunder5.wav")); + audios.put("water", new Audio("water.wav")); + audios.put("water", new Audio("win.wav")); } - - static public ImageIcon getImage(String name) - { + + /** + * A fuggven a megadott kulcs alapjan visszaadja az eltarolt kepet. + * @param name a keresett kep kulcsa. + * @return a keresett kep. + */ + static public ImageIcon getImage(String name) { return items.get(name); } - - static public ImageIcon getImageCovered(String name) - { + + /** + * A fuggven a megadott kulcs alapjan visszaadja az eltarolt kepet. A megadott kulcshoz hozzaadja a '_COVERED' utotagot, amivel a ho altal boritott targyak kulcsa meg van kulonboztetve a hoval nem boritott megfelelojuktol. + * @param name a keresett kep kulcsa. + * @return a keresett kep. + */ + static public ImageIcon getImageCovered(String name) { return items.get(name + "_COVERED"); } - - static public void play(String name) - { + + /** + * A fuggven a megadott kulcs alapjan lejatssza az eltarolt hangot. + * @param name a keresett hang kulcsa. + */ + static public void play(String name) { audios.get(name).play(); } - - static public void play(String name, float volume) - { + + /** + * A fuggven a megadott kulcs alapjan lejatssza az eltarolt hangot a megadott hangerovel. A hangero resz nem mukodik egyforman minden gepen. + * @param name a keresett hang kulcsa. + * @param volume a kivant hangero. + */ + static public void play(String name, float volume) { audios.get(name).play(volume); - } + } } diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Person.java b/Arctic_Nigthmare/src/arctic_nightmare/Person.java index 5df1a05b055ec1f0b5a1257d543881e02b747140..1daf9762015b6c3e862658c733fbd53dc2e01664 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Person.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Person.java @@ -4,8 +4,8 @@ import java.util.List; import java.util.ArrayList; import java.util.Vector; - public abstract class Person { + protected int bodyTemp; protected int maxTemp; protected int work; @@ -14,28 +14,27 @@ public abstract class Person { private Vector<Item> items; private Game game; private Tent builtTent; - + ///Person konstruktorba kell Game mindenképpen public Person(String name, Field f, Game g) { - work = 4; - this.name = name; - field = f; - items = new Vector<Item>(); - game = g; - builtTent = null; + work = 4; + this.name = name; + field = f; + items = new Vector<Item>(); + game = g; + builtTent = null; } - + public Person(String name, Game g) { - work = 4; - this.name = name; - field = null; - items = new Vector<Item>(); - game = g; - builtTent = null; + work = 4; + this.name = name; + field = null; + items = new Vector<Item>(); + game = g; + builtTent = null; } - - Person(String name, Field field) throws PlayerDiedException - { + + Person(String name, Field field) throws PlayerDiedException { items = new Vector<>(); this.field = field; field.accept(this); @@ -43,228 +42,220 @@ public abstract class Person { work = 4; } - Person(String name) - { + Person(String name) { items = new Vector<>(); this.name = name; work = 4; } - - public void assembleFlare() throws PlayersWinException{ - List<Person> persons = field.getPersons(); - String parts[] = {"Pistol", "Cartridge", "Flare"}; - boolean b[] = {false, false, false}; - for(int i = 0; i <3; ++i) { - for(Person p : persons) { - if(p.hasItem(parts[i])){ - b[i] = true; - break; - } - } - } - if(b[0] && b[1] && b[2] && persons.size() == game.getPlayerNumber()) { - throw new PlayersWinException(name + " shoot the flare, and the good guys win again!"); - } - + + public void assembleFlare() throws PlayersWinException { + List<Person> persons = field.getPersons(); + String parts[] = {"Pistol", "Cartridge", "Flare"}; + boolean b[] = {false, false, false}; + for (int i = 0; i < 3; ++i) { + for (Person p : persons) { + if (p.hasItem(parts[i])) { + b[i] = true; + break; + } + } + } + if (b[0] && b[1] && b[2] && persons.size() == game.getPlayerNumber()) { + throw new PlayersWinException(name + " shoot the flare, and the good guys win again!"); + } + } - - public void die() throws PlayerDiedException - { - this.bodyTemp = 0; + + public void die() throws PlayerDiedException { + this.bodyTemp = 0; throw new PlayerDiedException(name + " died on the icefield alone and miserably!"); } - - public void dig(){ - if(this.field.emitItem()){ + + public void dig() { + if (this.field.emitItem()) { MediaAssociation.play("dig"); work--; - } + } } - - public void event(Event ev) throws PlayerDiedException, PlayersWinException - { - switch (ev.getCode()) - { - case 0: + + public void event(Event ev) throws PlayerDiedException, PlayersWinException { + switch (ev.getCode()) { + case 0: step(ev.getParam()); break; case 1: shovel(); break; case 2: - dig(); - break; + dig(); + break; case 3: - pickUpItem(); + pickUpItem(); break; case 4: buildTent(); break; case 5: - assembleFlare(); - break; + assembleFlare(); + break; case 6: - useSpecialAbility(null); - break; + useSpecialAbility(null); + break; case 7: - useSpecialAbility(ev.getParam()); - break; + useSpecialAbility(ev.getParam()); + break; } } - - public void fall() throws PlayerDiedException - { + + public void fall() throws PlayerDiedException { MediaAssociation.play("water"); - if(hasItem("DivingSuit")) { - //step(field.getNeighbors().get(0)); - return; - } - else { - ArrayList<Person> potentialhelpers = findHelpers(); + if (hasItem("DivingSuit")) { + return; + } else { + ArrayList<Person> potentialhelpers = findHelpers(); boolean saved = false; - if(!potentialhelpers.isEmpty()) { - for (Person person : potentialhelpers) { + if (!potentialhelpers.isEmpty()) { + for (Person person : potentialhelpers) { saved = person.pullOut(this); - if(saved) { - bodyTemp--; - if(this.bodyTemp==0) die(); - work = 0; - return; + if (saved) { + bodyTemp--; + if (this.bodyTemp == 0) { + die(); + } + work = 0; + return; } - } + } } die(); } } - - public String getName() - { + + public String getName() { return name; } - - public int getWork(){ - return work; + + public int getWork() { + return work; } - - public Vector getItems() - { + + public Vector getItems() { return items; } - - public boolean hasItem(String itemname){ - for(Item it : items) - if(it.getName().equals(itemname)) + + public boolean hasItem(String itemname) { + for (Item it : items) { + if (it.getName().equals(itemname)) { return true; - return false; + } + } + return false; } - - public void hitByBlizzard() throws PlayerDiedException{ - this.bodyTemp--; - if(this.bodyTemp==0) die(); + + public void hitByBlizzard() throws PlayerDiedException { + this.bodyTemp--; + if (this.bodyTemp == 0) { + die(); + } } - - public ArrayList<Person> findHelpers(){ - ArrayList<Person> potentialhelpers = new ArrayList<Person>(); - List<Field> neighbors = field.getNeighbors(); - for(Field neighbor: neighbors) { //iteralas az osszes iranyt tartalmazo tombon - potentialhelpers.addAll(neighbor.getPersons()); - } - return potentialhelpers; + + public ArrayList<Person> findHelpers() { + ArrayList<Person> potentialhelpers = new ArrayList<Person>(); + List<Field> neighbors = field.getNeighbors(); + for (Field neighbor : neighbors) { //iteralas az osszes iranyt tartalmazo tombon + potentialhelpers.addAll(neighbor.getPersons()); + } + return potentialhelpers; } - - public void pickUpItem() - { + + public void pickUpItem() { Item item = field.getItem(); - if (item != null) - { + if (item != null) { MediaAssociation.play("pickup"); - if(item.getName().equals("Food")) - { - 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)) { + if (item.getName().equals("Food")) { + if (bodyTemp < maxTemp) { + bodyTemp++; // ha elelmet talalt a person azt nem tarolja el, hanem megeszi es noveli vele a bodyTempjét + work--; + } + } else { + if (!items.contains(item)) { items.add(item); - work --; + work--; } } } } - - public boolean pullOut(Person p) throws PlayerDiedException{ - if(hasItem("Rope")) { + + public boolean pullOut(Person p) throws PlayerDiedException { + if (hasItem("Rope")) { p.step(field); return true; - } - return false; + } + return false; } - - public void setWork(int i) - { + + public void setWork(int i) { work = i; } - - public void shovel() - { - int snow_layers = 1; - if(hasItem("Shovel") || hasItem("FragileShovel")) snow_layers = 2; - if(field.clearSnow(snow_layers)) - { + + public void shovel() { + int snow_layers = 1; + if (hasItem("Shovel") || hasItem("FragileShovel")) { + snow_layers = 2; + } + if (field.clearSnow(snow_layers)) { work--; MediaAssociation.play("shovel"); - for(int i = 0; i < items.size(); ++i) - { + for (int i = 0; i < items.size(); ++i) { Item it = items.get(i); - if(items.get(i).getName().equals("FragileShovel")) - { - if(!it.use(null)) - { + if (items.get(i).getName().equals("FragileShovel")) { + if (!it.use(null)) { items.remove(it); return; } } - } - } + } + } } - - - public void step(Field f) throws PlayerDiedException - { - if(field.isNeighbor(f)) { - this.field.remove(this); - work--; - f.accept(this); - if(work <= 0 && field.getCapacity() == 0) - die(); - } + + public void step(Field f) throws PlayerDiedException { + if (field.isNeighbor(f)) { + this.field.remove(this); + work--; + f.accept(this); + if (work <= 0 && field.getCapacity() == 0) { + die(); + } + } } public void setBodyTemp(int bodyTemp) { - this.bodyTemp=bodyTemp; + this.bodyTemp = bodyTemp; } - + public abstract void useSpecialAbility(Field f); //Segedfuggveny a teszthez. Nem a teszteset soran, hanem mar korabban megszerzett targy hozzaadása szereplohoz public void addItem(Item item) { - if(!items.contains(item)) + if (!items.contains(item)) { items.add(item); + } } public void addItem(String item) { Item newitem; - if(item.equals("FragileShovel")) { + if (item.equals("FragileShovel")) { newitem = new FragileShovel(); - } - else { - if(item.equals("Tent")) + } else { + if (item.equals("Tent")) { newitem = new Tent(); - else + } else { newitem = new Item(item); + } } - if(!items.contains(newitem)) + if (!items.contains(newitem)) { items.add(newitem); + } } //For initializing components @@ -274,18 +265,18 @@ public abstract class Person { public void enablePlayer() { setWork(4); - if(builtTent != null) { - builtTent.removeFromField(); - System.out.println("Sátor"); - builtTent = null; + if (builtTent != null) { + builtTent.removeFromField(); + System.out.println("Sátor"); + builtTent = null; } - } + } public void buildTent() { - if(work > 0) { - for(Item it : items) { - if(it.getName().equals("Tent")) { - if(it.use(field)) { + if (work > 0) { + for (Item it : items) { + if (it.getName().equals("Tent")) { + if (it.use(field)) { items.remove(it); work--; builtTent = (Tent) it; diff --git a/Arctic_Nigthmare/src/arctic_nightmare/ScaledImagePanel.java b/Arctic_Nigthmare/src/arctic_nightmare/ScaledImagePanel.java index 5cd674eb95e921be4413f01307f609ebb37929cc..93640acada5c3fd97a91fa5aa3fed83c07faf414 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/ScaledImagePanel.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/ScaledImagePanel.java @@ -1,34 +1,67 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package arctic_nightmare; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.RenderingHints; +import java.awt.image.BufferedImage; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; +/** + * Egy darab kep megjelenitesere hasznalt osztaly. + */ +public class ScaledImagePanel extends JLabel { -public class ScaledImagePanel extends JLabel{ - - + /** + * Altalanos konstruktor. Az egyszerubb hasznalat erdekeben a kepfajl nevet varja a kesz kep helyett. + * @param window az ablak, amihez a kepet hozza szeretnenk adni. + * @param file a fajl neve, amibol a kepet be szeretnenk tolteni. + * @param x a megjelenitett kep az ablakon belul kivant x koordinataja. + * @param y a megjelenitett kep az ablakon belul kivant x koordinataja. + * @param width a megjelenitett kep szelessege. + * @param height megjelenitett kep magassaga. + */ 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))); - setBounds(x, y, width, height); - setVisible(true); - window.add(this); + this(window, new ImageIcon(file), x, y, width, height); } - + + /** + * Altalanos konstruktor. + * @param window az ablak, amihez a kepet hozza szeretnenk adni. + * @param picture a kep, amit az ablakon meg szeretnenk jeleniteni. + * @param x a megjelenitett kep az ablakon belul kivant x koordinataja. + * @param y a megjelenitett kep az ablakon belul kivant x koordinataja. + * @param width a megjelenitett kep szelessege. + * @param height megjelenitett kep magassaga. + */ public ScaledImagePanel(JFrame window, ImageIcon picture, int x, int y, int width, int height) { - super(new ImageIcon(GameWindow.getScaledImage(picture.getImage(), width, height))); + super(new ImageIcon(ScaledImagePanel.getScaledImage(picture.getImage(), width, height))); setBounds(x, y, width, height); setVisible(true); window.add(this); } - void remove() - { + /** + * Kepek meretezesere hasznalt fuggveny. Azert statikus, mert a konstruktorban maskeppen nem tudnam haszanalni az os konstruktoranak hivasaval egy idoben. + * @param srcImg a meretezendo kep. + * @param w a kep kivant szelessege. + * @param h a kep kivant magassaga. + * @return az atmeretezett kep. + */ + static public Image getScaledImage(Image srcImg, int w, int h) { + BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); + Graphics2D g2 = resizedImg.createGraphics(); + g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); + g2.drawImage(srcImg, 0, 0, w, h, null); + g2.dispose(); + return resizedImg; + } + + /** + * Eltavolitja az objektumot.a szuloosztalybol + */ + void remove() { this.getParent().remove(this); - } -} \ No newline at end of file + } +} diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/bear.wav b/Arctic_Nigthmare/src/arctic_nightmare/bear.wav similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/bear.wav rename to Arctic_Nigthmare/src/arctic_nightmare/bear.wav diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/cartridge_covered.png b/Arctic_Nigthmare/src/arctic_nightmare/cartridge_covered.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/cartridge_covered.png rename to Arctic_Nigthmare/src/arctic_nightmare/cartridge_covered.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/cartridge_visible.png b/Arctic_Nigthmare/src/arctic_nightmare/cartridge_visible.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/cartridge_visible.png rename to Arctic_Nigthmare/src/arctic_nightmare/cartridge_visible.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/dig.wav b/Arctic_Nigthmare/src/arctic_nightmare/dig.wav similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/dig.wav rename to Arctic_Nigthmare/src/arctic_nightmare/dig.wav diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/divingsuit_covered.png b/Arctic_Nigthmare/src/arctic_nightmare/divingsuit_covered.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/divingsuit_covered.png rename to Arctic_Nigthmare/src/arctic_nightmare/divingsuit_covered.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/divingsuit_visible.png b/Arctic_Nigthmare/src/arctic_nightmare/divingsuit_visible.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/divingsuit_visible.png rename to Arctic_Nigthmare/src/arctic_nightmare/divingsuit_visible.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/eskimo.png b/Arctic_Nigthmare/src/arctic_nightmare/eskimo.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/eskimo.png rename to Arctic_Nigthmare/src/arctic_nightmare/eskimo.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/eskimo_half.png b/Arctic_Nigthmare/src/arctic_nightmare/eskimo_half.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/eskimo_half.png rename to Arctic_Nigthmare/src/arctic_nightmare/eskimo_half.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/explorer.png b/Arctic_Nigthmare/src/arctic_nightmare/explorer.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/explorer.png rename to Arctic_Nigthmare/src/arctic_nightmare/explorer.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/explorer_half.png b/Arctic_Nigthmare/src/arctic_nightmare/explorer_half.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/explorer_half.png rename to Arctic_Nigthmare/src/arctic_nightmare/explorer_half.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/field_0snow.png b/Arctic_Nigthmare/src/arctic_nightmare/field_0snow.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/field_0snow.png rename to Arctic_Nigthmare/src/arctic_nightmare/field_0snow.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/field_1snow.png b/Arctic_Nigthmare/src/arctic_nightmare/field_1snow.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/field_1snow.png rename to Arctic_Nigthmare/src/arctic_nightmare/field_1snow.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/field_2snow.png b/Arctic_Nigthmare/src/arctic_nightmare/field_2snow.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/field_2snow.png rename to Arctic_Nigthmare/src/arctic_nightmare/field_2snow.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/field_3snow.png b/Arctic_Nigthmare/src/arctic_nightmare/field_3snow.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/field_3snow.png rename to Arctic_Nigthmare/src/arctic_nightmare/field_3snow.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/field_4snow.png b/Arctic_Nigthmare/src/arctic_nightmare/field_4snow.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/field_4snow.png rename to Arctic_Nigthmare/src/arctic_nightmare/field_4snow.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/field_water.png b/Arctic_Nigthmare/src/arctic_nightmare/field_water.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/field_water.png rename to Arctic_Nigthmare/src/arctic_nightmare/field_water.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/food_covered.png b/Arctic_Nigthmare/src/arctic_nightmare/food_covered.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/food_covered.png rename to Arctic_Nigthmare/src/arctic_nightmare/food_covered.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/food_visible.png b/Arctic_Nigthmare/src/arctic_nightmare/food_visible.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/food_visible.png rename to Arctic_Nigthmare/src/arctic_nightmare/food_visible.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/fragile_shovel_covered.png b/Arctic_Nigthmare/src/arctic_nightmare/fragile_shovel_covered.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/fragile_shovel_covered.png rename to Arctic_Nigthmare/src/arctic_nightmare/fragile_shovel_covered.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/fragile_shovel_visible.png b/Arctic_Nigthmare/src/arctic_nightmare/fragile_shovel_visible.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/fragile_shovel_visible.png rename to Arctic_Nigthmare/src/arctic_nightmare/fragile_shovel_visible.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/icebear.gif b/Arctic_Nigthmare/src/arctic_nightmare/icebear.gif similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/icebear.gif rename to Arctic_Nigthmare/src/arctic_nightmare/icebear.gif diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/icebear.png b/Arctic_Nigthmare/src/arctic_nightmare/icebear.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/icebear.png rename to Arctic_Nigthmare/src/arctic_nightmare/icebear.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/icebear_half.png b/Arctic_Nigthmare/src/arctic_nightmare/icebear_half.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/icebear_half.png rename to Arctic_Nigthmare/src/arctic_nightmare/icebear_half.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/igloo_set.png b/Arctic_Nigthmare/src/arctic_nightmare/igloo_set.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/igloo_set.png rename to Arctic_Nigthmare/src/arctic_nightmare/igloo_set.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/logo.gif b/Arctic_Nigthmare/src/arctic_nightmare/logo.gif similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/logo.gif rename to Arctic_Nigthmare/src/arctic_nightmare/logo.gif diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/pistol_covered.png b/Arctic_Nigthmare/src/arctic_nightmare/pistol_covered.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/pistol_covered.png rename to Arctic_Nigthmare/src/arctic_nightmare/pistol_covered.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/pistol_visible.png b/Arctic_Nigthmare/src/arctic_nightmare/pistol_visible.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/pistol_visible.png rename to Arctic_Nigthmare/src/arctic_nightmare/pistol_visible.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/rope_covered.png b/Arctic_Nigthmare/src/arctic_nightmare/rope_covered.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/rope_covered.png rename to Arctic_Nigthmare/src/arctic_nightmare/rope_covered.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/rope_visible.png b/Arctic_Nigthmare/src/arctic_nightmare/rope_visible.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/rope_visible.png rename to Arctic_Nigthmare/src/arctic_nightmare/rope_visible.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/shovel.wav b/Arctic_Nigthmare/src/arctic_nightmare/shovel.wav similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/shovel.wav rename to Arctic_Nigthmare/src/arctic_nightmare/shovel.wav diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/shovel_covered.png b/Arctic_Nigthmare/src/arctic_nightmare/shovel_covered.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/shovel_covered.png rename to Arctic_Nigthmare/src/arctic_nightmare/shovel_covered.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/shovel_visible.png b/Arctic_Nigthmare/src/arctic_nightmare/shovel_visible.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/shovel_visible.png rename to Arctic_Nigthmare/src/arctic_nightmare/shovel_visible.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/signalflare_covered.png b/Arctic_Nigthmare/src/arctic_nightmare/signalflare_covered.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/signalflare_covered.png rename to Arctic_Nigthmare/src/arctic_nightmare/signalflare_covered.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/signalflare_visible.png b/Arctic_Nigthmare/src/arctic_nightmare/signalflare_visible.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/signalflare_visible.png rename to Arctic_Nigthmare/src/arctic_nightmare/signalflare_visible.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/storm.wav b/Arctic_Nigthmare/src/arctic_nightmare/storm.wav similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/storm.wav rename to Arctic_Nigthmare/src/arctic_nightmare/storm.wav diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/storm1.png b/Arctic_Nigthmare/src/arctic_nightmare/storm1.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/storm1.png rename to Arctic_Nigthmare/src/arctic_nightmare/storm1.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/storm2.png b/Arctic_Nigthmare/src/arctic_nightmare/storm2.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/storm2.png rename to Arctic_Nigthmare/src/arctic_nightmare/storm2.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/storm_cat.png b/Arctic_Nigthmare/src/arctic_nightmare/storm_cat.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/storm_cat.png rename to Arctic_Nigthmare/src/arctic_nightmare/storm_cat.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/tent_covered.png b/Arctic_Nigthmare/src/arctic_nightmare/tent_covered.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/tent_covered.png rename to Arctic_Nigthmare/src/arctic_nightmare/tent_covered.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/tent_set.png b/Arctic_Nigthmare/src/arctic_nightmare/tent_set.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/tent_set.png rename to Arctic_Nigthmare/src/arctic_nightmare/tent_set.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/tent_visible.png b/Arctic_Nigthmare/src/arctic_nightmare/tent_visible.png similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/tent_visible.png rename to Arctic_Nigthmare/src/arctic_nightmare/tent_visible.png diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/thunder1.wav b/Arctic_Nigthmare/src/arctic_nightmare/thunder1.wav similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/thunder1.wav rename to Arctic_Nigthmare/src/arctic_nightmare/thunder1.wav diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/thunder2.wav b/Arctic_Nigthmare/src/arctic_nightmare/thunder2.wav similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/thunder2.wav rename to Arctic_Nigthmare/src/arctic_nightmare/thunder2.wav diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/thunder3.wav b/Arctic_Nigthmare/src/arctic_nightmare/thunder3.wav similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/thunder3.wav rename to Arctic_Nigthmare/src/arctic_nightmare/thunder3.wav diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/thunder4.wav b/Arctic_Nigthmare/src/arctic_nightmare/thunder4.wav similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/thunder4.wav rename to Arctic_Nigthmare/src/arctic_nightmare/thunder4.wav diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/thunder5.wav b/Arctic_Nigthmare/src/arctic_nightmare/thunder5.wav similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/thunder5.wav rename to Arctic_Nigthmare/src/arctic_nightmare/thunder5.wav diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/water.wav b/Arctic_Nigthmare/src/arctic_nightmare/water.wav similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/water.wav rename to Arctic_Nigthmare/src/arctic_nightmare/water.wav diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/win.wav b/Arctic_Nigthmare/src/arctic_nightmare/win.wav similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/win.wav rename to Arctic_Nigthmare/src/arctic_nightmare/win.wav diff --git a/Arctic_Nigthmare/src/arctic_nightmare/resources/wow.wav b/Arctic_Nigthmare/src/arctic_nightmare/wow.wav similarity index 100% rename from Arctic_Nigthmare/src/arctic_nightmare/resources/wow.wav rename to Arctic_Nigthmare/src/arctic_nightmare/wow.wav