diff --git a/Code/Steiner/simpleGame/.vscode/settings.json b/Code/Steiner/simpleGame/.vscode/settings.json new file mode 100644 index 0000000..e112a70 --- /dev/null +++ b/Code/Steiner/simpleGame/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/Code/Steiner/simpleGame/README.md b/Code/Steiner/simpleGame/README.md new file mode 100644 index 0000000..7c03a53 --- /dev/null +++ b/Code/Steiner/simpleGame/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/Code/Steiner/simpleGame/bin/Character.class b/Code/Steiner/simpleGame/bin/Character.class new file mode 100644 index 0000000..927d495 Binary files /dev/null and b/Code/Steiner/simpleGame/bin/Character.class differ diff --git a/Code/Steiner/simpleGame/bin/Enemy.class b/Code/Steiner/simpleGame/bin/Enemy.class new file mode 100644 index 0000000..d590fe9 Binary files /dev/null and b/Code/Steiner/simpleGame/bin/Enemy.class differ diff --git a/Code/Steiner/simpleGame/bin/FightingGame.class b/Code/Steiner/simpleGame/bin/FightingGame.class new file mode 100644 index 0000000..8b977fe Binary files /dev/null and b/Code/Steiner/simpleGame/bin/FightingGame.class differ diff --git a/Code/Steiner/simpleGame/bin/Player.class b/Code/Steiner/simpleGame/bin/Player.class new file mode 100644 index 0000000..0998b23 Binary files /dev/null and b/Code/Steiner/simpleGame/bin/Player.class differ diff --git a/Code/Steiner/simpleGame/src/Character.class b/Code/Steiner/simpleGame/src/Character.class new file mode 100644 index 0000000..8538ec9 Binary files /dev/null and b/Code/Steiner/simpleGame/src/Character.class differ diff --git a/Code/Steiner/simpleGame/src/Character.java b/Code/Steiner/simpleGame/src/Character.java new file mode 100644 index 0000000..c38ac84 --- /dev/null +++ b/Code/Steiner/simpleGame/src/Character.java @@ -0,0 +1,33 @@ +public abstract class Character { + protected String name; + protected int health; + protected int attackPower; + + public Character(String name, int health, int attackPower) { + this.name = name; + this.health = health; + this.attackPower = attackPower; + } + + public void takeDamage(int damage) { + this.health -= damage; + } + + public boolean isAlive() { + return this.health > 0; + } + + public String getName() { + return name; + } + + public int getHealth() { + return health; + } + + public int getAttackPower() { + return attackPower; + } + + public abstract void displayInfo(); // Abstract method to be implemented by subclasses +} diff --git a/Code/Steiner/simpleGame/src/Enemy.class b/Code/Steiner/simpleGame/src/Enemy.class new file mode 100644 index 0000000..21112c0 Binary files /dev/null and b/Code/Steiner/simpleGame/src/Enemy.class differ diff --git a/Code/Steiner/simpleGame/src/Enemy.java b/Code/Steiner/simpleGame/src/Enemy.java new file mode 100644 index 0000000..235a98b --- /dev/null +++ b/Code/Steiner/simpleGame/src/Enemy.java @@ -0,0 +1,18 @@ +public class Enemy extends Character { + private int maxHealth; // Store the original health value + + public Enemy(String name, int health, int attackPower) { + super(name, health, attackPower); + this.maxHealth = health; // Initialize maxHealth to the starting health + } + + public void resetHealth() { + this.health = maxHealth; // Restore health to its original value + } + + @Override + public void displayInfo() { + System.out.printf("Enemy: %s | Health: %d | Attack: %d%n", + name, health, attackPower); + } +} diff --git a/Code/Steiner/simpleGame/src/FightingGame.class b/Code/Steiner/simpleGame/src/FightingGame.class new file mode 100644 index 0000000..32f408d Binary files /dev/null and b/Code/Steiner/simpleGame/src/FightingGame.class differ diff --git a/Code/Steiner/simpleGame/src/FightingGame.java b/Code/Steiner/simpleGame/src/FightingGame.java new file mode 100644 index 0000000..ce21127 --- /dev/null +++ b/Code/Steiner/simpleGame/src/FightingGame.java @@ -0,0 +1,91 @@ +import java.util.Random; +import java.util.Scanner; + +public class FightingGame { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + Random random = new Random(); + + System.out.println("Choose your class: Fighter, Ranger, Mage"); + String playerClass = scanner.nextLine(); + + Player player; + if (playerClass.equalsIgnoreCase("Fighter")) { + player = new Player("Fighter", 100, 15, "Fighter"); + } else if (playerClass.equalsIgnoreCase("Ranger")) { + player = new Player("Ranger", 75, 20, "Ranger"); + } else { + player = new Player("Mage", 50, 30, "Mage"); + } + + // Enemy pool + Enemy[] enemies = { + new Enemy("Bear", 80, 10), + new Enemy("Slime", 50, 5), + new Enemy("Herr Steiner der Mächtige", 150, 25) + }; + + boolean playing = true; + while (playing && player.isAlive()) { + System.out.println("\nA new enemy appears!"); + Enemy enemy = enemies[random.nextInt(enemies.length)]; + enemy.resetHealth(); // Reset the enemy's health + enemy.displayInfo(); + + while (enemy.isAlive() && player.isAlive()) { + System.out.println("\nChoose an action: Attack / Defend / Run"); + String action = scanner.nextLine(); + + if (action.equalsIgnoreCase("Attack")) { + System.out.printf("You attack %s for %d damage!%n", + enemy.getName(), player.getAttackPower()); + enemy.takeDamage(player.getAttackPower()); + + if (enemy.isAlive()) { + System.out.printf("%s attacks you for %d damage!%n", + enemy.getName(), enemy.getAttackPower()); + player.takeDamage(enemy.getAttackPower()); + } else { + System.out.printf("You defeated %s!%n", enemy.getName()); + } + } else if (action.equalsIgnoreCase("Defend")) { + System.out.println("You defend yourself and take less damage!"); + int reducedDamage = Math.max(0, enemy.getAttackPower() / 2); + System.out.printf("%s attacks you for %d damage!%n", + enemy.getName(), reducedDamage); + player.takeDamage(reducedDamage); + } else if (action.equalsIgnoreCase("Run")) { + System.out.println("You attempt to flee..."); + if (random.nextBoolean()) { + System.out.println("You successfully escaped!"); + break; + } else { + System.out.println("You failed to escape!"); + System.out.printf("%s attacks you for %d damage!%n", + enemy.getName(), enemy.getAttackPower()); + player.takeDamage(enemy.getAttackPower()); + } + } else { + System.out.println("Invalid action! Try again."); + } + + System.out.printf("Your Health: %d | %s's Health: %d%n", + player.getHealth(), enemy.getName(), enemy.getHealth()); + } + + if (!player.isAlive()) { + System.out.println("You have been defeated! Game over."); + playing = false; + } else if (!enemy.isAlive()) { + System.out.println("Do you want to continue? (yes/no)"); + String continueGame = scanner.nextLine(); + if (continueGame.equalsIgnoreCase("no")) { + playing = false; + } + } + } + + System.out.println("Thanks for playing!"); + scanner.close(); + } +} diff --git a/Code/Steiner/simpleGame/src/Player.class b/Code/Steiner/simpleGame/src/Player.class new file mode 100644 index 0000000..d5dbe0f Binary files /dev/null and b/Code/Steiner/simpleGame/src/Player.class differ diff --git a/Code/Steiner/simpleGame/src/Player.java b/Code/Steiner/simpleGame/src/Player.java new file mode 100644 index 0000000..5d452a1 --- /dev/null +++ b/Code/Steiner/simpleGame/src/Player.java @@ -0,0 +1,14 @@ +public class Player extends Character { + private String playerClass; + + public Player(String name, int health, int attackPower, String playerClass) { + super(name, health, attackPower); + this.playerClass = playerClass; + } + + @Override + public void displayInfo() { + System.out.printf("Player: %s | Class: %s | Health: %d | Attack: %d%n", + name, playerClass, health, attackPower); + } +} diff --git a/Code/Steiner/smartArrayList/.vscode/settings.json b/Code/Steiner/smartArrayList/.vscode/settings.json new file mode 100644 index 0000000..e112a70 --- /dev/null +++ b/Code/Steiner/smartArrayList/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/Code/Steiner/smartArrayList/README.md b/Code/Steiner/smartArrayList/README.md new file mode 100644 index 0000000..7c03a53 --- /dev/null +++ b/Code/Steiner/smartArrayList/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/Code/Steiner/smartArrayList/bin/App.class b/Code/Steiner/smartArrayList/bin/App.class new file mode 100644 index 0000000..c97fa9f Binary files /dev/null and b/Code/Steiner/smartArrayList/bin/App.class differ diff --git a/Code/Steiner/smartArrayList/bin/SmartArrayList.class b/Code/Steiner/smartArrayList/bin/SmartArrayList.class new file mode 100644 index 0000000..f02a125 Binary files /dev/null and b/Code/Steiner/smartArrayList/bin/SmartArrayList.class differ diff --git a/Code/Steiner/smartArrayList/src/App.class b/Code/Steiner/smartArrayList/src/App.class new file mode 100644 index 0000000..771ffde Binary files /dev/null and b/Code/Steiner/smartArrayList/src/App.class differ diff --git a/Code/Steiner/smartArrayList/src/App.java b/Code/Steiner/smartArrayList/src/App.java new file mode 100644 index 0000000..28d62f3 --- /dev/null +++ b/Code/Steiner/smartArrayList/src/App.java @@ -0,0 +1,18 @@ +public class App { + public static void main(String[] args) throws Exception { + SmartArrayList intList = new SmartArrayList(); + SmartArrayList stringList = new SmartArrayList(); + intList.add(10); + intList.add(20); + intList.add(5); + + stringList.add("Apfel"); + stringList.add("Banane"); + stringList.add("Kirsche"); + + System.out.println("Integer-Liste:"); + intList.printElements(); + System.out.println("\nString-Liste:"); + stringList.printElements(); + } +} diff --git a/Code/Steiner/smartArrayList/src/SmartArrayList.class b/Code/Steiner/smartArrayList/src/SmartArrayList.class new file mode 100644 index 0000000..44ff915 Binary files /dev/null and b/Code/Steiner/smartArrayList/src/SmartArrayList.class differ diff --git a/Code/Steiner/smartArrayList/src/SmartArrayList.java b/Code/Steiner/smartArrayList/src/SmartArrayList.java new file mode 100644 index 0000000..f6f3d3d --- /dev/null +++ b/Code/Steiner/smartArrayList/src/SmartArrayList.java @@ -0,0 +1,10 @@ +import java.util.ArrayList; + +public class SmartArrayList extends ArrayList { + public void printElements() { + System.out.print("Output of the list:"); + for (T object : this) { + System.out.print(" " + object + ","); + } + } +}