Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions Project1_Delicostea_Robert_Alexandru/src/Hero.java
Original file line number Diff line number Diff line change
@@ -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);

}
14 changes: 14 additions & 0 deletions Project1_Delicostea_Robert_Alexandru/src/Hero_Factory.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
5 changes: 5 additions & 0 deletions Project1_Delicostea_Robert_Alexandru/src/Heroes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public enum Heroes {
P,
W,
R
}
48 changes: 48 additions & 0 deletions Project1_Delicostea_Robert_Alexandru/src/Main.java
Original file line number Diff line number Diff line change
@@ -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<Hero> 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));
}
}
}


}
}
57 changes: 57 additions & 0 deletions Project1_Delicostea_Robert_Alexandru/src/Pyromancer.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
57 changes: 57 additions & 0 deletions Project1_Delicostea_Robert_Alexandru/src/Rogue.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
11 changes: 11 additions & 0 deletions Project1_Delicostea_Robert_Alexandru/src/Strategy.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
57 changes: 57 additions & 0 deletions Project1_Delicostea_Robert_Alexandru/src/Wizard.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
17 changes: 17 additions & 0 deletions Project1_Delicostea_Robert_Alexandru/src/input.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion _1_basics/src/main/java/code/_3_in_class/HelloWorld.java
Original file line number Diff line number Diff line change
@@ -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");
}
Expand Down