Set up starting new game

This commit is contained in:
2026-05-14 22:59:26 +03:30
parent b03aad9420
commit 0e04d8a1a2
34 changed files with 178 additions and 39 deletions
+129 -5
View File
@@ -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;
}
}