LETS START A RIOT OOO A RIOT

This commit is contained in:
Sage The DM 2024-11-27 15:00:54 +01:00
parent 72f7a2e529
commit a491769914
22 changed files with 234 additions and 0 deletions

View file

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View file

@ -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).

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -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
}

Binary file not shown.

View file

@ -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);
}
}

Binary file not shown.

View file

@ -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();
}
}

Binary file not shown.

View file

@ -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);
}
}

View file

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View file

@ -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).

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,18 @@
public class App {
public static void main(String[] args) throws Exception {
SmartArrayList<Integer> intList = new SmartArrayList<Integer>();
SmartArrayList<String> stringList = new SmartArrayList<String>();
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();
}
}

Binary file not shown.

View file

@ -0,0 +1,10 @@
import java.util.ArrayList;
public class SmartArrayList<T> extends ArrayList<T> {
public void printElements() {
System.out.print("Output of the list:");
for (T object : this) {
System.out.print(" " + object + ",");
}
}
}