Professional Documents
Culture Documents
Among Us
Among Us
Форма N Н-6.01
КУРСОВА РОБОТА
з дисципліни ” Об’єктно-орієнтоване програмування ”
на тему: РОЗРОБКА ПРОГРАМНОЇ СИСТЕМИ ДЛЯ МОДЕЛЮВАННЯ
ОБ’ЄКТІВ ” Світ гри The Crusader Stronghold; Перша фортеця, Друга фортеця;
списоносець, лучник, лицар-тамплієр ”
З ВИКОРИСТАННЯМ UML ТА МОВИ ПРОГРАМУВАННЯ JAVA
ЗАТВЕРДЖУЮ
Зав. кафедри ПЗ, проф., д.т.н.
ІНДИВІДУАЛЬНЕ ЗАВДАННЯ
на курсову роботу з дисципліни ”Об'єктно-орієнтоване програмування”
студенту групи 2ПІ-20б Захарчуку М.
РОЗРОБКА ПРОГРАМНОЇ СИСТЕМИ ДЛЯ МОДЕЛЮВАННЯ ОБ’ЄКТІВ ” Світ гри The Crusader
Stronghold; Перша фортеця, Друга фортеця; списоносець, лучник, лицар-тамплієр ” З ВИКОРИСТАННЯМ UML
ТА МОВИ ПРОГРАМУВАННЯ JAVA
Вихідні дані:
- Середовища розробки NetBeans IDE, IntelliJ IDEA або Eclipse, платформа JavaFX.
АНОТАЦІЯ
ЗМІСТ
ВСТУП…………………………………………………………………...5
6 КЕРІВНИЦТВО КОРИСТУВАЧА……………………..……………….32
ВИСНОВКИ…………….………………………………………………....36
ПЕРЕЛІК ПОСИЛАНЬ.……………………………………………..……37
ВСТУП
Дослідження історичних періодів завжди цікавило істориків. Особливо
привертає увагу доба середньовіччя, яка завжди характеризувалася своєю
загадковістю, жорстокістю, бідністю, занепадом економіки та найчастіше
кровопролитними битвами та хрестовими походами. Думки та здогадки істориків
та дослідників цієї історичної епохи ніколи не могли збігтися через недостатню
кількість інформації про цю містичну добу.
Доба середньовіччя [1] або ж «темні віки» — період історії від 5 століття до
кінця 15 століття — час примітивної культури та цілковитого занепаду науки,
формування нових держав, епідемій, міжусобиць та війн, поширення впливу
церкви та християнської релігії у всіх галузях суспільного і культурного життя.
Середньовічне суспільство, складалося з безлічі соціальних станів . Людина
за народженням належала до одного з них і практично не мала можливості змінити
своє соціальне становище. Майже всі представники тогочасного суспільства не
знали письма, що унеможливлювало передачу достовірної інформації між
поколіннями. Лише одиниці володіли такими знаннями і могли писати історію
тогочасного суспільства, але й вони зазнавали певного утиску з боку церкви та
влади, тому говорити про достовірність тогочасних документів з повною
впевненістю не можна. Церква фактично була головним правлячим органом влади
на той час(до 1100 року). Їй повністю підпорядковувалась система освіти,
контролювалось прийняття рішень та законів, проведення виборів. Саме вона
вирішувала долю історичних документів та іноді корегувала історичні факти, задля
власної вигоди.
Ще одним фактом , який вплинув на долю історичного надбання були
постійні війни та міжусобиці, внаслідок яких руйнувалися цілі міста, зникали
важливі документи та інформація про історичну епоху.
Саме тому інформації про середньовіччя так мало, що не дозволяє історикам
скласти єдину повноцінну картину про ті дні. Особливо мало інформації про
хрестові походи, адже повноцінні документи про них так і не дійшли до наших
часів. Твердження істориків завжди різняться між собою, що іноді призводить до
6
Cаме через переваги, вказані вище, мову Java було обрано мовою
програмування для курсової роботи.
1.5 Висновки
Проаналізувавши стан стратегії в реальному часі Stronghold Crusader,
переглянувши усі проблеми цього питання та зваживши усі переваги та недоліки
було вирішено створити власну реалізацію програмного продукту.
Створено список завдань, які повинні бути реалізовані в програмному
продукті. Найефективнішою мовою програмування для даного продукту шляхом
аналізу обрано Java.
16
Робоча область
Клонування
Ви дійсно хочете
клонувати виділених
Вікно “Клонування”
найманців?
НІ ТАК
Перемога
Переміг
Закрити
Поточна
Ім’я:
Рівень:
Чи активний:
Закрити
Увага
Переглядати інформацію
можна лише про один
Вікно “Попередження”
мікрооб’єкт
Закрити
Мікрооб’єкти Макрооб’єкт
(Spusonosech,Lychnik,Luchar (Фортеця)
) Princess)
Рисунок 4.2 – Діаграма агрегації
setS alary
-Конец5 -Конец6
Spusonosech salary
1 1
Мікрооб’єкт Spusunosech містить об’єкт класу salary, який було додано для
того, щоб глибинне копіювання стало необхідним.
27
Вікно програми
1 1
1 1
Універсальний об’єкт(Map)
та макрооб’єкти (фортеці)
1:serialize()
File Cеріалізація
newUnit
() Auto_move()
Map.addNew s:
Spusonosech
Unit()
timer.start()
Поява на
карті
Рух
Зайшов у Пересікся
Чи Пересікся
дружню із ворожою Ні
здоровий із ворогом
фортецю фортецею
Лікування Вихід
Нанесення
урону
Бій
Найманець Ворог
живий? живий?
Так Так
Ні
Видалення
Смерть
5 РОЗРОБКА ПІДСИСТЕМИ
СЕРІАЛІЗАЦІЇ/ДЕСЕРІАЛІЗАЦІЇ ДАНИХ
Параметр Пояснення
12 Рівень здоров’я
31
6 КЕРІВНИЦТВО КОРИСТУВАЧА
ВИСНОВКИ
ПЕРЕЛІК ПОСИЛАНЬ
ДОДАТКИ
39
ДОДАТОК А
ЛІСТИНГ ПРОГРАМИ
//Main
package sample;
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import sample.macro.Fortness;
import sample.macro.KrusaFortress;
import sample.macro.LordFortress;
import sample.micro.Luchar;
import sample.micro.Lychnik;
import sample.micro.Spusonosech;
import javax.xml.crypto.dom.DOMCryptoContext;
import java.security.Key;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedList;
import java.util.Random;
import java.util.concurrent.ForkJoinPool;
"Roma","Rey","Bogban","Travis","Mukola","Liza","Gamura","Vinston","Alex","Hohol192
"};
//getters
//setters
private void setPrimaryStage(Stage pStage){
Main.pStage = pStage;
}
@Override
public void start(Stage primaryStage) throws Exception {
setPrimaryStage(primaryStage);
scrollPane.setFitToHeight(true);
scrollPane.setFitToWidth(true);
map.addFort(new LordFortress());
map.addFort(new KrusaFortress());
map.addNewUnit(new Spusonosech(),true);
map.addNewUnit(new Luchar(),true);
map.addNewUnit(new Lychnik(),true);
map.addNewUnit(new Lychnik(),true);
map.miniMapInFront();
}
}
}
if (event.isShiftDown()){
++moveSpeed;
}
if (event.isControlDown()){
if (moveSpeed >0)
--moveSpeed;
}
if (event.getCode() == KeyCode.DIGIT1){
map.addNewUnit(new Spusonosech(), true);
map.miniMapInFront();
}
if (event.getCode() == KeyCode.DIGIT2){
map.addNewUnit(new Lychnik(), true);
map.miniMapInFront();
}
if (event.getCode() == KeyCode.DIGIT3){
map.addNewUnit(new Luchar(), true);
map.miniMapInFront();
}
if (event.getCode() == KeyCode.DIGIT4){
map.addNewUnit(new
Spusonosech(namesArray[Main.random.nextInt(namesArray.length)], "Криси",78,false),
true);
map.miniMapInFront();
}
if (event.getCode() == KeyCode.DIGIT5){
map.addNewUnit(new
Lychnik(namesArray[Main.random.nextInt(namesArray.length)],"Лорда",78,false),
true);
map.miniMapInFront();
}
if (event.getCode() == KeyCode.DIGIT6){
map.addNewUnit(new
Luchar(namesArray[Main.random.nextInt(namesArray.length)], "Криси",78,false),
true);
map.miniMapInFront();
}
if (event.getCode() == KeyCode.DELETE){
for (int i = 0; i < map.getUnits().size(); ++i){
Spusonosech s = map.getUnits().get(i);
if (s.getIsActive()){
map.deleteUnit(s);
}
}
}
if (event.getCode() == KeyCode.ESCAPE){
for (Spusonosech s : map.getUnits()){
if (s.getIsActive()){
s.setActive();
}
}
}
if (event.getCode() == KeyCode.ENTER){
for (Spusonosech s : map.getUnits()){
if (!s.getIsActive()){
s.setActive();
}
}
}
43
if (event.getCode() == KeyCode.C){
LinkedList<Spusonosech> arr=new LinkedList<>();
int c=0;
for (int i = 0; i < map.getUnits().size(); ++i)
{
if (map.getUnits().get(i).getIsActive())
{
arr.add(map.getUnits().get(i));
c++;
}
}
if(c>=2)
{
try {
newWindOw(primaryStage);
} catch (Exception e) {
e.printStackTrace();
}
}
else {
LinkedList<Spusonosech> clone_arr = new LinkedList<>();
for (int i = 0; i < arr.size(); ++i) {
try {
clone_arr.add((Spusonosech) arr.get(i).clone());
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
}
for (int i = 0; i < arr.size(); ++i)
map.addNewUnit(clone_arr.get(i), false);
}
}
if (event.getCode() == KeyCode.H){
stayFortness = !stayFortness;
}
if (event.getCode() == KeyCode.J){
removeFromMap = !removeFromMap;
}
if (event.getCode() == KeyCode.I ||
event.getCode() == KeyCode.INSERT ){
try {
newWindow(primaryStage);
} catch (Exception e) {
e.printStackTrace();
}
}
if (event.getCode() == KeyCode.K){
closeFortness = !closeFortness;
}
if (event.getCode() == KeyCode.DIGIT0){
System.out.println("*********************************************");
System.out.println("Масив до використання інтерфейсу Сomparable");
System.out.println("*********************************************");
for (int i = 0; i<ArrayHealth.size(); ++i){
System.out.print( "Level: " + map.getUnits().get(i).getLevel()
+ " Name: "
44
+ map.getUnits().get(i).getnAme().getText() + "
Health: ");
System.out.println(ArrayHealth.get(i).getHp());
}
ArrayHealth.sort(Spusonosech.HPComparator);
System.out.println("*********************************************");
System.out.println("Масив після використання java.utils.Arrays;");
System.out.println("*********************************************");
for (int i = 0; i<ArrayHealth.size(); ++i){
System.out.print( "Level: " + map.getUnits().get(i).getLevel()
+ " Name: "
+ map.getUnits().get(i).getnAme().getText() + "
Health: ");
System.out.println(ArrayHealth.get(i).getHp());
}
System.out.println("*********************************************");
System.out.println("Три персонажі з найнижчим рівнем життя");
System.out.println("*********************************************");
for (int i = 0; i<3; ++i)
{
ArrayCopy.add(ArrayHealth.get(i));
}
for (int i = 0; i<ArrayCopy.size(); ++i){
System.out.print( "Level: " + map.getUnits().get(i).getLevel()
+ " Name: "
+ map.getUnits().get(i).getnAme().getText() + "
Health: ");
System.out.println(ArrayCopy.get(i).getHp());
}
ArrayCopy.clear();
ArrayHealth.clear();
}
if (event.getCode() == KeyCode.TAB){
infoOpacity = !infoOpacity;
if (infoOpacity){
map.getKrusaCounterText().setOpacity(1);
map.getLordCounterText().setOpacity(1);
map.getCloseFortText().setOpacity(1);
map.getRemoveFromMapText().setOpacity(1);
map.getStayFortressText().setOpacity(1);
}else{
map.getKrusaCounterText().setOpacity(0);
map.getLordCounterText().setOpacity(0);
map.getCloseFortText().setOpacity(0);
map.getRemoveFromMapText().setOpacity(0);
map.getStayFortressText().setOpacity(0);
}
}
if (event.getCode() == KeyCode.DIGIT8){
System.out.println("Використання статичного поліморфізму:");
sum(10,10);
sum(10,10,10);
System.out.println("Використання динамічного поліморфізму:");
Spusonosech.say_to_child();
Lychnik.say_to_child();
Luchar.say_to_child();
45
}
} );
scrollPane.viewportBoundsProperty().addListener((observable, oldBounds,
bounds) -> {
parent.setLayoutX(scrollX);
parent.setLayoutY(scrollY);
updateChordINFO();
if (map.getUnits().size() == 0){
currentStatusINFO();
}
map.getMiniMap().getPane().setLayoutX(scrollX + 1430);
map.getMiniMap().getPane().setLayoutY(scrollY + scene.getHeight() -
map.getMiniMap().getPane().getHeight() - 500);
map.getMiniMap().getMap().setLayoutX(scrollX*MiniMap.getSCALE());
map.getMiniMap().getMap().setLayoutY(scrollY*MiniMap.getSCALE());
});
primaryStage.setMaximized(true);
primaryStage.setScene(scene);
primaryStage.setTitle("**Stronghold Crusaider**");
46
ckrusaFort = 0;
clordFort = 0;
for (Spusonosech s : map.getUnits()){
for (Fortness p : map.getFortness()){
switch (p.getName()){
case "Фортеця Лорда Криси":
p.setCounterKrusa(ckrusaFort);
break;
case "Фортеця Лорда Христоносця":
p.setCounterLord(clordFort);
break;
default:
break;
}
if(s.getMicroImage().getBoundsInParent().intersects(p.getFort_Image().getBoundsInP
arent())){
switch (p.getName()){
case "Фортеця Лорда Криси":
if (s.getTeam().equals("Криси")){
++ckrusaFort;
s.healthUpKrusa();
KrusaFortress.krusa.add(s);
p.setCounterKrusa(ckrusaFort);
}else {
Spusonosech.inetactive_spus_fort(p, s);
if (p.getHp() <= 0) {
if (p.getName().equals("Фортеця Лорда
Криси")) {
try {
setKrusawin(primaryStage);
} catch (Exception e) {
e.printStackTrace();
}
} else
try {
setLordwin(primaryStage);
} catch (Exception e) {
e.printStackTrace();
}
}
}
if(!stayFortness)
{
KrusaFortress.krusa.clear();
}
break;
case "Фортеця Лорда Христоносця":
if (s.getTeam().equals("Лорда")) {
++clordFort;
s.healthUpLord();
LordFortress.lord.add(s);
p.setCounterLord(clordFort);
} else {
Spusonosech.inetactive_spus_fort(p,s);
if (p.getHp()<=0)
{
47
if (p.getName().equals("Фортеця Лорда
Криси"))
{
try {
setKrusawin(primaryStage);
} catch (Exception e) {
e.printStackTrace();
}
}
else
try {
setLordwin(primaryStage);
} catch (Exception e) {
e.printStackTrace();
}
}
}
if(!stayFortness)
{
LordFortress.lord.clear();
}
break;
default:
break;
}
}
}
for (Spusonosech sp : map.getUnits())
{
if (s != sp &&
s.getMicroImage().getBoundsInParent().intersects(sp.getMicroImage().getBoundsInPar
ent())){
if(removeFromMap){Spusonosech.inetactive_spus(s, sp);}
if (s.getHp() <= 0){
map.deleteUnit(s);
}
}
}
if (closeFortness){
s.auto_move();
}else{
if (s.getHp() < 10 || stayFortness){
s.moveToFort();
}else{
s.auto_move();
}
}
s.setmicroChord();
currentStatusINFO();
}
map.getMiniMap().updateMap();
for(Fortness i: Main.getMap().getFortness())
{
if(i.getHp()<=0)
{
timer.stop();
}
}
}
};
timer.start();
48
primaryStage.show();
if (!removeFromMap){
map.getRemoveFromMapText().setText("Функція смерті вимкнена");
}else{
map.getRemoveFromMapText().setText("Функція смерті ввімкнена");
}
if (stayFortness){
map.getStayFortressText().setText("Залишатися у фортецях");
}else{
map.getStayFortressText().setText("Не залишатися у фортецях");
}
map.getLordCounterText().setX(scrollX + 20);
map.getLordCounterText().setY(scrollY + 90);
map.getCloseFortText().setX(scrollX + 20);
map.getCloseFortText().setY(scrollY + 120);
map.getRemoveFromMapText().setX(scrollX + 20);
map.getRemoveFromMapText().setY(scrollY + 150);
map.getStayFortressText().setX(scrollX + 20);
map.getStayFortressText().setY(scrollY + 180);
}
}
50
//Map
package sample;
import javafx.scene.image.Image;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import sample.macro.Fortness;
import sample.macro.KrusaFortress;
import sample.macro.LordFortress;
import sample.micro.Spusonosech;
import sun.misc.FpUtils;
import java.util.ArrayList;
//getters
public static Pane getRoot() {
return root;
}
public ArrayList<Spusonosech> getUnits() {
return units;
}
public ArrayList<Fortness> getFortness() {return fortness;}
public static int getRootHeight() {
return rootHeight;
}
public static int getRootWidth() {
return rootWidth;
}
public MiniMap getMiniMap() {return miniMap;}
public Text getKrusaCounterText() {
return krusaCounterText;
}
public Text getLordCounterText() {
return lordCounterText;
}
public Text getCloseFortText() {
return closeFortText;
}
public Text getRemoveFromMapText() {
return removeFromMapText;
51
}
public Text getStayFortressText() {
return stayFortressText;
}
public Map(){
root.setMinWidth(rootWidth);
root.setMinHeight(rootHeight);
//closePlanetsText
closeFortText = new Text();
closeFortText.setFill(Color.WHITE);
closeFortText.setFont(new Font("Monaco", 24));
root.getChildren().add(closeFortText);
}
//MiniMap
package sample;
import javafx.scene.Group;
import sample.macro.KrusaFortress;
import sample.macro.LordFortress;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import sample.macro.Fortness;
import sample.micro.Spusonosech;
import java.util.HashMap;
//getters
public Pane getPane() {
return pane;
}
public Rectangle getMap() {
return map;
}
public static double getSCALE() {
return SCALE;
}
public MiniMap() {
this.pane = new Pane();
this.pane.setMinWidth(Map.getRootWidth() * MiniMap.SCALE);
this.pane.setMinHeight(Map.getRootHeight() * MiniMap.SCALE);
try {
miniMap = new Image("image/map.png");
} catch (Exception e) {
System.out.println("Не удалось загрузить изображение!");
}
this.mapOpacity = false;
Rectangle rectangle = new Rectangle(0, 0, pane.getMinWidth(),
pane.getMinHeight());
rectangle.setFill(new ImagePattern(miniMap));
rectangle.setStroke(Color.BLACK);
rectangle.setStrokeWidth(5);
this.pane.getChildren().addAll(rectangle, map);
if (y < map.getHeight() / 2) {
Main.getScrollPane().setVvalue(0);
} else if (y > pane.getHeight() - map.getHeight() / 2) {
Main.getScrollPane().setVvalue(1);
} else Main.getScrollPane().setVvalue(y / pane.getHeight());
}
switch (spusonosech.getLevel()) {
case "Списоносець":
imageView = new ImageView(new Image("image/spus.png"));
break;
case "Лучник":
imageView = new ImageView(new Image("image/lych.png"));
break;
default:
imageView = new ImageView(new Image("image/luch.png"));
break;
}
imageView.setLayoutX(spusonosech.getChordX() * SCALE);
imageView.setLayoutY(spusonosech.getChordY() * SCALE);
imageView.setPreserveRatio(true);
imageView.setFitHeight(200 * SCALE);
unitsMap.put(spusonosech, imageView);
pane.getChildren().add(imageView);
}
rectangle.setLayoutY((f.getY()) * MiniMap.SCALE);
group = new Group(imageView, rectangle);
fortMap.put(f, group);
pane.getChildren().addAll(imageView, rectangle);
}
import sample.macro.Fortness;
import sample.micro.Luchar;
import sample.micro.Lychnik;
import sample.micro.Spusonosech;
import java.awt.*;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
Main.getMap().deleteFortness(fort);
}
HashMap<String, Object> hashMap = (HashMap<String,
Object>)decoder.readObject();
}
decoder.close();
} catch (FileNotFoundException e) {
System.out.println("Помилка відкриття файлу");
}
}
}
//Spusonosech
package sample.micro;
import javafx.scene.Group;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import sample.Main;
import sample.Map;
import sample.macro.Fortness;
import sample.macro.KrusaFortress;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;
import java.util.Scanner;
//******************************getters and
setters*************************************************//
public String getName(){return name;} public void setName(String nm){name=nm;}
public String getTeam(){return team;} public void setTeam(String
tem){team=tem;}
public String getLevel(){return level;} public void setLevel(String
lvl){level=lvl;}
public double getDamage(){return damage;} public void setDamage(double
dmg){damage=dmg;}
public double getHp(){return hp;} public void setHp(double h){hp=h;}
public int getSpeed(){return speed;} public void setSpeed(int
spd){this.speed=spd;}
public int getStrong(){return strong;} public void setStrong(int s){strong=s;}
public int getArmor(){return armor;} public void setArmor(int ar){armor=ar;}
public int getFood(){return food;} public void setFood(int f){food=f;}
public boolean getAlive(){return alive;} public void setAlive(boolean
al){alive=al;}
public Group getmicroGroup() { return microGroup; }
public double getChordX() { return chordX; } public void setChordX(double
x){this.chordX=x;}
public double getChordY() {
return chordY;
} public void setChordY(double y){this.chordY=y;}
public boolean getIsActive(){return isActive;} public void setActive()
{this.isActive = !this.isActive; }
public ImageView getMicroImage(){return microImage;}
public static int getNumberOfmicro_obj(){return numberOfmicro_obj;}
public Text getnAme(){return nAme;}
public static void setNumberOfmicro_obj(int number) {
Spusonosech.numberOfmicro_obj = number;}
public int getHomeX(){return homeX;} public void setHomeX(int
x){this.homeX=x;}
public int getHomeY(){return homeY;} public void setHomeY(int
y){this.homeY=y;}
public boolean isCatch() {
return isCatch;
}
public boolean isLord() {
return isLord;
}
58
{
speed=4;
}
//*****************************methods********************************************
********//
//1.
public void setSalaryhistory(double itm)
{
if (salary == null) salary = new double[1];
else salary = Arrays.copyOf(salary, salary.length + 1);
salary[salary.length - 1] = itm;
}
public double equalSalary()
{
if (salary == null) return 0;
else{
double sum=0,c=salary.length;
for (int i=0;i<salary.length;i++)
{
sum+=salary[i];
}
return sum/c;
}
}
/*2.*/public void training(){this.strong+=5;}
/*3.*/public void eat(){this.food+=10;}
/*4.*/public static void fight(Spusonosech sp1,Spusonosech sp2) throws
InterruptedException
{
if(!sp1.alive)
{
System.out.printf("Бійка не можлива! Персонаж мертвий!\n",sp1);
return;
}
if(!sp2.alive)
{
System.out.printf("Бійка не можлива! Персонаж мертвий!\n",sp2);
return;
}
System.out.println("Здоров'я "+sp1.getName()+" = "+sp1.getHp()+"," +
"Здоров'я "+sp2.getName()+" = "+sp2.getHp());
while (true)
{
Thread.sleep(135);
sp1.hp-=sp2.damage-sp1.armor*0.1;
if(sp1.hp<=0)
{
System.out.printf("%s наніс %s - %7.2f шкоду\n%s загинув! %s
переміг!\n\n",sp2.name,sp1.name,sp2.damage-sp1.armor*0.1,sp1.name,sp2.name);
sp1.alive=false;
sp1.hp=0;
break;
}
else {
System.out.printf("%s наніс %s - %7.2f урон DMG\n в %s залишається
%7.2f\n",sp2.name,sp1.name,sp2.damage-sp1.armor*0.1,sp1.name,sp1.hp);
59
}
System.out.println();
Thread.sleep(135);
sp2.hp-=sp1.damage-sp2.armor*0.1;
if(sp2.hp<=0)
{
System.out.printf("%s наніс %s - %7.2f шкоду\n%s загинув! %s
переміг!\n\n",sp1.name,sp2.name,sp1.damage-sp2.armor*0.1,sp2.name,sp1.name);
sp2.alive=false;
sp2.hp=0;
break;
}
else {
System.out.printf("%s наніс %s - %7.2f урон DMG\n в %s залишається
%7.2f\n",sp1.name,sp2.name,sp1.damage-sp2.armor*0.1,sp2.name,sp2.hp);
}
}
}
public String setRandteam()
{
String s1="Криси",s2="Лорда";
int v=Main.random.nextInt(2);
if(v==1){return s1;}
else return s2;
}
//*****************************constructors***************************************
*******//
//constructor without arguments
public Spusonosech()
{
numberOfmicro_obj++;
this.name=Main.getNamesArray()[Main.random.nextInt(Main.getNamesArray().length)];
this.team=setRandteam();
this.alive=true;
this.food=67;
salary=new double[0];
//this.speed=4;
this.isActive=false;
Main.setParam(this);
if(this.team.equals("Криси"))
{this.homeX=500;this.homeY=4100;}
else {this.homeX=4100;this.homeY=270;}
this.nAme=new Text(name);
this.nAme.setFont(new Font("Muna", 20));
this.nAme.setFill(Color.WHITE);
this.microGroup=new
Group(microImage,this.nAme,rectActive,lineHealth,lineDamage);
}
// if(event.getButton() == MouseButton.SECONDARY){
// System.out.println("Ім'я: " + this.getnAme().getText());
// System.out.println("Рівень" + this.getLevel());
// System.out.println("Сторона: " + this.getTeam());
// System.out.println("Активований: " + this.getIsActive());
// System.out.println("Рівень життя: " + this.getHp());
// System.out.println("Рівень сили: " + this.getDamage());
// System.out.println("Поточна швидкість: " + this.getSpeed());
// System.out.println("Координати по Х" + this.getChordX());
// System.out.println("Координати по Y" + this.getChordY());
// }
} );
}
//constructor
public Spusonosech(String nm, String team, int fd, boolean isActive)
{
numberOfmicro_obj++;
this.name=nm;
this.team=team;
this.alive=true;
this.food=fd;
salary=new double[0];
this.isActive=isActive;
Main.setParam(this);
if(this.getTeam().equals("Криси"))
{this.homeX=500;this.homeY=4100;}
else {this.homeX=4100;this.homeY=270;}
try{this.microImage=new ImageView("image/spus.png");}catch (Exception e){
System.out.println("Eror with load spus_img");}
this.microImage.setFitHeight(100);
this.microImage.setPreserveRatio(true);
this.nAme=new Text(name);
this.nAme.setFont(new Font("Muna", 20));
this.nAme.setFill(Color.WHITE);
this.microGroup=new
Group(microImage,this.nAme,rectActive,lineHealth,lineDamage);
}
if(event.getButton() == MouseButton.SECONDARY){
System.out.println("Ім'я: " + this.getnAme().getText());
System.out.println("Рівень" + this.getLevel());
System.out.println("Сторона: " + this.getTeam());
System.out.println("Активований: " + this.getIsActive());
System.out.println("Рівень життя: " + this.getHp());
System.out.println("Рівень сили: " + this.getDamage());
System.out.println("Поточна швидкість: " + this.getSpeed());
System.out.println("Координати по Х" + this.getChordX());
System.out.println("Координати по Y" + this.getChordY());
}
} );
}
//делегування конструкторів
public Spusonosech(String nm, String team, int fd, boolean isActive, double
chordX, double chordY)
{
this(nm, team, fd, isActive);
this.chordY=chordY;
this.chordX=chordX;
Main.setParam(this);
}
if(this.getTeam().equals("Криси")){this.setHomeX(500);this.setHomeY(3100);}
else{this.setHomeX(4100);this.setHomeY(270);}
if (homeX + 40 < this.chordX){
this.chordX -= this.speed + Main.getMoveSpeed();
}
if (homeX + 40 > this.chordX){
this.chordX += this.speed + Main.getMoveSpeed();
}
if (homeX + 40 > this.chordY){
this.chordY += this.speed + Main.getMoveSpeed();
}
if (homeX + 40 < this.chordY){
this.chordY -= this.speed + Main.getMoveSpeed();
}
}
}
public void healthUpLord(){
if (this.team.equals("Лорда")){
this.microGroup.setOpacity(0);
if (this.hp < 10){
this.hp+=4;
}
}
}
public void healthUpKrusa(){
if (this.team.equals("Криси")){
this.microGroup.setOpacity(0);
if (this.hp <10){
this.hp+=4;
}
}
}
public void auto_move(){
this.microGroup.setOpacity(1);
if (!this.isActive){
switch (this.auto_move){
case 0:
this.chordY -= this.speed + Main.getMoveSpeed();
break;
case 1:
this.chordY -= this.speed + Main.getMoveSpeed();
63
if (!s1.getTeam().equals(s2.getTeam())){
if (s1.getHp() >= 0 && s2.getHp() >= 0){
s1.setHp(s1.getHp() - s2.getDamage());
}
if (s2.getHp() >= 0 && s1.getHp() >= 0){
64
s2.setHp(s2.getHp() - s1.getDamage());
}
}
if(s1.getHp()<=0){s1.setHp(0);return;}
if(s2.getHp()<=0){s2.setHp(0);return;}
}
ник";this.setSalaryhistory(100);this.strong=60;}
public void
setParametersforLuchar(){this.armor=8;this.damage=30.0;this.hp=100;this.level="Лиц
ар";this.setSalaryhistory(150);this.strong=90;}
}
//Lychnik
package sample.micro;
import javafx.scene.Group;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import sample.Main;
this.nAme=new Text(this.getName());
this.nAme.setFont(new Font("Muna", 20));
this.nAme.setFill(Color.WHITE);
this.microGroup=new
Group(microImage,this.nAme,rectActive,lineHealth,lineDamage);
}
if(event.getButton() == MouseButton.SECONDARY){
System.out.println("Ім'я: " + this.getnAme().getText());
System.out.println("Рівень" + this.getLevel());
System.out.println("Сторона: " + this.getTeam());
System.out.println("Активований: " + this.getIsActive());
System.out.println("Рівень життя: " + this.getHp());
System.out.println("Рівень сили: " + this.getDamage());
System.out.println("Поточна швидкість: " + this.getSpeed());
System.out.println("Координати по Х" + this.getChordX());
System.out.println("Координати по Y" + this.getChordY());
}
} );
}
{
this.setSpeed(5);
}
public Lychnik()
{
numberOfmicro_obj++;
this.setName(Main.getNamesArray()[Main.random.nextInt(Main.getNamesArray().length)
]);
this.setTeam(setRandteam());
this.setAlive(true);
this.setFood(67);
this.isActive=false;
Main.setParam(this);
if (this.getTeam().equals("Криси")){
this.homeX = 500;
this.homeY = 4100;
}else{
this.homeX = 270;
this.homeY = 4100;
}
try{this.microImage=new ImageView("image/lych.png");}catch (Exception e){
System.out.println("Eror with load lych_img");}
this.microImage.setFitHeight(100);
this.microImage.setPreserveRatio(true);
this.nAme=new Text(this.getName());
this.nAme.setFont(new Font("Muna", 20));
this.nAme.setFill(Color.WHITE);
this.microGroup=new
Group(microImage,this.nAme,rectActive,lineHealth,lineDamage);
68
}
// if(event.getButton() == MouseButton.SECONDARY){
// System.out.println("Ім'я: " + this.getnAme().getText());
// System.out.println("Рівень" + this.getLevel());
// System.out.println("Сторона: " + this.getTeam());
// System.out.println("Активований: " + this.getIsActive());
// System.out.println("Рівень життя: " + this.getHp());
// System.out.println("Рівень сили: " + this.getDamage());
// System.out.println("Поточна швидкість: " + this.getSpeed());
// System.out.println("Координати по Х" + this.getChordX());
// System.out.println("Координати по Y" + this.getChordY());
// }
} );
}
public Lychnik(String nm, String team, int fd, boolean isActive, double
chordX, double chordY)
{
this(nm, team, fd, isActive);
this.chordY=chordY;
this.chordX=chordX;
}
//динамічний поліморфізм
//клас Лучник
public static void say_to_child()
{
System.out.println("Лучник може говорити");
}
}
//Luchar
package sample.micro;
import javafx.scene.Group;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import sample.Main;
numberOfmicro_obj++;
Main.setParam(this);
if(this.getTeam().equals("Криси"))
{this.homeX=500;this.homeY=4100;}
else {this.homeX=4100;this.homeY=270;}
try{this.microImage=new ImageView("image/luch.png");}catch (Exception e){
System.out.println("Eror with load spus_img");}
this.microImage.setFitHeight(100);
this.microImage.setPreserveRatio(true);
this.nAme=new Text(this.getName());
this.nAme.setFont(new Font("Muna", 20));
this.nAme.setFill(Color.WHITE);
this.microGroup=new
Group(microImage,this.nAme,rectActive,lineHealth,lineDamage);
}
if(event.getButton() == MouseButton.SECONDARY){
System.out.println("Ім'я: " + this.getnAme().getText());
System.out.println("Рівень" + this.getLevel());
System.out.println("Сторона: " + this.getTeam());
System.out.println("Активований: " + this.getIsActive());
System.out.println("Рівень життя: " + this.getHp());
System.out.println("Рівень сили: " + this.getDamage());
System.out.println("Поточна швидкість: " + this.getSpeed());
System.out.println("Координати по Х" + this.getChordX());
System.out.println("Координати по Y" + this.getChordY());
}
} );}
{
this.setSpeed(6);
}
public Luchar()
{
numberOfmicro_obj++;
this.setName(Main.getNamesArray()[Main.random.nextInt(Main.getNamesArray().length)
]);
this.setTeam(setRandteam());
this.setAlive(true);
this.setFood(67);
this.isActive=false;
70
Main.setParam(this);
if (this.getTeam().equals("Криси")){
this.setHomeX(500);
this.setHomeY(4100);
}else{
this.setHomeX(270);
this.setHomeY(4100);
}
try{this.microImage=new ImageView("image/luch.png");}catch (Exception e){
System.out.println("Eror with load luch_img");}
this.microImage.setFitHeight(100);
this.microImage.setPreserveRatio(true);
this.nAme=new Text(this.getName());
this.nAme.setFont(new Font("Muna", 20));
this.nAme.setFill(Color.WHITE);
this.microGroup=new
Group(microImage,this.nAme,rectActive,lineHealth,lineDamage);
}
// if(event.getButton() == MouseButton.SECONDARY){
// System.out.println("Ім'я: " + this.getnAme().getText());
// System.out.println("Рівень" + this.getLevel());
// System.out.println("Сторона: " + this.getTeam());
// System.out.println("Активований: " + this.getIsActive());
// System.out.println("Рівень життя: " + this.getHp());
// System.out.println("Рівень сили: " + this.getDamage());
// System.out.println("Поточна швидкість: " + this.getSpeed());
// System.out.println("Координати по Х" + this.getChordX());
// System.out.println("Координати по Y" + this.getChordY());
// }
} );
}
public Luchar(String nm, String team, int fd, boolean isActive, double chordX,
double chordY)
{
this(nm, team, fd, isActive);
this.chordY=chordY;
this.chordX=chordX;
try{this.microImage=new ImageView("image/luch.png");}catch (Exception e){
System.out.println("Eror with load luch_img");}
this.microImage.setFitHeight(100);
71
this.microImage.setPreserveRatio(true);
}
public void print()
{ System.out.println(this); }
@Override
public double equalSalary()
{
return super.equalSalary()*3;
}
//динамічний поліморфізм
//клас Лицар
public static void say_to_child()
{
System.out.println("Лицар може говорити");
}
}
//Fortness
package sample.macro;
import javafx.scene.Group;
import javafx.scene.image.ImageView;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.scene.Group;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import sample.micro.Spusonosech;
import java.util.LinkedList;
this.lineHealth=new Line();
this.lineHealth.setStroke(Color.GREEN);
this.lineHealth.setStrokeWidth(20);
this.lineDamage.setStrokeWidth(20);
this.group=new
Group(activeZone,Fort_Image,this.FortName,lineHealth,lineDamage,counterText);
}
@Override
public void set_FortChord()
{
this.Fort_Image.setX(this.chordX);
this.Fort_Image.setY(this.chordY);
this.FortName.setX(this.chordX-20);
this.FortName.setY(this.chordY-80);
this.activeZone.setLayoutX(this.chordX-20);
this.activeZone.setLayoutY(this.chordY-120) ;
this.lineHealth.setStartX(this.chordX);
this.lineHealth.setStartY(this.chordY-50);
this.lineHealth.setEndX(this.chordX+this.getHp()/2);
this.lineHealth.setEndY(this.chordY-50);
this.lineDamage.setStartX(this.chordX-10);
this.lineDamage.setStartY(this.chordY-20);
this.lineDamage.setEndX(this.chordX + this.getDamage()*10);
this.lineDamage.setEndY(this.chordY-20);
counterText.setX(this.chordX-20);
counterText.setY(this.chordY + 40);
}
}
//LordFortness
package sample.macro;
import javafx.scene.Group;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import sample.micro.Spusonosech;
import java.util.LinkedList;
public LordFortress()
{
this.setNameLOrd("Фортеця Лорда Христоносця");
lord=new LinkedList<>();
this.setHp(1000);
this.setDamage(40);
74
this.chordX=4000;
this.chordY=4000;
this.activeZone=new Rectangle(550,650);
this.activeZone.setFill(Color.GREY);
this.activeZone.setOpacity(0.3);
Fort_Image=new ImageView(new Image("image/castle.png"));
Fort_Image.setPreserveRatio(true);
Fort_Image.setFitHeight(450);
this.FortName1=new Text("Фортеця Лорда Христоносця");
this.FortName=new Text("Фортеця Лорда Христоносця");
this.FortName.setFont(new Font("Monaco", 30));
this.FortName.setFill(Color.WHITE);
this.lineHealth=new Line();
this.lineHealth.setStroke(Color.GREEN);
this.lineHealth.setStrokeWidth(20);
this.group=new
Group(activeZone,Fort_Image,this.FortName,lineHealth,lineDamage,counterText);
}
@Override
public void set_FortChord()
{
this.Fort_Image.setX(this.chordX);
this.Fort_Image.setY(this.chordY);
this.FortName.setX(this.chordX-20);
this.FortName.setY(this.chordY-80);
this.activeZone.setLayoutX(this.chordX-20);
this.activeZone.setLayoutY(this.chordY-120) ;
this.lineHealth.setStartX(this.chordX);
this.lineHealth.setStartY(this.chordY-50);
this.lineHealth.setEndX(this.chordX+this.getHp()/2);
this.lineHealth.setEndY(this.chordY-50);
this.lineDamage.setStartX(this.chordX-10);
this.lineDamage.setStartY(this.chordY-20);
this.lineDamage.setEndX(this.chordX + this.getDamage()*10);
this.lineDamage.setEndY(this.chordY-20);
counterText.setX(this.chordX-20);
counterText.setY(this.chordY + 40);
}
}