diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..19dd361 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..4261cfa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/homework-java-ironbattle.iml b/.idea/homework-java-ironbattle.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/homework-java-ironbattle.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..da84b14 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..54cb84e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HomeWork1/README.md b/HomeWork1/README.md new file mode 100644 index 0000000..2307309 --- /dev/null +++ b/HomeWork1/README.md @@ -0,0 +1,26 @@ +# Text-Based Battle Simulator + +## Description +This is a console-based Java battle simulator where Warriors and Wizards fight in a 1v1 duel. +The battle is round-based and continues until there is a single winner. If both characters die in the same round, the battle restarts. + +## Features +- Object-Oriented Design (Inheritance, Polymorphism, Interface) +- Warrior and Wizard character types +- Random stat generation +- Round-based combat system +- Detailed battle log in console +- Tie detection and automatic restart +- Text-based menu navigation + +## How to Run +1. Clone the repository +2. Open the project in your IDE +3. Run `Main.java` +4. Use the console menu to create characters and start the battle + +## Technologies Used +- Java +- OOP Principles +- Scanner (Standard Input) +- Random class \ No newline at end of file diff --git a/HomeWork1/pom.xml b/HomeWork1/pom.xml new file mode 100644 index 0000000..4b11559 --- /dev/null +++ b/HomeWork1/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.example + HomeWork1 + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/HomeWork1/src/main/java/org/example/Attacker.java b/HomeWork1/src/main/java/org/example/Attacker.java new file mode 100644 index 0000000..cf3321e --- /dev/null +++ b/HomeWork1/src/main/java/org/example/Attacker.java @@ -0,0 +1,7 @@ +package org.example; + +public interface Attacker { + + void attack(Character target); + +} diff --git a/HomeWork1/src/main/java/org/example/BattleSimulator.java b/HomeWork1/src/main/java/org/example/BattleSimulator.java new file mode 100644 index 0000000..0e63a8e --- /dev/null +++ b/HomeWork1/src/main/java/org/example/BattleSimulator.java @@ -0,0 +1,39 @@ +package org.example; + +public class BattleSimulator { + + public static void fight(Character c1, Character c2){ + + while (true) { +// Wizard wizard1=(Wizard) wizard; +// Warrior warrior1=(Warrior) warrior; + + int round = 1; + + while (c1.isAlive() && c2.isAlive()) { + + System.out.println("===== ROUND " + round + " ====="); + + c1.attack(c2); + c2.attack(c1); + + round++; + } + + if (!c1.isAlive() && !c2.isAlive()) { + System.out.println("It's a TIE! Restarting battle..."); + + + } + else if (c1.isAlive()) { + System.out.println(c1.getName() + " WINS!"); + break; + } + else { + System.out.println(c2.getName() + " WINS!"); + break; + } + } + } + +} diff --git a/HomeWork1/src/main/java/org/example/Character.java b/HomeWork1/src/main/java/org/example/Character.java new file mode 100644 index 0000000..e704a42 --- /dev/null +++ b/HomeWork1/src/main/java/org/example/Character.java @@ -0,0 +1,46 @@ +package org.example; + +import java.util.UUID; + +public abstract class Character implements Attacker { + + private String id; + private String name; + private int hp; + private boolean isAlive=true; + public Character(String name, int hp){ + this.id= UUID.randomUUID().toString().substring(0,8); + this.name=name; + this.hp=hp; + } + + public String getId(){ + return id; + } + public String getName(){ + return name; + } + + public int getHp(){ + return hp; + } + public boolean isAlive() { + return isAlive; + } + + public void setHp(int hp){ + this.hp=hp; + if(this.hp<=0){ + this.hp=0; + this.isAlive=false; + } + + } + + public void setName(String name){ + this.name=name; + } + + + +} diff --git a/HomeWork1/src/main/java/org/example/Main.java b/HomeWork1/src/main/java/org/example/Main.java new file mode 100644 index 0000000..01def53 --- /dev/null +++ b/HomeWork1/src/main/java/org/example/Main.java @@ -0,0 +1,97 @@ +package org.example; + +import java.util.Random; +import java.util.Scanner; + + +public class Main { + public static void main(String[] args) { + + Scanner scanner = new Scanner(System.in); + Random random = new Random(); + + Character player1 = null; + Character player2 = null; + + while (true) { + System.out.println("1. Create Player 1"); + System.out.println("2. Create Player 2"); + System.out.println("3. Start Battle"); + System.out.println("4. Exit"); + System.out.print("Choose option: "); + + int choice = scanner.nextInt(); + scanner.nextLine(); + + switch (choice) { + + case 1: + player1 = createCharacter(scanner, random); + break; + + case 2: + player2 = createCharacter(scanner, random); + break; + case 3: + if (player1 == null || player2 == null) { + System.out.println("Both players must be created first!"); + } else { + BattleSimulator.fight(player1, player2); + } + break; + + case 4: + System.out.println("Exiting game..."); + return; + + default: + System.out.println("Invalid option!"); + } + } + } + + private static Character createCharacter(Scanner scanner, Random random) { + + System.out.println("Choose character type:"); + System.out.println("1. Warrior"); + System.out.println("2. Wizard"); + System.out.print("Your choice: "); + + int type = scanner.nextInt(); + scanner.nextLine(); + + System.out.print("Enter name: "); + String name = scanner.nextLine(); + + if (type == 1) { + + int hp = random.nextInt(101) + 100; + int stamina = random.nextInt(41) + 10; + int strength = random.nextInt(10) + 1; + + Warrior warrior = new Warrior(name, hp, stamina, strength); + + System.out.println("Warrior created!"); + System.out.println("HP: " + hp + " | Stamina: " + stamina + " | Strength: " + strength); + + return warrior; + + } else if (type == 2) { + + int hp = random.nextInt(51) + 50; // 50-100 + int mana = random.nextInt(41) + 10; // 10-50 + int intelligence = random.nextInt(50) + 1; // 1-50 + + Wizard wizard = new Wizard(name, hp, mana, intelligence); + + System.out.println("Wizard created!"); + System.out.println("HP: " + hp + " | Mana: " + mana + " | Intelligence: " + intelligence); + + return wizard; + + } else { + System.out.println("Invalid type!"); + return null; + } + } +} diff --git a/HomeWork1/src/main/java/org/example/Warrior.java b/HomeWork1/src/main/java/org/example/Warrior.java new file mode 100644 index 0000000..3b5e63a --- /dev/null +++ b/HomeWork1/src/main/java/org/example/Warrior.java @@ -0,0 +1,58 @@ +package org.example; + +public class Warrior extends Character { + private int stamina; + private int strength; + public Warrior(String name, int hp, int stamina, int strength){ + super(name,hp); + this.stamina=stamina; + this.strength=strength; + } + + public int getStamina(){ + return stamina; + } + + public int getStrength(){ + return strength; + } + + public void setStamina(int stamina){ + this.stamina=stamina; + } + + public void setStrength(int strength){ + this.strength=strength; + } + + + @Override + public void attack(Character target){ + if (!this.isAlive()) return; + boolean heavy= Math.random()<0.5; + int damage = 0; + if (heavy && stamina >= 5){ + damage = strength; + + stamina-=5; + System.out.println(getName() + " does attack HEAVY!"); + } + else { + if (stamina > 0){ + damage = strength / 2; + stamina += 1; + + System.out.println(getName() + " does attack WEAK!"); + } + else{ + damage = 0; + stamina += 2; + System.out.println(getName() + " Doesnt have enough stamina to attack"); + } + } + target.setHp(target.getHp()- strength); + + System.out.println(getName()+" attacked "+ target.getName()); + System.out.println(damage+" Damaged"); + } +} diff --git a/HomeWork1/src/main/java/org/example/Wizard.java b/HomeWork1/src/main/java/org/example/Wizard.java new file mode 100644 index 0000000..ef6c192 --- /dev/null +++ b/HomeWork1/src/main/java/org/example/Wizard.java @@ -0,0 +1,66 @@ +package org.example; + +public class Wizard extends Character{ + private int mana; + private int intelligence; + + + public Wizard(String name, int hp, int mana, int intelligence){ + super(name,hp); + this.mana=mana; + this.intelligence=intelligence; + } + + public int getMana(){ + return mana; + } + + public int getIntelligence(){ + return intelligence; + } + + public void setMana(int mana){ + this.mana=mana; + } + + public void setIntelligence(int intelligence){ + this.intelligence=intelligence; + } + + @Override + public void attack(Character target){ + + if (!this.isAlive()) return; + + boolean fireball = Math.random() < 0.5; + int damage = 0; + if (fireball && mana >= 5) { + + damage = intelligence; + mana -= 5; + + System.out.println(getName() + " casts FIREBALL!"); + + } + else{ + if (mana > 0) { + + damage = 2; + mana += 1; + + System.out.println(getName() + " does STAFF!"); + + } + else{ + damage = 0; + mana += 2; + + System.out.println(getName() + " has no mana!"); + } + } + + target.setHp(target.getHp()-intelligence); + System.out.println(getName()+" attacked "+ target.getName()); + System.out.println("Damage: " +damage); + } +} diff --git a/HomeWork1/target/classes/org/example/Attacker.class b/HomeWork1/target/classes/org/example/Attacker.class new file mode 100644 index 0000000..e2b1184 Binary files /dev/null and b/HomeWork1/target/classes/org/example/Attacker.class differ diff --git a/HomeWork1/target/classes/org/example/BattleSimulator.class b/HomeWork1/target/classes/org/example/BattleSimulator.class new file mode 100644 index 0000000..84fb886 Binary files /dev/null and b/HomeWork1/target/classes/org/example/BattleSimulator.class differ diff --git a/HomeWork1/target/classes/org/example/Character.class b/HomeWork1/target/classes/org/example/Character.class new file mode 100644 index 0000000..1077954 Binary files /dev/null and b/HomeWork1/target/classes/org/example/Character.class differ diff --git a/HomeWork1/target/classes/org/example/Main.class b/HomeWork1/target/classes/org/example/Main.class new file mode 100644 index 0000000..2b66692 Binary files /dev/null and b/HomeWork1/target/classes/org/example/Main.class differ diff --git a/HomeWork1/target/classes/org/example/Warrior.class b/HomeWork1/target/classes/org/example/Warrior.class new file mode 100644 index 0000000..d2af612 Binary files /dev/null and b/HomeWork1/target/classes/org/example/Warrior.class differ diff --git a/HomeWork1/target/classes/org/example/Wizard.class b/HomeWork1/target/classes/org/example/Wizard.class new file mode 100644 index 0000000..fbb2089 Binary files /dev/null and b/HomeWork1/target/classes/org/example/Wizard.class differ