Initial commit

This commit is contained in:
Andrew
2022-11-25 11:49:17 +02:00
commit a7e6362658
22 changed files with 470 additions and 0 deletions

BIN
Main/Battlefield.class Normal file

Binary file not shown.

73
Main/Battlefield.java Normal file
View File

@@ -0,0 +1,73 @@
package Main;
import java.util.*;
public class Battlefield {
protected HashMap<Integer, Lutemon> battlefield = new HashMap<Integer, Lutemon>();
protected int id1, id2, deadLutemon;
protected Lutemon lutemon1, lutemon2, temp;
Scanner scanner;
private Boolean exit = true;
public Battlefield(Scanner scanner) {
this.scanner = scanner;
}
public void addLutemon(int id, Lutemon lutemon) {
battlefield.put(id, lutemon);
}
public void removeLutemon(int id) {
battlefield.remove(id);
}
public void fight() {
exit = true;
try {
System.out.println("Give the ID of the first fighter:");
id1 = Integer.parseInt(scanner.nextLine());
lutemon1 = battlefield.get(id1);
System.out.println("Give the ID of the second fighter:");
id2 = Integer.parseInt(scanner.nextLine());
lutemon2 = battlefield.get(id2);
} catch (NumberFormatException e) {
e.printStackTrace();
}
while (exit) {
System.out.println(lutemon1.printStats());
System.out.println(lutemon2.printStats());
lutemon2.defense(lutemon1.attack());
System.out.println(
lutemon1.getColor() + "(" + lutemon1.getName() + ") attacks " + lutemon2.getColor() + "("
+ lutemon2.getName() + ")");
if (lutemon2.checkAlive()) {
System.out
.println(lutemon2.getColor() + "(" + lutemon2.getName() + ") manages to escape death.");
temp = lutemon1;
lutemon1 = lutemon2;
lutemon2 = temp;
} else {
System.out.println(lutemon2.getColor() + "(" + lutemon2.getName() + ") gets killed.");
System.out.println("The battle is over.");
if (battlefield.get(id2) == lutemon2) {
battlefield.remove(id2);
lutemon1.train();
deadLutemon = id2;
} else {
battlefield.remove(id1);
lutemon2.train();
deadLutemon = id1;
}
exit = false;
}
}
}
public HashMap<Integer, Lutemon> getBattlefield() {
return battlefield;
}
public int deadLutemon() {
return deadLutemon;
}
}

BIN
Main/Black.class Normal file

Binary file not shown.

7
Main/Black.java Normal file
View File

@@ -0,0 +1,7 @@
package Main;
public class Black extends Lutemon {
public Black(String name, String color, int exp, int attack, int defense, int health) {
super(name, color, exp, attack, defense, health);
}
}

BIN
Main/Green.class Normal file

Binary file not shown.

7
Main/Green.java Normal file
View File

@@ -0,0 +1,7 @@
package Main;
public class Green extends Lutemon {
public Green(String name, String color, int exp, int attack, int defense, int health) {
super(name, color, exp, attack, defense, health);
}
}

BIN
Main/Home.class Normal file

Binary file not shown.

28
Main/Home.java Normal file
View File

@@ -0,0 +1,28 @@
package Main;
import java.util.*;
public class Home {
protected HashMap<Integer, Lutemon> home = new HashMap<Integer, Lutemon>();
public Home() {
}
public void addLutemon(int id, Lutemon lutemon) {
home.put(id, lutemon);
heal(lutemon);
}
public void removeLutemon(int id) {
home.remove(id);
}
public void heal(Lutemon lutemon) {
lutemon.heal();
}
public HashMap<Integer, Lutemon> getHome() {
return home;
}
}

BIN
Main/Lutemon.class Normal file

Binary file not shown.

88
Main/Lutemon.java Normal file
View File

