some added

This commit is contained in:
root 2022-12-03 01:36:48 +04:00
parent bd8607a796
commit ea1dd16b8e
7 changed files with 118 additions and 255 deletions

3
.idea/dictionaries/zyzf.xml generated Normal file
View File

@ -0,0 +1,3 @@
<component name="ProjectDictionaryState">
<dictionary name="zyzf" />
</component>

View File

@ -33,125 +33,23 @@ public abstract class AbstractMap
public void MoveObject(Direction direction)
{
boolean roadIsClear = true;
float[] position = _drawningObject.GetCurrentPosition();
int xNumOfCells;
int yNumOfCells;
int xObjOffset;
int yObjOffset;
boolean enoughPlace = false;
switch (direction)
{
case Up:
xNumOfCells = (int)Math.ceil((position[2] - position[0]) / _size_x);
yNumOfCells = (int)Math.ceil(_drawningObject.GetStep() / _size_y);
xObjOffset = (int)(position[0] / _size_x);
yObjOffset = (int)Math.floor(position[1] / _size_y);
for (int i = 0; i < yNumOfCells; i++)
{
if (!roadIsClear)
{
break;
}
for (int j = 0; j < xNumOfCells; j++)
{
if (yObjOffset - i < 0 || xObjOffset + j >= _map[0].length)
{
break;
}
if (_map[xObjOffset + j][yObjOffset - i] == _barrier)
{
roadIsClear = false;
break;
}
}
}
enoughPlace = CheckEnoughPlace(0, _drawningObject.GetStep() * -1);
break;
case Down:
xNumOfCells = (int)Math.ceil((position[2] - position[0]) / _size_x);
yNumOfCells = (int)Math.ceil(_drawningObject.GetStep() / _size_y);
xObjOffset = (int)(position[0] / _size_x);
yObjOffset = (int)Math.ceil(position[3]/ _size_y);
for (int i = 0; i < yNumOfCells; i++)
{
if (!roadIsClear)
{
break;
}
for (int j = 0; j < xNumOfCells; j++)
{
if (yObjOffset + i >= _map.length || xObjOffset + j >= _map[0].length)
{
break;
}
if (_map[xObjOffset + j][yObjOffset + i] == _barrier)
{
roadIsClear = false;
break;
}
}
}
enoughPlace = CheckEnoughPlace(0, _drawningObject.GetStep());
break;
case Left:
xNumOfCells = (int)Math.ceil(_drawningObject.GetStep() / _size_x);
yNumOfCells = (int)Math.ceil((position[3] - position[1]) / _size_y);
xObjOffset = (int)Math.floor(position[0] / _size_x);
yObjOffset = (int)(position[1] / _size_y);
for (int i = 0; i < yNumOfCells; i++)
{
if (!roadIsClear)
{
break;
}
for (int j = 0; j < xNumOfCells; j++)
{
if (yObjOffset + i >= _map.length || xObjOffset - j < 0)
{
break;
}
if (_map[xObjOffset - j][yObjOffset + i] == _barrier)
{
roadIsClear = false;
break;
}
}
}
enoughPlace = CheckEnoughPlace(_drawningObject.GetStep() * -1, 0);
break;
case Right:
xNumOfCells = (int)Math.ceil(_drawningObject.GetStep() / _size_x);
yNumOfCells = (int)Math.ceil((position[3] - position[1]) / _size_y);
xObjOffset = (int)(position[2] / _size_x);
yObjOffset = (int)Math.ceil(position[1] / _size_y);
for (int i = 0; i < yNumOfCells; i++)
{
if (!roadIsClear)
{
break;
}
for (int j = 0; j < xNumOfCells; j++)
{
if (yObjOffset + i >= _map.length || xObjOffset + j >= _map[0].length)
{
break;
}
if (_map[xObjOffset + j][yObjOffset + i] == _barrier)
{
roadIsClear = false;
break;
}
}
}
enoughPlace = CheckEnoughPlace(_drawningObject.GetStep(), 0);
break;
}
if (roadIsClear)
if (enoughPlace)
{
_drawningObject.MoveObject(direction);
}
@ -164,52 +62,46 @@ public abstract class AbstractMap
{
return false;
}
int x = _random.nextInt(0, 10);
int y = _random.nextInt(0, 10);
int x = _random.nextInt(10);
int y = _random.nextInt(10);
_drawningObject.SetObject(x, y, _width, _height);
float[] position = _drawningObject.GetCurrentPosition();
int xNumOfCells = (int)Math.ceil(position[2] / _size_x) - (int)Math.floor(position[0] / _size_x);
int yNumOfCells = (int)Math.ceil(position[3] / _size_y) - (int)Math.floor(position[1] / _size_y);
int xObjOffset = (int)(x / _size_x);
int yObjOffset = (int)(y / _size_y);
while (y < _height - (position[3] - position[1]))
while (!CheckEnoughPlace(0, 0))
{
while (x < _width - (position[2] - position[0]))
x += 10;
if (x >= _width)
{
if (AreaIsFree(xNumOfCells, yNumOfCells, xObjOffset, yObjOffset))
if (y <= _height)
{
_drawningObject.SetObject(x, y, _width, _height);
return true;
y += 10;
x = 0;
} else
{
return false;
}
x += (int)_size_x;
xObjOffset = (int)(x / _size_x);
}
x = 0;
y += (int)_size_y;
yObjOffset = (int)(y / _size_y);
_drawningObject.SetObject(x, y, _width, _height);
}
return false;
return true;
}
private boolean AreaIsFree(int xNumOfCells, int yNumOfCells, int xObjOffset, int yObjOffset)
private boolean CheckEnoughPlace(float x, float y)
{
for (int i = 0; i <= yNumOfCells; i++)
float[] position = _drawningObject.GetCurrentPosition();
float right = (position[2] + x) / _size_x > 0 ? (position[2] + x) / _size_x : 0;
float left = (position[0] + x) / _size_x > 0 ? (position[0] + x) / _size_x : 0;
float up = (position[1] + y) / _size_y > 0 ? (position[1] + y) / _size_y : 0;
float down = (position[3] + y) / _size_y > 0 ? (position[3] + y) / _size_y : 0;
if (position[3] + y > _height || position[2] + x > _width || position[1] + y < 0 || position[0] + x < 0) return false;
for (float i = left; i <= right; i+=0.5)
{
for (int j = 0; j <= xNumOfCells; j++)
for (float j = up; j <= down; j+=0.5)
{
if (yObjOffset + i >= _map.length || xObjOffset + j >= _map[0].length)
{
return false;
}
if (_map[xObjOffset + j][yObjOffset + i] == _barrier)
if (_map[Math.round(i)][Math.round(j)] == _barrier)
{
return false;
}
}
}
return true;
}
@ -220,9 +112,9 @@ public abstract class AbstractMap
return;
}
for (int i = 0; i < _map.length; ++i)
for (int i = 0; i < _map.length; i++)
{
for (int j = 0; j < _map[0].length; ++j)
for (int j = 0; j < _map[i].length; j++)
{
if (_map[i][j] == _freeRoad)
{

View File

@ -2,11 +2,13 @@ package com.example.pibd22_kalyshev_y_v_motorboat_hard;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
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.layout.Border;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;

View File

@ -18,96 +18,66 @@ public class DrawningSpeedboat extends DrawningBoat
return;
}
_startPosX += 8;
_startPosY += 1;
super.DrawTransport(gc);
_startPosX -= 8;
_startPosY -= 1;
gc.setStroke(Color.BLACK);
gc.setLineWidth(2);
if (speedboat.GetBodyKit())
{
double[] turretX =
{
31.0 + _startPosX,
31.0 + _startPosX,
45.0 + _startPosX,
83.0 + _startPosX,
97.0 + _startPosX,
97.0 + _startPosX,
};
double[] turretY =
{
24.0 + _startPosY,
12.0 + _startPosY,
2.0 + _startPosY,
2.0 + _startPosY,
12.0 + _startPosY,
24.0 + _startPosY,
};
gc.setFill(speedboat.GetDopColor());
gc.fillPolygon(turretX, turretY, 6);
gc.strokePolygon(turretX, turretY, 6);
gc.strokeRect(32 + _startPosX, 22 + _startPosY, 64, 2);
double[] muzzleX =
{
94 + _startPosX,
84 + _startPosX,
120 + _startPosX,
120 + _startPosX,
};
double[] muzzleY =
{
9 + _startPosY,
3 + _startPosY,
3 + _startPosY,
9 + _startPosY,
};
gc.setFill(Color.rgb(109, 137, 165));
gc.fillPolygon(muzzleX, muzzleY, 4);
gc.strokePolygon(muzzleX, muzzleY, 4);
gc.fillRect(120 + _startPosX, 2 + _startPosY, 16, 8);
gc.strokeRect(120 + _startPosX, 2 + _startPosY, 16, 8);
}
_startPosX += 25;
_startPosY -= 30;
super.DrawTransport(gc);
_startPosX -= 25;
_startPosY += 30;
if (speedboat.GetWing())
{
gc.moveTo(60 + _startPosX, 1 + _startPosY);
gc.lineTo(60 + _startPosX, 24 + _startPosY);
gc.closePath();
gc.setFill(speedboat.GetDopColor());
gc.fillRect(_startPosX, 2 + _startPosY, 58, 8);
gc.strokeRect(_startPosX, 2 + _startPosY, 58, 8);
gc.fillRect(_startPosX, 10 + _startPosY, 58, 8);
gc.strokeRect(_startPosX, 10 + _startPosY, 58, 8);
gc.fillRect(_startPosX, _startPosY, 6, 17);
gc.strokeRect(_startPosX, _startPosY, 6, 17);
double[] batteryMoutX =
{
24 + _startPosX,
15 + _startPosX,
58 + _startPosX,
58 + _startPosX
};
double[] batteryMoutY =
{
24 + _startPosY,
18 + _startPosY,
18 + _startPosY,
24 + _startPosY
};
gc.setFill(Color.rgb(21, 39, 71));
gc.fillPolygon(batteryMoutX, batteryMoutY, 4);
gc.strokePolygon(batteryMoutX, batteryMoutY, 4);
gc.fillRect(_startPosX, _startPosY, 20, 80);
gc.strokeRect(_startPosX, _startPosY, 20, 80);
gc.setFill(speedboat.GetBodyColor());
gc.fillRect(_startPosX + 20, _startPosY + 20, 10, 40);
gc.strokeRect(_startPosX + 20, _startPosY + 20, 10, 40);
}
_startPosX += 25;
_startPosY += 10;
if (speedboat.GetBodyKit())
{
double[] bodyKitX = {
_startPosX + 120,
_startPosX + 155,
_startPosX + 120,
_startPosX + 120,
_startPosX + 145,
_startPosX + 120
};
double[] bodyKitY = {
_startPosY + 10,
_startPosY + 30,
_startPosY + 50,
_startPosY + 45,
_startPosY + 30,
_startPosY + 15
};
gc.setFill(speedboat.GetDopColor());
gc.fillPolygon(bodyKitX, bodyKitY, 6);
}
if (speedboat.GetSportLine())
{
double[] sportLineX = {
_startPosX + 70,
_startPosX + 80,
_startPosX + 120,
_startPosX + 110
};
double[] sportLineY = {
_startPosY,
_startPosY,
_startPosY + 60,
_startPosY + 60
};
gc.setFill(speedboat.GetDopColor());
gc.fillPolygon(sportLineX, sportLineY, 4);
gc.setFill(Color.BROWN);
gc.fillOval(_startPosX + 10, _startPosY + 10, 110, 40);
}
_startPosX -= 25;
_startPosY -= 10;
}
}

