Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
64792b2
Added a super power for Sword(bounos track) complete the methods and …
MRL0R3 Apr 9, 2025
c6c19a6
Main java changed
MRL0R3 Apr 10, 2025
47cd0c6
some eror fixed
MRL0R3 Apr 10, 2025
974202a
Bouns super power add for sword called fireWhirlAttack
MRL0R3 Apr 10, 2025
6fe6f18
Use Special ability method updated added set level and getlevel
MRL0R3 Apr 10, 2025
1dde45f
take damage method updated(Bouns) and defend system updated
MRL0R3 Apr 10, 2025
e56dc02
Nothing new
MRL0R3 Apr 10, 2025
43e5e8e
Object Interface updated
MRL0R3 Apr 10, 2025
8c0046b
Abstract class consumables updated
MRL0R3 Apr 10, 2025
b0ad48b
Abstract class consumables updated
MRL0R3 Apr 10, 2025
65f49f6
Added a getter method
MRL0R3 Apr 12, 2025
a024fda
Updated
MRL0R3 Apr 12, 2025
0b8874f
Merge pull request #1 from MRL0R3/develop
MRL0R3 Apr 12, 2025
3d0bb6d
for checking problems
MRL0R3 Apr 12, 2025
4144adf
Entity is completed
MRL0R3 Apr 13, 2025
72ac6ce
New enemy added with superpower
MRL0R3 Apr 13, 2025
d89b349
Goblin is now completed and now can dage the attack
MRL0R3 Apr 13, 2025
8476a79
Skeleton has two lives and a RustySword to attack
MRL0R3 Apr 13, 2025
ce631a2
Knight now has super power and can recover his hp
MRL0R3 Apr 13, 2025
3b9d139
Updated
MRL0R3 Apr 13, 2025
12c4c25
Location is now updated
MRL0R3 Apr 13, 2025
e319d14
Remove unused OtherWeaopns.java
MRL0R3 Apr 13, 2025
422c67f
The main game is fully completed
MRL0R3 Apr 13, 2025
15f50a0
It's ability for Goblin
MRL0R3 Apr 13, 2025
c6307f8
It's a special ability for Skeleton
MRL0R3 Apr 13, 2025
786f1eb
Add Staff weapon for Wizard
MRL0R3 Apr 13, 2025
8d99890
Add ManaPotion consumable
MRL0R3 Apr 13, 2025
cf8d4f8
Add ManaPotion consumable
MRL0R3 Apr 13, 2025
e78d11f
Wizard is character that player can choose to play
MRL0R3 Apr 13, 2025
ba52131
modified for using manapotion
MRL0R3 Apr 13, 2025
294f639
modified for using manapotion
MRL0R3 Apr 13, 2025
ff15435
it is completed
MRL0R3 Apr 13, 2025
8cd9c30
completed
MRL0R3 Apr 13, 2025
344c1e0
Modified for Manapotion
MRL0R3 Apr 13, 2025
2974fc9
Merge pull request #2 from MRL0R3/develop
MRL0R3 Apr 13, 2025
07764cf
Update README.md
MRL0R3 Apr 15, 2025
6e7ad72
Comments are added
MRL0R3 Apr 15, 2025
8b047c3
<Added comments>
MRL0R3 Apr 15, 2025
320262a
Merge pull request #3 from MRL0R3/develop
MRL0R3 Apr 15, 2025
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
5 changes: 4 additions & 1 deletion .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.

4 changes: 3 additions & 1 deletion Java-Ring/.idea/gradle.xml

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.

271 changes: 271 additions & 0 deletions Java-Ring/src/main/java/org/project/GameEngine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
package org.project;

import org.project.entity.enemies.Enemy;
import org.project.entity.players.*;
import org.project.location.Location;
import org.project.object.consumables.Consumable;
import java.util.Scanner;