@@ -0,0 +1,88 @@
package Main;
public class Lutemon {
protected String name, color;
protected int id, exp, attack, defense, health, maxHealth;
private static int idCounter = 0;
public Lutemon(String name, String color, int exp, int attack, int defense, int health) {
this.name = name;
this.color = color;
this.exp = 0;
this.attack = attack;
this.defense = defense;
this.health = health;
this.maxHealth = health;
this.id = idCounter;
idCounter++;
}
public String getName() {
return name;
}
public String getColor() {
return color;
}
public int getId() {
return id;
}
public int getExp() {
return exp;
}
public int getAttack() {
return attack;
}
public int getDefense() {
return defense;
}
public int getMaxHealth() {
return maxHealth;
}
public int getHealth() {
return health;
}
public void heal() {
this.health = this.maxHealth;
}
public void train() {
this.exp++;
}
public String printStats() {
return (getId() + ": " + getColor() + "(" + getName() + ") " + "att: "
+ getAttack() + "; def: " + getDefense() + "; exp:"
+ getExp() + "; health: " + getHealth() + "/"
+ getMaxHealth());
}
public static int getIdCounter() {
return idCounter;
}
public int attack() {
return getAttack() + getExp();
}
public void defense(int attack) {
this.health -= attack - this.defense;
}
public boolean checkAlive() {
if (this.health > 0) {
return true;
} else {
return false;
}
}
}

BIN
Main/Main.class Normal file

Binary file not shown.

59
Main/Main.java Normal file
View File