View File

@ -17,7 +17,7 @@ public class FormMap extends Application
public void start(Stage stage) throws IOException
{
FXMLLoader fxmlLoader = new FXMLLoader(FormMap.class.getResource("form-map-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 320, 240);
Scene scene = new Scene(fxmlLoader.load(), 400, 400);
stage.setTitle("Map");
stage.setScene(scene);

View File

@ -23,7 +23,7 @@ public class SimpleMap extends AbstractMap
int counter = 0;
for (int i = 0; i < _map.length; ++i)
{
for (int j = 0; j < _map[0].length; ++j)
for (int j = 0; j < _map[i].length; ++j)
{
_map[i][j] = _freeRoad;
}

View File

@ -1,18 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.Pane?>
<?import java.lang.*?>
<?import javafx.collections.*?>
<?import javafx.scene.canvas.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.canvas.Canvas?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.collections.FXCollections?>
<?import java.lang.String?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<Pane xmlns:fx="http://javafx.com/fxml" fx:id="root" fx:controller="com.example.pibd22_kalyshev_y_v_motorboat_hard.ControllerMap">
<Canvas fx:id="canvas">
<Pane fx:id="root" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.pibd22_kalyshev_y_v_motorboat_hard.ControllerMap">
<Canvas fx:id="canvas" height="400.0" width="400.0">
</Canvas>
<FlowPane fx:id="flowPane" style="-fx-background-color: #31374c;">
<Label style="-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;">
@ -39,9 +35,9 @@
<ComboBox fx:id="comboBoxNumOars" value="1">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="1"/>
<String fx:value="2"/>
<String fx:value="3"/>
<String fx:value="1" />
<String fx:value="2" />
<String fx:value="3" />
</FXCollections>
</items>
</ComboBox>
@ -51,18 +47,18 @@
<ComboBox fx:id="comboBoxOarsType" value="None">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="None"/>
<String fx:value="Short"/>
<String fx:value="Long"/>
<String fx:value="None" />
<String fx:value="Short" />
<String fx:value="Long" />
</FXCollections>
</items>
</ComboBox>
</FlowPane>
<ComboBox fx:id="comboBoxSelectorMap" value="Simple map" onAction="#ComboBoxSelectorMap_Changed">
<ComboBox fx:id="comboBoxSelectorMap" onAction="#ComboBoxSelectorMap_Changed" value="Simple map">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="Simple map"/>
<String fx:value="My second map"/>
<String fx:value="Simple map" />
<String fx:value="My second map" />
</FXCollections>
</items>
</ComboBox>
@ -72,31 +68,31 @@
<Button fx:id="buttonCreateModif" onAction="#ButtonCreateModif_Click">
Modification
</Button>
<Button fx:id="buttonLeft" minWidth="30" minHeight="30" onAction="#ButtonMove_Click">
<Button fx:id="buttonLeft" minHeight="30" minWidth="30" onAction="#ButtonMove_Click">
<graphic>
<ImageView fitHeight="14.0" fitWidth="14.0" pickOnBounds="true" preserveRatio="true">
<Image url="@/arrowLeft.png"/>
<Image url="@/arrowLeft.png" />
</ImageView>
</graphic>
</Button>
<Button fx:id="buttonRight" minWidth="30" minHeight="30" onAction="#ButtonMove_Click">
<Button fx:id="buttonRight" minHeight="30" minWidth="30" onAction="#ButtonMove_Click">
<graphic>
<ImageView fitHeight="14.0" fitWidth="14.0" pickOnBounds="true" preserveRatio="true">
<Image url="@/arrowRight.png"/>
<Image url="@/arrowRight.png" />
</ImageView>
</graphic>
</Button>
<Button fx:id="buttonUp" minWidth="30" minHeight="30" onAction="#ButtonMove_Click">
<Button fx:id="buttonUp" minHeight="30" minWidth="30" onAction="#ButtonMove_Click">
<graphic>
<ImageView fitHeight="14.0" fitWidth="14.0" pickOnBounds="true" preserveRatio="true">
<Image url="@/arrowUp.png"/>
<Image url="@/arrowUp.png" />
</ImageView>
</graphic>
</Button>
<Button fx:id="buttonDown" minWidth="30" minHeight="30" onAction="#ButtonMove_Click">
<Button fx:id="buttonDown" minHeight="30" minWidth="30" onAction="#ButtonMove_Click">
<graphic>
<ImageView fitHeight="14.0" fitWidth="14.0" pickOnBounds="true" preserveRatio="true">
<Image url="@/arrowDown.png"/>
<Image url="@/arrowDown.png" />
</ImageView>
</graphic>
</Button>