diff --git a/IronBattle/battleLogs.txt b/IronBattle/battleLogs.txt new file mode 100644 index 0000000..85e10e1 --- /dev/null +++ b/IronBattle/battleLogs.txt @@ -0,0 +1,254 @@ + +---ROUND 1--- +>>> s attacked q +>>> q's health is: 183 +>>> q attacked s +>>> s's health is: 153 + +---ROUND 1--- +>>> q attacked w +>>> w's health is: 150 +>>> w attacked q +>>> q's health is: 185 + +---ROUND 2--- +>>> q attacked w +>>> w's health is: 143 +>>> w attacked q +>>> q's health is: 182 + +---ROUND 3--- +>>> q attacked w +>>> w's health is: 140 +>>> w attacked q +>>> q's health is: 179 + +---ROUND 4--- +>>> q attacked w +>>> w's health is: 137 +>>> w attacked q +>>> q's health is: 172 + +---ROUND 5--- +>>> q attacked w +>>> w's health is: 134 +>>> w attacked q +>>> q's health is: 169 + +---ROUND 6--- +>>> q attacked w +>>> w's health is: 127 +>>> w attacked q +>>> q's health is: 166 + +---ROUND 7--- +>>> q attacked w +>>> w's health is: 120 +>>> w attacked q +>>> q's health is: 163 + +---ROUND 8--- +>>> q attacked w +>>> w's health is: 113 +>>> w attacked q +>>> q's health is: 160 + +---ROUND 9--- +>>> q attacked w +>>> w's health is: 110 +>>> w attacked q +>>> q's health is: 157 + +---ROUND 10--- +>>> q attacked w +>>> w's health is: 107 +>>> w attacked q +>>> q's health is: 150 + +---ROUND 11--- +>>> q attacked w +>>> w's health is: 100 +>>> w attacked q +>>> q's health is: 147 + +---ROUND 12--- +>>> q attacked w +>>> w's health is: 93 +>>> w attacked q +>>> q's health is: 140 + +---ROUND 13--- +>>> q attacked w +>>> w's health is: 93 +>>> w attacked q +>>> q's health is: 137 + +---ROUND 14--- +>>> q attacked w +>>> w's health is: 90 +>>> w attacked q +>>> q's health is: 134 + +---ROUND 15--- +>>> q attacked w +>>> w's health is: 83 +>>> w attacked q +>>> q's health is: 134 + +---ROUND 16--- +>>> q attacked w +>>> w's health is: 80 +>>> w attacked q +>>> q's health is: 131 + +---ROUND 17--- +>>> q attacked w +>>> w's health is: 77 +>>> w attacked q +>>> q's health is: 128 + +---ROUND 18--- +>>> q attacked w +>>> w's health is: 74 +>>> w attacked q +>>> q's health is: 121 + +---ROUND 19--- +>>> q attacked w +>>> w's health is: 71 +>>> w attacked q +>>> q's health is: 118 + +---ROUND 20--- +>>> q attacked w +>>> w's health is: 68 +>>> w attacked q +>>> q's health is: 111 + +---ROUND 21--- +>>> q attacked w +>>> w's health is: 68 +>>> w attacked q +>>> q's health is: 108 + +---ROUND 22--- +>>> q attacked w +>>> w's health is: 65 +>>> w attacked q +>>> q's health is: 105 + +---ROUND 23--- +>>> q attacked w +>>> w's health is: 62 +>>> w attacked q +>>> q's health is: 98 + +---ROUND 24--- +>>> q attacked w +>>> w's health is: 59 +>>> w attacked q +>>> q's health is: 95 + +---ROUND 25--- +>>> q attacked w +>>> w's health is: 56 +>>> w attacked q +>>> q's health is: 92 + +---ROUND 26--- +>>> q attacked w +>>> w's health is: 49 +>>> w attacked q +>>> q's health is: 92 + +---ROUND 27--- +>>> q attacked w +>>> w's health is: 46 +>>> w attacked q +>>> q's health is: 89 + +---ROUND 28--- +>>> q attacked w +>>> w's health is: 43 +>>> w attacked q +>>> q's health is: 86 + +---ROUND 29--- +>>> q attacked w +>>> w's health is: 36 +>>> w attacked q +>>> q's health is: 83 + +---ROUND 30--- +>>> q attacked w +>>> w's health is: 33 +>>> w attacked q +>>> q's health is: 80 + +---ROUND 31--- +>>> q attacked w +>>> w's health is: 30 +>>> w attacked q +>>> q's health is: 73 + +---ROUND 32--- +>>> q attacked w +>>> w's health is: 30 +>>> w attacked q +>>> q's health is: 70 + +---ROUND 33--- +>>> q attacked w +>>> w's health is: 27 +>>> w attacked q +>>> q's health is: 67 + +---ROUND 34--- +>>> q attacked w +>>> w's health is: 20 +>>> w attacked q +>>> q's health is: 67 + +---ROUND 35--- +>>> q attacked w +>>> w's health is: 17 +>>> w attacked q +>>> q's health is: 64 + +---ROUND 36--- +>>> q attacked w +>>> w's health is: 14 +>>> w attacked q +>>> q's health is: 57 + +---ROUND 37--- +>>> q attacked w +>>> w's health is: 14 +>>> w attacked q +>>> q's health is: 54 + +---ROUND 38--- +>>> q attacked w +>>> w's health is: 11 +>>> w attacked q +>>> q's health is: 51 + +---ROUND 39--- +>>> q attacked w +>>> w's health is: 8 +>>> w attacked q +>>> q's health is: 48 + +---ROUND 40--- +>>> q attacked w +>>> w's health is: 1 +>>> w attacked q +>>> q's health is: 45 + +---ROUND 41--- +>>> q attacked w +>>> w's health is: -2 +>>> w attacked q +>>> q's health is: 42 +>>> q wins! +w has been defeated! diff --git a/IronBattle/characters.csv b/IronBattle/characters.csv new file mode 100644 index 0000000..c773c3b --- /dev/null +++ b/IronBattle/characters.csv @@ -0,0 +1,11 @@ +c1,Aragorn,Warrior,150,35,8 +c2,Gimli,Warrior,180,42,6 +c3,Legolas,Warrior,120,28,9 +c4,Thorin,Warrior,160,30,7 +c5,Boromir,Warrior,170,38,8 +c6,Gandalf,Wizard,80,20,45 +c7,Saruman,Wizard,90,15,50 +c8,Radagast,Wizard,70,18,35 +c9,Elrond,Wizard,85,22,40 +c10,Merlin,Wizard,95,25,48 +c11,Morgana,Wizard,60,12,30 \ No newline at end of file diff --git a/IronBattle/ironbattle/.vscode/settings.json b/IronBattle/ironbattle/.vscode/settings.json new file mode 100644 index 0000000..e112a70 --- /dev/null +++ b/IronBattle/ironbattle/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/IronBattle/ironbattle/README.md b/IronBattle/ironbattle/README.md new file mode 100644 index 0000000..7c03a53 --- /dev/null +++ b/IronBattle/ironbattle/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/IronBattle/ironbattle/bin/App.class b/IronBattle/ironbattle/bin/App.class new file mode 100644 index 0000000..e261383 Binary files /dev/null and b/IronBattle/ironbattle/bin/App.class differ diff --git a/IronBattle/ironbattle/bin/characters/Character.class b/IronBattle/ironbattle/bin/characters/Character.class new file mode 100644 index 0000000..70233c4 Binary files /dev/null and b/IronBattle/ironbattle/bin/characters/Character.class differ diff --git a/IronBattle/ironbattle/bin/characters/Warrior.class b/IronBattle/ironbattle/bin/characters/Warrior.class new file mode 100644 index 0000000..facdb81 Binary files /dev/null and b/IronBattle/ironbattle/bin/characters/Warrior.class differ diff --git a/IronBattle/ironbattle/bin/characters/Wizard.class b/IronBattle/ironbattle/bin/characters/Wizard.class new file mode 100644 index 0000000..fa691b1 Binary files /dev/null and b/IronBattle/ironbattle/bin/characters/Wizard.class differ diff --git a/IronBattle/ironbattle/bin/services/Attacker.class b/IronBattle/ironbattle/bin/services/Attacker.class new file mode 100644 index 0000000..b607bf7 Binary files /dev/null and b/IronBattle/ironbattle/bin/services/Attacker.class differ diff --git a/IronBattle/ironbattle/src/Main.java b/IronBattle/ironbattle/src/Main.java new file mode 100644 index 0000000..cb28594 --- /dev/null +++ b/IronBattle/ironbattle/src/Main.java @@ -0,0 +1,55 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.Scanner; + +import characters.Warrior; +import characters.Wizard; +import services.BattleSimulator; +import services.Creating1v1; +import services.CreatingBattleGround; + +public class Main { + + private static Scanner sc = new Scanner(System.in); + private static Random random = new Random(); + + public static void main(String[] args) throws FileNotFoundException { + + List characters; + String choise; + + System.out.println("--- WELCOME TO IRONBATTLE ---"); + System.out.println("PLEASE SELECT WHAT DO YOU WANT"); + System.out.println("TYPE 'W' IF YOU WANT WATCH BATTLEGROUND, 'Q' IF YOU WANT 1V1"); + + do { + choise = sc.next(); + } while(!choise.equals("Q") && !choise.equals("W") && !choise.equals("q") && !choise.equals("w")); + + + + if(choise.equals("w")|| choise.equals("W")){ + characters = CreatingBattleGround.addCharactersToBattleGround(); + } + else{ + characters = Creating1v1.prepareCharacters(); + } + + // System.out.println("\n---GAME STARTS---\n"); + + new BattleSimulator().startTheGame(characters); //en boyuk listi verir + + + // } + + } + + + + +} \ No newline at end of file diff --git a/IronBattle/ironbattle/src/characters/Attacker.java b/IronBattle/ironbattle/src/characters/Attacker.java new file mode 100644 index 0000000..12012ce --- /dev/null +++ b/IronBattle/ironbattle/src/characters/Attacker.java @@ -0,0 +1,7 @@ +package characters; + +public interface Attacker { + + public void attack(Character attacksThisCharacter); + +} diff --git a/IronBattle/ironbattle/src/characters/Character.java b/IronBattle/ironbattle/src/characters/Character.java new file mode 100644 index 0000000..1745cc1 --- /dev/null +++ b/IronBattle/ironbattle/src/characters/Character.java @@ -0,0 +1,60 @@ +package characters; + +public abstract class Character implements Attacker { + private String id; + private String name; + private int hp; + private boolean isAlive; + + + public Character(String name, int hp) { + this.name = name; + this.hp = hp; + } + + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public int getHp() { + return hp; + } + + + public void setHp(int hp) { + this.hp = hp; + } + + + public boolean isAlive() { + return isAlive; + } + + + public void setAlive(boolean isAlive) { + this.isAlive = isAlive; + } + + + + + + +} diff --git a/IronBattle/ironbattle/src/characters/Warrior.java b/IronBattle/ironbattle/src/characters/Warrior.java new file mode 100644 index 0000000..8eb0ee9 --- /dev/null +++ b/IronBattle/ironbattle/src/characters/Warrior.java @@ -0,0 +1,63 @@ +package characters; + +import java.util.Random; + + +public class Warrior extends Character{ + + static Random random = new Random(); + // (max - int +1) + min + + + private static int hp; + private static int stamina; + private static int strength; + + + public static characters.Character createWarrior(String name){ + return new Warrior(name, random.nextInt(101)+100, random.nextInt(41)+10, random.nextInt(10)+1); + } + + public Warrior(String name, int hp, int stamina, int strength) { + super(name, hp); + this.stamina = stamina; + this.strength = strength; + } + + @Override + public void attack(Character attacksThisCharacter) { + + // if false --> Weak attack, else --> Heavy attack + boolean attackType = random.nextBoolean(); + + if (stamina >= 5 && attackType) { + heavyAttack(attacksThisCharacter); + + } + else if(stamina == 0) { + stamina+=2; + } + else{ + weakAttack(attacksThisCharacter); + } + + } + + public static void heavyAttack(Character attacksThisCharacter){ + + attacksThisCharacter.setHp(attacksThisCharacter.getHp()-strength); + stamina-=5; + } + + public static void weakAttack(Character attacksThisCharacter){ + attacksThisCharacter.setHp(attacksThisCharacter.getHp()-(int)(strength/2)); + stamina++; + } + + + + + + + +} diff --git a/IronBattle/ironbattle/src/characters/Wizard.java b/IronBattle/ironbattle/src/characters/Wizard.java new file mode 100644 index 0000000..08d01ec --- /dev/null +++ b/IronBattle/ironbattle/src/characters/Wizard.java @@ -0,0 +1,84 @@ +package characters; + +import java.util.Random; +import characters.Character; + +public class Wizard extends Character { + + static Random random = new Random(); + + private static int hp; + private static int mana; + private static int intelligence; + + public static characters.Character createWizard(String name) { + return new Wizard(name, random.nextInt(51) + 50, random.nextInt(41) + 10, random.nextInt(50) + 1); + } + + public Wizard(String name, int hp, int mana, int intelligence) { + super(name, hp); + this.mana = mana; + this.intelligence = intelligence; + } + + @Override + public void attack(Character attacksThisCharacter) { + + //if true --> fireBall, else --> staffHit + boolean skill = random.nextBoolean(); + + if(skill && mana>=5){ + fireBall(attacksThisCharacter); + + } + else if(mana==0){ + mana+=2; + } + else{ + staffHit(attacksThisCharacter); + } + + } + + public static void fireBall(Character attacksThisCharacter){ + attacksThisCharacter.setHp(attacksThisCharacter.getHp()- intelligence); + mana-=5; + } + + public static void staffHit(Character attacksThisCharacter){ + + attacksThisCharacter.setHp(attacksThisCharacter.getHp()- 2); + mana++; + + + + } + + + + public int getHp() { + return hp; + } + + public void setHp(int hp) { + this.hp = hp; + } + + public int getMana() { + return mana; + } + + public void setMana(int mana) { + this.mana = mana; + } + + public int getIntelligence() { + return intelligence; + } + + public void setIntelligence(int intelligence) { + this.intelligence = intelligence; + } + + +} diff --git a/IronBattle/ironbattle/src/services/BattleLog.java b/IronBattle/ironbattle/src/services/BattleLog.java new file mode 100644 index 0000000..fca3c8d --- /dev/null +++ b/IronBattle/ironbattle/src/services/BattleLog.java @@ -0,0 +1,49 @@ +package services; + +import java.io.FileWriter; +import java.io.IOException; + +public class BattleLog { + + private static final String FILE_NAME = "battleLogs.txt"; + + // Fayla yazma helper metodu + private static void writeToFile(String text) { + try (FileWriter writer = new FileWriter(FILE_NAME, true)) { + writer.write(text); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void writeBattleAction(characters.Character attacker, characters.Character defender) { + String log = + ">>> " + attacker.getName() + " attacked " + defender.getName() + "\n" + + ">>> " + defender.getName() + "'s health is: " + defender.getHp() + "\n"; + + writeToFile(log); + System.out.print(log); + } + + public static void writeRound(int round) { + String log = "\n---ROUND " + round + "---\n"; + writeToFile(log); + System.out.print(log); + } + + public static void writeBattleResult(characters.Character winner, characters.Character loser) { + String log = + ">>> " + winner.getName() + " wins!\n" + + loser.getName() + " has been defeated!\n"; + + writeToFile(log); + System.out.print(log); + } + + public static void writeBattleResultTie() { + String log = "It's a tie!\nMatch starts again!\n"; + + writeToFile(log); + System.out.print(log); + } +} \ No newline at end of file diff --git a/IronBattle/ironbattle/src/services/BattleSimulator.java b/IronBattle/ironbattle/src/services/BattleSimulator.java new file mode 100644 index 0000000..6fa300e --- /dev/null +++ b/IronBattle/ironbattle/src/services/BattleSimulator.java @@ -0,0 +1,93 @@ +package services; + +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; +import characters.Character; + +public class BattleSimulator { + + private static List characters; + + private static List newList = new ArrayList<>(); + + + + public void startTheGame(List characters){ + + this.characters = characters; + + + List selectedCharacters = selectMatchers(); + start( selectedCharacters.get(0), selectedCharacters.get(1) ); + + } + + public static void start(characters.Character c1, characters.Character c2 ){ + int round = 1; + Character ch1 = c1; + Character ch2 = c2; + + while(ch1.getHp()>0 && ch2.getHp()>0){ + + BattleLog.writeRound(round); + + ch1.attack(ch2); + BattleLog.writeBattleAction(ch1, ch2); + ch2.attack(ch1); + BattleLog.writeBattleAction(ch2, ch1); + + if(ch2.getHp()<=0 && ch1.getHp()>0){ + BattleLog.writeBattleResult(ch1, ch2); + newList.add(ch1); + } + else if(ch1.getHp()<=0 && ch2.getHp()>0){ + BattleLog.writeBattleResult(ch2, ch1); + newList.add(ch2); + } + else if(ch1.getHp()<=0 && ch2.getHp()<=0){ + BattleLog.writeBattleResultTie(); + ch1 = c1; + ch2 = c2; + start(ch1, ch2); + + } + round++; + selectMatchers(); + + } + + + } + + + public static List selectMatchers() { + List returnList = new ArrayList<>(); + + if (characters.size() == 1) { + + newList.add(characters.get(0)); + characters.clear(); + + } + else if(characters.size() == 0){ + characters = newList; + newList = new ArrayList<>(); + + } + + else { + + Collections.shuffle(characters); + returnList.add(characters.get(0)); + returnList.add(characters.get(1)); + + characters.remove(1); + characters.remove(0); + } + return returnList; + } + + + +} diff --git a/IronBattle/ironbattle/src/services/Creating1v1.java b/IronBattle/ironbattle/src/services/Creating1v1.java new file mode 100644 index 0000000..0731937 --- /dev/null +++ b/IronBattle/ironbattle/src/services/Creating1v1.java @@ -0,0 +1,80 @@ +package services; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.Scanner; + +import characters.*; +import characters.Character; +//everywhere in project i wrote as characters.Character +// to remember and don't make that mistake again +// Even a donkey falls into mud once + +public class Creating1v1 { + + private static Scanner sc = new Scanner(System.in); + private static Random random = new Random(); + + static List characters = new ArrayList<>(); + + public static List prepareCharacters(){ + + + System.out.println("\n---GAME PREPARATION---\n"); + + System.out.println("PLAYER 1 SELECT YOUR CHARACTER\n"); + + boolean p1Character = selectCharacter(); + System.out.println("Write your name: "); + String p1Name = sc.next(); + + + + System.out.println("PLAYER 2 SELECT YOUR CHARACTER"); + + boolean p2Character = selectCharacter(); + System.out.print("Write your name: "); + String p2Name = sc.next(); + + + characters.add(createPlayer(p1Character, p1Name)); + characters.add(createPlayer(p2Character, p2Name)); + + return characters; + + } + + private static boolean selectCharacter(){ + + System.out.println("press 1 if 'WARRIOR', press 0 if 'WIZARD'"); + + while(true){ + + int eded = sc.nextInt(); + + if(eded == 1){ + return true; + } + if(eded == 0){ + return false; + } + else{ + System.out.println("PLEASE ENTER 1 OR 0 !!!"); + sc.nextInt(); + } + + } + } + + private static characters.Character createPlayer(boolean character, String name){ + if(character == true){ + System.out.println("Creating WARRIOR for "+name+"..."); + return Warrior.createWarrior(name);} + else{ + System.out.println("Creating WIZARD for "+name+"..."); + return Wizard.createWizard(name);} + + } + +} diff --git a/IronBattle/ironbattle/src/services/CreatingBattleGround.java b/IronBattle/ironbattle/src/services/CreatingBattleGround.java new file mode 100644 index 0000000..304e4da --- /dev/null +++ b/IronBattle/ironbattle/src/services/CreatingBattleGround.java @@ -0,0 +1,43 @@ +package services; + +import java.io.FileNotFoundException; +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +import characters.Warrior; +import characters.Wizard; + +public class CreatingBattleGround { + + static List characters = new ArrayList<>(); + + + public static List addCharactersToBattleGround() throws FileNotFoundException { + try (Scanner scanner = new Scanner(new File("characters.csv"))) { + + String[] playerdata = new String[6]; + + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + + playerdata = line.split(","); + + //String name, int hp, int stamina, int strength + if(playerdata[2].equals("Warrior")){ + characters.add(new Warrior(playerdata[1], Integer.parseInt(playerdata[3]), Integer.parseInt(playerdata[4]), Integer.parseInt(playerdata[5]))); + } + else{ + characters.add(new Wizard(playerdata[1], Integer.parseInt(playerdata[3]), Integer.parseInt(playerdata[4]), Integer.parseInt(playerdata[5]))); + + } + + + + + } + } + return characters; + } +}