complete classes + part of main

This commit is contained in:
2026-05-14 01:00:06 +03:30
parent a7ff45292f
commit 38fdd06a03
42 changed files with 557 additions and 66 deletions
+432 -12
View File
@@ -1,34 +1,227 @@
package org.project;
import org.project.entity.Entity;
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.item.consumables.Flask;
import org.project.item.consumables.Teriak;
import org.project.location.Location;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static final String RESET = "\u001B[0m";
public static final String RED = "\u001B[31m";
public static final String GREEN = "\u001B[32m";
public static final String YELLOW = "\u001B[33m";
public static final String BLUE = "\u001B[34m";
public static Entity player;
public static Entity enemy;
public static Scanner input = new Scanner(System.in);
public static ArrayList<Boolean> keys = new ArrayList<Boolean>();
public static void main(String[] args) {
ArrayList<String> names = new ArrayList<>();
names.add("Nou Camp");
names.add("Bernabeu");
names.add("Azadi");
System.out.println("----------Welcome to Java-Knight");
startMenu();
while (true){
do{
System.out.println("===============================");
Location fightLoc = fightMenu();
enemy = fightLoc.getEnemie();
System.out.println(enemy.toString() + "| HP:" + enemy.getHp());
System.out.println("Do you want fight?");
System.out.println("1.Yes");
System.out.println("2.No(Go to another location)");
int n = input.nextInt();
if(n==1){
gameplay();
if(!player.isalive()){
System.out.println("===============================");
System.out.println( YELLOW + "Goodby!");
return;
}
else {
System.out.println(BLUE);
player.repair();
System.out.println(RESET);
}
}
else if(n >= 3){
System.out.println("Invalid input");
}
}while (true);
}
// TODO: IMPLEMENT GAMEPLAY
}
public static void setKeys(){
boolean goblinkey=false;
boolean skeletonkey = false;
boolean vampirekey = false;
keys.add(goblinkey);
keys.add(skeletonkey);
keys.add(vampirekey);
}
public static void startMenu(){
System.out.println("----------Welcome to Java-Knight----------");
setKeys();
System.out.print("Please enter your name:");
String name = input.next();
System.out.println("Choose tor player:");
System.out.println("1. ⚔\uFE0F Knight (High Damage)");
System.out.println("2. \uD83E\uDDD9\u200D♂\uFE0F Wizard (High HP)");
System.out.println("3. \uD83D\uDDE1\uFE0F Assassin (High Mana)");
boolean validInput = false;
while (!validInput){
System.out.print("chose:");
int choose =input.nextInt();
switch (choose){
case 1:
{
player = new Knight(name);
validInput= true;
break;
}
case 2:
{
player = new Wizard(name);
validInput = true;
break;
}
case 3:
{
player = new Assassin(name);
validInput = true;
break;
}
default:
{
System.out.println("Invalid input");
validInput = false;
}
}
}
}
public static Location fightMenu(){
boolean dragonOpen = true;
for (Boolean b : keys){
if(b == false){
dragonOpen = false;
break;
}
}
System.out.println("Where do you want to go?");
System.out.println("1.Desert");
System.out.println("2.Sea");
System.out.println("3.Jungle");
for(boolean b : keys){
if(b){
System.out.print("\uFE0F");
}
else{
System.out.print("🔒");
}
}
if(dragonOpen) {
System.out.println("4.Dranon");
}
else {
System.out.println("Dragon");
}
int n = (int) ((Math.random()) *3);
Entity enemy = null;
if(n == 0){
enemy = new Goblin();
}
if(n==1){
enemy = new Skeleton();
}
if(n==2){
enemy = new Vampire();
}
Location location = null;
boolean validInput = false;
while (!validInput){
System.out.print("chose:");
int choose =input.nextInt();
switch (choose){
case 1:
{
location = new Location("Desert" , enemy);
validInput = true;
break;
}
case 2:
{
location = new Location("Sea" , enemy);
validInput=true;
break;
}
case 3:
{
location = new Location("Jungle" , enemy);
validInput =true;
break;
}
case 4:
{
if(dragonOpen){
enemy = new Dragon();
location = new Location("The end of line" , enemy);
validInput = true;
}
else {
System.out.println("It's locked!!!!!!");
validInput = false;
}
break;
}
default:
{
System.out.println("Invalid input");
validInput = false;
break;
}
}
@@ -39,11 +232,238 @@ public class Main {
}
// TODO: IMPLEMENT GAMEPLAY
System.out.println("===============================");
return location;
}
public static void gameplay(){
boolean playerTurn = true;
while (player.isalive() && enemy.isalive()){
System.out.println("=========================================");
if(playerTurn){
System.out.println(player.toString());
System.out.println(enemy.toString() + "| HP:" + enemy.getHp());
System.out.println("\n"+GREEN + "It's your Turn" +RESET);
while (true){
if(playerAttakMenu()){
break;
}
}
playerTurn = !playerTurn;
if(enemy instanceof Skeleton && !enemy.isalive()){
System.out.println("\n"+ RED);
enemy.specialAbility(player);
System.out.println(RESET);
playerTurn = !playerTurn;
}
if(!enemy.isalive()){
System.out.println("you WIN");
int n = (int) (Math.random()*2);
if(n== 0){
if(enemy instanceof Goblin){
if(keys.get(0) == true){
System.out.println("You have got this key befor");
return;
}
keys.set(0, true);
}
else if (enemy instanceof Skeleton){
if(keys.get(1) == true){
System.out.println("You have got this key befor");
return;
}
keys.set(1 , true);
}
else if (enemy instanceof Vampire) {
if(keys.get(2) == true){
System.out.println("You have got this key befor");
return;
}
keys.set(2 , true);
}
System.out.println( YELLOW +"You chatck the" + enemy.toString() +"keys"+ RESET);
}
else {
System.out.println("There is no keys here");
}
return;
}
}
if(!enemy.getpossible()){
System.out.println(enemy.toString() + " Can't do any act");
enemy.truepossible();
playerTurn = !playerTurn;
continue;
}
if(enemy.getpossible() && !playerTurn){
System.out.println("\n" + RED +"It's enemy Turn" + RESET);
enemyAttakMenu();
playerTurn = !playerTurn;
}
if(!player.isalive()){
System.out.println("you lose");
return;
}
}
}
public static void enemyAttakMenu(){
if(enemy instanceof Goblin || enemy instanceof Vampire){
int n = (int) (Math.random()*3);
if(n ==0 && enemy.getMp() >=10){
enemy.specialAbility(player);
}
else if(n == 1){
enemy.lightattack(player);
}
else {
enemy.heavyattack(player);
}
}
else if(enemy instanceof Skeleton){
if(enemy.getHp() <= 0){
enemy.heavyattack(player);
}
else {
enemy.lightattack(player);
}
}
}
public static boolean playerAttakMenu() {
System.out.print("1.Light attak| ");
System.out.print("2.Heavy attak("+player.getWeapon().getManaCost()+ " mana)| ");
System.out.print("3.Defend(12 mana)| ");
System.out.print("4.Heal(14 mana)| ");
System.out.println("5.Special action (30 mana)");
int n ;
while (true){
System.out.print("choose:");
n = input.nextInt();
if(n > 0 && n < 6){
break;
}
else {
System.out.println("Invalid input");
}
}
switch (n){
case 1:
{
player.lightattack(enemy);
return true;
}
case 2:
{
if(player.getMp() >= player.getWeapon().getManaCost()){
player.heavyattack(enemy);
return true;
}
else {
System.out.println("Not enough Mp");
return false;
}
}
case 3:
{
if(player.getMp() >= 12){
player.defend();
return true;
}
else {
System.out.println("Not enough Mp");
return false;
}
}
case 4:
{
if(player.getMp() >= 14){
System.out.println("1.Flask | 2. Teriak");
int k ;
while (true){
k = input.nextInt();
System.out.print("choose:");
if(k == 1){
Flask flask = new Flask();
flask.use(player);
break;
}
else if(k==2){
Teriak teriak = new Teriak();
teriak.use(player);
break;
}
else {
System.out.print("Invalid input");
}
}
return true;
}
else {
System.out.println("Not enough Mp");
return false;
}
}
case 5:
{
if(player.getMp() >= 30){
player.specialAbility(enemy);
return true;
}
else {
System.out.println("Not enough Mp");
return false;
}
}
default:
{
return false;
}
}
}
private void
}