Add colors and emojies
This commit is contained in:
@@ -11,6 +11,12 @@ import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
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) {
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
@@ -27,13 +33,13 @@ public class Main {
|
||||
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
|
||||
|
||||
System.out.println("\t=============== Java Knight ===============\n");
|
||||
System.out.println(BLUE_TEXT + "\t=============== Java Knight ===============\n" + RESET);
|
||||
boolean running = true;
|
||||
while(running){
|
||||
|
||||
System.out.println("\tChoose your option:");
|
||||
System.out.println(YELLOW_TEXT + "\tChoose your option:");
|
||||
System.out.println("\t1. Start game" +
|
||||
" 2. Exit");
|
||||
" 2. Exit" + RESET);
|
||||
int option = scanner.nextInt();
|
||||
if(option == 1){
|
||||
startGame(locations);
|
||||
@@ -60,28 +66,28 @@ public class Main {
|
||||
int option = 0;
|
||||
while(option > 3 || option < 1){
|
||||
System.out.println("\n Select your character: (Enter number)");
|
||||
System.out.println("\t1. Knight (fights with a sword)\n" +
|
||||
"\t2. Assassin (fights with dual daggers)\n" +
|
||||
"\t3. Wizard (fights with his magic staff)");
|
||||
System.out.println("\t1. ⚔\uFE0F Knight (fights with a sword)\n" +
|
||||
"\t2. \uD83D\uDD2A Assassin (fights with dual daggers)\n" +
|
||||
"\t3. \uD83E\uDDD9 Wizard (fights with his magic staff)");
|
||||
if (scanner.hasNextInt()) {
|
||||
option = scanner.nextInt();
|
||||
} else {
|
||||
System.out.println("\tInvalid input! Please enter a number.");
|
||||
System.out.println(RED_TEXT + "\tInvalid input! Please enter a number." + RESET);
|
||||
scanner.next();
|
||||
}
|
||||
}
|
||||
switch (option){
|
||||
case 1:
|
||||
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;
|
||||
case 2:
|
||||
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;
|
||||
case 3:
|
||||
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;
|
||||
default:
|
||||
player = null;
|
||||
@@ -94,7 +100,7 @@ public class Main {
|
||||
loc = setLocation(loc, locations, player, random, scanner);
|
||||
Enemy enemy = loc.getEnemy();
|
||||
|
||||
System.out.println("\t=============== Prepare to fight ===============");
|
||||
System.out.println(BLUE_TEXT + "\t=============== Prepare to fight ===============" + RESET);
|
||||
|
||||
while(player.isAlive()){
|
||||
|
||||
@@ -112,7 +118,7 @@ public class Main {
|
||||
enemy.heal();
|
||||
// Key dropping (50% chance)
|
||||
boolean[] logics = {false, true};
|
||||
boolean drop = true;
|
||||
boolean drop = logics[random.nextInt(logics.length)];
|
||||
if(enemy.hasKey() && drop){
|
||||
player.addKey(enemy);
|
||||
}
|
||||
@@ -123,7 +129,7 @@ public class Main {
|
||||
|
||||
// the final battle, Dragon fight
|
||||
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();
|
||||
loc = new Location("ashen peak", enemy);
|
||||
|
||||
@@ -153,13 +159,13 @@ public class Main {
|
||||
player.getName(), currentLocation.getEnemy().getName(), currentLocation.getEnemy().getWeapon().getName(), currentLocation.getName());
|
||||
int option = 0;
|
||||
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() +
|
||||
"\t2. Change location");
|
||||
"\t\t2. Change location" + RESET);
|
||||
if (scanner.hasNextInt()) {
|
||||
option = scanner.nextInt();
|
||||
} else {
|
||||
System.out.println("\tInvalid input! Please enter a number.");
|
||||
System.out.println(RED_TEXT + "\tInvalid input! Please enter a number." + RESET);
|
||||
scanner.next();
|
||||
}
|
||||
}
|
||||
@@ -199,16 +205,16 @@ public class Main {
|
||||
option = scanner.nextInt();
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
} else {
|
||||
System.out.println("\tInvalid input! Please enter a number.");
|
||||
System.out.println(RED_TEXT + "\tInvalid input! Please enter a number." + RESET);
|
||||
scanner.next();
|
||||
}
|
||||
}
|
||||
@@ -224,7 +230,7 @@ public class Main {
|
||||
player.heavyAttack(enemy);
|
||||
}
|
||||
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);
|
||||
}
|
||||
break;
|
||||
@@ -233,7 +239,7 @@ public class Main {
|
||||
player.defend(true);
|
||||
}
|
||||
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);
|
||||
}
|
||||
break;
|
||||
@@ -242,7 +248,7 @@ public class Main {
|
||||
player.heal( (int)((0.2)*player.getMaxHP()) );
|
||||
}
|
||||
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);
|
||||
}
|
||||
break;
|
||||
@@ -251,7 +257,7 @@ public class Main {
|
||||
player.specialAbility(enemy);
|
||||
}
|
||||
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);
|
||||
}
|
||||
break;
|
||||
@@ -292,7 +298,7 @@ public class Main {
|
||||
}
|
||||
|
||||
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(),
|
||||
enemy.getName(), enemy.getHp(), enemy.getMaxHP()
|
||||
);
|
||||
|
||||
@@ -9,6 +9,9 @@ public class Dragon extends Enemy{
|
||||
private static int maxHP = 220;
|
||||
private int hp = maxHP;
|
||||
|
||||
public static final String RESET = "\u001B[0m";
|
||||
public static final String GREEN_TEXT = "\u001B[32m";
|
||||
|
||||
public Dragon(){
|
||||
Weapon DragonWeapon = new Flame();
|
||||
super(maxHP, DragonWeapon);
|
||||
@@ -22,7 +25,7 @@ public class Dragon extends Enemy{
|
||||
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -32,13 +35,13 @@ public class Dragon extends Enemy{
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
return "Dragon";
|
||||
return " \uD83D\uDC09 Dragon";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlive() {
|
||||
if(hp <= 0){
|
||||
System.out.printf("\t=============== Victory! ===============\n", getName());
|
||||
System.out.printf(GREEN_TEXT + "\t=============== Victory! ===============\n" + RESET, getName());
|
||||
alive = false;
|
||||
}
|
||||
return alive;
|
||||
|
||||
@@ -13,6 +13,9 @@ public abstract class Enemy implements Entity {
|
||||
protected boolean alive = 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) {
|
||||
this.hp = hp;
|
||||
maxHP = hp; // TODO: fix this from superclasses
|
||||
@@ -22,7 +25,7 @@ public abstract class Enemy implements Entity {
|
||||
@Override
|
||||
public void takeDamage(int 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) {
|
||||
@@ -37,7 +40,7 @@ public abstract class Enemy implements Entity {
|
||||
@Override
|
||||
public void defend(boolean 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;
|
||||
return;
|
||||
}
|
||||
@@ -46,7 +49,7 @@ public abstract class Enemy implements Entity {
|
||||
|
||||
@Override
|
||||
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;
|
||||
if (hp > maxHP) {
|
||||
hp = maxHP;
|
||||
@@ -103,7 +106,7 @@ public abstract class Enemy implements Entity {
|
||||
@Override
|
||||
public boolean isAlive() {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ public class Goblin extends Enemy{
|
||||
@Override
|
||||
public void specialAbility(Entity target) {
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Goblin extends Enemy{
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
return "Goblin";
|
||||
return " \uD83D\uDC7A Goblin";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public class Skeleton extends Enemy{
|
||||
|
||||
@Override
|
||||
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)
|
||||
revived = true;
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public class Skeleton extends Enemy{
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
return "Skeleton";
|
||||
return " \uD83D\uDC80 Skeleton";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public class Vampire extends Enemy{
|
||||
|
||||
@Override
|
||||
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())));
|
||||
hp += (int)((0.2)*(weapon.getDamage()));
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public class Vampire extends Enemy{
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
return "Vampire";
|
||||
return " \uD83E\uDDDB Vampire";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class Assassin extends Player {
|
||||
|
||||
@Override
|
||||
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
|
||||
this.mp -= specialAbilityMP;
|
||||
defending = true; // dodging (becomes invisible), technically does what Defend does.
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Knight extends Player {
|
||||
|
||||
@Override
|
||||
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);
|
||||
this.mp -= specialAbilityMP;
|
||||
target.stun(true);
|
||||
|
||||
@@ -19,6 +19,9 @@ public abstract class Player implements Entity {
|
||||
protected final int defendMP = 20;
|
||||
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) {
|
||||
this.name = name;
|
||||
@@ -31,17 +34,17 @@ public abstract class Player implements Entity {
|
||||
|
||||
public void lightAttack(Entity target){
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public void heavyAttack(Entity target){ // Uses weapons
|
||||
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;
|
||||
}
|
||||
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());
|
||||
mp -= weapon.getManaCost();
|
||||
}
|
||||
@@ -49,7 +52,7 @@ public abstract class Player implements Entity {
|
||||
@Override
|
||||
public void defend(boolean 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;
|
||||
defending = true;
|
||||
return;
|
||||
@@ -60,12 +63,12 @@ public abstract class Player implements Entity {
|
||||
@Override
|
||||
public void takeDamage(int 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
|
||||
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;
|
||||
if (hp > maxHP) {
|
||||
hp = maxHP;
|
||||
@@ -87,11 +90,11 @@ public abstract class Player implements Entity {
|
||||
public void addKey(Enemy target){
|
||||
keys++;
|
||||
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){
|
||||
System.out.printf("\t%d XP added.\n", xp);
|
||||
System.out.printf("\n\t%d XP added.\n", xp);
|
||||
maxMP += xp;
|
||||
maxHP += xp;
|
||||
}
|
||||
@@ -142,7 +145,7 @@ public abstract class Player implements Entity {
|
||||
@Override
|
||||
public boolean isAlive() {
|
||||
if(hp <= 0){
|
||||
System.out.println("\t=============== Game Over ===============");
|
||||
System.out.println(RED_TEXT + "\t=============== Game Over ===============" + RESET);
|
||||
alive = false;
|
||||
}
|
||||
return alive;
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Wizard extends Player {
|
||||
|
||||
@Override
|
||||
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
|
||||
this.mp -= specialAbilityMP;
|
||||
heal(15);
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user