LETS START A RIOT OOO A RIOT
This commit is contained in:
		
							parent
							
								
									72f7a2e529
								
							
						
					
					
						commit
						a491769914
					
				
					 22 changed files with 234 additions and 0 deletions
				
			
		
							
								
								
									
										
											BIN
										
									
								
								Code/Steiner/simpleGame/src/Character.class
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Code/Steiner/simpleGame/src/Character.class
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										33
									
								
								Code/Steiner/simpleGame/src/Character.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								Code/Steiner/simpleGame/src/Character.java
									
										
									
									
									
										Normal 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 | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								Code/Steiner/simpleGame/src/Enemy.class
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Code/Steiner/simpleGame/src/Enemy.class
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										18
									
								
								Code/Steiner/simpleGame/src/Enemy.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								Code/Steiner/simpleGame/src/Enemy.java
									
										
									
									
									
										Normal 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); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								Code/Steiner/simpleGame/src/FightingGame.class
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Code/Steiner/simpleGame/src/FightingGame.class
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										91
									
								
								Code/Steiner/simpleGame/src/FightingGame.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								Code/Steiner/simpleGame/src/FightingGame.java
									
										
									
									
									
										Normal 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(); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								Code/Steiner/simpleGame/src/Player.class
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Code/Steiner/simpleGame/src/Player.class
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										14
									
								
								Code/Steiner/simpleGame/src/Player.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								Code/Steiner/simpleGame/src/Player.java
									
										
									
									
									
										Normal 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); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Sage The DM
						Sage The DM