diff --git a/bin/szoftlab4/Application.class b/bin/szoftlab4/Application.class index c43c944..e3753eb 100644 Binary files a/bin/szoftlab4/Application.class and b/bin/szoftlab4/Application.class differ diff --git a/bin/szoftlab4/Ellenseg.class b/bin/szoftlab4/Ellenseg.class index 7354bd4..4ef8df8 100644 Binary files a/bin/szoftlab4/Ellenseg.class and b/bin/szoftlab4/Ellenseg.class differ diff --git a/src/szoftlab4/Application.java b/src/szoftlab4/Application.java index e2b5abc..f74e8d4 100644 --- a/src/szoftlab4/Application.java +++ b/src/szoftlab4/Application.java @@ -194,13 +194,13 @@ public static void printstate() { for (int i = 0; i < game.ellenseglista.size(); i++) { if (game.ellenseglista.get(i) instanceof Hobbit) - System.out.println("Hobbit " + game.ellenseglista.get(i).id); + System.out.println("Hobbit " + game.ellenseglista.get(i).id + " " + Application.game.getCoord(game.ellenseglista.get(i).sajatUt).x + " " + Application.game.getCoord(game.ellenseglista.get(i).sajatUt).y); if (game.ellenseglista.get(i) instanceof Ember) - System.out.println("Ember " + game.ellenseglista.get(i).id); + System.out.println("Ember " + game.ellenseglista.get(i).id + " " + Application.game.getCoord(game.ellenseglista.get(i).sajatUt).x + " " + Application.game.getCoord(game.ellenseglista.get(i).sajatUt).y); if (game.ellenseglista.get(i) instanceof Tunde) - System.out.println("Tunde " + game.ellenseglista.get(i).id); + System.out.println("Tunde " + game.ellenseglista.get(i).id + " " + Application.game.getCoord(game.ellenseglista.get(i).sajatUt).x + " " + Application.game.getCoord(game.ellenseglista.get(i).sajatUt).y); if (game.ellenseglista.get(i) instanceof Torpe) - System.out.println("Torpe " + game.ellenseglista.get(i).id); + System.out.println("Torpe " + game.ellenseglista.get(i).id + " " + Application.game.getCoord(game.ellenseglista.get(i).sajatUt).x + " " + Application.game.getCoord(game.ellenseglista.get(i).sajatUt).y ); } for (int i = 0; i < game.akadalylista.size(); i++) { @@ -215,7 +215,8 @@ public static void tick(String args[]) { count = Integer.parseInt(args[1]); else count = 1; - int i = 0; + + int i=0; for (i = 0; i < count; i++) { for (int j = 0; j < game.controller.aktiv.size(); j++) { game.controller.aktiv.get(j).tick(); @@ -276,348 +277,321 @@ public static void printgems() { public static void buygem(String args[]) { boolean success = false; - if (args[0].matches("barna") - && game.jatekter.felhasznalo.varazsero > 50) { - game.jatekter.felhasznalo.varazskovek.add(new Barnavarazsko()); + if(args.length > 1){ + if (args[1].matches("barna")){ + if(game.jatekter.felhasznalo.varazsero >= 50){ + game.jatekter.felhasznalo.varazskovek.add(new Barnavarazsko()); + } + else System.out.println("Nincs eleg varazsero"); success = true; } - if (args[0].matches("kek") && game.jatekter.felhasznalo.varazsero > 50) { - game.jatekter.felhasznalo.varazskovek.add(new Kekvarazsko()); + else if (args[1].matches("kek")){ + if(game.jatekter.felhasznalo.varazsero >= 50){ + game.jatekter.felhasznalo.varazskovek.add(new Kekvarazsko()); + } + else System.out.println("Nincs eleg varazsero"); success = true; } - if (args[0].matches("lila") && game.jatekter.felhasznalo.varazsero > 50) { - game.jatekter.felhasznalo.varazskovek.add(new Lilavarazsko()); + else if (args[1].matches("lila")){ + if(game.jatekter.felhasznalo.varazsero >= 50){ + game.jatekter.felhasznalo.varazskovek.add(new Lilavarazsko()); + } + else System.out.println("Nincs eleg varazsero"); success = true; } - if (args[0].matches("narancs") - && game.jatekter.felhasznalo.varazsero > 50) { - game.jatekter.felhasznalo.varazskovek.add(new Narancsvarazsko()); + else if (args[1].matches("narancs")){ + if(game.jatekter.felhasznalo.varazsero >= 50){ + game.jatekter.felhasznalo.varazskovek.add(new Narancsvarazsko()); + } + else System.out.println("Nincs eleg varazsero"); success = true; } - if (args[0].matches("piros") - && game.jatekter.felhasznalo.varazsero > 50) { - game.jatekter.felhasznalo.varazskovek.add(new Pirosvarazsko()); + else if (args[1].matches("piros")){ + if(game.jatekter.felhasznalo.varazsero >= 50){ + game.jatekter.felhasznalo.varazskovek.add(new Pirosvarazsko()); + } + else System.out.println("Nincs eleg varazsero"); success = true; } - if (args[0].matches("sarga") - && game.jatekter.felhasznalo.varazsero > 50) { - game.jatekter.felhasznalo.varazskovek.add(new Sargavarazsko()); + else if (args[1].matches("sarga")){ + if(game.jatekter.felhasznalo.varazsero >= 50){ + game.jatekter.felhasznalo.varazskovek.add(new Sargavarazsko()); + } + else System.out.println("Nincs eleg varazsero"); success = true; } - if (args[0].matches("zold") && game.jatekter.felhasznalo.varazsero > 50) { - game.jatekter.felhasznalo.varazskovek.add(new Zoldvarazsko()); + else if (args[1].matches("zold")){ + if(game.jatekter.felhasznalo.varazsero >= 50){ + game.jatekter.felhasznalo.varazskovek.add(new Zoldvarazsko()); + } + else System.out.println("Nincs eleg varazsero"); success = true; } - + } if (!success) System.out.println("Bad parameter"); + else System.out.println("Varazsko megvasarolva"); } public static void addtower(String args[]) { - int sor = Integer.parseInt(args[2]); - int oszlop = Integer.parseInt(args[3]); - boolean joid = true; - - for (int i = 0; i < game.toronylista.size(); i++) { - if (game.toronylista.get(i).id.matches(args[1])) - joid = false; - } - - if (joid) { - Torony uj = new Torony(args[1]); - game.toronylista.add(uj); - Cella valasztott = game.jatekter.cellak.get(sor).get(oszlop); - if (valasztott.mezovagyok()) - game.jatekter.felhasznalo.ujTorony((Mezo) valasztott, uj); - } else { - System.out.println("Mar letezo ID"); + if(args.length > 3){ + int sor = Integer.parseInt(args[2]); + int oszlop = Integer.parseInt(args[3]); + boolean joid = true; + + for (int i = 0; i < game.toronylista.size(); i++) { + if (game.toronylista.get(i).id.matches(args[1])) + joid = false; + } + + if (joid) { + Torony uj = new Torony(); + game.toronylista.add(uj); + game.controller.addAktiv(uj); + Cella valasztott = game.jatekter.cellak.get(sor).get(oszlop); + if (valasztott.mezovagyok()){ + game.jatekter.felhasznalo.ujTorony((Mezo) valasztott, uj); + uj.id =args[1]; + } + } else { + System.out.println("Mar letezo ID"); + } } + else System.out.println("Bad parameter"); } public static void addtowergem(String args[]) { - int id = 0; - boolean success = false; - Torony erre = null; - for (int i = 0; i < game.toronylista.size(); i++) { - if (game.toronylista.get(i).id.matches(args[1])) - id = Integer.parseInt(game.toronylista.get(i).id); - erre = game.toronylista.get(i); - } - if (id == 0) { - System.out.println("Nem letezo ID"); - } - - if (erre != null) { - if (args[2].matches("barna")) { - game.jatekter.felhasznalo.fejleszt(erre, new Barnavarazsko()); - success = true; - } - if (args[2].matches("kek")) { - game.jatekter.felhasznalo.fejleszt(erre, new Kekvarazsko()); - success = true; - } - if (args[2].matches("narancs")) { - game.jatekter.felhasznalo.fejleszt(erre, new Narancsvarazsko()); - success = true; - } - if (args[2].matches("piros")) { - game.jatekter.felhasznalo.fejleszt(erre, new Pirosvarazsko()); - success = true; - } - if (args[2].matches("sarga")) { - game.jatekter.felhasznalo.fejleszt(erre, new Sargavarazsko()); - success = true; + if(args.length > 2){ + int id = 0; + boolean success = false; + Torony erre = null; + for (int i = 0; i < game.toronylista.size(); i++) { + if(game.toronylista.get(i).id.matches(args[1])) erre = game.toronylista.get(i); } - if (args[2].matches("zold")) { - game.jatekter.felhasznalo.fejleszt(erre, new Zoldvarazsko()); - success = true; + if(erre == null) System.out.println("Bad parameter"); + + if (erre != null) { + if (args[2].matches("barna")) { + game.jatekter.felhasznalo.fejleszt(erre, new Barnavarazsko()); + success = true; + } + if (args[2].matches("kek")) { + game.jatekter.felhasznalo.fejleszt(erre, new Kekvarazsko()); + success = true; + } + if (args[2].matches("narancs")) { + game.jatekter.felhasznalo.fejleszt(erre, new Narancsvarazsko()); + success = true; + } + if (args[2].matches("piros")) { + game.jatekter.felhasznalo.fejleszt(erre, new Pirosvarazsko()); + success = true; + } + if (args[2].matches("sarga")) { + game.jatekter.felhasznalo.fejleszt(erre, new Sargavarazsko()); + success = true; + } + if (args[2].matches("zold")) { + game.jatekter.felhasznalo.fejleszt(erre, new Zoldvarazsko()); + success = true; + } } + + if (!success) + System.out.println("Bad parameter"); + if (success) + System.out.println("Varazsko hozzaadva"); } - - if (!success) - System.out.println("Bad parameter"); - if (success) - System.out.println("Varazsko hozzaadva"); + else System.out.println("Bad parameter"); } public static void addtrapgem(String args[]) { - boolean megvan = false; - int index = 0; - Lilavarazsko l = new Lilavarazsko(); - if (game.jatekter.felhasznalo.varazskovek.contains(l)) { - - while (megvan == false && index < game.akadalylista.size()) { - if (game.akadalylista.get(index).id.equals(args[1])) { - game.akadalylista.get(index).addko(l); - System.out.printf("Varazsko hozzaadva \n"); - megvan = true; - - } else { - index++; - } + if(args.length > 2){ + int id = 0; + boolean success = false; + Akadaly erre = null; + for (int i = 0; i < game.akadalylista.size(); i++) { + if(game.akadalylista.get(i).id.matches(args[1])) erre = game.akadalylista.get(i); } - if (megvan == false) { - System.out.printf("Nem letezo ID \n"); + if(erre == null) System.out.println("Bad parameter"); + + if (erre != null) { + if (args[2].matches("lila")) { + game.jatekter.felhasznalo.fejleszt(erre, new Lilavarazsko()); + success = true; + } } - } else { - System.out.printf("Nem letezo varazsko \n"); + + if (!success) + System.out.println("Bad parameter"); + if (success) + System.out.println("Varazsko hozzaadva"); } + else System.out.println("Bad parameter"); } public static void addenemy(String args[]) { - int sor = Integer.parseInt(args[3]); - int oszlop = Integer.parseInt(args[4]); - Cella valasztott = (Ut)game.jatekter.cellak.get(sor).get(oszlop); - if (!valasztott.mezovagyok()) { - int type = 0; - if (args[1].matches("hobbit")) - type = 0; - else if (args[1].matches("ember")) - type = 1; - else if (args[1].matches("tunder")) - type = 2; - else if (args[1].matches("torpe")) - type = 3; - else{ - System.out.println("Bad parameter"); - return; - } - - switch (type) { - case 0: - Hobbit h = new Hobbit((Ut) valasztott); - h.id = args[2]; - valasztott.ratesz(h); - game.ellenseglista.add(h); - System.out.println("Ellenseg letrehozva"); - break; - case 1: - Ember e = new Ember((Ut) valasztott); - e.id = args[2]; - valasztott.ratesz(e); - game.ellenseglista.add(e); - System.out.println("Ellenseg letrehozva"); - break; - case 2: - Tunde t = new Tunde((Ut) valasztott); - t.id = args[2]; - valasztott.ratesz(t); - game.ellenseglista.add(t); - System.out.println("Ellenseg letrehozva"); - break; - case 3: - Torpe t1 = new Torpe((Ut) valasztott); - t1.id = args[2]; - valasztott.ratesz(t1); - game.ellenseglista.add(t1); - System.out.println("Ellenseg letrehozva"); - break; - default: - System.out.println("Bad parameter"); + if(args.length > 4){ + int sor = Integer.parseInt(args[3]); + int oszlop = Integer.parseInt(args[4]); + Cella valasztott = (Ut)game.jatekter.cellak.get(sor).get(oszlop); + if (!valasztott.mezovagyok()) { + int type = 0; + if (args[1].matches("hobbit")) + type = 0; + else if (args[1].matches("ember")) + type = 1; + else if (args[1].matches("tunder")) + type = 2; + else if (args[1].matches("torpe")) + type = 3; + else{ + System.out.println("Bad parameter"); + return; + } + + switch (type) { + case 0: + Hobbit h = new Hobbit((Ut) valasztott); + h.id = args[2]; + valasztott.ratesz(h); + game.ellenseglista.add(h); + game.controller.addAktiv(h); + System.out.println("Ellenseg letrehozva"); + break; + case 1: + Ember e = new Ember((Ut) valasztott); + e.id = args[2]; + valasztott.ratesz(e); + game.ellenseglista.add(e); + game.controller.addAktiv(e); + System.out.println("Ellenseg letrehozva"); + break; + case 2: + Tunde t = new Tunde((Ut) valasztott); + t.id = args[2]; + valasztott.ratesz(t); + game.ellenseglista.add(t); + game.controller.addAktiv(t); + System.out.println("Ellenseg letrehozva"); + break; + case 3: + Torpe t1 = new Torpe((Ut) valasztott); + t1.id = args[2]; + valasztott.ratesz(t1); + game.ellenseglista.add(t1); + game.controller.addAktiv(t1); + System.out.println("Ellenseg letrehozva"); + break; + default: + System.out.println("Bad parameter"); + } + + + } else { + System.out.printf(" Nem mezo, vagy valami baj van \n"); } - - - } else { - System.out.printf(" Nem mezo, vagy valami baj van \n"); } + else System.out.println("Bad parameter"); } public static void addspecialprojectile(String args[]) { - if (args.length == 1) { + if (args.length > 1) { Torony ebben = null; for (int i = 0; i < game.toronylista.size(); i++) { - if (args[1].matches(game.toronylista.get(i).id)) - ; - ebben = game.toronylista.get(i); + if (args[1].matches(game.toronylista.get(i).id)) ebben = game.toronylista.get(i); + } + if(ebben != null){ + ebben.specprojectile = true; + System.out.println("Specialis lovedek hozzaadva"); } - ebben.specprojectile = true; - System.out.println("Specialis lovedek hozzaadva"); + else System.out.println("Bad parameters"); + - } else - System.out.println("Bad parameters"); + } + else System.out.println("Bad parameters"); } public static void addfog(String args[]) { - boolean megvan = false; - int index = 0; - while (megvan == false && index < game.toronylista.size()) { - if (game.toronylista.get(index).id == args[0]) { - game.toronylista.get(index).kodosit(); - megvan = true; + if(args.length > 1){ + Torony ebben = null; + for (int i = 0; i < game.toronylista.size(); i++) { + if (args[1].matches(game.toronylista.get(i).id)) ebben = game.toronylista.get(i); + } + if(ebben != null){ + ebben.kodosit(); System.out.println("Kod hozzaadva"); - } else { - index++; } + else System.out.println("Bad parameters"); + } - if (!megvan) - System.out.println("Nem letezo ID"); + else System.out.println("Bad parameters"); } public static void enemydirection(String args[]) { - boolean megvan = false; - int index = 0; - for (Ellenseg ell : game.ellenseglista) { - if (ell.id.matches(args[1])) { - index = game.ellenseglista.indexOf(ell); - megvan = true; - } - } - - - - if (megvan) { - Ellenseg temp = game.ellenseglista.get(index); - int irany; - if (args[2].matches("N")) - irany = 1; - else if (args[2].matches("S")) - irany = 2; - else if (args[2].matches("E")) - irany = 3; - else if (args[2].matches("W")) - irany = 4; - else - irany = 0; - int x, y; - switch (irany) { - case 1: - x = Application.game.getCoord(temp.sajatUt).x; - y = Application.game.getCoord(temp.sajatUt).y; - y--; - - for (Cella sj : temp.sajatUt.szomszedok) { - if (Application.game.getCoord(sj).x == x - && Application.game.getCoord(sj).y == y) { - sj.ratesz(temp); - System.out.println("Ellenseg iranya beallitva"); - return; - } - } - System.out.println("Invalid Parameter"); - break; - - case 2: - x = Application.game.getCoord(temp.sajatUt).x; - y = Application.game.getCoord(temp.sajatUt).y; - y++; - - for (Cella sj : temp.sajatUt.szomszedok) { - if (Application.game.getCoord(sj).x == x - && Application.game.getCoord(sj).y == y) { - sj.ratesz(temp); - System.out.println("Ellenseg iranya beallitva"); - return; - } - } - System.out.println("Invalid Parameter"); - break; - - case 3: - x = Application.game.getCoord(temp.sajatUt).x; - y = Application.game.getCoord(temp.sajatUt).y; - x--; - - for (Cella sj : temp.sajatUt.szomszedok) { - if (Application.game.getCoord(sj).x == x - && Application.game.getCoord(sj).y == y) { - sj.ratesz(temp); - System.out.println("Ellenseg iranya beallitva"); - return; - } - } - System.out.println("Invalid Parameter"); - break; - - case 4: - x = Application.game.getCoord(temp.sajatUt).x; - y = Application.game.getCoord(temp.sajatUt).y; - x++; - - for (Cella sj : temp.sajatUt.szomszedok) { - if (Application.game.getCoord(sj).x == x - && Application.game.getCoord(sj).y == y) { - sj.ratesz(temp); - System.out.println("Ellenseg iranya beallitva"); - return; - } + if(args.length > 2){ + boolean megvan = false; + int index = 0; + for (Ellenseg ell : game.ellenseglista) { + if (ell.id.matches(args[1])) { + index = game.ellenseglista.indexOf(ell); + megvan = true; } - System.out.println("Invalid Parameter"); - break; - case 0: - default: - System.out.printf("Invalid Parameter \n"); - break; - } - } else - System.out.printf("Invalid Parameter \n"); + + + + if (megvan) { + Ellenseg temp = game.ellenseglista.get(index); + if (args[2].matches("N")) + temp.irany = 1; + else if (args[2].matches("S")) + temp.irany = 2; + else if (args[2].matches("E")) + temp.irany = 3; + else if (args[2].matches("W")) + temp.irany = 4; + else + temp.irany = 0; + + System.out.println("Ellenseg iranyba alltiva"); + } else + System.out.printf("Invalid Parameter \n"); + + } + else System.out.println("Bad parameters"); } public static void addtrap(String[] args) { - int sor = Integer.parseInt(args[2]); - int oszlop = Integer.parseInt(args[3]); - boolean joid = true; - - for (int i = 0; i < game.akadalylista.size(); i++) { - if (game.akadalylista.get(i).id.matches(args[1])) - joid = false; - } - - if (joid) { - Akadaly uj = new Akadaly(args[1]); - game.akadalylista.add(uj); - Cella valasztott = game.jatekter.cellak.get(sor).get(oszlop); - if (!valasztott.mezovagyok()) - game.jatekter.felhasznalo.ujAkadaly((Ut) valasztott, uj); - } else { - System.out.println("Mar letezo ID"); + if(args.length > 3){ + int sor = Integer.parseInt(args[2]); + int oszlop = Integer.parseInt(args[3]); + boolean joid = true; + + for (int i = 0; i < game.akadalylista.size(); i++) { + if (game.akadalylista.get(i).id.matches(args[1])) + joid = false; + } + + if (joid) { + Akadaly uj = new Akadaly(); + game.akadalylista.add(uj); + Cella valasztott = game.jatekter.cellak.get(sor).get(oszlop); + if (!valasztott.mezovagyok()){ + game.jatekter.felhasznalo.ujAkadaly((Ut) valasztott, uj); + uj.id =args[1]; + } + } else { + System.out.println("Mar letezo ID"); + } } + else System.out.println("Bad parameters"); } public static void exit() { diff --git a/src/szoftlab4/Ellenseg.java b/src/szoftlab4/Ellenseg.java index 2796c4f..cd9fb51 100644 --- a/src/szoftlab4/Ellenseg.java +++ b/src/szoftlab4/Ellenseg.java @@ -1,12 +1,12 @@ package szoftlab4; -import java.io.IOException; -import java.util.Random; import java.util.ArrayList; public class Ellenseg implements Utravalo, Aktiv { public String id; + public int irany=0; + public int count=0; //Tartalmazza hogy az Elenség éppen melyik mezőn van rajta public Ut sajatUt; @@ -31,10 +31,12 @@ public Ellenseg(Ut sajat){ //Leszármazott osztályban felülírni! public void tick(){ - if(false){ + if(count%4 == 0){ ArrayList lehetsegesutak = sajatUt.lepnek(); lepek(lehetsegesutak); - } + System.out.println(lehetsegesutak.size()); + count = 0; + } else count++; } @@ -69,10 +71,69 @@ public void sebez(Lovedek lovedek){ //Kiválaszt egy utat ahova lépni szeretne public void lepek(ArrayList utak){ - Random randomGenerator = new Random(); - int index = randomGenerator.nextInt(utak.size()); - Ut kovetkezout = utak.get(index); - kovetkezout.ratesz(this); + int x,y; + switch (irany) { + case 1: + x = Application.game.getCoord(sajatUt).x; + y = Application.game.getCoord(sajatUt).y; + y--; + + for (Cella sj : utak) { + if (Application.game.getCoord(sj).x == x + && Application.game.getCoord(sj).y == y) { + sj.ratesz(this); + return; + } + } + break; + + case 2: + x = Application.game.getCoord(sajatUt).x; + y = Application.game.getCoord(sajatUt).y; + y++; + + for (Cella sj : utak) { + if (Application.game.getCoord(sj).x == x + && Application.game.getCoord(sj).y == y) { + sj.ratesz(this); + return; + } + } + break; + + case 3: + x = Application.game.getCoord(sajatUt).x; + y = Application.game.getCoord(sajatUt).y; + x--; + + for (Cella sj : utak) { + if (Application.game.getCoord(sj).x == x + && Application.game.getCoord(sj).y == y) { + sj.ratesz(this); + return; + } + } + break; + + case 4: + x = Application.game.getCoord(sajatUt).x; + y = Application.game.getCoord(sajatUt).y; + x++; + + for (Cella sj : utak) { + if (Application.game.getCoord(sj).x == x + && Application.game.getCoord(sj).y == y) { + sj.ratesz(this); + return; + } + } + break; + case 0: + default: + break; + + } + } //A sajatUt attribútumot inicializálja