diff --git a/Naufal Dzaki Imtiyaz_Undip/README.md b/Naufal Dzaki Imtiyaz_Undip/README.md new file mode 100644 index 0000000..7b68442 --- /dev/null +++ b/Naufal Dzaki Imtiyaz_Undip/README.md @@ -0,0 +1,48 @@ +# Game CLI Based Narto Storm V + +## Pejelasan Program +### Deskripsi Program +- Program ini merupakan sebuah game battle sederhana yang berbasi CLI dengan menggunakan bahasa Java. +- User dapat melakukan set player sebagai human ataupun computer. +- Jika player human maka user akan bermain pada game dan melakukan input untuk memberikan aksi pada game. +- Jika player computer maka aksi player tersebut akan dilakukan otomatis oleh sistem. +- Pertarungan yang dapat dilakukan hanya terbatas 2 player saja. +- Dan bisa untuk seluruh player adalah human maupun seluruh player adalah computer. + +### Penerapan Konsep OOP +- Inheritance terimplementasikan pada kelas yang memiliki ragam seperti pada kelas Jutsu yang memiliki child class yaitu AttackJutsu dan BuffJutsu. +- Polimorfisme terimplementasikan pada saat membuat instance sebuah Jutsu dan Player. +- Interface terimplementasikan pada interface Player yang nantinya akan diimplemen oleh kelas HumanPlayer dan NonHumanPlayer. + +### Penerapan Prinsip SOLID +- Single responsibility Principle +Prinsip ini terimplementasi dimana untuk satu kelas hanya menangani satu tugas saja. Tidak terdapat satu kelas dewa yang menangani semua urusan. +- Open-closed Principle +Prinsip ini terimplementasi dimana untuk menambahkan jenis jutsu yang lain misal UltimateJutsu, kita tidak perlu melakukan modifikasi, cukup lakukan ekstensi dari kelas abstrak Jutsu. +- Dependency Inversion Principle +Prinsip ini terimplementasi dimana untuk kelas yang dependent terhadap kelas lain, ia tidak bergantung pada kelas yang konkrit melainkan sebuah kelas abstrak atau interface. +Seperti pada kelas Shinobi yang dependent terhadap kelas abstrak Jutsu. Serta kelas GameManager yang dependenet terhadap interface Player. + +### Penjelasan design pattern yang dipilih +- Disini design pattern yang dipilih adalah **Singleton** dimana terdapat pada class GameManager. +Class tersebut hanya bisa diinstansiasi sebanyak satu kali dan itu berfungsi untuk memulai pertarungan. +Alasan pemilihan design tersebut karena jika terdapat banyak objek dengan kelas tersebut akan sia-sia dan boros resource. Satu saja sudah cukup. +- Kemudian design pattern yang dipilih adalah **Adaptor** +Implementasi tersebut terletak pada kelas StatsEffect dimana merupakan sebuah adaptor untuk kelas Jutsu untuk bisa digunakan oleh kelas Shinobi. +Alasan pemilihan design pattern tersebut adalah agar semua jenis Jutsu hasil turunan dari kelas Jutsu dapat diterima oleh kelas Shinobi +dan tidak memerlukan modifikasi melainkan cukup lakukan ekstensi dari kelas Jutsu. + + +## Cara Menjalankan Program +1. Clone repository +2. Buka project pada folder yang sudah di clone tadi menggunakan IDE Intellij IDEA (untuk IDE atau text editor lain tidak terjamin aman) +3. Buka file Main.java +4. Lakukan set player 1 dan player 2 ingin sebagai human player atau computer player +5. Pilih karakter dengan memasukkan index list karakter yang sudah disediakan di atas +6. Jalankan program Main.java +7. Selamat bertarung + +## Versi Bahasa dan Dependency +Program ditulis menggunakan bahasa Java 19.0.2 dan menggunakan IDE Intellij IDEA. + +Kalau dibuka menggunakan VSC entah mengapa terdapat trouble pada saat mengambil inputan dari user. diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/.idea/.gitignore b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/.idea/misc.xml b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/.idea/misc.xml new file mode 100644 index 0000000..03f397c --- /dev/null +++ b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/.idea/modules.xml b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/.idea/modules.xml new file mode 100644 index 0000000..2405c69 --- /dev/null +++ b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/nartoStormV.iml b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/nartoStormV.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/nartoStormV.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/GameManager.class b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/GameManager.class new file mode 100644 index 0000000..bb9c654 Binary files /dev/null and b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/GameManager.class differ diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/Main.class b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/Main.class new file mode 100644 index 0000000..198bb4d Binary files /dev/null and b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/Main.class differ diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/character/Shinobi.class b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/character/Shinobi.class new file mode 100644 index 0000000..981f0ec Binary files /dev/null and b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/character/Shinobi.class differ diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/character/StatsEffect.class b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/character/StatsEffect.class new file mode 100644 index 0000000..cae27d2 Binary files /dev/null and b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/character/StatsEffect.class differ diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/jutsu/AttackJutsu.class b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/jutsu/AttackJutsu.class new file mode 100644 index 0000000..ae2bdaf Binary files /dev/null and b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/jutsu/AttackJutsu.class differ diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/jutsu/BuffJutsu.class b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/jutsu/BuffJutsu.class new file mode 100644 index 0000000..3a76054 Binary files /dev/null and b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/jutsu/BuffJutsu.class differ diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/jutsu/Jutsu.class b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/jutsu/Jutsu.class new file mode 100644 index 0000000..a2f4f89 Binary files /dev/null and b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/jutsu/Jutsu.class differ diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/player/HumanPlayer.class b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/player/HumanPlayer.class new file mode 100644 index 0000000..f52001e Binary files /dev/null and b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/player/HumanPlayer.class differ diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/player/NonHumanPlayer.class b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/player/NonHumanPlayer.class new file mode 100644 index 0000000..182c944 Binary files /dev/null and b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/player/NonHumanPlayer.class differ diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/player/Player.class b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/player/Player.class new file mode 100644 index 0000000..25a338c Binary files /dev/null and b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/out/production/nartoStormV/player/Player.class differ diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/GameManager.java b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/GameManager.java new file mode 100644 index 0000000..2657132 --- /dev/null +++ b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/GameManager.java @@ -0,0 +1,281 @@ +import java.util.Scanner; +import java.util.Random; +import java.util.ArrayList; +import java.util.List; +import jutsu.*; +import player.HumanPlayer; +import player.Player; + +public class GameManager { + private static GameManager instance; + private List players; + private boolean isEndGame = false; + + private GameManager() { + this.players = new ArrayList<>(); + this.players.add(null); + this.players.add(null); + } + + public static GameManager getInstance() { + if (instance == null) { + instance = new GameManager(); + } + return instance; + } + + public void registerPlayer(Player player1, Player player2) { + this.players.set(0, player1); + this.players.set(1, player2); + } + + // Start battle game + public void startGame() { + int match = 1; + Player player1 = this.players.get(0); + Player player2 = this.players.get(1); + System.out.println("Game Start!"); + System.out.println(player1.getName() + " character : " + player1.getSelectedCharacter().getName()); + System.out.println("VS"); + System.out.println(player2.getName() + " character : " + player2.getSelectedCharacter().getName()); + + while (!isEndGame) { + delay(1500); + System.out.println("====================================="); + System.out.println(); + System.out.println("Match " + match); + System.out.println(); + + delay(1500); + + System.out.println("-------------------------------------"); + System.out.println(); + System.out.println(player1.getName() + " character status : "); + player1.getSelectedCharacter().status(); + delay(1500); + System.out.println(player2.getName() + " character status : "); + player2.getSelectedCharacter().status(); + System.out.println("-------------------------------------"); + + delay(1500); + + System.out.println(); + System.out.println(player1.getName() + " turn"); + + if (player1 instanceof HumanPlayer) { + chooseMoveHuman(player1, player2); + } + else { + delay(2500); + chooseMoveComputer(player1, player2); + } + + if (player2.getSelectedCharacter().getHp() <= 0) { + System.out.println(player2.getName() + " loses"); + System.out.println(player1.getName() + " wins"); + endGame(); + break; + } + if (player1.getSelectedCharacter().getHp() <= 0) { + System.out.println(player1.getName() + " loses"); + System.out.println(player2.getName() + " wins"); + endGame(); + break; + } + + System.out.println(); + delay(1500); + System.out.println("-------------------------------------"); + System.out.println(); + System.out.println(player1.getName() + " character status : "); + player1.getSelectedCharacter().status(); + delay(1500); + System.out.println(player2.getName() + " character status : "); + player2.getSelectedCharacter().status(); + System.out.println("-------------------------------------"); + + delay(1500); + + System.out.println(); + System.out.println(player2.getName() + " turn"); + + if (player2 instanceof HumanPlayer) { + chooseMoveHuman(player2, player1); + } + else { + delay(2500); + chooseMoveComputer(player2, player1); + } + + if (player1.getSelectedCharacter().getHp() <= 0) { + System.out.println(player1.getName() + " loses"); + System.out.println(player2.getName() + " wins"); + endGame(); + break; + } + if (player2.getSelectedCharacter().getHp() <= 0) { + System.out.println(player2.getName() + " loses"); + System.out.println(player1.getName() + " wins"); + endGame(); + break; + } + + match++; + + System.out.println(); + } + + } + + // State game over + private void endGame(){ + this.isEndGame = true; + System.out.println("Game Over"); + } + + // Move list player human + private void chooseMoveHuman(Player human, Player opponent) { + Scanner input1 = new Scanner(System.in); + System.out.println("Move list : "); + System.out.println("1. Basic Attack"); + System.out.println("2. Jutsu"); + System.out.println("3. Chakra Recovery"); + System.out.println("4. Surrender"); + System.out.println("Choose your move: "); + int move = input1.nextInt(); + switch (move) { + case 1: + System.out.println(human.getSelectedCharacter().getName() + " uses basic attack"); + human.getSelectedCharacter().basicAttack(opponent.getSelectedCharacter()); + break; + + case 2: + chooseJutsuHuman(human, opponent); + break; + + case 3: + System.out.println(human.getSelectedCharacter().getName() + " healing chakra"); + human.getSelectedCharacter().healChakra(); + break; + + case 4: + System.out.println(human.getName() + " surrenders"); + System.out.println(opponent.getName() + " wins"); + endGame(); + break; + + default: + break; + } + } + + // Pick jutsu player human + private void chooseJutsuHuman(Player human, Player opponent) { + Scanner input2 = new Scanner(System.in); + System.out.println("Jutsu list : "); + System.out.println("0. Back"); + human.getSelectedCharacter().showMasteredJutsu(); + Jutsu jutsu; + System.out.println("Choose your jutsu : "); + int choice = input2.nextInt(); + switch (choice) { + case 0: + chooseMoveHuman(human, opponent); + break; + + case 1: + jutsu = human.getSelectedCharacter().pickMasteredJutsu(choice-1); + System.out.println(human.getSelectedCharacter().getName() + " casts " + jutsu.getName()); + human.getSelectedCharacter().castJutsu(jutsu, opponent.getSelectedCharacter()); + break; + + case 2: + jutsu = human.getSelectedCharacter().pickMasteredJutsu(choice-1); + System.out.println(human.getSelectedCharacter().getName() + " casts " + jutsu.getName()); + human.getSelectedCharacter().castJutsu(jutsu, opponent.getSelectedCharacter()); + break; + + case 3: + jutsu = human.getSelectedCharacter().pickMasteredJutsu(choice-1); + System.out.println(human.getSelectedCharacter().getName() + " casts " + jutsu.getName()); + human.getSelectedCharacter().castJutsu(jutsu, opponent.getSelectedCharacter()); + break; + + default: + break; + } + } + + // Move list player computer + private void chooseMoveComputer(Player computer, Player opponent) { + Random rand = new Random(); + int move = rand.nextInt(3) + 1; + switch (move) { + case 1: + System.out.println(computer.getSelectedCharacter().getName() + " uses basic attack"); + computer.getSelectedCharacter().basicAttack(opponent.getSelectedCharacter()); + break; + + case 2: + chooseJutsuComputer(computer, opponent); + break; + + case 3: + System.out.println(computer.getSelectedCharacter().getName() + " healing chakra"); + computer.getSelectedCharacter().healChakra(); + break; + + case 4: + System.out.println(computer.getName() + " surrenders"); + System.out.println(opponent.getName() + " wins"); + endGame(); + break; + + default: + break; + } + } + + // Pick jutsu untuk player computer + private void chooseJutsuComputer(Player computer, Player opponent) { + Random rand = new Random(); + Jutsu jutsu; + int choice = rand.nextInt(4); + switch (choice) { + case 0: + chooseMoveComputer(computer, opponent); + break; + + case 1: + jutsu = computer.getSelectedCharacter().pickMasteredJutsu(choice-1); + System.out.println(computer.getSelectedCharacter().getName() + " casts " + jutsu.getName()); + computer.getSelectedCharacter().castJutsu(jutsu, opponent.getSelectedCharacter()); + break; + + case 2: + jutsu = computer.getSelectedCharacter().pickMasteredJutsu(choice-1); + System.out.println(computer.getSelectedCharacter().getName() + " casts " + jutsu.getName()); + computer.getSelectedCharacter().castJutsu(jutsu, opponent.getSelectedCharacter()); + break; + + case 3: + jutsu = computer.getSelectedCharacter().pickMasteredJutsu(choice-1); + System.out.println(computer.getSelectedCharacter().getName() + " casts " + jutsu.getName()); + computer.getSelectedCharacter().castJutsu(jutsu, opponent.getSelectedCharacter()); + break; + + default: + break; + } + } + + // Delay untuk animasi interaktif pada CLI + private void delay(int ms) { + try { + Thread.sleep(ms); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + +} diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/Main.java b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/Main.java new file mode 100644 index 0000000..71a800c --- /dev/null +++ b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/Main.java @@ -0,0 +1,63 @@ +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +import character.*; +import jutsu.*; +import player.*; + +public class Main { + public static void main(String[] args) { + // Creating Characters Sets + Shinobi naruto = new Shinobi("Naruto", 10, 10); + Shinobi sasuke = new Shinobi("Sasuke", 10, 10); + Shinobi madara = new Shinobi("Madara", 10, 10); + Shinobi obito = new Shinobi("Obito", 10, 10); + + // Creating Jutsu Sets + Jutsu rasengan = new AttackJutsu("Rasengan", 20, 20); + Jutsu shadowClone = new BuffJutsu("Shadow Clone", 25, 0, 5, 5); + Jutsu sageMode = new BuffJutsu("Sage Mode", 50, 0, 20, 0); + Jutsu chidori = new AttackJutsu("Chidori", 20, 20); + Jutsu sharingan = new BuffJutsu("Sharingan", 25, 0, 10, 0); + Jutsu susanoo = new BuffJutsu("Susanoo", 50, 0, 0, 20); + Jutsu fireBall = new AttackJutsu("Fire Ball", 15, 15); + Jutsu doubleMeteor = new AttackJutsu("Double Meteor", 50, 50); + Jutsu kamui = new BuffJutsu("Kamui", 30, 0, 0, 15); + + // Learning Jutsu + naruto.learnJutsu(rasengan); + naruto.learnJutsu(shadowClone); + naruto.learnJutsu(sageMode); + sasuke.learnJutsu(chidori); + sasuke.learnJutsu(sharingan); + sasuke.learnJutsu(susanoo); + madara.learnJutsu(doubleMeteor); + madara.learnJutsu(sharingan); + madara.learnJutsu(susanoo); + obito.learnJutsu(fireBall); + obito.learnJutsu(sharingan); + obito.learnJutsu(kamui); + + // Load Characters + List charactersList = new ArrayList(); + charactersList.add(naruto); + charactersList.add(sasuke); + charactersList.add(madara); + charactersList.add(obito); + + // Creating Players + Player player1 = new HumanPlayer("Alan Turing"); + Player player2 = new NonHumanPlayer(); + + // Choose Character + player1.chooseCharacter(charactersList.get(0)); + player2.chooseCharacter(charactersList.get(1)); + + // Register Players + GameManager.getInstance().registerPlayer(player1, player2); + + // Start Game + GameManager.getInstance().startGame(); + } +} diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/character/Shinobi.java b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/character/Shinobi.java new file mode 100644 index 0000000..0af0670 --- /dev/null +++ b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/character/Shinobi.java @@ -0,0 +1,162 @@ +package character; + +import java.util.ArrayList; +import java.util.List; +import jutsu.*; + +// Class character set +public class Shinobi { + private String name; + private int hp; + private int chakra; + private int attack; + private int defense; + private List masteredJutsu = new ArrayList(); + + public Shinobi(String name, int attack, int defense) { + this.name = name; + this.hp = 100; + this.chakra = 100; + this.attack = attack; + this.defense = defense; + } + + public String getName() { + return name; + } + + public int getHp() { + return hp; + } + + public int getChakra() { + return chakra; + } + + public int getAttack() { + return attack; + } + + public int getDefense() { + return defense; + } + + public void setName(String name) { + this.name = name; + } + + public void setHp(int hp) { + this.hp = hp; + } + + public void setChakra(int chakra) { + this.chakra = chakra; + } + + public void setAttack(int attack) { + this.attack = attack; + } + + public void setDefense(int defense) { + this.defense = defense; + } + + // Status dari character + public void status() { + System.out.println("Name: " + name); + System.out.println("HP: " + hp + "/100"); + System.out.println("Chakra: " + chakra + "/100"); + System.out.println("Attack: " + attack); + System.out.println("Defense: " + defense); + System.out.println(); + } + + // Memberikan damage pada lawan + private void attack(Shinobi enemy, int attackDmg) { + int damageDealt = attackDmg - (enemy.getDefense()/2); + enemy.takeDamage(damageDealt); + System.out.println(enemy.getName() + " takes " + damageDealt + " damage from " + name); + } + + // Menerima damage dari lawan + private void takeDamage(int damage) { + setHp(getHp() - damage); + } + + // Menyerang lawan dengan basic attack + public void basicAttack(Shinobi enemy) { + attack(enemy, attack); + } + + // Mengisi ulang chakra + public void healChakra() { + this.chakra += 25; + System.out.println(name + " heals 25 chakra"); + if(chakra > 100) { + chakra = 100; + } + } + + // Menambah jutsu yang dikuasai + public void learnJutsu(Jutsu jutsu) { + masteredJutsu.add(jutsu); + } + + // Mengambil jutsu dari jutsu-jutsu yang dikuasai + public Jutsu pickMasteredJutsu(int index) { + return masteredJutsu.get(index); + } + + // Mengirim seluruh jutsu yang dikuasai + public List getMasteredJutsu() { + return masteredJutsu; + } + + // Menampilkan daftar jutsu yang dikuasai + public void showMasteredJutsu() { + for(int i = 0; i < masteredJutsu.size(); i++) { + System.out.println((i+1) + ". " + masteredJutsu.get(i).getName()); + } + } + + // Mengaktifkan jutsu, semua tipe jutsu dapat digunakan karena adanya adaptor StatsEffect + public void castJutsu(Jutsu jutsu, Shinobi enemy) { + StatsEffect effect = new StatsEffect(); + jutsu.useJutsu(effect); + if(this.chakra < jutsu.getChakraCost()) { // Gagal aktifkan jutsu karena chakra tidak cukup + System.out.println("Not enough chakra!"); + } + + else { + System.out.println(name + " uses " + jutsu.getName() + "!"); + System.out.println("Jutsu cost " + jutsu.getChakraCost() + " chakra"); + System.out.println(); + this.chakra -= jutsu.getChakraCost(); + + if(effect.getHpDelta() > 0) { // Jutsu ngebuff HP + System.out.println(name + " heals " + effect.getHpDelta() + " amounts of HP"); + this.hp += effect.getHpDelta(); + + if(hp > 100) { + hp = 100; + } + } + + if(effect.getAttackDelta() > 0){ // Jutsu ngebuff attack + System.out.println(name + " increases attack by " + effect.getAttackDelta()); + this.attack += effect.getAttackDelta(); + } + + if(effect.getDefenseDelta() > 0) { // Jutsu ngebuff defense + System.out.println(name + " increases defense by " + effect.getDefenseDelta()); + this.defense += effect.getDefenseDelta(); + } + + if(effect.getDamage() > 0) { // Jutsu menyerang lawan dan memberikan damage + attack(enemy, effect.getDamage()); + } + + } + + } +} diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/character/StatsEffect.java b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/character/StatsEffect.java new file mode 100644 index 0000000..94180de --- /dev/null +++ b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/character/StatsEffect.java @@ -0,0 +1,48 @@ +package character; + +// Adaptor untuk class Jutsu agar bisa digunakan class Shinobi +public class StatsEffect { + private int hpDelta; + private int attackDelta; + private int defenseDelta; + private int damage; + + public StatsEffect() { + this.hpDelta = 0; + this.attackDelta = 0; + this.defenseDelta = 0; + this.damage = 0; + } + + public int getHpDelta() { + return hpDelta; + } + + public int getAttackDelta() { + return attackDelta; + } + + public int getDefenseDelta() { + return defenseDelta; + } + + public int getDamage() { + return damage; + } + + public void setHpDelta(int hpDelta) { + this.hpDelta = hpDelta; + } + + public void setAttackDelta(int attackDelta) { + this.attackDelta = attackDelta; + } + + public void setDefenseDelta(int defenseDelta) { + this.defenseDelta = defenseDelta; + } + + public void setDamage(int damage) { + this.damage = damage; + } +} diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/jutsu/AttackJutsu.java b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/jutsu/AttackJutsu.java new file mode 100644 index 0000000..6a3f28e --- /dev/null +++ b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/jutsu/AttackJutsu.java @@ -0,0 +1,26 @@ +package jutsu; + +import character.StatsEffect; + +// Jutsu menyerang memberi damage pada lawan +public class AttackJutsu extends Jutsu{ + private int damage; + + public AttackJutsu(String name, int chakraCost, int damage) { + super(name, chakraCost); + this.damage = damage; + } + + public int getDamage() { + return damage; + } + + public void display() { + System.out.printf("Jutsu Name: %s\nChakra Cost: %d\nDamage: %d\n", getName(), getChakraCost(), damage); + } + + @Override + public void useJutsu(StatsEffect effect) { + effect.setDamage(damage); + } +} diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/jutsu/BuffJutsu.java b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/jutsu/BuffJutsu.java new file mode 100644 index 0000000..a8e2301 --- /dev/null +++ b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/jutsu/BuffJutsu.java @@ -0,0 +1,40 @@ +package jutsu; + +import character.StatsEffect; + +// Jutsu dengan efek memberi buff pada pengguna +public class BuffJutsu extends Jutsu { + private int buffHP; + private int buffAttack; + private int buffDefense; + + public BuffJutsu(String name, int chakraCost, int buffHP, int buffAttack, int buffDefense) { + super(name, chakraCost); + this.buffHP = buffHP; + this.buffAttack = buffAttack; + this.buffDefense = buffDefense; + } + + public int getBuffHP() { + return buffHP; + } + + public int getBuffAttack() { + return buffAttack; + } + + public int getBuffDefense() { + return buffDefense; + } + + public void display() { + System.out.printf("Jutsu Name: %s\nChakra Cost: %d\nBuff HP: %d\nBuff Attack: %d\nBuff Defense: %d\n", getName(), getChakraCost(), buffHP, buffAttack, buffDefense); + } + + @Override + public void useJutsu(StatsEffect effect) { + effect.setHpDelta(buffHP); + effect.setAttackDelta(buffAttack); + effect.setDefenseDelta(buffDefense); + } +} diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/jutsu/Jutsu.java b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/jutsu/Jutsu.java new file mode 100644 index 0000000..336ab6e --- /dev/null +++ b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/jutsu/Jutsu.java @@ -0,0 +1,25 @@ +package jutsu; + +import character.StatsEffect; + +public abstract class Jutsu { + private String name; + private int chakraCost; + + public Jutsu(String name, int chakraCost) { + this.name = name; + this.chakraCost = chakraCost; + } + + public String getName() { + return name; + } + + public int getChakraCost() { + return chakraCost; + } + + public abstract void display(); + + public abstract void useJutsu(StatsEffect effect); +} diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/player/HumanPlayer.java b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/player/HumanPlayer.java new file mode 100644 index 0000000..76cdddc --- /dev/null +++ b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/player/HumanPlayer.java @@ -0,0 +1,28 @@ +package player; +import character.Shinobi; + +// Player manusia +public class HumanPlayer implements Player { + private Shinobi selectedCharacter; + private String name; + + public HumanPlayer(String name) { + this.selectedCharacter = null; + this.name = name; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public Shinobi getSelectedCharacter() { + return this.selectedCharacter; + } + + @Override + public void chooseCharacter(Shinobi selectedCharacter) { + this.selectedCharacter = selectedCharacter; + } +} diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/player/NonHumanPlayer.java b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/player/NonHumanPlayer.java new file mode 100644 index 0000000..857867f --- /dev/null +++ b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/player/NonHumanPlayer.java @@ -0,0 +1,33 @@ +package player; +import character.Shinobi; + +// Player bukan manusia / computer +public class NonHumanPlayer implements Player { + private Shinobi selectedCharacter; + private String name; + + public NonHumanPlayer() { + this.selectedCharacter = null; + this.name = "Computer"; + } + + public NonHumanPlayer(String name) { + this(); + this.name = name; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public Shinobi getSelectedCharacter() { + return this.selectedCharacter; + } + + @Override + public void chooseCharacter(Shinobi selectedCharacter) { + this.selectedCharacter = selectedCharacter; + } +} diff --git a/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/player/Player.java b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/player/Player.java new file mode 100644 index 0000000..4188484 --- /dev/null +++ b/Naufal Dzaki Imtiyaz_Undip/nartoStormV/src/player/Player.java @@ -0,0 +1,8 @@ +package player; +import character.Shinobi; + +public interface Player{ + String getName(); + Shinobi getSelectedCharacter(); + void chooseCharacter(Shinobi selectedCharacter); +}