diff --git a/src/interfacce/Eroe.java b/src/interfacce/Eroe.java index a2dad5e..8c2ba47 100644 --- a/src/interfacce/Eroe.java +++ b/src/interfacce/Eroe.java @@ -8,6 +8,18 @@ package interfacce; * * @author Verde */ -public class Eroe { +public class Eroe implements Umano { + protected int forza = 15; + public Eroe() { + + } + + public String getForza() { + return "Forza rimanente: " + this.forza; + } + + public void combatti() { + this.forza -= 3; + } } \ No newline at end of file diff --git a/src/interfacce/Giochiamo.java b/src/interfacce/Giochiamo.java new file mode 100644 index 0000000..07fe163 --- /dev/null +++ b/src/interfacce/Giochiamo.java @@ -0,0 +1,46 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template + */ +package interfacce; + +import java.util.InputMismatchException; +import java.util.Scanner; + +/** + * + * @author Verde + */ +public class Giochiamo { + + /** + * @param args the command line arguments + */ + + static Scanner sc = new Scanner(System.in); + + public static void main(String[] args) { + Eroe eroe = new Eroe(); + Vampiro vampiro = new Vampiro(); + Licantropo licantropo = new Licantropo(true); + + eroe.combatti(); + eroe.combatti(); + eroe.combatti(); + + vampiro.azzanna(); + + licantropo.azzanna(); + licantropo.azzanna(); + + System.out.println("Eroe: " + eroe.getForza()); + System.out.println("Vampiro: " + vampiro.getForza()); + System.out.println(licantropo.getForza()); + pausa(); + } + + public static void pausa() { + System.out.println("Premere un tasto per continuare. . ."); + sc.nextLine(); + } +} diff --git a/src/interfacce/Licantropo.java b/src/interfacce/Licantropo.java index 54f24a2..a73380f 100644 --- a/src/interfacce/Licantropo.java +++ b/src/interfacce/Licantropo.java @@ -8,6 +8,37 @@ package interfacce; * * @author Verde */ -public class Licantropo { +public class Licantropo implements Mostro, Umano{ + private boolean isUomo; + protected int forzaUmano; + protected int forzaMostro; + + public Licantropo(boolean luna) { + isUomo = !luna; + if (luna) { + forzaMostro = 15; + forzaUmano = 0; + } else { + forzaMostro = 0; + forzaUmano = 15; + } + } + + public String getForza() { + return "Forza rimanente come umano: " + forzaUmano + + "\nForza rimanente come mostro: " + forzaMostro; + } + + public void azzanna() { + if (!isUomo) { + forzaMostro -= 2; + } + } + + public void combatti() { + if (isUomo) { + forzaUmano -= 3; + } + } } \ No newline at end of file diff --git a/src/interfacce/Mostro.java b/src/interfacce/Mostro.java index d60d341..9546645 100644 --- a/src/interfacce/Mostro.java +++ b/src/interfacce/Mostro.java @@ -8,6 +8,6 @@ package interfacce; * * @author Verde */ -public interface Mostro { - +public interface Mostro extends Personaggio { + public void azzanna(); } \ No newline at end of file diff --git a/src/interfacce/Personaggio.java b/src/interfacce/Personaggio.java index 72e1730..e9c5882 100644 --- a/src/interfacce/Personaggio.java +++ b/src/interfacce/Personaggio.java @@ -8,6 +8,6 @@ package interfacce; * * @author Verde */ -public interface { - +public interface Personaggio { + public String getForza(); } \ No newline at end of file diff --git a/src/interfacce/Umano.java b/src/interfacce/Umano.java index 9a8673b..99e1a79 100644 --- a/src/interfacce/Umano.java +++ b/src/interfacce/Umano.java @@ -8,6 +8,6 @@ package interfacce; * * @author Verde */ -public interface Umano { - +public interface Umano extends Personaggio { + public void combatti(); } \ No newline at end of file diff --git a/src/interfacce/Vampiro.java b/src/interfacce/Vampiro.java index 7690c8d..fca1edb 100644 --- a/src/interfacce/Vampiro.java +++ b/src/interfacce/Vampiro.java @@ -8,6 +8,17 @@ package interfacce; * * @author Verde */ -public class Vampiro { +public class Vampiro implements Mostro { + protected int forza; + public Vampiro() { + } + + public String getForza() { + return "Forza rimanente: " + this.forza; + } + + public void azzanna() { + this.forza -= 2; + } } \ No newline at end of file diff --git a/src/interfacce/interfacce.java b/src/interfacce/interfacce.java deleted file mode 100644 index 3718ec9..0000000 --- a/src/interfacce/interfacce.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license - * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template - */ -package interfacce; - -import java.util.InputMismatchException; -import java.util.Scanner; - -/** - * - * @author Verde - */ -public class interfacce { - - /** - * @param args the command line arguments - */ - - static Scanner sc = new Scanner(System.in); - - public static void main(String[] args) { - int scelta = -1; - - do { - System.out.println("Scegliere un'opzione:"); - System.out.println("1. "); - System.out.println("2. "); - System.out.println("3. "); - System.out.println("0. Esci"); - System.out.print("Opzione: "); - - try { - scelta = sc.nextInt(); - sc.nextLine(); - - switch (scelta) { - case 0: - break; - case 1: - - pausa(); - break; - case 2: - - pausa(); - break; - case 3: - - pausa(); - break; - default: - System.out.println("Opzione non valida."); - pausa(); - break; - } - } - catch (InputMismatchException _) { - System.out.println("Errore: scelta non valida."); - pausa(); - } - } while (scelta != 0); - } - - public static void pausa() { - System.out.println("Premere un tasto per continuare. . ."); - sc.nextLine(); - } -}