/**
* Main game engine class that controls the game flow and manages player interactions.
* Handles initialization, game loop, combat, and menu systems.
*/
public class GameEngine {
// Game state variables
private Player player; // Current player character
private Location currentLocation; // Active game location
private Scanner scanner = new Scanner(System.in); // Input handler
private boolean gameRunning = true; // Main game loop flag

/**
* Starts the main game loop and manages the game lifecycle
*/
public void startGame() {
initializePlayer(); // Set up player character
initializeLocations(); // Initialize game world

// Main game loop - runs while game is active and player is alive
while (gameRunning && player.isAlive()) {
displayMainMenu(); // Show player options
handleMainMenuInput(); // Process player choice
}

endGame(); // Handle game conclusion
}

/**
* Initializes player character with name and class selection
*/
private void initializePlayer() {
System.out.println("=== CHARACTER CREATION ===");
System.out.print("Enter your name: ");
String name = scanner.nextLine();

// Class selection menu
System.out.println("Choose your class:");
System.out.println("1. Knight\n2. Wizard\n3. Assassin");

int classChoice = Integer.parseInt(scanner.nextLine());

// Create player based on class choice
player = switch (classChoice) {
case 1 -> new Knight(name); // Tank class
case 2 -> new Wizard(name); // Mage class
default -> new Knight(name); // Default to Knight
};

System.out.printf("%s the %s enters the Java Ring!%n",
player.getName(), player.getClass().getSimpleName());
}

/**
* Initializes game locations and starting area
*/
private void initializeLocations() {
// Create starting location with description
currentLocation = new Location("Forgotten Forest",
"A dense woodland shrouded in mist");
}

/**
* Displays the main game menu options
*/
private void displayMainMenu() {
System.out.println("\n=== MAIN MENU ===");
System.out.println("Location: " + currentLocation.getName());
System.out.println("1. Explore"); // Risk encounter
System.out.println("2. Character Info"); // View stats
System.out.println("3. Quit"); // Exit game
System.out.print("Choose an action: ");
}

/**
* Handles player input from main menu
*/
private void handleMainMenuInput() {
int choice = getValidInput(1, 3); // Get validated input

switch (choice) {
case 1 -> explore(); // Enter exploration
case 2 -> displayCharacterInfo(); // Show character sheet
case 3 -> gameRunning = false; // Quit game
default -> System.out.println("Invalid choice!");
}
}

/**
* Handles exploration logic and random encounters
*/
private void explore() {
System.out.println("\nYou venture deeper into " + currentLocation.getName());

// 70% chance of enemy encounter
if (Math.random() < 0.7) {
Enemy enemy = currentLocation.generateEnemy();
if (enemy != null) {
System.out.println("Encountered: " + enemy.getDescription());
startCombat(enemy); // Begin combat if enemy exists
} else {
System.out.println("The enemy mysteriously vanished...");
}
} else {
System.out.println("The path is clear for now...");
}
currentLocation.increaseDanger(); // Scale difficulty
}

/**
* Manages combat between player and enemy
* @param enemy The enemy to fight
*/
private void startCombat(Enemy enemy) {
System.out.printf("%nA wild %s appears!%n", enemy.getName());

// Combat continues until one combatant is defeated
while (player.isAlive() && enemy.isAlive()) {
playerTurn(enemy); // Player action phase

if (!enemy.isAlive()) break; // Check if enemy defeated

enemyTurn(enemy); // Enemy action phase
}

// Combat resolution
if (player.isAlive()) {
System.out.printf("You defeated the %s!%n", enemy.getName());
player.gainExperience(enemy.getExpReward()); // Award XP
} else {
System.out.println("You have been defeated...");
}
}

/**
* Handles player's turn during combat
* @param enemy The current combat target
*/
private void playerTurn(Enemy enemy) {
System.out.println("\n=== YOUR TURN ===");
// Display combat status
System.out.printf("HP: %d/%d | Enemy HP: %d%n",
player.getHealth(), player.getMaxHealth(), enemy.getHealth());

// Combat action menu
System.out.println("1. Attack");
System.out.println("2. Defend");
System.out.println("3. Special Ability");
System.out.println("4. Use Item");
System.out.print("Choose action: ");

int choice = getValidInput(1, 4); // Validate input

// Process player choice
switch (choice) {
case 1 -> { // Standard attack
player.attack(enemy);
System.out.printf("%s attacks %s!%n",
player.getName(), enemy.getName());
}
case 2 -> { // Defensive stance
player.defend();
System.out.println(player.getName() + " defends!");
}
case 3 -> { // Class-specific ability
if (player instanceof Knight) {
((Knight)player).useSpecialAbility(enemy);
} else {
player.useSpecialAbility(enemy);
}
System.out.printf("%s uses special ability on %s!%n",
player.getName(), enemy.getName());
}
case 4 -> useItemInCombat(); // Inventory usage
default -> System.out.println("Invalid choice! Lost your turn...");
}
}

/**
* Validates player input within a specified range
* @param min Minimum valid value
* @param max Maximum valid value
* @return Validated user input
*/
private int getValidInput(int min, int max) {
while (true) {
try {
int choice = Integer.parseInt(scanner.nextLine());
if (choice >= min && choice <= max) return choice;
System.out.printf("Enter %d-%d: ", min, max);
} catch (NumberFormatException e) {
System.out.print("(Numbers only) ");
}
}
}

/**
* Handles enemy's turn during combat
* @param enemy The attacking enemy
*/
private void enemyTurn(Enemy enemy) {
System.out.printf("%n=== %s's TURN ===%n", enemy.getName());
enemy.attack(player); // Enemy performs attack
}

/**
* Manages item usage during combat
*/
private void useItemInCombat() {
if (player.getInventory().isEmpty()) {
System.out.println("Your inventory is empty!");
return;
}

// Display inventory
System.out.println("\nAvailable items:");
for (int i = 0; i < player.getInventory().size(); i++) {
Consumable item = player.getInventory().get(i);
System.out.printf("%d. %s (%d uses)%n",
i + 1, item.getName(), item.getRemainingUses());
}

System.out.print("Select item (0 to cancel): ");
int choice = getValidInput(0, player.getInventory().size()) - 1;

if (choice >= 0) {
player.useItem(choice); // Use selected item
}
}

/**
* Displays character statistics and equipment
*/
private void displayCharacterInfo() {
System.out.println("\n=== CHARACTER SHEET ===");
System.out.printf("Name: %s%n", player.getName());
System.out.printf("Class: %s%n", player.getClass().getSimpleName());
System.out.printf("Level: %d%n", player.getLevel());
System.out.printf("HP: %d/%d%n", player.getHealth(), player.getMaxHealth());
System.out.printf("XP: %d/%d%n",
player.getExperience(), player.getLevel() * 100);
System.out.printf("Weapon: %s%n", player.getWeapon().getDescription());
System.out.printf("Armor: %s%n", player.getArmor().getDescription());
}

/**
* Handles game conclusion with appropriate message
*/
private void endGame() {
if (player.isAlive()) {
System.out.println("You leave the Java Ring... for now.");
} else {
System.out.println("GAME OVER");
}
}

/**
* Entry point for the game
* @param args Command line arguments (unused)
*/
public static void main(String[] args) {
new GameEngine().startGame(); // Launch game
}
}
15 changes: 0 additions & 15 deletions Java-Ring/src/main/java/org/project/Main.java

This file was deleted.

32 changes: 22 additions & 10 deletions Java-Ring/src/main/java/org/project/entity/Entity.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
package org.project.entity;

public interface Entity {
// Combat Core
void attack(Entity target);

void defend();

void takeDamage(int damage);
void heal(int health);

void fillMana(int mana);

void takeDamage(int damage);

int getMaxHP();
// Status methods
boolean isAlive();

int getHealth();
int getMaxHealth();

int getMaxMP();

/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
// Magic/Ability system
void useSpecialAbility(Entity target);
void defend();

String getName();

// Resource management
void gainExperience(int amount);
default boolean isDefending() { return false; }
void healMana(int amount);
default int getMana() { return 0; }
default int getMaxMana() { return 0; }


String getDescription();
}
Loading