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
1 change: 1 addition & 0 deletions .idea/.name

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

1 change: 1 addition & 0 deletions .idea/gradle.xml

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

1 change: 1 addition & 0 deletions Java-Ring/.idea/.name

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

2 changes: 1 addition & 1 deletion Java-Ring/.idea/misc.xml

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

82 changes: 73 additions & 9 deletions Java-Ring/src/main/java/org/project/Main.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,79 @@
package org.project;
import org.project.entity.Entity;
import org.project.entity.players.Assassin;
import org.project.entity.players.Knight;
import org.project.entity.players.Wizard;
import org.project.entity.enemies.Dragon;
import org.project.entity.enemies.Goblin;
import org.project.entity.enemies.Skeleton;
import org.project.object.weapons;
import org.project.object.weapons.Sward;
import org.project.object.armors;
import org.project.object.armors.KnightArmor;

import org.project.location.Location;

import java.util.ArrayList;
import java.util.List;

public class Main {
import java.util.Scanner;

public class JavaRingGame {

public static void main(String[] args) {
// TODO: ADD SOME LOCATIONS TO YOUR GAME
List<Location> locations = new ArrayList<>();
Scanner scanner = new Scanner(System.in);

System.out.println("Select your character: ");
System.out.println("1. Wizard");
System.out.println("2. Knight");
System.out.println("3. Assassin");

int choice = scanner.nextInt();
Entity player = null;

switch (choice) {
case 1:
player = new Wizard(100, 50, new Sword(30, 10));
break;
case 2:
player = new Knight(120, 30, new Sword(40, 15));
break;
case 3:
player = new Assassin(80, 70, new Sword(25, 5));
break;
default:
System.out.println("Invalid choice, defaulting to Wizard.");
player = new Wizard(100, 50, new Sword(30, 10));
}

Entity enemy = generateRandomEnemy();

System.out.println("\nYour enemy: " + enemy.getClass().getSimpleName());
System.out.println("Battle Start!");

while (player.isAlive() && enemy.isAlive()) {
System.out.println("\nYour turn to attack!");
player.attack(enemy);
if (enemy.isAlive()) {
System.out.println("\nEnemy's turn to attack!");
enemy.attack(player);
}
}

if (!player.isAlive()) {
System.out.println("You have been defeated by " + enemy.getClass().getSimpleName() + "!");
} else if (!enemy.isAlive()) {
System.out.println("You have defeated " + enemy.getClass().getSimpleName() + "!");
}
}

// TODO: IMPLEMENT GAMEPLAY
public static Entity generateRandomEnemy() {
int rand = (int) (Math.random() * 3);
switch (rand) {
case 0:
return new Goblin(50, 20, new Sword(15, 5));
case 1:
return new Skeleton(70, 25, new Sword(20, 8));
case 2:
return new Dragon(200, 50, new Sword(50, 20));
default:
return new Goblin(50, 20, new Sword(15, 5)); // Default enemy
}
}
}
}
4 changes: 1 addition & 3 deletions Java-Ring/src/main/java/org/project/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ public interface Entity {

int getMaxMP();

/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
boolean isAlive();
}
70 changes: 70 additions & 0 deletions Java-Ring/src/main/java/org/project/entity/enemies/Dragon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.project.entity.enemies;

import org.project.object.armors.Armor;
import org.project.object.weapons.Weapon;
import org.project.entity.Entity;

public class Dragon extends Enemy {
private static final int FIREBALL_DAMAGE = 30;
private static final int FIREBALL_MANA_COST = 20;

public Dragon(int hp, int mp, Weapon weapon) {
super(hp, mp, weapon);
}

@Override
public void attack(Entity target) {
if (getMp() >= FIREBALL_MANA_COST) {
System.out.println("🔥 Dragon breathes fire!");
target.takeDamage(FIREBALL_DAMAGE);
fillMana(-FIREBALL_MANA_COST);
} else {
super.attack(target);
}
}

@Override
public void takeDamage(int damage) {
int reducedDamage = damage / 2;
super.takeDamage(reducedDamage);
System.out.println("🛡️ Dragon's tough scales reduce damage!");
}

public void fly() {
System.out.println("🐉 Dragon flies into the sky, preparing for a powerful attack!");
}
}
package org.project.entity.enemies;

import org.project.object.weapons.Weapon;

public class Dragon extends Enemy {
private static final int FIREBALL_DAMAGE = 30;
private static final int FIREBALL_MANA_COST = 20;

public Dragon(int hp, int mp, Weapon weapon) {
super(hp, mp, weapon);
}

@Override
public void attack(Entity target) {
if (getMp() >= FIREBALL_MANA_COST) {
System.out.println("🔥 Dragon breathes fire!");
target.takeDamage(FIREBALL_DAMAGE);
fillMana(-FIREBALL_MANA_COST);
} else {
super.attack(target);
}
}

@Override
public void takeDamage(int damage) {
int reducedDamage = damage / 2;
super.takeDamage(reducedDamage);
System.out.println("🛡️ Dragon's tough scales reduce damage!");
}

public void fly() {
System.out.println("🐉 Dragon flies into the sky, preparing for a powerful attack!");
}
}
51 changes: 46 additions & 5 deletions Java-Ring/src/main/java/org/project/entity/enemies/Enemy.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,64 @@

