Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
8b9754e0a4 | ||
|
f3180c1e37 |
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
|
@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_19">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:19-ea+7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:linux:19-ea+7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:19-ea+7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:linux:19-ea+7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.openjfx:javafx-base:19-ea+7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.openjfx:javafx-base:linux:19-ea+7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:19-ea+7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:linux:19-ea+7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.controlsfx:controlsfx:11.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.dlsc.formsfx:formsfx-core:11.5.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.8.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.8.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.8.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.8.2" level="project" />
|
||||
</component>
|
||||
</module>
|
@ -4,49 +4,27 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="3d7ff202-9cad-4078-bd8f-498ca8bb863e" name="Changes" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/../.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/../.gitignore" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../PIbd-22_Kalyshev_Y_V_MotorBoat_Hard.iml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../pom.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/Direction.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningBoat.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningOars.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/EntityBoat.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/FormBoat.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/HelloController.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/NumberOars.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../src/main/java/module-info.java" beforeDir="false" afterPath="$PROJECT_DIR$/../src/main/java/module-info.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../src/main/resources/arrowDown.png" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../src/main/resources/arrowLeft.png" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../src/main/resources/arrowRight.png" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../src/main/resources/arrowUp.png" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../src/main/resources/com/example/pibd22_kalyshev_y_v_motorboat_hard/hello-view.fxml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../target/classes/arrowDown.png" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../target/classes/arrowLeft.png" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../target/classes/arrowRight.png" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../target/classes/arrowUp.png" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../target/classes/com/example/pibd22_kalyshev_y_v_motorboat_hard/Direction.class" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../target/classes/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningBoat$1.class" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../target/classes/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningBoat.class" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../target/classes/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningOars$1.class" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../target/classes/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningOars.class" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../target/classes/com/example/pibd22_kalyshev_y_v_motorboat_hard/EntityBoat.class" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../target/classes/com/example/pibd22_kalyshev_y_v_motorboat_hard/FormBoat.class" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../target/classes/com/example/pibd22_kalyshev_y_v_motorboat_hard/HelloController.class" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../target/classes/com/example/pibd22_kalyshev_y_v_motorboat_hard/NumberOars.class" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../target/classes/com/example/pibd22_kalyshev_y_v_motorboat_hard/hello-view.fxml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../target/classes/module-info.class" beforeDir="false" />
|
||||
</list>
|
||||
<list default="true" id="2d1216e0-b7d3-4ac2-84ce-a7bb2dc057ec" name="Changes" comment="" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Enum" />
|
||||
<option value="Class" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
|
||||
</component>
|
||||
<component name="ProjectId" id="2GajoRqizwxNpAzsDBkYvL8dopf" />
|
||||
<component name="MarkdownSettingsMigration">
|
||||
<option name="stateVersion" value="1" />
|
||||
</component>
|
||||
<component name="ProjectId" id="2GZGMEhxNuxaGk45kFR2jtFs8iE" />
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
@ -56,17 +34,18 @@
|
||||
"keyToString": {
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true"
|
||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
"UI_DESIGNER_EDITOR_MODE.UIDesignerToolWindowManager.WIDTH": "590"
|
||||
}
|
||||
}]]></component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="3d7ff202-9cad-4078-bd8f-498ca8bb863e" name="Changes" comment="" />
|
||||
<created>1666633764627</created>
|
||||
<changelist id="2d1216e0-b7d3-4ac2-84ce-a7bb2dc057ec" name="Changes" comment="" />
|
||||
<created>1666588645694</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1666633764627</updated>
|
||||
<updated>1666588645694</updated>
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
|
4
pom.xml
4
pom.xml
@ -4,7 +4,7 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.zyzf</groupId>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>PIbd-22_Kalyshev_Y_V_MotorBoat_Hard</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>PIbd-22_Kalyshev_Y_V_MotorBoat_Hard</name>
|
||||
@ -76,7 +76,7 @@
|
||||
<id>default-cli</id>
|
||||
<configuration>
|
||||
<mainClass>
|
||||
com.zyzf.pibd22_kalyshev_y_v_motorboat_hard/com.zyzf.pibd22_kalyshev_y_v_motorboat_hard.HelloApplication
|
||||
com.example.pibd22_kalyshev_y_v_motorboat_hard/com.example.pibd22_kalyshev_y_v_motorboat_hard.HelloApplication
|
||||
</mainClass>
|
||||
<launcher>app</launcher>
|
||||
<jlinkZipName>app</jlinkZipName>
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.example.pibd22_kalyshev_y_v_motorboat_hard;
|
||||
|
||||
public enum Direction {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right;
|
||||
|
||||
public static Direction FromInteger(int intValue)
|
||||
{
|
||||
switch(intValue)
|
||||
{
|
||||
case 1:
|
||||
return Up;
|
||||
case 2:
|
||||
return Down;
|
||||
case 3:
|
||||
return Left;
|
||||
case 4:
|
||||
return Right;
|
||||
default:
|
||||
System.out.println("Error: incorrect value for enum");
|
||||
return Up;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
package com.example.pibd22_kalyshev_y_v_motorboat_hard;
|
||||
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
public class DrawningBoat
|
||||
{
|
||||
private EntityBoat _boat;
|
||||
private DrawningOars _drawningOars;
|
||||
private float _startPosX;
|
||||
private float _startPosY;
|
||||
private Integer _pictureWidth;
|
||||
private Integer _pictureHeight;
|
||||
private int _boatWidth = 170;
|
||||
private int _boatHeight = 60;
|
||||
|
||||
public EntityBoat GetBoat()
|
||||
{
|
||||
return _boat;
|
||||
}
|
||||
public DrawningOars GetDrawningOars()
|
||||
{
|
||||
return _drawningOars;
|
||||
}
|
||||
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
_boat = new EntityBoat();
|
||||
_boat.Init(speed, weight, bodyColor);
|
||||
|
||||
_drawningOars = new DrawningOars();
|
||||
_drawningOars.Init(bodyColor);
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (x < 0 || y < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (x + _boatWidth > width || y + _boatHeight > height) {
|
||||
return;
|
||||
}
|
||||
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
}
|
||||
|
||||
public void MoveTransport(Direction direction)
|
||||
{
|
||||
if (_pictureWidth == null || _pictureHeight == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (direction) {
|
||||
case Up:
|
||||
if (_startPosY - _boat.GetStep() > 0) {
|
||||
_startPosY -= _boat.GetStep();
|
||||
}
|
||||
break;
|
||||
|
||||
case Down:
|
||||
if (_startPosY + _boatHeight + _boat.GetStep() + _drawningOars.deltaYdown < _pictureHeight) {
|
||||
_startPosY += _boat.GetStep();
|
||||
}
|
||||
break;
|
||||
|
||||
case Left:
|
||||
if (_startPosX - _boat.GetStep() > 0) {
|
||||
_startPosX -= _boat.GetStep();
|
||||
}
|
||||
break;
|
||||
|
||||
case Right:
|
||||
if (_startPosX + _boatWidth + _boat.GetStep() < _pictureWidth) {
|
||||
_startPosX += _boat.GetStep();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(GraphicsContext gc)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0 || _pictureWidth == null || _pictureHeight == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
_startPosY += 40;
|
||||
// Корпус
|
||||
gc.setStroke(Color.BLACK);
|
||||
gc.setLineWidth(2);
|
||||
gc.setFill(_boat.GetBodyColor());
|
||||
gc.fillPolygon(new double[] {_startPosX, _startPosX+120, _startPosX+170, _startPosX+120, _startPosX, _startPosX},
|
||||
new double[] {_startPosY, _startPosY, _startPosY+30, _startPosY+60, _startPosY+60, _startPosY}, 6);
|
||||
gc.strokePolyline(new double[] {_startPosX, _startPosX+120, _startPosX+170, _startPosX+120, _startPosX, _startPosX},
|
||||
new double[] {_startPosY, _startPosY, _startPosY+30, _startPosY+60, _startPosY+60, _startPosY}, 6);
|
||||
|
||||
// Седло
|
||||
gc.setFill(Color.BROWN);
|
||||
gc.fillOval(_startPosX+10, _startPosY+10, 110, 40);
|
||||
_startPosY -= 40;
|
||||
_drawningOars.DrawOars(gc, _startPosX, _startPosY);
|
||||
|
||||
}
|
||||
|
||||
public void ChangeBorders(int width, int height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
|
||||
if (_pictureWidth <= _boatWidth || _pictureHeight <= _boatHeight) {
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_startPosX + _boatWidth > _pictureWidth) {
|
||||
_startPosX = _pictureWidth - _boatWidth;
|
||||
}
|
||||
|
||||
if (_startPosY + _boatHeight > _pictureHeight) {
|
||||
_startPosY = _pictureHeight - _boatHeight;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package com.example.pibd22_kalyshev_y_v_motorboat_hard;
|
||||
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
public class DrawningOars {
|
||||
private Color _OarsColor;
|
||||
private NumberOars _numOars;
|
||||
public void SetNumberOars(int numberOars)
|
||||
{
|
||||
_numOars = NumberOars.FromInteger(numberOars);
|
||||
}
|
||||
public int deltaYdown = 0;
|
||||
public void Init(Color oarsColor)
|
||||
{
|
||||
_OarsColor = oarsColor;
|
||||
}
|
||||
|
||||
public void DrawOars(GraphicsContext gc, float startPosX, float startPosY) {
|
||||
if (_OarsColor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
gc.setFill(_OarsColor);
|
||||
|
||||
switch (_numOars) {
|
||||
case One:
|
||||
DrawOar1(gc, startPosX, startPosY);
|
||||
deltaYdown = 40;
|
||||
break;
|
||||
|
||||
case Two:
|
||||
DrawOar1(gc, startPosX, startPosY);
|
||||
DrawOar2(gc, startPosX, startPosY);
|
||||
deltaYdown = 80;
|
||||
break;
|
||||
|
||||
case Three:
|
||||
DrawOar1(gc, startPosX, startPosY);
|
||||
DrawOar2(gc, startPosX, startPosY);
|
||||
DrawOar3(gc, startPosX, startPosY);
|
||||
deltaYdown = 80;
|
||||
break;
|
||||
}
|
||||
}
|
||||
void DrawOar1(GraphicsContext gc, float startPosX, float startPosY) {
|
||||
gc.setFill(_OarsColor);
|
||||
gc.setStroke(Color.BLACK);
|
||||
gc.setLineWidth(2);
|
||||
gc.strokePolyline(new double[]{startPosX + 60, startPosX + 80, startPosX + 80, startPosX + 90, startPosX + 100, startPosX + 90, startPosX + 70, startPosX + 60},
|
||||
new double[]{startPosY + 60, startPosY + 20, startPosY + 10, startPosY, startPosY + 10, startPosY + 20, startPosY + 60, startPosY + 60}, 8);
|
||||
gc.fillPolygon(new double[]{startPosX + 60, startPosX + 80, startPosX + 80, startPosX + 90, startPosX + 100, startPosX + 90, startPosX + 70, startPosX + 60},
|
||||
new double[]{startPosY + 60, startPosY + 20, startPosY + 10, startPosY, startPosY + 10, startPosY + 20, startPosY + 60, startPosY + 60}, 8);
|
||||
}
|
||||
void DrawOar2(GraphicsContext gc, float startPosX, float startPosY) {
|
||||
gc.setFill(_OarsColor);
|
||||
gc.setStroke(Color.BLACK);
|
||||
gc.setLineWidth(2);
|
||||
gc.strokePolyline(new double[]{startPosX+50, startPosX+30, startPosX+20, startPosX+30, startPosX+40, startPosX+40, startPosX+60, startPosX+50},
|
||||
new double[]{startPosY+80, startPosY+120, startPosY+130, startPosY+140, startPosY+130, startPosY+120, startPosY+80, startPosY+80}, 8);
|
||||
gc.fillPolygon(new double[]{startPosX+50, startPosX+30, startPosX+20, startPosX+30, startPosX+40, startPosX+40, startPosX+60, startPosX+50},
|
||||
new double[]{startPosY+80, startPosY+120, startPosY+130, startPosY+140, startPosY+130, startPosY+120, startPosY+80, startPosY+80}, 8);
|
||||
}
|
||||
void DrawOar3(GraphicsContext gc, float startPosX, float startPosY) {
|
||||
gc.setFill(_OarsColor);
|
||||
gc.setStroke(Color.BLACK);
|
||||
gc.setLineWidth(2);
|
||||
gc.strokePolyline(new double[]{startPosX+90, startPosX+100, startPosX+100, startPosX+100, startPosX+110, startPosX+100, startPosX+90, startPosX+90},
|
||||
new double[]{startPosY+90, startPosY+90, startPosY+30, startPosY+40, startPosY+30, startPosY+20, startPosY+30, startPosY+90}, 8);
|
||||
gc.fillPolygon(new double[]{startPosX+90, startPosX+100, startPosX+100, startPosX+100, startPosX+110, startPosX+100, startPosX+90, startPosX+90},
|
||||
new double[]{startPosY+90, startPosY+90, startPosY+30, startPosY+40, startPosY+30, startPosY+20, startPosY+30, startPosY+90}, 8);
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.example.pibd22_kalyshev_y_v_motorboat_hard;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
import java.util.Random;
|
||||
|
||||
public class EntityBoat
|
||||
{
|
||||
private int _speed;
|
||||
private float _weight;
|
||||
private Color _bodyColor;
|
||||
public int GetSpeed()
|
||||
{
|
||||
return _speed;
|
||||
}
|
||||
|
||||
public float GetWeight()
|
||||
{
|
||||
return _weight;
|
||||
}
|
||||
|
||||
public Color GetBodyColor()
|
||||
{
|
||||
return _bodyColor;
|
||||
}
|
||||
|
||||
public float GetStep()
|
||||
{
|
||||
return _speed * 100 / _weight;
|
||||
}
|
||||
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random random = new Random();
|
||||
_speed = speed <= 0 ? random.nextInt(5) + 25 : speed;
|
||||
_weight = weight <= 0 ? random.nextInt(30) + 70 : weight;
|
||||
_bodyColor = bodyColor;
|
||||
}
|
||||
}
|
@ -0,0 +1,305 @@
|
||||
package com.example.pibd22_kalyshev_y_v_motorboat_hard;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormBoat extends Application
|
||||
{
|
||||
private Pane _root;
|
||||
private Scene _scene;
|
||||
private Canvas _canvas;
|
||||
private HBox _hBox;
|
||||
private Button _buttonCreate;
|
||||
private Button _buttonUp;
|
||||
private Button _buttonDown;
|
||||
private Button _buttonLeft;
|
||||
private Button _buttonRight;
|
||||
private Label _labelSpeedValue;
|
||||
private Label _labelWeightValue;
|
||||
private Label _labelBodyColorValue;
|
||||
private ComboBox<String> _comboBoxNumOars;
|
||||
private double _hBoxHeight;
|
||||
private double _buttonCreateHeight;
|
||||
private final int _buttonMoveWidth = 30;
|
||||
private final int _buttonMoveHeight = 30;
|
||||
private final int _distanceBetweenMoveButtons = 5;
|
||||
private final double _buttonMargin = 10.0;
|
||||
private DrawningBoat _boat;
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException
|
||||
{
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(FormBoat.class.getResource("hello-view.fxml"));
|
||||
_scene = new Scene(fxmlLoader.load(), 600, 400);
|
||||
|
||||
_root = (Pane) _scene.lookup("#root");
|
||||
_root.setStyle("-fx-background-color: #31374c;");
|
||||
|
||||
_canvas = new Canvas();
|
||||
_root.getChildren().add(_canvas);
|
||||
|
||||
InitHBox();
|
||||
InitButtonCreate();
|
||||
InitMoveButtons();
|
||||
|
||||
stage.setTitle("Boat");
|
||||
stage.setScene(_scene);
|
||||
|
||||
_scene.widthProperty().addListener((obs, oldVal, newVal) -> {
|
||||
UpdateGUI();
|
||||
if (_boat != null)
|
||||
{
|
||||
_boat.ChangeBorders((int) _canvas.getWidth(), (int) _canvas.getHeight());
|
||||
}
|
||||
Draw();
|
||||
});
|
||||
|
||||
_scene.heightProperty().addListener((obs, oldVal, newVal) -> {
|
||||
UpdateGUI();
|
||||
if (_boat != null)
|
||||
{
|
||||
_boat.ChangeBorders((int) _canvas.getWidth(), (int) _canvas.getHeight());
|
||||
}
|
||||
Draw();
|
||||
});
|
||||
|
||||
_root.applyCss();
|
||||
_root.layout();
|
||||
|
||||
stage.setOnShowing(event -> {
|
||||
_hBoxHeight = _hBox.getHeight();
|
||||
_buttonCreateHeight = _buttonCreate.getHeight();
|
||||
UpdateGUI();
|
||||
Draw();
|
||||
});
|
||||
|
||||
stage.show();
|
||||
}
|
||||
|
||||
private void InitHBox()
|
||||
{
|
||||
_hBox = new HBox();
|
||||
_hBox.setStyle("-fx-background-color: #31374c;");
|
||||
_root.getChildren().add(_hBox);
|
||||
|
||||
Label labelSpeed = new Label("Speed:");
|
||||
labelSpeed.setStyle("-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;");
|
||||
_hBox.getChildren().add(labelSpeed);
|
||||
|
||||
_labelSpeedValue = new Label("-");
|
||||
_labelSpeedValue.setStyle("-fx-text-fill: #ffffff; -fx-padding: 5 5 5 0; -fx-font-weight: bold;");
|
||||
_hBox.getChildren().add(_labelSpeedValue);
|
||||
|
||||
Label labelWeight = new Label("Weight:");
|
||||
labelWeight.setStyle("-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;");
|
||||
_hBox.getChildren().add(labelWeight);
|
||||
|
||||
_labelWeightValue = new Label("-");
|
||||
_labelWeightValue.setStyle("-fx-text-fill: #ffffff; -fx-padding: 5 5 5 0; -fx-font-weight: bold;");
|
||||
_hBox.getChildren().add(_labelWeightValue);
|
||||
|
||||
Label labelHullColor = new Label("Color:");
|
||||
labelHullColor.setStyle("-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;");
|
||||
_hBox.getChildren().add(labelHullColor);
|
||||
|
||||
_labelBodyColorValue = new Label("-");
|
||||
_labelBodyColorValue.setStyle("-fx-text-fill: #ffffff; -fx-padding: 5 5 5 0; -fx-font-weight: bold;");
|
||||
_hBox.getChildren().add(_labelBodyColorValue);
|
||||
|
||||
Label labelNumOars = new Label("Oars:");
|
||||
labelNumOars.setStyle("-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;");
|
||||
_hBox.getChildren().add(labelNumOars);
|
||||
|
||||
ObservableList<String> optionsForNumOars = FXCollections.observableArrayList("1", "2", "3");
|
||||
_comboBoxNumOars = new ComboBox<>(optionsForNumOars);
|
||||
_comboBoxNumOars.setValue("1");
|
||||
|
||||
_comboBoxNumOars.setOnAction(e -> {
|
||||
if (_boat != null) {
|
||||
_boat.GetDrawningOars().SetNumberOars(Integer.parseInt(_comboBoxNumOars.getValue()));
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
|
||||
_hBox.getChildren().add(_comboBoxNumOars);
|
||||
}
|
||||
private void InitButtonCreate()
|
||||
{
|
||||
_buttonCreate = new Button("Create");
|
||||
_buttonCreate.setTranslateX(_buttonMargin);
|
||||
_root.getChildren().add(_buttonCreate);
|
||||
|
||||
_buttonCreate.setOnAction(e -> {
|
||||
Random rnd = new Random();
|
||||
|
||||
_boat = new DrawningBoat();
|
||||
_boat.Init(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000,
|
||||
Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
||||
_boat.SetPosition(rnd.nextInt(90) + 10, rnd.nextInt(90)+50,
|
||||
(int) _canvas.getWidth(), (int) _canvas.getHeight());
|
||||
|
||||
_boat.GetDrawningOars().SetNumberOars(Integer.parseInt(_comboBoxNumOars.getValue()));
|
||||
|
||||
_labelSpeedValue.setText(Integer.toString(_boat.GetBoat().GetSpeed()));
|
||||
_labelWeightValue.setText(Double.toString(_boat.GetBoat().GetWeight()));
|
||||
_labelBodyColorValue.setText(_boat.GetBoat().GetBodyColor().toString());
|
||||
|
||||
Draw();
|
||||
});
|
||||
}
|
||||
private void InitMoveButtons()
|
||||
{
|
||||
Image img;
|
||||
ImageView view;
|
||||
|
||||
// Button "Up"
|
||||
_buttonUp = new Button();
|
||||
|
||||
img = new Image("arrowUp.png");
|
||||
view = new ImageView(img);
|
||||
view.setFitHeight(14);
|
||||
view.setFitWidth(14);
|
||||
_buttonUp.setGraphic(view);
|
||||
|
||||
_buttonUp.setPrefWidth(_buttonMoveWidth);
|
||||
_buttonUp.setPrefHeight(_buttonMoveHeight);
|
||||
|
||||
_buttonUp.setOnAction(e -> {
|
||||
if (_boat != null) {
|
||||
_boat.MoveTransport(Direction.Up);
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
|
||||
_root.getChildren().add(_buttonUp);
|
||||
|
||||
// Button "Down"
|
||||
_buttonDown = new Button();
|
||||
|
||||
img = new Image("arrowDown.png");
|
||||
view = new ImageView(img);
|
||||
view.setFitHeight(14);
|
||||
view.setFitWidth(14);
|
||||
_buttonDown.setGraphic(view);
|
||||
|
||||
_buttonDown.setPrefWidth(_buttonMoveWidth);
|
||||
_buttonDown.setPrefHeight(_buttonMoveHeight);
|
||||
|
||||
_buttonDown.setOnAction(e -> {
|
||||
if (_boat != null) {
|
||||
_boat.MoveTransport(Direction.Down);
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
|
||||
_root.getChildren().add(_buttonDown);
|
||||
|
||||
// Button "Left"
|
||||
_buttonLeft = new Button();
|
||||
|
||||
img = new Image("arrowLeft.png");
|
||||
view = new ImageView(img);
|
||||
view.setFitHeight(14);
|
||||
view.setFitWidth(14);
|
||||
_buttonLeft.setGraphic(view);
|
||||
|
||||
_buttonLeft.setPrefWidth(_buttonMoveWidth);
|
||||
_buttonLeft.setPrefHeight(_buttonMoveHeight);
|
||||
|
||||
_buttonLeft.setOnAction(e -> {
|
||||
if (_boat != null) {
|
||||
_boat.MoveTransport(Direction.Left);
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
|
||||
_root.getChildren().add(_buttonLeft);
|
||||
|
||||
// Button "Right"
|
||||
_buttonRight = new Button();
|
||||
|
||||
img = new Image("arrowRight.png");
|
||||
view = new ImageView(img);
|
||||
view.setFitHeight(14);
|
||||
view.setFitWidth(14);
|
||||
_buttonRight.setGraphic(view);
|
||||
|
||||
_buttonRight.setPrefWidth(_buttonMoveWidth);
|
||||
_buttonRight.setPrefHeight(_buttonMoveHeight);
|
||||
|
||||
_buttonRight.setOnAction(e -> {
|
||||
if (_boat != null) {
|
||||
_boat.MoveTransport(Direction.Right);
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
|
||||
_root.getChildren().add(_buttonRight);
|
||||
}
|
||||
private void UpdateGUI()
|
||||
{
|
||||
double sceneWidth = _scene.getWidth();
|
||||
double sceneHeight = _scene.getHeight();
|
||||
|
||||
_canvas.setWidth(sceneWidth);
|
||||
_hBox.setPrefWidth(sceneWidth);
|
||||
_canvas.setHeight(sceneHeight - _hBoxHeight);
|
||||
_hBox.setTranslateY(sceneHeight - _hBoxHeight);
|
||||
|
||||
_buttonCreate.setTranslateY(sceneHeight - _hBoxHeight - _buttonCreateHeight - _buttonMargin);
|
||||
|
||||
_buttonUp.setTranslateY(sceneHeight - _hBoxHeight - _buttonMoveHeight * 2.0 - _buttonMargin -
|
||||
_distanceBetweenMoveButtons);
|
||||
_buttonUp.setTranslateX(sceneWidth - _buttonMargin - _buttonMoveWidth * 2.0 - _distanceBetweenMoveButtons);
|
||||
|
||||
_buttonDown.setTranslateY(sceneHeight - _hBoxHeight - _buttonMoveHeight - _buttonMargin);
|
||||
_buttonDown.setTranslateX(sceneWidth- _buttonMargin - _buttonMoveWidth * 2.0 - _distanceBetweenMoveButtons);
|
||||
|
||||
_buttonLeft.setTranslateY(sceneHeight - _hBoxHeight - _buttonMoveHeight - _buttonMargin);
|
||||
_buttonLeft.setTranslateX(sceneWidth - _buttonMargin - _buttonMoveWidth * 3.0 -
|
||||
_distanceBetweenMoveButtons * 2.0);
|
||||
|
||||
_buttonRight.setTranslateY(sceneHeight - _hBoxHeight - _buttonMoveHeight - _buttonMargin);
|
||||
_buttonRight.setTranslateX(sceneWidth - _buttonMargin - _buttonMoveWidth);
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
GraphicsContext gc = _canvas.getGraphicsContext2D();
|
||||
|
||||
gc.clearRect(0.0, 0.0, _canvas.getWidth(), _canvas.getHeight());
|
||||
gc.setFill(Color.WHITE);
|
||||
gc.fillRect(0.0, 0.0, _canvas.getWidth(), _canvas.getHeight());
|
||||
|
||||
gc.setStroke(Color.BLACK);
|
||||
gc.setLineWidth(4);
|
||||
gc.strokeRect(0.0, 0.0, _canvas.getWidth(), _canvas.getHeight());
|
||||
|
||||
if (_boat != null)
|
||||
{
|
||||
_boat.DrawTransport(gc);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
launch();
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.example.pibd22_kalyshev_y_v_motorboat_hard;
|
||||
|
||||
public enum NumberOars
|
||||
{
|
||||
One,
|
||||
Two,
|
||||
Three;
|
||||
|
||||
public static NumberOars FromInteger(int intValue)
|
||||
{
|
||||
switch(intValue)
|
||||
{
|
||||
case 1:
|
||||
return One;
|
||||
|
||||
case 2:
|
||||
return Two;
|
||||
|
||||
case 3:
|
||||
return Three;
|
||||
|
||||
default:
|
||||
System.out.println("Error: incorrect value for enum");
|
||||
return One;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.zyzf.pibd22_kalyshev_y_v_motorboat_hard;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class HelloApplication extends Application {
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load(), 320, 240);
|
||||
stage.setTitle("Hello!");
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch();
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.zyzf.pibd22_kalyshev_y_v_motorboat_hard;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Label;
|
||||
|
||||
public class HelloController {
|
||||
@FXML
|
||||
private Label welcomeText;
|
||||
|
||||
@FXML
|
||||
protected void onHelloButtonClick() {
|
||||
welcomeText.setText("Welcome to JavaFX Application!");
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
module com.zyzf.pibd22_kalyshev_y_v_motorboat_hard {
|
||||
module com.example.pibd22_kalyshev_y_v_motorboat_hard {
|
||||
requires javafx.controls;
|
||||
requires javafx.fxml;
|
||||
|
||||
requires org.controlsfx.controls;
|
||||
requires com.dlsc.formsfx;
|
||||
|
||||
opens com.zyzf.pibd22_kalyshev_y_v_motorboat_hard to javafx.fxml;
|
||||
exports com.zyzf.pibd22_kalyshev_y_v_motorboat_hard;
|
||||
opens com.example.pibd22_kalyshev_y_v_motorboat_hard to javafx.fxml;
|
||||
exports com.example.pibd22_kalyshev_y_v_motorboat_hard;
|
||||
}
|
BIN
src/main/resources/arrowDown.png
Normal file
BIN
src/main/resources/arrowDown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 245 B |
BIN
src/main/resources/arrowLeft.png
Normal file
BIN
src/main/resources/arrowLeft.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 257 B |
BIN
src/main/resources/arrowRight.png
Normal file
BIN
src/main/resources/arrowRight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 254 B |
BIN
src/main/resources/arrowUp.png
Normal file
BIN
src/main/resources/arrowUp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 234 B |
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.layout.Pane?>
|
||||
|
||||
<Pane xmlns:fx="http://javafx.com/fxml" fx:id="root">
|
||||
</Pane>
|
Loading…
Reference in New Issue
Block a user