Compare commits
6
Commits
78d4bedb08
...
38d72be138
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38d72be138 | ||
|
|
aac9687228 | ||
|
|
0e04d8a1a2 | ||
|
|
b03aad9420 | ||
|
|
ababde553b | ||
|
|
9db7c5cc3c |
Generated
+5
@@ -16,5 +16,10 @@
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://maven.myket.ir/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,15 +1,308 @@
|
||||
package org.project;
|
||||
|
||||
import org.project.entity.enemies.*;
|
||||
import org.project.entity.players.Assassin;
|
||||
import org.project.entity.players.Knight;
|
||||
import org.project.entity.players.Player;
|
||||
import org.project.entity.players.Wizard;
|
||||
import org.project.location.Location;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
// TODO: ADD LOCATIONS TO YOUR GAME
|
||||
List<Location> locations = new ArrayList<>();
|
||||
|
||||
// TODO: IMPLEMENT GAMEPLAY
|
||||
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);
|
||||
|
||||
// Enemies
|
||||
Enemy goblin = new Goblin();
|
||||
Enemy skeleton = new Skeleton();
|
||||
Enemy vampire = new Vampire();
|
||||
Enemy[] enemies = {goblin, vampire, skeleton}; // An array of the enemies except Dragon which is the final boss
|
||||
|
||||
// Locations, one for each enemy
|
||||
Location forest = new Location("Whispering forest", goblin);
|
||||
Location catacombs = new Location("forgotten catacombs", skeleton);
|
||||
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(BLUE_TEXT + "\t=============== Java Knight ===============\n" + RESET);
|
||||
boolean running = true;
|
||||
while(running){
|
||||
|
||||
System.out.println(YELLOW_TEXT + "\tChoose your option:");
|
||||
System.out.println("\t1. Start game" +
|
||||
" 2. Exit" + RESET);
|
||||
int option = scanner.nextInt();
|
||||
if(option == 1){
|
||||
startGame(locations);
|
||||
} else if (option == 2) {
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void startGame(Location[] locations){
|
||||
//
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
Random random = new Random();
|
||||
|
||||
// Set up
|
||||
System.out.print("\tEnter your name: ");
|
||||
String name = scanner.next();
|
||||
Player player = null;
|
||||
int option = 0;
|
||||
while(option > 3 || option < 1){
|
||||
System.out.println("\n Select your character: (Enter number)");
|
||||
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(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", " ⚔\uFE0F Knight", player.getName());
|
||||
break;
|
||||
case 2:
|
||||
player = new Assassin(name);
|
||||
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", " \uD83E\uDDD9 Wizard", player.getName());
|
||||
break;
|
||||
default:
|
||||
player = null;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// Choosing location and enemy
|
||||
Location loc = locations[random.nextInt(locations.length)];
|
||||
loc = setLocation(loc, locations, player, random, scanner);
|
||||
Enemy enemy = loc.getEnemy();
|
||||
|
||||
System.out.println(BLUE_TEXT + "\t=============== Prepare to fight ===============" + RESET);
|
||||
|
||||
while(player.isAlive()){
|
||||
|
||||
while(enemy.isAlive()){
|
||||
playerMove(player, enemy, scanner);
|
||||
if(!enemy.isStunned() && enemy.getAlive()) {
|
||||
enemyMove(enemy, player, random);
|
||||
}
|
||||
else{
|
||||
enemy.stun(false);
|
||||
}
|
||||
}
|
||||
|
||||
player.addXP(30);
|
||||
enemy.heal();
|
||||
// Key dropping (50% chance)
|
||||
boolean[] logics = {false, true};
|
||||
boolean drop = logics[random.nextInt(logics.length)];
|
||||
if(enemy.hasKey() && drop){
|
||||
player.addKey(enemy);
|
||||
}
|
||||
|
||||
// resetting player and enemy for the next battle
|
||||
player.fillMana();
|
||||
enemy.fillHP();
|
||||
|
||||
// the final battle, Dragon fight
|
||||
if(player.getKeys() == 3){
|
||||
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);
|
||||
|
||||
while(enemy.isAlive() && player.isAlive()){
|
||||
playerMove(player, enemy, scanner);
|
||||
if(!enemy.isStunned() && enemy.isAlive()) {
|
||||
enemyMove(enemy, player, random);
|
||||
}
|
||||
else{
|
||||
enemy.stun(false);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else{
|
||||
loc = setLocation(loc, locations, player, random, scanner);
|
||||
enemy = loc.getEnemy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Location setLocation(Location currentLocation, Location[] locations, Player player, Random random, Scanner scanner){
|
||||
System.out.printf("\t%s should fight %s who fights with %s in %s\n",
|
||||
player.getName(), currentLocation.getEnemy().getName(), currentLocation.getEnemy().getWeapon().getName(), currentLocation.getName());
|
||||
int option = 0;
|
||||
while(option > 2 || option < 1){
|
||||
System.out.println(YELLOW_TEXT + "\tChoose your option: ");
|
||||
System.out.println("\t1. Fight" + currentLocation.getEnemy().getName() +
|
||||
"\t\t2. Change location" + RESET);
|
||||
if (scanner.hasNextInt()) {
|
||||
option = scanner.nextInt();
|
||||
} else {
|
||||
System.out.println(RED_TEXT + "\tInvalid input! Please enter a number." + RESET);
|
||||
scanner.next();
|
||||
}
|
||||
}
|
||||
|
||||
if(option == 1){
|
||||
return currentLocation;
|
||||
}
|
||||
else{
|
||||
Location[] temp_locations = new Location[locations.length - 1];
|
||||
int counter = 0;
|
||||
for(Location l : locations){
|
||||
if (l != currentLocation) {
|
||||
temp_locations[counter] = l;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
currentLocation = temp_locations[random.nextInt(temp_locations.length)];
|
||||
System.out.println("\tChanging locations...\n");
|
||||
setLocation(currentLocation, locations, player, random, scanner);
|
||||
}
|
||||
return currentLocation;
|
||||
}
|
||||
|
||||
public static void playerMove(Player player, Enemy enemy, Scanner scanner){
|
||||
|
||||
player.defend(false);
|
||||
|
||||
int option = 0;
|
||||
while(option > 5 || option < 1){
|
||||
System.out.println("\n Your turn. Choose your move: \n" +
|
||||
" 1. Light attack" +
|
||||
" 2. Heavy attack" +
|
||||
" 3. Defend" +
|
||||
" 4. Heal" +
|
||||
" 5. Special Ability");
|
||||
if (scanner.hasNextInt()) {
|
||||
option = scanner.nextInt();
|
||||
|
||||
if(option != 1 && player.getMp() <= 0){ // when mana runs out the only available action is 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(RED_TEXT + "\tYour HP is at its maximum. Choose another option." + RESET);
|
||||
option = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
System.out.println(RED_TEXT + "\tInvalid input! Please enter a number." + RESET);
|
||||
scanner.next();
|
||||
}
|
||||
}
|
||||
|
||||
switch (option){
|
||||
case 1: // light attack
|
||||
if(!enemy.isDefending()){
|
||||
player.lightAttack(enemy);
|
||||
}
|
||||
break;
|
||||
case 2: // heavy attack
|
||||
if(player.getMp() >= player.getWeapon().getManaCost()) {
|
||||
player.heavyAttack(enemy);
|
||||
}
|
||||
else{
|
||||
System.out.println(RED_TEXT + "\tYou don't have enough Mana" + RESET);
|
||||
playerMove(player, enemy, scanner);
|
||||
}
|
||||
break;
|
||||
case 3: // defend
|
||||
if(player.getMp() >= player.getDefendMP()) {
|
||||
player.defend(true);
|
||||
}
|
||||
else{
|
||||
System.out.println(RED_TEXT + "\tYou don't have enough Mana" + RESET);
|
||||
playerMove(player, enemy, scanner);
|
||||
}
|
||||
break;
|
||||
case 4: // heal
|
||||
if(player.getMp() >= player.getDefendMP()) {
|
||||
player.heal( (int)((0.2)*player.getMaxHP()) );
|
||||
}
|
||||
else{
|
||||
System.out.println(RED_TEXT + "\tYou don't have enough Mana" + RESET);
|
||||
playerMove(player, enemy, scanner);
|
||||
}
|
||||
break;
|
||||
case 5: // special ability
|
||||
if(player.getMp() >= player.getSpecialAbilityMP()) {
|
||||
player.specialAbility(enemy);
|
||||
}
|
||||
else{
|
||||
System.out.println(RED_TEXT + "\tYou don't have enough Mana" + RESET);
|
||||
playerMove(player, enemy, scanner);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
showStatus(player, enemy);
|
||||
|
||||
}
|
||||
|
||||
public static void enemyMove(Enemy enemy, Player player, Random random){
|
||||
|
||||
enemy.defend(false);
|
||||
enemy.stun(false); // have been checked before calling this method
|
||||
|
||||
System.out.println("\t" + enemy.getName() + "'s turn: ");
|
||||
|
||||
int move_id = random.nextInt(5) + 1;
|
||||
switch (move_id){
|
||||
case 1: // attack (light attack)
|
||||
enemy.attack(player);
|
||||
break;
|
||||
case 2: // special ability (heavy attack)
|
||||
if(enemy instanceof Skeleton && enemy.isRevived()){
|
||||
enemyMove(enemy, player, random);
|
||||
}
|
||||
enemy.specialAbility(player);
|
||||
break;
|
||||
case 3: // defend
|
||||
enemy.defend(true);
|
||||
break;
|
||||
case 4: // heal
|
||||
enemy.heal( (int)((0.2)*player.getMaxHP()) );
|
||||
break;
|
||||
}
|
||||
|
||||
showStatus(player, enemy);
|
||||
|
||||
}
|
||||
|
||||
public static void showStatus(Player player, Enemy enemy){
|
||||
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()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,21 +1,23 @@
|
||||
package org.project.entity;
|
||||
|
||||
public interface Entity {
|
||||
void attack(Entity target);
|
||||
|
||||
void defend();
|
||||
void specialAbility(Entity target);
|
||||
|
||||
void defend(boolean value);
|
||||
|
||||
boolean isDefending();
|
||||
|
||||
void heal(int health);
|
||||
|
||||
void fillMana(int mana);
|
||||
// void fillMana(int mana);
|
||||
|
||||
void takeDamage(int damage);
|
||||
|
||||
int getMaxHP();
|
||||
void stun(boolean value);
|
||||
|
||||
int getMaxMP();
|
||||
String getName();
|
||||
|
||||
boolean isAlive();
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Flame;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Entity target) {
|
||||
System.out.printf("\t%s attacks!\n", getName());
|
||||
target.takeDamage(28);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void specialAbility(Entity target) {
|
||||
System.out.printf("\t%s breathes fire! \uD83D\uDD25\n", getName());
|
||||
target.takeDamage(weapon.getDamage());
|
||||
}
|
||||
|
||||
public int getMaxHP() {
|
||||
return maxHP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
return " \uD83D\uDC09 Dragon";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlive() {
|
||||
if(hp <= 0){
|
||||
System.out.printf(GREEN_TEXT + "\t=============== Victory! ===============\n" + RESET, getName());
|
||||
alive = false;
|
||||
}
|
||||
return alive;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,34 +1,124 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Enemy {
|
||||
public abstract class Enemy implements Entity {
|
||||
Weapon weapon;
|
||||
private int hp;
|
||||
private int mp;
|
||||
protected int hp;
|
||||
protected int maxHP;
|
||||
protected boolean defending = false;
|
||||
private boolean stunned = false;
|
||||
protected boolean revived = false;
|
||||
protected boolean alive = true;
|
||||
protected boolean key = true;
|
||||
|
||||
public Enemy(int hp, int mp, Weapon weapon) {
|
||||
public static final String BLUE_TEXT = "\u001B[34m";
|
||||
public static final String RESET = "\u001B[0m";
|
||||
|
||||
public Enemy(int hp, Weapon weapon) {
|
||||
this.hp = hp;
|
||||
this.mp = mp;
|
||||
|
||||
maxHP = hp; // TODO: fix this from superclasses
|
||||
this.weapon = weapon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
hp -= damage;
|
||||
System.out.printf("\t%s took %d damage \uD83D\uDCA5\n", getName(), damage);
|
||||
}
|
||||
|
||||
public void attack(Entity target) {
|
||||
System.out.printf("\t%s used Light Attack!\n", getName());
|
||||
if(target.isDefending()){
|
||||
System.out.printf("\t%s is defending. %s lost his attack.\n", target.getName(), getName());
|
||||
return;
|
||||
}
|
||||
target.takeDamage(weapon.getDamage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend(boolean value) {
|
||||
if(value) {
|
||||
System.out.printf("\t%s used Defend, You cannot attack in your next turn! \uD83D\uDEE1\uFE0F\n", getName());
|
||||
defending = true;
|
||||
return;
|
||||
}
|
||||
defending = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
System.out.printf("\t%s used Heal! ❤\uFE0F\n", getName());
|
||||
hp += health;
|
||||
if (hp > maxHP) {
|
||||
hp = maxHP;
|
||||
}
|
||||
}
|
||||
|
||||
public void heal(){
|
||||
hp = maxHP;
|
||||
alive = true;
|
||||
}
|
||||
|
||||
public void fillHP(){
|
||||
hp = maxHP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stun(boolean value) {
|
||||
stunned = value;
|
||||
}
|
||||
|
||||
public void dropKey(){
|
||||
key = false;
|
||||
}
|
||||
|
||||
public int getHp() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
public int getMp() {
|
||||
return mp;
|
||||
public int getMaxHP() {
|
||||
return maxHP;
|
||||
}
|
||||
|
||||
public Weapon getWeapon() {
|
||||
return weapon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefending() {
|
||||
return defending;
|
||||
}
|
||||
|
||||
public boolean isStunned() {
|
||||
return stunned;
|
||||
}
|
||||
|
||||
public boolean isRevived() {
|
||||
return revived;
|
||||
}
|
||||
|
||||
public boolean hasKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlive() {
|
||||
if(hp <= 0){
|
||||
System.out.printf(BLUE_TEXT + "\t=============== You defeated %s =============== " + RESET + "\n\tGoing to the next Location...", getName());
|
||||
|
||||
alive = false;
|
||||
}
|
||||
return alive;
|
||||
}
|
||||
|
||||
public boolean getAlive(){
|
||||
if(hp <= 0){
|
||||
alive = false;
|
||||
}
|
||||
return alive;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Dagger;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
public class Goblin extends Enemy{
|
||||
|
||||
private static int maxHP = 65;
|
||||
private int hp = maxHP;
|
||||
private int criticalHit_damage = 20;
|
||||
|
||||
public Goblin(){
|
||||
Weapon goblinWeapon = new Dagger();
|
||||
super(maxHP, goblinWeapon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void specialAbility(Entity target) {
|
||||
if(target.isDefending()){
|
||||
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! \uD83D\uDCA5\n", getName());
|
||||
target.takeDamage(criticalHit_damage);
|
||||
}
|
||||
|
||||
public int getMaxHP() {
|
||||
return maxHP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
return " \uD83D\uDC7A Goblin";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,33 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Skeleton {
|
||||
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
|
||||
}
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.BoneClub;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
public class Skeleton extends Enemy{
|
||||
|
||||
private static int maxHP = 80;
|
||||
private int hp = maxHP;
|
||||
|
||||
public Skeleton(){
|
||||
Weapon SkeletonWeapon = new BoneClub();
|
||||
super(maxHP, SkeletonWeapon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void specialAbility(Entity target) {
|
||||
System.out.printf("\t%s revived itself! ❤\uFE0F\n", getName());
|
||||
hp = maxHP/2; // revive (once per battle)
|
||||
revived = true;
|
||||
}
|
||||
|
||||
public int getMaxHP() {
|
||||
return maxHP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
return " \uD83D\uDC80 Skeleton";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Bite;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
public class Vampire extends Enemy{
|
||||
|
||||
private static int maxHP = 95;
|
||||
private int hp = maxHP;
|
||||
|
||||
public Vampire(){
|
||||
Weapon VampireWeapon = new Bite();
|
||||
super(maxHP, VampireWeapon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void specialAbility(Entity target) {
|
||||
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()));
|
||||
}
|
||||
|
||||
public int getMaxHP() {
|
||||
return maxHP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
return " \uD83E\uDDDB Vampire";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.DualDagger;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
|
||||
public class Assassin extends Player {
|
||||
|
||||
private static final int maxHP = 110;
|
||||
private static final int maxMP = 110;
|
||||
|
||||
public Assassin(String name){
|
||||
Weapon AssassinWeapon = new DualDagger();
|
||||
super(name, maxHP, maxMP, AssassinWeapon);
|
||||
specialAbilityMP = 30;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lightAttack(Entity target) {
|
||||
super.lightAttack(target);
|
||||
System.out.printf("\t%s used Light Attack! (%d Mana)\n", name, 0);
|
||||
target.takeDamage(18);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void specialAbility(Entity target) {
|
||||
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.
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,37 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Knight {
|
||||
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Sword;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
|
||||
public class Knight extends Player {
|
||||
|
||||
private static final int maxHP = 130;
|
||||
private static final int maxMP = 70;
|
||||
|
||||
public Knight(String name){
|
||||
Weapon knightWeapon = new Sword();
|
||||
super(name, maxHP, maxMP, knightWeapon);
|
||||
specialAbilityMP = 25;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lightAttack(Entity target) {
|
||||
super.lightAttack(target);
|
||||
System.out.printf("\t%s used Light Attack! (%d Mana)\n", name, 0);
|
||||
target.takeDamage(22);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void specialAbility(Entity target) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,61 +1,106 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.entity.enemies.Enemy;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Player {
|
||||
public abstract class Player implements Entity {
|
||||
protected String name;
|
||||
Weapon weapon;
|
||||
Armor armor;
|
||||
private int hp;
|
||||
private int maxHP;
|
||||
private int mp;
|
||||
private int maxMP;
|
||||
protected int hp;
|
||||
protected int maxHP;
|
||||
protected int mp;
|
||||
protected int maxMP;
|
||||
protected boolean defending = false;
|
||||
private boolean stunned = false;
|
||||
protected int keys;
|
||||
protected boolean alive = true;
|
||||
|
||||
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
||||
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;
|
||||
this.hp = hp;
|
||||
maxHP = hp;
|
||||
this.mp = mp;
|
||||
|
||||
maxMP = mp;
|
||||
this.weapon = weapon;
|
||||
this.armor = armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Entity target) {
|
||||
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. \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. \uD83D\uDEE1\uFE0F\n", target.getName());
|
||||
return;
|
||||
}
|
||||
System.out.printf("\t%s used Heavy Attack \uD83D\uDCA5! (%d Mana)\n", name, weapon.getManaCost());
|
||||
target.takeDamage(weapon.getDamage());
|
||||
mp -= weapon.getManaCost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
// TODO
|
||||
public void defend(boolean value) {
|
||||
if(value){
|
||||
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;
|
||||
}
|
||||
defending = false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
hp -= damage - armor.getDefense();
|
||||
hp -= 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 ❤\uFE0F! (%d Mana)\n", name, 20);
|
||||
hp += health;
|
||||
if (hp > maxHP) {
|
||||
hp = maxHP;
|
||||
}
|
||||
mp -= 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillMana(int mana) {
|
||||
mp += mana;
|
||||
if (mp > maxMP) {
|
||||
mp = maxMP;
|
||||
}
|
||||
public void stun(boolean value) {
|
||||
stunned = value;
|
||||
}
|
||||
|
||||
|
||||
public void fillMana() {
|
||||
mp = maxMP;
|
||||
hp = maxHP;
|
||||
}
|
||||
|
||||
public void addKey(Enemy target){
|
||||
keys++;
|
||||
target.dropKey();
|
||||
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("\n\t%d XP added.\n", xp);
|
||||
maxMP += xp;
|
||||
maxHP += xp;
|
||||
}
|
||||
|
||||
|
||||
// Getter Methods
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -64,7 +109,6 @@ public abstract class Player {
|
||||
return hp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHP() {
|
||||
return maxHP;
|
||||
}
|
||||
@@ -73,7 +117,6 @@ public abstract class Player {
|
||||
return mp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMP() {
|
||||
return maxMP;
|
||||
}
|
||||
@@ -82,8 +125,29 @@ public abstract class Player {
|
||||
return weapon;
|
||||
}
|
||||
|
||||
public Armor getArmor() {
|
||||
return armor;
|
||||
@Override
|
||||
public boolean isDefending() {
|
||||
return defending;
|
||||
}
|
||||
|
||||
public int getKeys() {
|
||||
return keys;
|
||||
}
|
||||
|
||||
public int getDefendMP() {
|
||||
return defendMP;
|
||||
}
|
||||
|
||||
public int getSpecialAbilityMP() {
|
||||
return specialAbilityMP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlive() {
|
||||
if(hp <= 0){
|
||||
System.out.println(RED_TEXT + "\t=============== Game Over ===============" + RESET);
|
||||
alive = false;
|
||||
}
|
||||
return alive;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.MagicStaff;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
|
||||
public class Wizard extends Player {
|
||||
|
||||
private static final int maxHP = 150;
|
||||
private static final int maxMP = 85;
|
||||
|
||||
public Wizard(String name){
|
||||
Weapon WizardWeapon = new MagicStaff();
|
||||
super(name, maxHP, maxMP, WizardWeapon);
|
||||
specialAbilityMP = 28;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lightAttack(Entity target) {
|
||||
super.lightAttack(target);
|
||||
System.out.printf("\t%s used Light Attack! (%d Mana)\n", name, 0);
|
||||
target.takeDamage(16);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void specialAbility(Entity target) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,4 @@ import org.project.entity.Entity;
|
||||
public interface Item {
|
||||
void use(Entity target);
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package org.project.item.armors;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Armor {
|
||||
private int defense;
|
||||
private int maxDefense;
|
||||
private int durability;
|
||||
private int maxDurability;
|
||||
|
||||
private boolean isBroke;
|
||||
|
||||
public Armor(int defense, int durability) {
|
||||
this.defense = defense;
|
||||
this.durability = durability;
|
||||
}
|
||||
|
||||
public void checkBreak() {
|
||||
if (durability <= 0) {
|
||||
isBroke = true;
|
||||
defense = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: (BONUS) UPDATE THE REPAIR METHOD
|
||||
public void repair() {
|
||||
isBroke = false;
|
||||
defense = maxDefense;
|
||||
durability = maxDurability;
|
||||
}
|
||||
|
||||
public int getDefense() {
|
||||
return defense;
|
||||
}
|
||||
|
||||
public int getDurability() {
|
||||
return durability;
|
||||
}
|
||||
|
||||
public boolean isBroke() {
|
||||
return isBroke;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package org.project.item.armors;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class KnightArmor {
|
||||
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package org.project.item.consumables;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Consumable {
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package org.project.item.consumables;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Flask {
|
||||
/*
|
||||
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
|
||||
*/
|
||||
|
||||
// TODO: UPDATE USE METHOD
|
||||
@Override
|
||||
public void use(Entity target) {
|
||||
target.heal(target.getMaxHP() / 10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Bite is used by Vampire
|
||||
|
||||
package org.project.item.weapons;
|
||||
|
||||
public class Bite extends Weapon {
|
||||
|
||||
private static final int damage = 16;
|
||||
|
||||
public Bite() {
|
||||
super(damage, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Bite";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// BoneClub is used by Skeleton
|
||||
|
||||
package org.project.item.weapons;
|
||||
|
||||
public class BoneClub extends Weapon {
|
||||
|
||||
private static final int damage = 14;
|
||||
|
||||
public BoneClub() {
|
||||
super(damage, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Bone Club";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Dagger is used by Goblin
|
||||
|
||||
package org.project.item.weapons;
|
||||
|
||||
public class Dagger extends Weapon {
|
||||
|
||||
private static final int damage = 12;
|
||||
|
||||
public Dagger() {
|
||||
super(damage, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Daggers";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// DualDagger is used by Assassin
|
||||
|
||||
package org.project.item.weapons;
|
||||
|
||||
public class DualDagger extends Weapon {
|
||||
|
||||
private static final int damage = 30;
|
||||
private static final int manaCost = 15;
|
||||
|
||||
public DualDagger() {
|
||||
super(damage, manaCost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Dual Daggers";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Flame is used by Dragon
|
||||
|
||||
package org.project.item.weapons;
|
||||
|
||||
public class Flame extends Weapon {
|
||||
|
||||
private static final int damage = 36;
|
||||
|
||||
public Flame() {
|
||||
super(damage, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Flame";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Maggic Staff is used by Wizard
|
||||
|
||||
package org.project.item.weapons;
|
||||
|
||||
public class MagicStaff extends Weapon {
|
||||
|
||||
private static final int damage = 28;
|
||||
private static final int manaCost = 16;
|
||||
|
||||
public MagicStaff() {
|
||||
super(damage, manaCost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Magic Staff";
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,18 @@
|
||||
// Sword is used by Knight
|
||||
|
||||
package org.project.item.weapons;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
public class Sword extends Weapon {
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Sword {
|
||||
/*
|
||||
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
|
||||
*/
|
||||
|
||||
int abilityCharge;
|
||||
private static final int damage = 34;
|
||||
private static final int manaCost = 15;
|
||||
|
||||
public Sword() {
|
||||
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
||||
super(damage, manaCost);
|
||||
}
|
||||
|
||||
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
|
||||
public void uniqueAbility(ArrayList<Entity> targets) {
|
||||
abilityCharge += 2;
|
||||
for (Entity target : targets) {
|
||||
target.takeDamage(getDamage());
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Sword";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package org.project.item.weapons;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.Item;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Weapon {
|
||||
public abstract class Weapon implements Item {
|
||||
private int damage;
|
||||
private int manaCost;
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES
|
||||
*/
|
||||
|
||||
public Weapon(int damage, int manaCost) {
|
||||
this.damage = damage;
|
||||
@@ -29,7 +26,6 @@ public abstract class Weapon {
|
||||
return manaCost;
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
}
|
||||
|
||||
@@ -6,23 +6,19 @@ import java.util.ArrayList;
|
||||
|
||||
public class Location {
|
||||
private String name;
|
||||
private Enemy enemy;
|
||||
|
||||
private ArrayList<Enemy> enemies;
|
||||
|
||||
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
|
||||
this.locations = locations;
|
||||
this.enemies = enemies;
|
||||
public Location(String name, Enemy enemy) {
|
||||
this.name = name;
|
||||
this.enemy = enemy;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public ArrayList<Location> getLocations() {
|
||||
return locations;
|
||||
public Enemy getEnemy() {
|
||||
return enemy;
|
||||
}
|
||||
|
||||
public ArrayList<Enemy> getEnemies() {
|
||||
return enemies;
|
||||
}
|
||||
}
|
||||
|
||||
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.
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