diff --git a/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Hero.class b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Hero.class new file mode 100644 index 000000000..4eb8ddb0e Binary files /dev/null and b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Hero.class differ diff --git a/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Hero_Factory.class b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Hero_Factory.class new file mode 100644 index 000000000..3b1f27365 Binary files /dev/null and b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Hero_Factory.class differ diff --git a/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Heroes.class b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Heroes.class new file mode 100644 index 000000000..9bdae1252 Binary files /dev/null and b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Heroes.class differ diff --git a/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Main.class b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Main.class new file mode 100644 index 000000000..571839e5e Binary files /dev/null and b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Main.class differ diff --git a/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Pyromancer.class b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Pyromancer.class new file mode 100644 index 000000000..8fb170c6a Binary files /dev/null and b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Pyromancer.class differ diff --git a/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Rogue.class b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Rogue.class new file mode 100644 index 000000000..388553375 Binary files /dev/null and b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Rogue.class differ diff --git a/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Strategy.class b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Strategy.class new file mode 100644 index 000000000..4d978fb95 Binary files /dev/null and b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Strategy.class differ diff --git a/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Wizard.class b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Wizard.class new file mode 100644 index 000000000..be8ef7455 Binary files /dev/null and b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/Wizard.class differ diff --git a/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/input.txt b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/input.txt new file mode 100644 index 000000000..f255cdab0 --- /dev/null +++ b/Project1_Delicostea_Robert_Alexandru/out/production/Project1_Delicostea_Robert_Alexandru/input.txt @@ -0,0 +1,17 @@ +5 +W 2000 0 0 +R 1500 3 4 +R 1000 4 5 +P 3000 2 3 +W 4050 6 7 +10 +3 4 +1 1 +1 1 +4 4 +-5 0 +1 1 +-1 -2 +-3 2 +5 7 +0 -4 \ No newline at end of file diff --git a/Project1_Delicostea_Robert_Alexandru/src/Hero.java b/Project1_Delicostea_Robert_Alexandru/src/Hero.java new file mode 100644 index 000000000..546feac43 --- /dev/null +++ b/Project1_Delicostea_Robert_Alexandru/src/Hero.java @@ -0,0 +1,9 @@ +public interface Hero { + void Hero_Strategy(Hero hero); + Enum getName(); + int getX(); + void setX(int x); + int getY(); + void setY(int y); + +} diff --git a/Project1_Delicostea_Robert_Alexandru/src/Hero_Factory.java b/Project1_Delicostea_Robert_Alexandru/src/Hero_Factory.java new file mode 100644 index 000000000..fdb99bdfd --- /dev/null +++ b/Project1_Delicostea_Robert_Alexandru/src/Hero_Factory.java @@ -0,0 +1,14 @@ +//Factory pattern for production of the heroes +public class Hero_Factory { + public Hero getHero(int life, Heroes name, int x, int y, int id){ + if(name == Heroes.P){ + return new Pyromancer(life, name, x, y, id); + }else if(name == Heroes.W){ + return new Wizard(life, Heroes.W, x, y, id); + }else if(name == Heroes.R){ + return new Rogue(life, name, x, y, id); + }else{ + return null; + } + } +} diff --git a/Project1_Delicostea_Robert_Alexandru/src/Heroes.java b/Project1_Delicostea_Robert_Alexandru/src/Heroes.java new file mode 100644 index 000000000..3d0b4548a --- /dev/null +++ b/Project1_Delicostea_Robert_Alexandru/src/Heroes.java @@ -0,0 +1,5 @@ +public enum Heroes { + P, + W, + R +} diff --git a/Project1_Delicostea_Robert_Alexandru/src/Main.java b/Project1_Delicostea_Robert_Alexandru/src/Main.java new file mode 100644 index 000000000..6d124177c --- /dev/null +++ b/Project1_Delicostea_Robert_Alexandru/src/Main.java @@ -0,0 +1,48 @@ +import java.io.File; +import java.io.IOException; +import java.io.*; +import java.util.ArrayList; +import java.util.List; + +public class Main { + public static void main(String[] args) throws IOException { + File file = new File("src/input.txt"); + BufferedReader br = new BufferedReader(new FileReader(file)); + String st; + Strategy strategy; + List heroes = new ArrayList<>(20); + Hero_Factory factory = new Hero_Factory(); + int n = Integer.parseInt(br.readLine()); + for(int i = 0; i < n; i++) + { + st=br.readLine(); + String[] arr = st.split(" ", 4); + + Heroes name = Heroes.valueOf(arr[0]); + int life = Integer.parseInt(arr[1]); + int x = Integer.parseInt(arr[2]); + int y = Integer.parseInt(arr[3]); + heroes.add(factory.getHero(life, name, x, y, i)); + + } + int m = Integer.parseInt(br.readLine()); + for(int i = 0; i < m; i++){ + st=br.readLine(); + String[] arr = st.split(" ", 2); + int x_dev = Integer.parseInt(arr[0]); + int y_dev = Integer.parseInt(arr[1]); + heroes.get(i%n).setX(heroes.get(i%n).getX() + x_dev); + heroes.get(i%n).setY(heroes.get(i%n).getY() + y_dev); + for(int j = (i%n) + 1; j < n; j++){ + if(heroes.get(i%n).getX() == heroes.get(j).getX() && heroes.get(i%n).getY() == heroes.get(j).getY()){ + strategy = new Strategy(heroes.get(i%n)); + strategy.execute_strategy(heroes.get(j)); + strategy = new Strategy(heroes.get(j)); + strategy.execute_strategy(heroes.get(i%n)); + } + } + } + + + } +} diff --git a/Project1_Delicostea_Robert_Alexandru/src/Pyromancer.java b/Project1_Delicostea_Robert_Alexandru/src/Pyromancer.java new file mode 100644 index 000000000..22d1bc654 --- /dev/null +++ b/Project1_Delicostea_Robert_Alexandru/src/Pyromancer.java @@ -0,0 +1,57 @@ +public class Pyromancer implements Hero { + private int life; + private Heroes name; + private int x, y; + private int id; + public Pyromancer(int life, Heroes name, int x, int y , int id){ + this.life = life; + this.name = name; + this.x = x; + this.y = y; + this.id = id; + } + public int getX(){ + return x; + } + public void setX(int x){ + this.x = x; + } + public int getY(){ + return y; + } + public void setY(int y){ + this.y = y; + } + public Heroes getName(){ + return name; + } + int getLife(){ + return life; + } + void setLife(int life){ + this.life =life; + } + @Override + public void Hero_Strategy(Hero hero) { + if(hero.getName() == Heroes.P){ + if(this.getLife() < 1000){ + this.setLife(this.getLife()/2); + }else{ + this.setLife((int) (0.75 * this.getLife())); + } + }else if(hero.getName() == Heroes.W){ + if(this.getLife() > 1000){ + this.setLife(this.getLife()/3); + }else{ + this.setLife((int) (0.66 * this.getLife())); + } + }else if(hero.getName() == Heroes.R){ + if(this.getLife() > 1000){ + this.setLife(this.getLife()/5); + }else{ + this.setLife((int) (0.5 * this.getLife())); + } + } + System.out.println("Hero " + this.getName() + " " + this.id + " has " + this.getLife() + " points left"); + } +} diff --git a/Project1_Delicostea_Robert_Alexandru/src/Rogue.java b/Project1_Delicostea_Robert_Alexandru/src/Rogue.java new file mode 100644 index 000000000..736cd262d --- /dev/null +++ b/Project1_Delicostea_Robert_Alexandru/src/Rogue.java @@ -0,0 +1,57 @@ +public class Rogue implements Hero { + private int life; + private Heroes name; + private int x, y; + private int id; + public Rogue(int life, Heroes name, int x, int y, int id){ + this.life = life; + this.name = name; + this.x = x; + this.y = y; + this.id = id; + } + public int getX(){ + return x; + } + public void setX(int x){ + this.x = x; + } + public int getY(){ + return y; + } + public void setY(int y){ + this.y = y; + } + public Heroes getName(){ + return name; + } + int getLife(){ + return life; + } + void setLife(int life){ + this.life =life; + } + @Override + public void Hero_Strategy(Hero hero) { + if(hero.getName() == Heroes.P){ + if(this.getLife() < 1000){ + this.setLife(this.getLife()/4); + }else{ + this.setLife((int) (0.25 * this.getLife())); + } + }else if(hero.getName() == Heroes.W){ + if(this.getLife() > 1000){ + this.setLife(this.getLife()/5); + }else{ + this.setLife((int) (0.4 * this.getLife())); + } + }else if(hero.getName() == Heroes.R){ + if(this.getLife() > 1000){ + this.setLife((int) (0.8 * this.getLife())); + }else{ + this.setLife((int) (this.getLife() / 5)); + } + } + System.out.println("Hero " + this.getName() + " " + this.id + " has " + this.getLife() + " points left"); + } +} diff --git a/Project1_Delicostea_Robert_Alexandru/src/Strategy.java b/Project1_Delicostea_Robert_Alexandru/src/Strategy.java new file mode 100644 index 000000000..ce0f21b37 --- /dev/null +++ b/Project1_Delicostea_Robert_Alexandru/src/Strategy.java @@ -0,0 +1,11 @@ +//Strategy pattern every hero executes his strategy considering his opponent, +// in Hero_Strategy method implemented from Hero interface +public class Strategy { + private Hero strategy; + public Strategy(Hero strategy){ + this.strategy = strategy; + } + void execute_strategy(Hero adversary){ + strategy.Hero_Strategy(adversary); + } +} diff --git a/Project1_Delicostea_Robert_Alexandru/src/Wizard.java b/Project1_Delicostea_Robert_Alexandru/src/Wizard.java new file mode 100644 index 000000000..916a285fd --- /dev/null +++ b/Project1_Delicostea_Robert_Alexandru/src/Wizard.java @@ -0,0 +1,57 @@ +public class Wizard implements Hero { + private int life; + private Heroes name; + private int x, y; + private int id; + public Heroes getName(){ + return name; + } + public Wizard(int life, Heroes name, int x, int y, int id){ + this.life = life; + this.name = name; + this.x = x; + this.y = y; + this.id = id; + } + public int getX(){ + return x; + } + public void setX(int x){ + this.x = x; + } + public int getY(){ + return y; + } + public void setY(int y){ + this.y = y; + } + int getLife(){ + return life; + } + void setLife(int life){ + this.life =life; + } + @Override + public void Hero_Strategy(Hero hero) { + if(hero.getName() == Heroes.P){ + if(this.getLife() < 1000){ + this.setLife(this.getLife()/3 + this.getLife()/5); + }else{ + this.setLife((int) (0.8 * this.getLife())); + } + }else if(hero.getName() == Heroes.W){ + if(this.getLife() > 1000){ + this.setLife(this.getLife()/2); + }else{ + this.setLife((int) (0.25 * this.getLife())); + } + }else if(hero.getName() == Heroes.R){ + if(this.getLife() > 1000){ + this.setLife(this.getLife()/6); + }else{ + this.setLife((int) (0.35 * this.getLife())); + } + } + System.out.println("Hero " + this.getName() + " " + this.id + " has " + this.getLife() + " points left"); + } +} diff --git a/Project1_Delicostea_Robert_Alexandru/src/input.txt b/Project1_Delicostea_Robert_Alexandru/src/input.txt new file mode 100644 index 000000000..f255cdab0 --- /dev/null +++ b/Project1_Delicostea_Robert_Alexandru/src/input.txt @@ -0,0 +1,17 @@ +5 +W 2000 0 0 +R 1500 3 4 +R 1000 4 5 +P 3000 2 3 +W 4050 6 7 +10 +3 4 +1 1 +1 1 +4 4 +-5 0 +1 1 +-1 -2 +-3 2 +5 7 +0 -4 \ No newline at end of file diff --git a/_1_basics/src/main/java/code/_3_in_class/HelloWorld.java b/_1_basics/src/main/java/code/_3_in_class/HelloWorld.java index ce7a7ffe1..9a872f8a2 100644 --- a/_1_basics/src/main/java/code/_3_in_class/HelloWorld.java +++ b/_1_basics/src/main/java/code/_3_in_class/HelloWorld.java @@ -1,7 +1,7 @@ package code._3_in_class; public class HelloWorld { - + //niceeeeee public static void main(String[] args) { System.out.println("hello world 2"); }