Add colors and emojies

This commit is contained in:
2026-05-16 01:10:24 +03:30
parent aac9687228
commit 38d72be138
23 changed files with 66 additions and 51 deletions
+31 -25
View File
@@ -11,6 +11,12 @@ import java.util.Random;
import java.util.Scanner; import java.util.Scanner;
public class Main { public class Main {
public static final String RESET = "\u001B[0m";
public static final String RED_TEXT = "\u001B[31m";
public static final String YELLOW_TEXT = "\u001B[33m";
public static final String BLUE_TEXT = "\u001B[34m";
public static void main(String[] args) { public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
@@ -27,13 +33,13 @@ public class Main {
Location castle = new Location("crimson castle", vampire); Location castle = new Location("crimson castle", vampire);
Location[] locations = {forest, catacombs, castle}; // An array of the location except peak where is the Dragon(final boss) located Location[] locations = {forest, catacombs, castle}; // An array of the location except peak where is the Dragon(final boss) located
System.out.println("\t=============== Java Knight ===============\n"); System.out.println(BLUE_TEXT + "\t=============== Java Knight ===============\n" + RESET);
boolean running = true; boolean running = true;
while(running){ while(running){
System.out.println("\tChoose your option:"); System.out.println(YELLOW_TEXT + "\tChoose your option:");
System.out.println("\t1. Start game" + System.out.println("\t1. Start game" +
" 2. Exit"); " 2. Exit" + RESET);
int option = scanner.nextInt(); int option = scanner.nextInt();
if(option == 1){ if(option == 1){
startGame(locations); startGame(locations);
@@ -60,28 +66,28 @@ public class Main {
int option = 0; int option = 0;
while(option > 3 || option < 1){ while(option > 3 || option < 1){
System.out.println("\n Select your character: (Enter number)"); System.out.println("\n Select your character: (Enter number)");
System.out.println("\t1. Knight (fights with a sword)\n" + System.out.println("\t1.\uFE0F Knight (fights with a sword)\n" +
"\t2. Assassin (fights with dual daggers)\n" + "\t2. \uD83D\uDD2A Assassin (fights with dual daggers)\n" +
"\t3. Wizard (fights with his magic staff)"); "\t3. \uD83E\uDDD9 Wizard (fights with his magic staff)");
if (scanner.hasNextInt()) { if (scanner.hasNextInt()) {
option = scanner.nextInt(); option = scanner.nextInt();
} else { } else {
System.out.println("\tInvalid input! Please enter a number."); System.out.println(RED_TEXT + "\tInvalid input! Please enter a number." + RESET);
scanner.next(); scanner.next();
} }
} }
switch (option){ switch (option){
case 1: case 1:
player = new Knight(name); player = new Knight(name);
System.out.printf("\n\tYour Character: %s, Your Name: %s\n\n", "Knight", player.getName()); System.out.printf("\n\tYour Character: %s, Your Name: %s\n\n", "\uFE0F Knight", player.getName());
break; break;
case 2: case 2:
player = new Assassin(name); player = new Assassin(name);
System.out.printf("\n\tYour Character: %s, Your Name: %s\n\n", "Assassin", player.getName()); System.out.printf("\n\tYour Character: %s, Your Name: %s\n\n", " \uD83D\uDD2A Assassin", player.getName());
break; break;
case 3: case 3:
player = new Wizard(name); player = new Wizard(name);
System.out.printf("\n\tYour Character: %s, Your Name: %s\n\n", "Wizard", player.getName()); System.out.printf("\n\tYour Character: %s, Your Name: %s\n\n", " \uD83E\uDDD9 Wizard", player.getName());
break; break;
default: default:
player = null; player = null;
@@ -94,7 +100,7 @@ public class Main {
loc = setLocation(loc, locations, player, random, scanner); loc = setLocation(loc, locations, player, random, scanner);
Enemy enemy = loc.getEnemy(); Enemy enemy = loc.getEnemy();
System.out.println("\t=============== Prepare to fight ==============="); System.out.println(BLUE_TEXT + "\t=============== Prepare to fight ===============" + RESET);
while(player.isAlive()){ while(player.isAlive()){
@@ -112,7 +118,7 @@ public class Main {
enemy.heal(); enemy.heal();
// Key dropping (50% chance) // Key dropping (50% chance)
boolean[] logics = {false, true}; boolean[] logics = {false, true};
boolean drop = true; boolean drop = logics[random.nextInt(logics.length)];
if(enemy.hasKey() && drop){ if(enemy.hasKey() && drop){
player.addKey(enemy); player.addKey(enemy);
} }
@@ -123,7 +129,7 @@ public class Main {
// the final battle, Dragon fight // the final battle, Dragon fight
if(player.getKeys() == 3){ if(player.getKeys() == 3){
System.out.println("\t=============== Entering Ashen Peak to fight the Dragon ==============="); System.out.println(BLUE_TEXT + "\t=============== Entering Ashen Peak to fight the Dragon \uD83D\uDC09 ===============" + RESET);
enemy = new Dragon(); enemy = new Dragon();
loc = new Location("ashen peak", enemy); loc = new Location("ashen peak", enemy);
@@ -153,13 +159,13 @@ public class Main {
player.getName(), currentLocation.getEnemy().getName(), currentLocation.getEnemy().getWeapon().getName(), currentLocation.getName()); player.getName(), currentLocation.getEnemy().getName(), currentLocation.getEnemy().getWeapon().getName(), currentLocation.getName());
int option = 0; int option = 0;
while(option > 2 || option < 1){ while(option > 2 || option < 1){
System.out.println("\tChoose your option: "); System.out.println(YELLOW_TEXT + "\tChoose your option: ");
System.out.println("\t1. Fight " + currentLocation.getEnemy().getName() + System.out.println("\t1. Fight" + currentLocation.getEnemy().getName() +
"\t2. Change location"); "\t\t2. Change location" + RESET);
if (scanner.hasNextInt()) { if (scanner.hasNextInt()) {
option = scanner.nextInt(); option = scanner.nextInt();
} else { } else {
System.out.println("\tInvalid input! Please enter a number."); System.out.println(RED_TEXT + "\tInvalid input! Please enter a number." + RESET);
scanner.next(); scanner.next();
} }
} }
@@ -199,16 +205,16 @@ public class Main {
option = scanner.nextInt(); option = scanner.nextInt();
if(option != 1 && player.getMp() <= 0){ // when mana runs out the only available action is light attack if(option != 1 && player.getMp() <= 0){ // when mana runs out the only available action is light attack
System.out.println("\tYou are out of Mana. You can only choose \"1. Light attack\""); System.out.println(RED_TEXT + "\tYou are out of Mana. You can only choose \"1. Light attack\"" + RESET);
option = 0; option = 0;
} }
else if(option == 4 && player.getHp() == player.getMaxHP()){ else if(option == 4 && player.getHp() == player.getMaxHP()){
System.out.println("\tYour HP is at its maximum. Choose another option."); System.out.println(RED_TEXT + "\tYour HP is at its maximum. Choose another option." + RESET);
option = 0; option = 0;
} }
} else { } else {
System.out.println("\tInvalid input! Please enter a number."); System.out.println(RED_TEXT + "\tInvalid input! Please enter a number." + RESET);
scanner.next(); scanner.next();
} }
} }
@@ -224,7 +230,7 @@ public class Main {
player.heavyAttack(enemy); player.heavyAttack(enemy);
} }
else{ else{
System.out.println("\tYou don\'t have enough Mana"); System.out.println(RED_TEXT + "\tYou don't have enough Mana" + RESET);
playerMove(player, enemy, scanner); playerMove(player, enemy, scanner);
} }
break; break;
@@ -233,7 +239,7 @@ public class Main {
player.defend(true); player.defend(true);
} }
else{ else{
System.out.println("\tYou don\'t have enough Mana"); System.out.println(RED_TEXT + "\tYou don't have enough Mana" + RESET);
playerMove(player, enemy, scanner); playerMove(player, enemy, scanner);
} }
break; break;
@@ -242,7 +248,7 @@ public class Main {
player.heal( (int)((0.2)*player.getMaxHP()) ); player.heal( (int)((0.2)*player.getMaxHP()) );
} }
else{ else{
System.out.println("\tYou don\'t have enough Mana"); System.out.println(RED_TEXT + "\tYou don't have enough Mana" + RESET);
playerMove(player, enemy, scanner); playerMove(player, enemy, scanner);
} }
break; break;
@@ -251,7 +257,7 @@ public class Main {
player.specialAbility(enemy); player.specialAbility(enemy);
} }
else{ else{
System.out.println("\tYou don\'t have enough Mana"); System.out.println(RED_TEXT + "\tYou don't have enough Mana" + RESET);
playerMove(player, enemy, scanner); playerMove(player, enemy, scanner);
} }
break; break;
@@ -292,7 +298,7 @@ public class Main {
} }
public static void showStatus(Player player, Enemy enemy){ public static void showStatus(Player player, Enemy enemy){
System.out.printf("\t[%s - %d/%d HP | %d/%d Mana]\t[%s - %d/%d HP]\n\n", System.out.printf("\n\t[%s - %d/%d HP | %d/%d Mana]\n\t[%s - %d/%d HP]\n\n",
player.getName(), player.getHp(), player.getMaxHP(), player.getMp(), player.getMaxMP(), player.getName(), player.getHp(), player.getMaxHP(), player.getMp(), player.getMaxMP(),
enemy.getName(), enemy.getHp(), enemy.getMaxHP() enemy.getName(), enemy.getHp(), enemy.getMaxHP()
); );
@@ -9,6 +9,9 @@ public class Dragon extends Enemy{
private static int maxHP = 220; private static int maxHP = 220;
private int hp = maxHP; private int hp = maxHP;
public static final String RESET = "\u001B[0m";
public static final String GREEN_TEXT = "\u001B[32m";
public Dragon(){ public Dragon(){
Weapon DragonWeapon = new Flame(); Weapon DragonWeapon = new Flame();
super(maxHP, DragonWeapon); super(maxHP, DragonWeapon);
@@ -22,7 +25,7 @@ public class Dragon extends Enemy{
@Override @Override
public void specialAbility(Entity target) { public void specialAbility(Entity target) {
System.out.printf("\t%s breathes fire!\n", getName()); System.out.printf("\t%s breathes fire! \uD83D\uDD25\n", getName());
target.takeDamage(weapon.getDamage()); target.takeDamage(weapon.getDamage());
} }
@@ -32,13 +35,13 @@ public class Dragon extends Enemy{
@Override @Override
public String getName(){ public String getName(){
return "Dragon"; return " \uD83D\uDC09 Dragon";
} }
@Override @Override
public boolean isAlive() { public boolean isAlive() {
if(hp <= 0){ if(hp <= 0){
System.out.printf("\t=============== Victory! ===============\n", getName()); System.out.printf(GREEN_TEXT + "\t=============== Victory! ===============\n" + RESET, getName());
alive = false; alive = false;
} }
return alive; return alive;
@@ -13,6 +13,9 @@ public abstract class Enemy implements Entity {
protected boolean alive = true; protected boolean alive = true;
protected boolean key = true; protected boolean key = true;
public static final String BLUE_TEXT = "\u001B[34m";
public static final String RESET = "\u001B[0m";
public Enemy(int hp, Weapon weapon) { public Enemy(int hp, Weapon weapon) {
this.hp = hp; this.hp = hp;
maxHP = hp; // TODO: fix this from superclasses maxHP = hp; // TODO: fix this from superclasses
@@ -22,7 +25,7 @@ public abstract class Enemy implements Entity {
@Override @Override
public void takeDamage(int damage) { public void takeDamage(int damage) {
hp -= damage; hp -= damage;
System.out.printf("\t%s took %d damage\n", getName(), damage); System.out.printf("\t%s took %d damage \uD83D\uDCA5\n", getName(), damage);
} }
public void attack(Entity target) { public void attack(Entity target) {
@@ -37,7 +40,7 @@ public abstract class Enemy implements Entity {
@Override @Override
public void defend(boolean value) { public void defend(boolean value) {
if(value) { if(value) {
System.out.printf("\t%s used Defend, You cannot attack in your next turn!\n", getName()); System.out.printf("\t%s used Defend, You cannot attack in your next turn! \uD83D\uDEE1\uFE0F\n", getName());
defending = true; defending = true;
return; return;
} }
@@ -46,7 +49,7 @@ public abstract class Enemy implements Entity {
@Override @Override
public void heal(int health) { public void heal(int health) {
System.out.printf("\t%s used Heal!\n", getName()); System.out.printf("\t%s used Heal!\uFE0F\n", getName());
hp += health; hp += health;
if (hp > maxHP) { if (hp > maxHP) {
hp = maxHP; hp = maxHP;
@@ -103,7 +106,7 @@ public abstract class Enemy implements Entity {
@Override @Override
public boolean isAlive() { public boolean isAlive() {
if(hp <= 0){ if(hp <= 0){
System.out.printf("\t=============== You defeated %s ===============\n\tGoing to the next Location...", getName()); System.out.printf(BLUE_TEXT + "\t=============== You defeated %s =============== " + RESET + "\n\tGoing to the next Location...", getName());
alive = false; alive = false;
} }
@@ -18,10 +18,10 @@ public class Goblin extends Enemy{
@Override @Override
public void specialAbility(Entity target) { public void specialAbility(Entity target) {
if(target.isDefending()){ if(target.isDefending()){
System.out.printf("\t%s is defending. %s lost his attack.\n", target.getName(), getName()); System.out.printf("\t%s is defending. %s lost his attack. \uD83D\uDEE1\uFE0F\n", target.getName(), getName());
return; return;
} }
System.out.printf("\t%s used critical hit!\n", getName()); System.out.printf("\t%s used critical hit! \uD83D\uDCA5\n", getName());
target.takeDamage(criticalHit_damage); target.takeDamage(criticalHit_damage);
} }
@@ -31,7 +31,7 @@ public class Goblin extends Enemy{
@Override @Override
public String getName(){ public String getName(){
return "Goblin"; return " \uD83D\uDC7A Goblin";
} }
} }
@@ -16,7 +16,7 @@ public class Skeleton extends Enemy{
@Override @Override
public void specialAbility(Entity target) { public void specialAbility(Entity target) {
System.out.printf("\t%s revived itself!\n", getName()); System.out.printf("\t%s revived itself!\uFE0F\n", getName());
hp = maxHP/2; // revive (once per battle) hp = maxHP/2; // revive (once per battle)
revived = true; revived = true;
} }
@@ -27,7 +27,7 @@ public class Skeleton extends Enemy{
@Override @Override
public String getName(){ public String getName(){
return "Skeleton"; return " \uD83D\uDC80 Skeleton";
} }
} }
@@ -16,7 +16,7 @@ public class Vampire extends Enemy{
@Override @Override
public void specialAbility(Entity target) { public void specialAbility(Entity target) {
System.out.printf("\t%s used life steal ability!\n", getName()); System.out.printf("\t%s used life steal ability! \uD83E\uDDEB\n", getName());
target.takeDamage((int)((0.8)*(weapon.getDamage()))); target.takeDamage((int)((0.8)*(weapon.getDamage())));
hp += (int)((0.2)*(weapon.getDamage())); hp += (int)((0.2)*(weapon.getDamage()));
} }
@@ -27,7 +27,7 @@ public class Vampire extends Enemy{
@Override @Override
public String getName(){ public String getName(){
return "Vampire"; return " \uD83E\uDDDB Vampire";
} }
} }
@@ -26,7 +26,7 @@ public class Assassin extends Player {
@Override @Override
public void specialAbility(Entity target) { public void specialAbility(Entity target) {
System.out.printf("\t%s used Special Ability! Enemy gets hit critically (%d Mana)\n", name, 30); System.out.printf("\t%s used Special Ability \uD83D\uDCA5! Enemy gets hit critically (%d Mana)\n", name, 30);
target.takeDamage(52); // critical attack target.takeDamage(52); // critical attack
this.mp -= specialAbilityMP; this.mp -= specialAbilityMP;
defending = true; // dodging (becomes invisible), technically does what Defend does. defending = true; // dodging (becomes invisible), technically does what Defend does.
@@ -26,7 +26,7 @@ public class Knight extends Player {
@Override @Override
public void specialAbility(Entity target) { public void specialAbility(Entity target) {
System.out.printf("\t%s used Special Ability! Enemy misses its next turn. (%d Mana)\n", name, 25); System.out.printf("\t%s used Special Ability! Enemy misses its next turn. \uD83E\uDDF1 (%d Mana)\n", name, 25);
target.takeDamage(30); target.takeDamage(30);
this.mp -= specialAbilityMP; this.mp -= specialAbilityMP;
target.stun(true); target.stun(true);
@@ -19,6 +19,9 @@ public abstract class Player implements Entity {
protected final int defendMP = 20; protected final int defendMP = 20;
protected int specialAbilityMP; protected int specialAbilityMP;
public static final String RESET = "\u001B[0m";
public static final String RED_TEXT = "\u001B[31m";
public Player(String name, int hp, int mp, Weapon weapon) { public Player(String name, int hp, int mp, Weapon weapon) {
this.name = name; this.name = name;
@@ -31,17 +34,17 @@ public abstract class Player implements Entity {
public void lightAttack(Entity target){ public void lightAttack(Entity target){
if(target.isDefending()){ // check if enemy is defending or not if(target.isDefending()){ // check if enemy is defending or not
System.out.printf("\t%s is Defending. You missed your attack.\n", target.getName()); System.out.printf("\t%s is Defending. You missed your attack. \uD83D\uDEE1\uFE0F \n", target.getName());
return; return;
} }
} }
public void heavyAttack(Entity target){ // Uses weapons public void heavyAttack(Entity target){ // Uses weapons
if(target.isDefending()){ // check if enemy is defending or not if(target.isDefending()){ // check if enemy is defending or not
System.out.printf("\t%s is Defending. You missed your attack.\n", target.getName()); System.out.printf("\t%s is Defending. You missed your attack. \uD83D\uDEE1\uFE0F\n", target.getName());
return; return;
} }
System.out.printf("\t%s used Heavy Attack! (%d Mana)\n", name, weapon.getManaCost()); System.out.printf("\t%s used Heavy Attack \uD83D\uDCA5! (%d Mana)\n", name, weapon.getManaCost());
target.takeDamage(weapon.getDamage()); target.takeDamage(weapon.getDamage());
mp -= weapon.getManaCost(); mp -= weapon.getManaCost();
} }
@@ -49,7 +52,7 @@ public abstract class Player implements Entity {
@Override @Override
public void defend(boolean value) { public void defend(boolean value) {
if(value){ if(value){
System.out.printf("\t%s used Defend, Enemy cannot attack in his next turn! (%d Mana)\n", name, 20); System.out.printf("\t%s used Defend, Enemy cannot attack in his next turn \uD83D\uDEE1\uFE0F! (%d Mana)\n", name, 20);
mp -= 20; mp -= 20;
defending = true; defending = true;
return; return;
@@ -60,12 +63,12 @@ public abstract class Player implements Entity {
@Override @Override
public void takeDamage(int damage) { public void takeDamage(int damage) {
hp -= damage; hp -= damage;
System.out.printf("\t%s took %d damage\n", name, damage); System.out.printf("\t%s took %d damage \uD83D\uDCA5\n", name, damage);
} }
@Override @Override
public void heal(int health) { public void heal(int health) {
System.out.printf("\t%s used Heal! (%d Mana)\n", name, 20); System.out.printf("\t%s used Heal\uFE0F! (%d Mana)\n", name, 20);
hp += health; hp += health;
if (hp > maxHP) { if (hp > maxHP) {
hp = maxHP; hp = maxHP;
@@ -87,11 +90,11 @@ public abstract class Player implements Entity {
public void addKey(Enemy target){ public void addKey(Enemy target){
keys++; keys++;
target.dropKey(); target.dropKey();
System.out.printf("\t%s gained %s's key! gained keys: %d\n\n", getName(), target.getName(), keys); System.out.printf("\t%s gained %s's key \uD83D\uDDDD\uFE0F! gained keys: %d\n\n", getName(), target.getName(), keys);
} }
public void addXP(int xp){ public void addXP(int xp){
System.out.printf("\t%d XP added.\n", xp); System.out.printf("\n\t%d XP added.\n", xp);
maxMP += xp; maxMP += xp;
maxHP += xp; maxHP += xp;
} }
@@ -142,7 +145,7 @@ public abstract class Player implements Entity {
@Override @Override
public boolean isAlive() { public boolean isAlive() {
if(hp <= 0){ if(hp <= 0){
System.out.println("\t=============== Game Over ==============="); System.out.println(RED_TEXT + "\t=============== Game Over ===============" + RESET);
alive = false; alive = false;
} }
return alive; return alive;
@@ -26,7 +26,7 @@ public class Wizard extends Player {
@Override @Override
public void specialAbility(Entity target) { public void specialAbility(Entity target) {
System.out.printf("\t%s used Special Ability! Casting spell. (%d Mana)\n", name, 28); System.out.printf("\t%s used Special Ability! Casting spell. \uD83E\uDE84 (%d Mana)\n", name, 28);
target.takeDamage(32); // casts spell target.takeDamage(32); // casts spell
this.mp -= specialAbilityMP; this.mp -= specialAbilityMP;
heal(15); heal(15);
Binary file not shown.