@@ -0,0 +1,59 @@
package Main;
import java.util.Scanner;
/**
*
* @author gessle
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean exit = false;
System.out.println("Welcome to the Lutemon simulator!");
Storage storage = new Storage(sc);
while (!exit) {
System.out.println(
"1) Create a Lutemon, 2) List all the Lutemons, 3) Move Lutemons, 4) Train Lutemons, 5) Let them fight, 0) Exit");
int i = 0;
String si = sc.nextLine();
try {
i = Integer.parseInt(si);
} catch (NumberFormatException ex) {
ex.printStackTrace();
}
switch (i) {
case 1:
storage.createLutemon();
break;
case 2:
storage.listLutemons();
break;
case 3:
storage.moveLutemons();
break;
case 4:
storage.trainLutemon();
break;
case 5:
storage.fightLutemon();
break;
case 0:
exit = true;
System.out.println(
"The game has closed. In total " + Lutemon.getIdCounter()
+ " Lutemons were created.");
break;
default:
System.out.println("Unknown option.");
break;
}
}
sc.close();
}
}

BIN
Main/Orange.class Normal file

Binary file not shown.

8
Main/Orange.java Normal file
View File

@@ -0,0 +1,8 @@
package Main;
public class Orange extends Lutemon {
public Orange(String name, String color, int exp, int attack, int defense, int health) {
super(name, color, exp, attack, defense, health);
}
}

BIN
Main/Pink.class Normal file

Binary file not shown.

7
Main/Pink.java Normal file
View File

@@ -0,0 +1,7 @@
package Main;
public class Pink extends Lutemon {
public Pink(String name, String color, int exp, int attack, int defense, int health) {
super(name, color, exp, attack, defense, health);
}
}

BIN
Main/Storage.class Normal file

Binary file not shown.

155
Main/Storage.java Normal file
View File

@@ -0,0 +1,155 @@
package Main;
import java.util.*;
public class Storage {
protected HashMap<Integer, Lutemon> storage = new HashMap<Integer, Lutemon>();
private int choice, id;
private String name;
Scanner scanner;
private Home home = new Home();
private TrainingArea training = new TrainingArea();
private Battlefield battlefield;
public Storage(Scanner scanner) {
this.scanner = scanner;
this.battlefield = new Battlefield(scanner);
}
public void createLutemon() {
try {
System.out.println("Add 1) White, 2) Green, 3) Pink, 4) Orange, 5) Black");
String a = scanner.nextLine();
choice = Integer.parseInt(a);
System.out.println("Give it a name:");
name = scanner.nextLine();
} catch (NumberFormatException e) {
e.printStackTrace();
}
switch (choice) {
case 1:
White white = new White(name, "White", 0, 5, 4, 20);
storage.put(white.getId(), white);
home.addLutemon(white.getId(), white);
break;
case 2:
Green green = new Green(name, "Green", 0, 6, 3, 19);
storage.put(green.getId(), green);
home.addLutemon(green.getId(), green);
break;
case 3:
Pink pink = new Pink(name, "Pink", 0, 7, 2, 18);
storage.put(pink.getId(), pink);
home.addLutemon(pink.getId(), pink);
break;
case 4:
Orange orange = new Orange(name, "Orange", 0, 8, 1, 17);
storage.put(orange.getId(), orange);
home.addLutemon(orange.getId(), orange);
break;
case 5:
Black black = new Black(name, "Black", 0, 9, 0, 16);
storage.put(black.getId(), black);
home.addLutemon(black.getId(), black);
break;
default:
System.out.println("Invalid choice.");
break;
}
}
public void listLutemons() {
System.out.println("There are the following Lutemons at Home:");
for (Lutemon lutemon : home.getHome().values()) {
System.out.println(lutemon.printStats());
}
System.out.println("There are the following Lutemons at Training area:");
for (Lutemon lutemon : training.getTraining().values()) {
System.out.println(lutemon.printStats());
}
System.out.println("There are the following Lutemons at Battle field:");
for (Lutemon lutemon : battlefield.getBattlefield().values()) {
System.out.println(lutemon.printStats());
}
}
public void moveLutemons() {
try {
System.out.println("Give the ID of Lutemon that should be moved:");
id = Integer.parseInt(scanner.nextLine());
System.out.println(
"Where would the Lutemon be moved? 1) Home, 2) Training area, 3) Battle field");
choice = Integer.parseInt(scanner.nextLine());
} catch (NumberFormatException e) {
e.printStackTrace();
}
if (checkIfExists(id)) {
switch (choice) {
case 1:
if (home.getHome().containsKey(id) == false) {
if (training.getTraining().containsKey(id)) {
training.removeLutemon(id);
home.addLutemon(id, storage.get(id));
} else if (battlefield.getBattlefield().containsKey(id)) {
battlefield.removeLutemon(id);
home.addLutemon(id, storage.get(id));
}
}
break;
case 2:
if (training.getTraining().containsKey(id) == false) {
if (home.getHome().containsKey(id)) {
home.removeLutemon(id);
training.addLutemon(id, storage.get(id));
} else if (battlefield.getBattlefield().containsKey(id)) {
battlefield.removeLutemon(id);
training.addLutemon(id, storage.get(id));
}
}
break;
case 3:
if (battlefield.getBattlefield().containsKey(id) == false) {
if (home.getHome().containsKey(id)) {
home.removeLutemon(id);
battlefield.addLutemon(id, storage.get(id));
} else if (training.getTraining().containsKey(id)) {
training.removeLutemon(id);
battlefield.addLutemon(id, storage.get(id));
}
}
break;
default:
System.out.println("Invalid choice.");
break;
}
}
}
public void trainLutemon() {
training.train();
}
public void fightLutemon() {
System.out.println("There are the following Lutemons at Battle field:");
for (Lutemon lutemon : battlefield.getBattlefield().values()) {
System.out.println(lutemon.printStats());
}
battlefield.fight();
storage.remove(battlefield.deadLutemon());
}
public HashMap<Integer, Lutemon> getStorage() {
return storage;
}
public boolean checkIfExists(Integer id) {
if (storage.containsKey(id) == false) {
System.out.println("No Lutemon with ID " + id + " could be found!");
return false;
} else {
return true;
}
}
}

BIN
Main/TrainingArea.class Normal file

Binary file not shown.

30
Main/TrainingArea.java Normal file
View File

@@ -0,0 +1,30 @@
package Main;
import java.util.*;
public class TrainingArea {
protected HashMap<Integer, Lutemon> training = new HashMap<Integer, Lutemon>();
public TrainingArea() {
}
public void addLutemon(int id, Lutemon lutemon) {
training.put(id, lutemon);
}
public void removeLutemon(int id) {
training.remove(id);
}
public void train() {
for (Lutemon lutemon : training.values()) {
System.out.println(lutemon.getColor() + "(" + lutemon.getName() + ") trains and gain experience!");
lutemon.train();
}
}
public HashMap<Integer, Lutemon> getTraining() {
return training;
}
}

BIN
Main/White.class Normal file

Binary file not shown.

8
Main/White.java Normal file
View File

@@ -0,0 +1,8 @@
package Main;
public class White extends Lutemon {
public White(String name, String color, int exp, int attack, int defense, int health) {
super(name, color, exp, attack, defense, health);
}
}