diff --git a/.devcontainer.json b/.devcontainer.json new file mode 100644 index 0000000..bfbeb0d --- /dev/null +++ b/.devcontainer.json @@ -0,0 +1,3 @@ +{ + "image": "mcr.microsoft.com/devcontainers/java:21" +} \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..add4f4e --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "vscjava.vscode-java-pack" + ] +} \ No newline at end of file diff --git a/Creature.java b/Creature.java new file mode 100644 index 0000000..9c93fb2 --- /dev/null +++ b/Creature.java @@ -0,0 +1,36 @@ +public class Creature { + + private String name; + private int attackValue; + private int hitpoints; + + public Creature(String name, int attackValue, int hitpoints) { + this.name = name; + this.attackValue = attackValue; + this.hitpoints = hitpoints; + } + + public String getName() { + return name; + } + + public int getAttackValue() { + return attackValue; + } + + public int getHitpoints() { + return hitpoints; + } + + public void attackCreature(Creature creature) { + creature.hitpoints -= this.attackValue; + System.out.println( + this.name + + " greift " + + creature.name + + " an und erzielt " + + this.attackValue + + " Schaden"); + System.out.println(creature.name + " hat noch " + creature.hitpoints + " Lebenspunkte"); + } +} diff --git a/Exercise.java b/Exercise.java index 3c092f9..6863923 100644 --- a/Exercise.java +++ b/Exercise.java @@ -1,6 +1,12 @@ public class Exercise { public static void main(String[] args) { - // implement exercise here + Creature zombie = new Creature("Zombie", 2, 10); + Creature vampire = new Creature("Vampir", 4, 6); + + zombie.attackCreature(vampire); + vampire.attackCreature(zombie); + zombie.attackCreature(vampire); + vampire.attackCreature(zombie); } }