import org.project.object.weapons.Weapon;

// TODO: UPDATE IMPLEMENTATION
public abstract class Enemy {
Weapon weapon;
public abstract class Enemy implements Entity {
protected Weapon weapon;
private int maxHP;
private int maxMP;
private int hp;
private int mp;

public Enemy(int hp, int mp, Weapon weapon) {
this.maxHP = hp;
this.maxMP = mp;
this.hp = hp;
this.mp = mp;

this.weapon = weapon;
}

// TODO: (BONUS) UPDATE THE FORMULA OF TAKING DAMAGE
@Override
public void attack(Entity target) {
if (weapon != null) {
System.out.println("Enemy attacks with " + weapon.getName());
target.takeDamage(weapon.getDamage());
} else {
System.out.println("Enemy has no weapon to attack!");
}
}

@Override
public void takeDamage(int damage) {
hp -= damage;
if (hp <= 0) {
hp = 0;
System.out.println("Enemy has been defeated!");
}
}

@Override
public void heal(int health) {
hp += health;
if (hp > maxHP) {
hp = maxHP;
}
}

@Override
public void fillMana(int mana) {
mp += mana;
if (mp > maxMP) {
mp = maxMP;
}
}

@Override
public int getMaxHP() {
return maxHP;
}

@Override
public int getMaxMP() {
return maxMP;
}

public int getHp() {
Expand Down
30 changes: 30 additions & 0 deletions Java-Ring/src/main/java/org/project/entity/enemies/Goblin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.project.entity.enemies;

import org.project.object.armors.Armor;
import org.project.object.weapons.Weapon;
import org.project.entity.Entity;
import java.util.Random;

public class Goblin extends Enemy {
private static final double CRITICAL_CHANCE = 0.1;

public Goblin(int hp, int mp, Weapon weapon) {
super(hp, mp, weapon);
}

@Override
public void attack(Entity target) {
Random rand = new Random();
for (int i = 0; i < 2; i++) { // دو بار حمله می‌کند
int damage = (weapon != null) ? weapon.getDamage() / 2 : 5;

if (i == 0 && rand.nextDouble() < CRITICAL_CHANCE) {
damage *= 2;
System.out.println("💥 Goblin lands a CRITICAL HIT!");
}

System.out.println("⚔️ Goblin attacks for " + damage + " damage!");
target.takeDamage(damage);
}
}
}
36 changes: 32 additions & 4 deletions Java-Ring/src/main/java/org/project/entity/enemies/Skeleton.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
package org.project.entity.enemies;

// TODO: UPDATE IMPLEMENTATION
public class Skeleton {
// TODO: DESIGN ENEMY'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
}
import org.project.object.armors.Armor;
import org.project.object.weapons.Weapon;
import org.project.entity.Entity;
import java.util.Random;

public class Skeleton extends Enemy {
private boolean resurrected = false;

public Skeleton(int hp, int mp, Weapon weapon) {
super(hp, mp, weapon);
}

@Override
public void takeDamage(int damage) {
int finalDamage = damage;
if (weapon != null) {
finalDamage *= 0.75;
}

super.takeDamage(finalDamage);
System.out.println("🦴 Skeleton resists some damage!");

if (getHp() == 0 && !resurrected) {
Random rand = new Random();
if (rand.nextBoolean()) {
resurrected = true;
heal(getMaxHP() / 2);
System.out.println("💀 Skeleton resurrects with half HP!");
}
}
}
}
42 changes: 42 additions & 0 deletions Java-Ring/src/main/java/org/project/entity/players/Assassin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.project.entity.players;

import org.project.object.armors.Armor;
import org.project.object.weapons.Weapon;
import org.project.entity.Entity;

public class Assassin extends Assassin {

public Assassin(String name, 200, 40, weapon, armor) {

@Override
public void attack(Entity target) {
System.out.println(getName() + " attacks with a" + weapon.getname());
super.attack(target);
}

@Override
public void defend() {
System.out.println(getName() + " raises his shield!");
super.defend();
}

@Override
public void takeDamage(int damage) {
System.out.println(getName() + " takes " + damage + " damage!");
super.takeDamage(damage);
}

@Override
public void heal(int health) {
System.out.println(getName() + " heals for " + health + " health!");
super.heal(health);
}

@Override
public void fillMana(int mana) {
System.out.println(getName() + " restores " + mana + " mana!");
super.fillMana(mana);
}
}
}
}
Loading