From fed900ade96a28824ee3ea8692d3c1f2c1d71205 Mon Sep 17 00:00:00 2001 From: Sevinc Date: Fri, 27 Feb 2026 11:37:14 +0400 Subject: [PATCH] homework finished --- IronBattle/battleLogs.txt | 254 ++++++++++++++++++ IronBattle/characters.csv | 11 + IronBattle/ironbattle/.vscode/settings.json | 7 + IronBattle/ironbattle/README.md | 18 ++ IronBattle/ironbattle/bin/App.class | Bin 0 -> 2107 bytes .../ironbattle/bin/characters/Character.class | Bin 0 -> 1178 bytes .../ironbattle/bin/characters/Warrior.class | Bin 0 -> 1410 bytes .../ironbattle/bin/characters/Wizard.class | Bin 0 -> 1850 bytes .../ironbattle/bin/services/Attacker.class | Bin 0 -> 150 bytes IronBattle/ironbattle/src/Main.java | 55 ++++ .../ironbattle/src/characters/Attacker.java | 7 + .../ironbattle/src/characters/Character.java | 60 +++++ .../ironbattle/src/characters/Warrior.java | 63 +++++ .../ironbattle/src/characters/Wizard.java | 84 ++++++ .../ironbattle/src/services/BattleLog.java | 49 ++++ .../src/services/BattleSimulator.java | 93 +++++++ .../ironbattle/src/services/Creating1v1.java | 80 ++++++ .../src/services/CreatingBattleGround.java | 43 +++ 18 files changed, 824 insertions(+) create mode 100644 IronBattle/battleLogs.txt create mode 100644 IronBattle/characters.csv create mode 100644 IronBattle/ironbattle/.vscode/settings.json create mode 100644 IronBattle/ironbattle/README.md create mode 100644 IronBattle/ironbattle/bin/App.class create mode 100644 IronBattle/ironbattle/bin/characters/Character.class create mode 100644 IronBattle/ironbattle/bin/characters/Warrior.class create mode 100644 IronBattle/ironbattle/bin/characters/Wizard.class create mode 100644 IronBattle/ironbattle/bin/services/Attacker.class create mode 100644 IronBattle/ironbattle/src/Main.java create mode 100644 IronBattle/ironbattle/src/characters/Attacker.java create mode 100644 IronBattle/ironbattle/src/characters/Character.java create mode 100644 IronBattle/ironbattle/src/characters/Warrior.java create mode 100644 IronBattle/ironbattle/src/characters/Wizard.java create mode 100644 IronBattle/ironbattle/src/services/BattleLog.java create mode 100644 IronBattle/ironbattle/src/services/BattleSimulator.java create mode 100644 IronBattle/ironbattle/src/services/Creating1v1.java create mode 100644 IronBattle/ironbattle/src/services/CreatingBattleGround.java 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 0000000000000000000000000000000000000000..e261383bb621bf36b27e5cb6680784380a211659 GIT binary patch literal 2107 zcmZ`)T~`xV6y2A6%rK6ihzcln&{l$o5p1ghe#96gZAj8dgo6DV!ib~EWI7qF_yhVM z^r>&Y_+WJ{bhT^s2lPMmSM;^3cHfy0(Z)9OKiCLu zQAZwM2qKpHztSE?DaT8T(5qO71qhhq5Ni~@&aRwI*ajDdC*p*vl1L#npTm1q}TT zef1^!USsf;T#T%~#_?A;@oSjF;HWW|9QSkISZD=v@S$pFN^=&pC(gXa$#>h5p-~OD z=urSp;bR8&;uD-^(s6#r=}AdI;v_8!Et@ZKX5ico&dd38&TnvOUVhK-;Oa{Z?I5!x zm$}GAQ@3k2e(dZU+?q{{4#(x3lOcG+J3-GQu6wZkAL)t0asU7T literal 0 HcmV?d00001 diff --git a/IronBattle/ironbattle/bin/characters/Character.class b/IronBattle/ironbattle/bin/characters/Character.class new file mode 100644 index 0000000000000000000000000000000000000000..70233c49bddc84d2d5482cf54b8e58bcdf9e506d GIT binary patch literal 1178 zcmZ{iO>fgc5Qg7%oHz+4Y11^c^aE%qwbKua3mia|stQD;s2qwSk(=YLl5Nuj*=~Ln z2au?cIPe4bQHYtfX&`kD_U?{n-g)L-|N8yoCxAEbEEodyVBm*-5X&&~PX2B!m;wtI z{>1l&{;2Q0?_J0swonjQjAS@bfsDN4IQD}}844KcT%gvT=AXr(8uecZm?Qs6Qo`Vq zfM^L=Dmosj357&gpzvCaRD2}RaPAhj+z!>BjL&5mIn-=auq2Rk+)fDs%Qi|V^6r6+ zGVTdf+iE0FudjMC{NVS7)S}iN2mY|*hl(2NHvqK@sXxrsR6mvM{6sXOjnChqsh zhJ_*}MoHpw20No$By_5$wyV8%pHOLzo;*w#j7XPkut|C)i}Xs$v~rsYs`Or<(?`n7(OPYO z$6|Bu2KDCp4H{o{!3w==Bng5tsklUiT)Ik;$4MC;VvSBDpxX((i1y4R|VMJfduavzc#midNRq6`FcgD>Ra!AX@~oJqLuZf!y7|8($(&6Gdm?3<9|{} zY$A!i`=g9^W|vZ=50aFbJ9F>3=bXLs`_GS`05@Wd>=6 zv7YnwlN5&G?lHra&2A7CyE$tNLy`ye&?oTC_xykt+sbPeUz;l_9+z)EI7DqV+R&!|0|Lh*xcYPsnY)*A!YvSmVtq zm!6K3!;zX4T#3XrhQ)j=x5F8>h`Tqzq*iC5A6= z0x6=fc_8X;E%aMnlPfO_+?EW;YO4svSgd+mwayM$Xgf!_fo@HSLkF@&74C8&&Yw>4n?RH)(RI^xR`22tT z&vQKGrAVI_G=%gNnZWmGhUp!hNPc0=6>|BUb{a5iD{RY}cUglQBT= za}X)|4bd*Erf<+!4kPG46=(xa!n* zk8oW_1sz!wP3y>_C{4laH>yh!10aVq{nz;Ph$vbhujkAyh{a9ZO1hPaA=CNCU^|P4 z8l50#JDC4!vNcwmF=6WMI2(Bs=q9ZnK!OyI>Onel7MG?vSezzqu?v#R8I&7U9)nGW7-c#KXK!$V^pQ7YZ3R7-X*%xS=KRDc5)9oc=(H=*om0^ fd=Gmo?&N5MCkevb8HA?^0yAF52wBQpGpOaifs{7J literal 0 HcmV?d00001 diff --git a/IronBattle/ironbattle/bin/characters/Wizard.class b/IronBattle/ironbattle/bin/characters/Wizard.class new file mode 100644 index 0000000000000000000000000000000000000000..fa691b147160e7eb672ecd133189cc1ab77ae0cc GIT binary patch literal 1850 zcma)6U2hvz5Ir}sV`sC(Tc-&rY05UGsqH`vN%*SMmJ$_VDeVJoQ{}BU>r1?_AJ+AC z1QkDt2WTZC5eeS;QHYtluH(2{iI?4-J2Pj_oSD1-{QKu$03KkkgeiebL04)S7^VBo zXWw(hB99_sRozbm868L+ zvOPR>1FfV{nIHmF5Ro~B(sO3=E519B(f#saEcDrp`Ph@P1+s4On z9ZaLn01bhqJOG<+x?x{nVVpxomc}q6jgi5R0#|C|{?Qm)^@9>VCN0iuKhQeWWo!xj z@-)$^pGGID;|FQn3nOX5H1T^nC3)i8zBBuztNd7*Zrbs)O0^Mm-A}*w&CfmMXKeg< z&^La1qO=Y>%1^Z)#yx^jiSec1AM}*A(HWfMpotys{ZoO(oZh+h;;}N{(w@-@(WVvq znZ?5=XNjB-?e3Mxk$qL@j22{U5i8`ocyeJC9_vTs=i?mAEYyayV59Z-E$HMg@x&b0^Eg20o;GLa^vu z$FqvD9v=THtezg_mZ>{|kFYtcy+a<3a?a2^tbTHe?Z3&&l*rgGkFj@#l>|P+=R*WW z;)(^5;Ma-VYh$^EQSKM`a+rIE-dw%7Len`PfnyKXi0Tasu#^Rj+AP}Uxa{pb8Y`1D z)^lmJa%rqg(r6HkjknNXWtqlq9*xyW8k@N^?&Q)KTgXg}Euyjg78*QO;qh4S5*fY< XYZu0PZ#Y(A7d#tlks|Ngaee(CzYJ0O literal 0 HcmV?d00001 diff --git a/IronBattle/ironbattle/bin/services/Attacker.class b/IronBattle/ironbattle/bin/services/Attacker.class new file mode 100644 index 0000000000000000000000000000000000000000..b607bf78231ea02058a52c5dba8d9590ff0a8214 GIT binary patch literal 150 zcmX^0Z`VEs1_oCKPId++Mh3y+)S|M?$c 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; + } +}