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
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,31 @@ For this project you must accomplish all of the following:
- All code must be reviewed before it is merged into the `master` branch.
- All squad members must participate in code review.
- Every repository should have a README file with clear instructions, demo files or any documentation needed so other teams don't have problems with the review.
- This is intended to be a challenging assignment. You will have to rely heavily on your teammates and independent research. Learning independently is a hallmark of a good developer and our job is to turn you into good developers. This process may be frustrating but you will learn a ton!
- This is intended to be a challenging assignment. You will have to rely heavily on your teammates and independent research. Learning independently is a hallmark of a good developer and our job is to turn you into good developers. This process may be frustrating but you will learn a ton!# RPG Battle Simulator

## About This Project
This is my RPG Battle Simulator project. The idea is simple: two characters fight 1v1 until one winner remains. You can have a Warrior or a Wizard, each with their own stats and fighting style. Battles happen in rounds, and both characters attack at the same time in each round. If both die in the same round, the battle is considered a draw and can be restarted.

## Classes and Interface
- **Character (abstract)**: This is the base class. It has common things like id,
ame, hp, and isAlive. You cannot create a Character directly.
- **Warrior**: Inherits from Character. Has stamina and strength. Can do Heavy or Weak attacks. Heavy costs stamina, Weak can recover stamina.
- **Wizard**: Inherits from Character. Has mana and intelligence. Can do Fireball or Staff hits. Fireball costs mana, Staff can recover mana.
- **Attacker (interface)**: Both Warriors and Wizards implement this interface to define the ttack(Character opponent) method.

The battle will start automatically between a Warrior and a Wizard. Each attack and change in HP, stamina, or mana is shown in the console.

## Features
- Characters have random stats (HP, stamina, mana, strength, intelligence) when they are created.
- Battle is 1v1, simultaneous attacks each round.
- If both characters die in the same round, it is a draw.
- Logs are printed to the console showing every attack and status change.

## Optional / Bonus
- Import characters from a CSV file.
- Create random characters and simulate battles automatically.

## Notes
- The project uses object-oriented concepts like inheritance, encapsulation, and polymorphism.
- Everything is logged so you can see the battle step by step.
- Warrior and Wizard attacks follow the rules for stamina/mana consumption and recovery.
39 changes: 39 additions & 0 deletions homework_ironbattle/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
.kotlin

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
10 changes: 10 additions & 0 deletions homework_ironbattle/.idea/.gitignore

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

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

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

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

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

6 changes: 6 additions & 0 deletions homework_ironbattle/.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 homework_ironbattle/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>org.example</groupId>
<artifactId>homework_ironbattle</artifactId>
<version>1.0-SNAPSHOT</version>

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

</project>
5 changes: 5 additions & 0 deletions homework_ironbattle/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(Character opponent);
}
44 changes: 44 additions & 0 deletions homework_ironbattle/src/main/java/org/example/Character.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.example;

import java.util.UUID;

public abstract class Character implements Attacker{
private String id;
private String name;
private int hp;
private boolean isAlive=true;
public Character(String name,int health){
this.name=name;
this.hp=health;
this.id= UUID.randomUUID().toString();
}
public String getId(){
return this.id;
}
public String getName(){
return this.name;
}
public int getHp(){
return this.hp;
}
public boolean isAlive(){
return this.isAlive;
}

public void setId(String id) {
this.id = id;
}
public void setHp(int hp){
this.hp=hp;
if(hp<=0){
this.hp=0;
this.isAlive=false;
}
}
public void setIsAlive(boolean isAlive){
this.isAlive=isAlive;
}
public void setName(String name){
this.name=name;
}
}
32 changes: 32 additions & 0 deletions homework_ironbattle/src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.example;
public class Main {
public static void main(String[] args){
Warrior warrior=new Warrior("Shebnem");
Wizard wizard=new Wizard("Mehemmed");
System.out.println("--- Battle Setup ---");
System.out.println(warrior.getName() + " (Warrior) HP: " + warrior.getHp());
System.out.println(wizard.getName() + " (Wizard) HP: " + wizard.getHp());
System.out.println("--------------------\n");

while(warrior.getHp()>0 && wizard.getHp()>0){
warrior.attack(wizard);
if (wizard.getHp() <= 0) {
break;
}
wizard.attack(warrior);
System.out.println("----------");
}
System.out.println("\n*** THE BATTLE IS OVER ***");
if(warrior.getHp()<=0 && wizard.getHp()<=0){
System.out.println("It's a draw! Both heroes fell in glory.");
}
else if(warrior.getHp()<=0 ){
System.out.println("Winner is "+wizard.getName() + "!");
}
else{
System.out.println("Winner is "+warrior.getName() + "!");
}

}

}
53 changes: 53 additions & 0 deletions homework_ironbattle/src/main/java/org/example/Warrior.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.example;

public class Warrior extends Character{
private int stamina;
private int strength;
public Warrior(String name){
super(name, 100 + (int)(Math.random() * 101));
this.stamina = 10 + (int)(Math.random() * 41);
this.strength = 1 + (int)(Math.random() * 10);

}
public int getStamina(){
return this.stamina;
}
public int getStrength(){
return this.strength;
}

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

public void setStrength(int strength) {
this.strength = strength;
}
public void attack(Character opponent){
int randomChoice=(int) (Math.random()*2);
if(randomChoice==1){
if(this.stamina>=5){
opponent.setHp(opponent.getHp()-getStrength());
this.stamina-=5;
System.out.println(getName() + " performed a Heavy Attack! " + opponent.getName() + " HP: " + opponent.getHp());
}
else{
weak(opponent);
}
}
else{
weak(opponent);
}
}
public void weak(Character opponent){
if(this.stamina>=1){
opponent.setHp(opponent.getHp()-getStrength()/2);
this.stamina+=1;
System.out.println(getName() + " performed a Weak Attack! " + opponent.getName() + " HP: " + opponent.getHp());
}
else{
System.out.println(getName() + " is out of stamina, resting... Stamina +2");
this.stamina+=2;
}
}
}
52 changes: 52 additions & 0 deletions homework_ironbattle/src/main/java/org/example/Wizard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.example;

public class Wizard extends Character{
private int mana;
private int intelligence;
public Wizard(String name){
super(name, 50 + (int)(Math.random() * 51));
this.mana = 10 + (int)(Math.random() * 41);
this.intelligence = 1 + (int)(Math.random() * 50);
}
public int getMana(){
return this.mana;
}
public int getIntelligence(){
return this.intelligence;
}
public void setMana(int mana){
this.mana=mana;
}
public void setIntelligence(int intelligence){
this.intelligence=intelligence;
}
public void attack(Character opponent){
int randomChoice=(int)(Math.random()*2);
if(randomChoice==1){
if(this.mana>=5){
opponent.setHp(opponent.getHp() - this.intelligence);
this.mana-=5;
System.out.println(getName() + " cast Fireball! " + opponent.getName() + " HP: " + opponent.getHp());
}
else{
staffHit(opponent);
}
}
else{
staffHit(opponent);
}
}
public void staffHit(Character opponent){
if(this.mana>=1){
opponent.setHp(opponent.getHp()-2);
this.mana+=1;
System.out.println(getName() + " used Staff Hit! " + opponent.getName() + " HP: " + opponent.getHp());

}
else{
this.mana+=2;
System.out.println(getName() + " is exhausted, resting... Mana +2");

}
}
}