Set up starting new game
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://maven.myket.ir/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,15 +1,139 @@
|
||||
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
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
// Enemies
|
||||
Enemy goblin = new Goblin();
|
||||
Enemy skeleton = new Skeleton();
|
||||
Enemy vampire = new Vampire();
|
||||
Enemy dragon = new Dragon();
|
||||
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 peak = new Location("ashen peak", dragon);
|
||||
Location[] locations = {forest, catacombs, castle}; // An array of the location except peak where is the Dragon(final boss) located
|
||||
|
||||
System.out.println(" =============== Java Knight ===============\n");
|
||||
boolean running = true;
|
||||
while(running){
|
||||
|
||||
System.out.println(" Choose your option:");
|
||||
System.out.println(" 1. Start game" +
|
||||
" 2. Exit");
|
||||
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(" Enter 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(" 1. Knight" +
|
||||
" 2. Assassin" +
|
||||
" 3. Wizard");
|
||||
if (scanner.hasNextInt()) {
|
||||
option = scanner.nextInt();
|
||||
} else {
|
||||
System.out.println(" Invalid input! Please enter a number.");
|
||||
scanner.next();
|
||||
}
|
||||
}
|
||||
switch (option){
|
||||
case 1:
|
||||
player = new Knight(name);
|
||||
System.out.printf("Your Character: %s, Your Name: %s\n", "Knight", player.getName());
|
||||
break;
|
||||
case 2:
|
||||
player = new Assassin(name);
|
||||
System.out.printf("Your Character: %s, Your Name: %s\n", "Assassin", player.getName());
|
||||
break;
|
||||
case 3:
|
||||
player = new Wizard(name);
|
||||
System.out.printf("\nYour Character: %s, Your Name: %s\n\n", "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);
|
||||
System.out.println(" =============== Prepare to fight ===============");
|
||||
|
||||
}
|
||||
|
||||
public static Location setLocation(Location currentLocation, Location[] locations, Player player, Random random, Scanner scanner){
|
||||
System.out.printf(" %s should fight %s in %s\n", player.getName(), currentLocation.getEnemy().getName(), currentLocation.getName());
|
||||
int option = 0;
|
||||
while(option > 3 || option < 1){
|
||||
System.out.println(" Choose your option: ");
|
||||
System.out.println(" 1. Fight " + currentLocation.getEnemy().getName() +
|
||||
" 2. Change location");
|
||||
if (scanner.hasNextInt()) {
|
||||
option = scanner.nextInt();
|
||||
} else {
|
||||
System.out.println(" Invalid input! Please enter a number.");
|
||||
scanner.next();
|
||||
}
|
||||
}
|
||||
|
||||
if(option == 1){
|
||||
return currentLocation;
|
||||
}
|
||||
else if(option == 2){
|
||||
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(" Changing locations...");
|
||||
setLocation(currentLocation, locations, player, random, scanner);
|
||||
}
|
||||
else{
|
||||
System.out.println(" Invalid input! Try again.");
|
||||
setLocation(currentLocation, locations, player, random, scanner);
|
||||
}
|
||||
return currentLocation;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package org.project.entity;
|
||||
|
||||
public interface Entity {
|
||||
|
||||
public void specialAbility(Entity target);
|
||||
void specialAbility(Entity target);
|
||||
|
||||
void defend();
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Dagger;
|
||||
import org.project.item.weapons.Flame;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
@@ -21,7 +20,7 @@ public class Dragon extends Enemy{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SpecialAbility(Entity target) {
|
||||
public void specialAbility(Entity target) {
|
||||
target.takeDamage(weapon.getDamage());
|
||||
}
|
||||
|
||||
@@ -37,6 +36,7 @@ public class Dragon extends Enemy{
|
||||
return maxHP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
return "Dragon";
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ public abstract class Enemy implements Entity {
|
||||
private boolean defending = false;
|
||||
protected boolean lifeStealing = false;
|
||||
private boolean stunned = false;
|
||||
private boolean dodged = false;
|
||||
|
||||
public Enemy(int hp, Weapon weapon) {
|
||||
this.hp = hp;
|
||||
@@ -24,13 +25,20 @@ public abstract class Enemy implements Entity {
|
||||
target.takeDamage(weapon.getDamage());
|
||||
}
|
||||
|
||||
public abstract void SpecialAbility(Entity target);
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
defending = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stun(boolean value) {
|
||||
stunned = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dodge(boolean value) {
|
||||
dodged = value;
|
||||
}
|
||||
|
||||
public int getHp() {
|
||||
return hp;
|
||||
@@ -51,4 +59,7 @@ public abstract class Enemy implements Entity {
|
||||
public boolean isStunned() {
|
||||
return stunned;
|
||||
}
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class Goblin extends Enemy{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SpecialAbility(Entity target) {
|
||||
public void specialAbility(Entity target) {
|
||||
target.takeDamage(criticalHit_damage);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ public class Goblin extends Enemy{
|
||||
return maxHP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
return "Goblin";
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class Skeleton extends Enemy{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SpecialAbility(Entity target) {
|
||||
public void specialAbility(Entity target) {
|
||||
hp = maxHP/2; // revive
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ public class Skeleton extends Enemy{
|
||||
return maxHP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
return "Skeleton";
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class Vampire extends Enemy{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SpecialAbility(Entity target) {
|
||||
public void specialAbility(Entity target) {
|
||||
lifeStealing = true;
|
||||
target.takeDamage((8/10)*(weapon.getDamage()));
|
||||
hp += (int)((2/10)*(weapon.getDamage()));
|
||||
@@ -33,6 +33,7 @@ public class Vampire extends Enemy{
|
||||
return maxHP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
return "Vampire";
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
//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);
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user