HW4
This commit is contained in:
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://mirror-maven.runflare.com/maven2" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
@@ -9,7 +9,21 @@ public class Main {
|
||||
public static void main(String[] args) {
|
||||
// TODO: ADD LOCATIONS TO YOUR GAME
|
||||
List<Location> locations = new ArrayList<>();
|
||||
Location forest = new Location("Forest");
|
||||
Location cave = new Location("Cave");
|
||||
|
||||
forest.addLocation(cave);
|
||||
cave.addLocation(forest);
|
||||
|
||||
locations.add(forest);
|
||||
locations.add(cave);
|
||||
|
||||
// TODO: IMPLEMENT GAMEPLAY
|
||||
System.out.println("Game started!");
|
||||
System.out.println("Locations created: ");
|
||||
|
||||
for (Location loc : locations) {
|
||||
System.out.println("- " + loc.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,53 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Enemy {
|
||||
Weapon weapon;
|
||||
public abstract class Enemy implements Entity {
|
||||
protected Weapon weapon;
|
||||
|
||||
private int hp;
|
||||
private int maxHP;
|
||||
|
||||
private int mp;
|
||||
private int maxMP;
|
||||
|
||||
public Enemy(int hp, int mp, Weapon weapon) {
|
||||
this.hp = hp;
|
||||
this.maxHP= hp;
|
||||
|
||||
this.mp = mp;
|
||||
this.maxMP= mp;
|
||||
|
||||
this.weapon = weapon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
hp -= damage;
|
||||
}
|
||||
|
||||
hp -= damage;
|
||||
if (hp < 0) hp = 0;
|
||||
}
|
||||
@Override
|
||||
public void heal(int health){
|
||||
hp+= health;
|
||||
if (hp>maxHP){
|
||||
hp=maxHP;
|
||||
}
|
||||
}
|
||||
public int getHp() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
public int getMaxHP(){
|
||||
return maxHP;
|
||||
}
|
||||
public int getMp() {
|
||||
return mp;
|
||||
}
|
||||
|
||||
public int getMaxMP(){
|
||||
return maxMP;
|
||||
}
|
||||
public Weapon getWeapon() {
|
||||
return weapon;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,51 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Skeleton {
|
||||
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
|
||||
}
|
||||
public class Skeleton extends Enemy {
|
||||
|
||||
private boolean hasRevived;
|
||||
|
||||
public Skeleton() {
|
||||
|
||||
super(
|
||||
80,
|
||||
30,
|
||||
null
|
||||
);
|
||||
|
||||
this.hasRevived = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Entity target) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillMana(int mana) {
|
||||
|
||||
}
|
||||
|
||||
// Skeleton revive ability (once per battle)
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
|
||||
super.takeDamage(damage);
|
||||
|
||||
if (getHp() <= 0 && !hasRevived) {
|
||||
|
||||
hasRevived = true;
|
||||
|
||||
System.out.println("Skeleton revived!");
|
||||
|
||||
heal(getMaxHP() / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,22 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.armors.KnightArmor;
|
||||
import org.project.item.weapons.Sword;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Knight {
|
||||
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
|
||||
|
||||
public class Knight extends Player{
|
||||
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
|
||||
public Knight(String name) {
|
||||
super(
|
||||
name,
|
||||
120,
|
||||
60,
|
||||
new Sword(),
|
||||
new KnightArmor()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.project.item.armors.Armor;
|
||||
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;
|
||||
@@ -18,7 +18,7 @@ public abstract class Player {
|
||||
this.name = name;
|
||||
this.hp = hp;
|
||||
this.mp = mp;
|
||||
|
||||
this.maxMP = mp;
|
||||
this.weapon = weapon;
|
||||
this.armor = armor;
|
||||
}
|
||||
@@ -31,6 +31,7 @@ public abstract class Player {
|
||||
@Override
|
||||
public void defend() {
|
||||
// TODO
|
||||
System.out.println(name+ "is defending!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@ package org.project.item.armors;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Armor {
|
||||
|
||||
private int defense;
|
||||
private int maxDefense;
|
||||
|
||||
private int durability;
|
||||
private int maxDurability;
|
||||
|
||||
@@ -11,7 +13,12 @@ public abstract class Armor {
|
||||
|
||||
public Armor(int defense, int durability) {
|
||||
this.defense = defense;
|
||||
this.maxDefense = defense;
|
||||
|
||||
this.durability = durability;
|
||||
this.maxDurability =durability;
|
||||
|
||||
this.isBroke=false;
|
||||
}
|
||||
|
||||
public void checkBreak() {
|
||||
@@ -23,9 +30,15 @@ public abstract class Armor {
|
||||
|
||||
// TODO: (BONUS) UPDATE THE REPAIR METHOD
|
||||
public void repair() {
|
||||
if (!isBroke){
|
||||
System.out.println("Armor is not broken.");
|
||||
return;
|
||||
}
|
||||
|
||||
isBroke = false;
|
||||
defense = maxDefense;
|
||||
durability = maxDurability;
|
||||
System.out.println("Armor repaired!");
|
||||
}
|
||||
|
||||
public int getDefense() {
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
package org.project.item.armors;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class KnightArmor {
|
||||
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
||||
public class KnightArmor extends Armor{
|
||||
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTO
|
||||
public KnightArmor(){
|
||||
super(
|
||||
15,
|
||||
120
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package org.project.item.consumables;
|
||||
|
||||
import org.project.item.Item;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Consumable {
|
||||
public abstract class Consumable implements Item {
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
public abstract void use();
|
||||
}
|
||||
|
||||
@@ -3,14 +3,25 @@ package org.project.item.consumables;
|
||||
import org.project.entity.Entity;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Flask {
|
||||
public abstract class Flask extends Consumable {
|
||||
|
||||
/*
|
||||
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
|
||||
*/
|
||||
public Flask(){
|
||||
|
||||
}
|
||||
|
||||
// TODO: UPDATE USE METHOD
|
||||
@Override
|
||||
public void use(Entity target) {
|
||||
target.heal(target.getMaxHP() / 10);
|
||||
int healAmount = target.getMaxHP() / 10;
|
||||
target.heal(healAmount);
|
||||
System.out.println("Flask used! Healed"+ healAmount+ "HP.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void use() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ import org.project.entity.Entity;
|
||||
import java.util.ArrayList;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Sword {
|
||||
public class Sword extends Weapon {
|
||||
|
||||
/*
|
||||
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
|
||||
*/
|
||||
@@ -13,14 +14,33 @@ public class Sword {
|
||||
int abilityCharge;
|
||||
|
||||
public Sword() {
|
||||
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
||||
|
||||
super(
|
||||
25, // damage
|
||||
10 // manaCost
|
||||
);
|
||||
|
||||
this.abilityCharge = 0;
|
||||
}
|
||||
|
||||
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
|
||||
public void uniqueAbility(ArrayList<Entity> targets) {
|
||||
|
||||
abilityCharge += 2;
|
||||
|
||||
System.out.println("Sword Unique Ability Activated!");
|
||||
|
||||
int damage = getDamage();
|
||||
|
||||
// BONUS EFFECT: charged attack
|
||||
if (abilityCharge >= 4) {
|
||||
damage *= 2;
|
||||
abilityCharge = 0;
|
||||
System.out.println("POWER STRIKE!");
|
||||
}
|
||||
|
||||
for (Entity target : targets) {
|
||||
target.takeDamage(getDamage());
|
||||
target.takeDamage(damage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
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
|
||||
*/
|
||||
@@ -24,12 +25,10 @@ public abstract class Weapon {
|
||||
public int getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
public int getManaCost() {
|
||||
return manaCost;
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,29 @@ import org.project.entity.enemies.Enemy;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Location {
|
||||
|
||||
private String name;
|
||||
|
||||
private ArrayList<Enemy> enemies;
|
||||
|
||||
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
|
||||
this.locations = locations;
|
||||
this.enemies = enemies;
|
||||
private ArrayList<Location> connectedLocations;
|
||||
|
||||
public Location(String name) {
|
||||
|
||||
this.name = name;
|
||||
|
||||
this.enemies = new ArrayList<>();
|
||||
this.connectedLocations = new ArrayList<>();
|
||||
}
|
||||
|
||||
// add enemy to location
|
||||
public void addEnemy(Enemy enemy) {
|
||||
enemies.add(enemy);
|
||||
}
|
||||
|
||||
// connect locations (for movement system)
|
||||
public void addLocation(Location location) {
|
||||
connectedLocations.add(location);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -19,10 +35,10 @@ public class Location {
|
||||
}
|
||||
|
||||
public ArrayList<Location> getLocations() {
|
||||
return locations;
|
||||
return connectedLocations;
|
||||
}
|
||||
|
||||
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.
Reference in New Issue
Block a user