Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/homework-java-ironbattle.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Battle/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.ironhack</groupId>
<artifactId>Battle</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
5 changes: 5 additions & 0 deletions Battle/src/main/java/org/example/Attacker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.example;

public interface Attacker {
void attack(Characters target);
}
38 changes: 38 additions & 0 deletions Battle/src/main/java/org/example/Characters.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.example;
import java.util.UUID;
public abstract class Characters {
private final String id;
private String name;
private int hp;
private boolean isAlive=true;
public Characters(String name,int hp){
this.id = UUID.randomUUID().toString();
this.name=name;
this.hp=hp;
this.isAlive=true;
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public int getHp(){
return hp;
}
public void setHp(int hp){
this.hp=hp;
if(this.hp<0) {
this.hp=0;
isAlive=false;
}}
public boolean getAlive(){return isAlive;}

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing. Line 29 should have consistent spacing around braces and the return statement, following Java formatting conventions.

Suggested change
public boolean getAlive(){return isAlive;}
public boolean getAlive() {
return isAlive;
}

Copilot uses AI. Check for mistakes.
public void setAlive(boolean isAlive){
this.isAlive=isAlive;
Comment on lines +7 to +31

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing around operators. Lines 10-12 have inconsistent spacing around the '=' operator (no spaces), which differs from standard Java formatting conventions.

Suggested change
private boolean isAlive=true;
public Characters(String name,int hp){
this.id = UUID.randomUUID().toString();
this.name=name;
this.hp=hp;
this.isAlive=true;
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public int getHp(){
return hp;
}
public void setHp(int hp){
this.hp=hp;
if(this.hp<0) {
this.hp=0;
isAlive=false;
}}
public boolean getAlive(){return isAlive;}
public void setAlive(boolean isAlive){
this.isAlive=isAlive;
private boolean isAlive = true;
public Characters(String name, int hp){
this.id = UUID.randomUUID().toString();
this.name = name;
this.hp = hp;
this.isAlive = true;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public int getHp(){
return hp;
}
public void setHp(int hp){
this.hp = hp;
if (this.hp < 0) {
this.hp = 0;
isAlive = false;
}}
public boolean getAlive(){return isAlive;}
public void setAlive(boolean isAlive){
this.isAlive = isAlive;

Copilot uses AI. Check for mistakes.
}

}




116 changes: 116 additions & 0 deletions Battle/src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package org.example;

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
boolean exit = false;
System.out.println("=================================");
System.out.println(" WELCOME TO IRON BATTLE!");
System.out.println("=================================\n");
while (!exit) {
System.out.println("\n--- MAIN MENU ---");
System.out.println("1. Create Battle");
System.out.println("2. Exit");
Comment on lines +13 to +14

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discrepancy between menu options. The Main.java source file shows a simplified menu with only "Create Battle" and "Exit" options (lines 13-14), while the compiled Main.class file shows the original menu had "Create Custom Battle", "Simulate Random Battle", and "Exit" options. This suggests the randomBattle functionality was removed. If this is intentional, ensure this aligns with the PR's purpose. If not, the source code may need to restore the missing menu option and randomBattle method.

Copilot uses AI. Check for mistakes.
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
customBattle(scanner);
break;
case 2:
System.out.println("Thanks for playing! Goodbye!");
exit = true;
break;
default:
System.out.println("Invalid option. Please try again.");
}
}
scanner.close();
}
private static void customBattle(Scanner scanner) {
System.out.println("\n=== CREATE CHARACTER 1 ===");
Characters character1 = createCharacter(scanner, "Character 1");
System.out.println("\n=== CREATE CHARACTER 2 ===");
Characters character2 = createCharacter(scanner, "Character 2");
startBattle(character1, character2);
}
private static Characters createCharacter(Scanner scanner, String prompt) {
System.out.println("Choose character type:");
System.out.println("1. Warrior");
System.out.println("2. Wizard");
System.out.print("Enter choice: ");
int type = scanner.nextInt();
scanner.nextLine();
System.out.print("Enter character name: ");
String name = scanner.nextLine();
Characters character;
if (type == 1) {
character = new Warriors(name);
System.out.println("Warrior created! HP: " + character.getHp());
} else {
character = new Wizards(name);
System.out.println("Wizard created! HP: " + character.getHp());
}
return character;
}
private static void startBattle(Characters char1, Characters char2) {
int battleNumber = 1;
while (true) {
System.out.println("\n" + "=".repeat(50));
System.out.println("BATTLE #" + battleNumber + " BEGINS!");
System.out.println("=".repeat(50));
System.out.println(char1.getName() + " (HP: " + char1.getHp() + ") VS " +
char2.getName() + " (HP: " + char2.getHp() + ")");
System.out.println("=".repeat(50) + "\n");
if (battleNumber > 1) {
String name1 = char1.getName();
String name2 = char2.getName();
if (char1 instanceof Warriors) {
char1 = new Warriors(name1);
} else {
char1 = new Wizards(name1);
}
if (char2 instanceof Warriors) {
char2 = new Warriors(name2);
} else {
char2 = new Wizards(name2);
}
System.out.println("Characters reset for new battle!");
System.out.println(char1.getName() + " HP: " + char1.getHp());
System.out.println(char2.getName() + " HP: " + char2.getHp());
}
Comment on lines +67 to +83

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect indentation. The if statement starting on line 67 should be properly indented to align with the surrounding code. The entire block from lines 67-83 appears to have inconsistent indentation.

Copilot uses AI. Check for mistakes.
int round = 1;
while (char1.getAlive() && char2.getAlive()) {
System.out.println("\n--- Round " + round + " ---");
if (char1 instanceof Attacker) {
((Attacker) char1).attack(char2);
}
if (char2 instanceof Attacker) {
((Attacker) char2).attack(char1);
}
System.out.println(char1.getName() + " HP: " + char1.getHp() + " | " +
char2.getName() + " HP: " + char2.getHp());
round++;
}
System.out.println("\n" + "=".repeat(50));
System.out.println(" BATTLE OVER!");
System.out.println("=".repeat(50));
if (!char1.getAlive() && !char2.getAlive()) {
System.out.println("IT'S A TIE! Both warriors fell!");
System.out.println("Restarting battle to determine a clear winner...\n");
battleNumber++;
continue; // Restart battle
} else if (char1.getAlive()) {
System.out.println(" WINNER: " + char1.getName());
System.out.println("Remaining HP: " + char1.getHp());
} else {
System.out.println("WINNER: " + char2.getName() );
System.out.println("Remaining HP: " + char2.getHp());
}
System.out.println("=".repeat(50));
break;
}
}
}
49 changes: 49 additions & 0 deletions Battle/src/main/java/org/example/Warriors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.example;
import java.util.concurrent.ThreadLocalRandom;
public class Warriors extends Characters implements Attacker {

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing. There is an extra space after 'extends' before 'Characters'. Java style guides recommend single spaces between keywords and types.

Suggested change
public class Warriors extends Characters implements Attacker {
public class Warriors extends Characters implements Attacker {

Copilot uses AI. Check for mistakes.
private int stamina;
private int strength;
public Warriors(String name){
super(name,ThreadLocalRandom.current().nextInt(100, 201));
this.stamina=ThreadLocalRandom.current().nextInt(10,51);
this.strength=ThreadLocalRandom.current().nextInt(1,11);
Comment on lines +8 to +9

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing around operators. The assignment operators should have consistent spacing. Lines 8-9 have inconsistent spacing around the '=' operator (no spaces).

Suggested change
this.stamina=ThreadLocalRandom.current().nextInt(10,51);
this.strength=ThreadLocalRandom.current().nextInt(1,11);
this.stamina = ThreadLocalRandom.current().nextInt(10, 51);
this.strength = ThreadLocalRandom.current().nextInt(1, 11);

Copilot uses AI. Check for mistakes.
}

public int getStamina() {
return stamina;
}

public void setStamina(int stamina) {
this.stamina = stamina;
}

public int getStrength() {
return strength;
}

public void setStrength(int strength) {
this.strength = strength;
}

@Override
public void attack(Characters target) {
int attackType = ThreadLocalRandom.current().nextInt(0, 2);

if (attackType == 0 && this.stamina >= 5) {
int damage = this.strength;
this.stamina -= 5;
target.setHp(target.getHp() - damage);
System.out.println(getName() + " uses HEAVY ATTACK! Deals " + damage + " damage.");
} else if (this.stamina >= 1) {
int damage = this.strength / 2;
this.stamina += 1;

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic error in attack method. When the warrior uses a WEAK ATTACK (line 37-41), the stamina is being incremented (+= 1) instead of decremented. This allows warriors to gain stamina while attacking, which contradicts the resource management logic. The weak attack should cost stamina, not increase it.

Suggested change
this.stamina += 1;
this.stamina -= 1;

Copilot uses AI. Check for mistakes.
target.setHp(target.getHp() - damage);
System.out.println(getName() + " uses WEAK ATTACK! Deals " + damage + " damage.");
} else {
this.stamina += 2;
System.out.println(getName() + " is exhausted! Recovers 2 stamina.");
}
}

}

50 changes: 50 additions & 0 deletions Battle/src/main/java/org/example/Wizards.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.example;
import java.util.concurrent.ThreadLocalRandom;
public class Wizards extends Characters implements Attacker {
private int mana;
private int intelligence;
public Wizards(String name){

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after keyword. There should be a space between 'public' and 'Wizards' in the constructor declaration to follow Java formatting conventions.

Suggested change
public Wizards(String name){
public Wizards(String name){

Copilot uses AI. Check for mistakes.
super(name,ThreadLocalRandom.current().nextInt(50,101));
this.mana=ThreadLocalRandom.current().nextInt(10,51);
this.intelligence=ThreadLocalRandom.current().nextInt(1,51);
Comment on lines +8 to +9

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing around operators. The assignment operators should have consistent spacing. Lines 8-9 have inconsistent spacing around the '=' operator (no spaces).

Suggested change
this.mana=ThreadLocalRandom.current().nextInt(10,51);
this.intelligence=ThreadLocalRandom.current().nextInt(1,51);
this.mana = ThreadLocalRandom.current().nextInt(10,51);
this.intelligence = ThreadLocalRandom.current().nextInt(1,51);

Copilot uses AI. Check for mistakes.
}

public int getMana() {
return mana;
}

public void setMana(int mana) {
this.mana = mana;
}

public int getIntelligence() {
return intelligence;
}

public void setIntelligence(int intelligence) {
this.intelligence = intelligence;
}

@Override
public void attack(Characters target) {
int attackType = ThreadLocalRandom.current().nextInt(0, 2);

if (attackType == 0 && this.mana >= 5) {
int damage = this.intelligence;
this.mana -= 5;
target.setHp(target.getHp() - damage);
System.out.println(getName() + " casts FIREBALL! Deals " + damage + " damage.");
} else if (this.mana >= 1) {
int damage = 2;
this.mana += 1;

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic error in attack method. When the wizard uses a STAFF attack (line 37-41), the mana is being incremented (+= 1) instead of decremented. This allows wizards to gain mana while attacking, which contradicts the resource management logic. The staff attack should either cost mana or not modify it, not increase it.

Suggested change
this.mana += 1;
this.mana -= 1;

Copilot uses AI. Check for mistakes.
target.setHp(target.getHp() - damage);
System.out.println(getName() + " hits with STAFF! Deals " + damage + " damage.");
} else { this.mana += 2;
System.out.println(getName() + " out of mana! Recovers 2 mana.");
}
}



Comment on lines +42 to +48

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation. The closing braces are misaligned with the rest of the code structure. Lines 42-44 should maintain consistent indentation throughout the else block.

Suggested change
} else { this.mana += 2;
System.out.println(getName() + " out of mana! Recovers 2 mana.");
}
}
} else {
this.mana += 2;
System.out.println(getName() + " out of mana! Recovers 2 mana.");
}
}

Copilot uses AI. Check for mistakes.
}

Binary file added Battle/target/classes/org/example/Attacker.class
Binary file not shown.
Binary file not shown.
Binary file added Battle/target/classes/org/example/Main.class
Binary file not shown.
Binary file added Battle/target/classes/org/example/Warriors.class
Binary file not shown.
Binary file added Battle/target/classes/org/example/Wizards.class
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![logo_ironhack_blue 7](https://user-images.githubusercontent.com/23629340/40541063-a07a0a8a-601a-11e8-91b5-2f13e4e6b441.png)
\![logo_ironhack_blue 7](https://user-images.githubusercontent.com/23629340/40541063-a07a0a8a-601a-11e8-91b5-2f13e4e6b441.png)

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect markdown syntax. The backslash before the exclamation mark escapes the markdown image syntax, causing the image not to render. Remove the backslash before the exclamation mark.

Suggested change
\![logo_ironhack_blue 7](https://user-images.githubusercontent.com/23629340/40541063-a07a0a8a-601a-11e8-91b5-2f13e4e6b441.png)
![logo_ironhack_blue 7](https://user-images.githubusercontent.com/23629340/40541063-a07a0a8a-601a-11e8-91b5-2f13e4e6b441.png)

Copilot uses AI. Check for mistakes.

# HW | Java IronBattle (Unit 1 homework)

Expand Down
Loading