Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
0f25143372 |
@ -2,7 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/ProjectGasolineTankerHard.iml" filepath="$PROJECT_DIR$/.idea/ProjectGasolineTankerHard.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/1 lab hard.iml" filepath="$PROJECT_DIR$/1 lab hard.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
Before Width: | Height: | Size: 808 B |
Binary file not shown.
Before Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.2 KiB |
@ -1,146 +0,0 @@
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class AbstractMap {
|
||||
private IDrawingObject _drawingObject = null;
|
||||
protected int[][] _map = null;
|
||||
protected int _width;
|
||||
protected int _height;
|
||||
protected float _size_x;
|
||||
protected float _size_y;
|
||||
protected final Random _random = new Random();
|
||||
protected final int _freeRoad = 0;
|
||||
protected final int _barrier = 1;
|
||||
|
||||
public BufferedImage CreateMap(int width, int height, IDrawingObject drawingObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawingObject = drawingObject;
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
public BufferedImage MoveObject(Direction direction)
|
||||
{
|
||||
if (true)
|
||||
{
|
||||
_drawingObject.MoveObject(direction);
|
||||
}
|
||||
float[] cortege = _drawingObject.GetCurrentPosition();
|
||||
if (CheckLand(cortege[0],cortege[1],cortege[2],cortege[3])!= 0)
|
||||
{
|
||||
_drawingObject.MoveObject(SetOppositDirection(direction));
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
private boolean SetObjectOnMap()
|
||||
{
|
||||
if (_drawingObject==null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = _random.nextInt(10);
|
||||
int y = _random.nextInt(10);
|
||||
_drawingObject.SetObject(x, y, _width, _height);
|
||||
|
||||
float[] dim = _drawingObject.GetCurrentPosition();
|
||||
|
||||
while (CheckLand(dim[0], dim[1], dim[2], dim[3]) != 2)
|
||||
{
|
||||
int res;
|
||||
do
|
||||
{
|
||||
res = CheckLand(dim[0], dim[1], dim[2], dim[3]);
|
||||
if (res == 0)
|
||||
{
|
||||
_drawingObject.SetObject((int)dim[0], (int)dim[1], _width, _height);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
dim[0] += _size_x;
|
||||
}
|
||||
} while (res != 2);
|
||||
dim[0] = x;
|
||||
dim[1] += _size_y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private BufferedImage DrawMapWithObject()
|
||||
{
|
||||
BufferedImage bmp = new BufferedImage(_width, _height,BufferedImage.TYPE_INT_RGB);
|
||||
if (_drawingObject == null || _map == null)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
Graphics gr = bmp.getGraphics();
|
||||
for (int i = 0; i < _map.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < _map[i].length; ++j)
|
||||
{
|
||||
if (_map[i][j] == _freeRoad)
|
||||
{
|
||||
DrawBarrierPart(gr, i, j);
|
||||
}
|
||||
else if (_map[i][j] == _barrier)
|
||||
{
|
||||
DrawRoadPart(gr, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawingObject.DrawingObject(gr);
|
||||
return bmp;
|
||||
}
|
||||
private int CheckLand(float Left, float Right, float Top, float Bottom)
|
||||
{
|
||||
int RUi = (int)(Left / _size_x);
|
||||
int RUj = (int)(Right / _size_y);
|
||||
int LDi = (int)(Top / _size_x);
|
||||
int LDj = (int)(Bottom / _size_y);
|
||||
|
||||
if (RUi < 0 || RUj < 0 || LDi >= _map[0].length || LDj >= _map.length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for (int x = RUi; x <= LDi; x++)
|
||||
{
|
||||
for (int y = RUj; y <= LDj; y++)
|
||||
{
|
||||
if (_map[x][y] == _barrier)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
private Direction SetOppositDirection(Direction dir)
|
||||
{
|
||||
switch (dir)
|
||||
{
|
||||
case Up:
|
||||
return Direction.Down;
|
||||
case Down:
|
||||
return Direction.Up;
|
||||
case Left:
|
||||
return Direction.Right;
|
||||
case Right:
|
||||
return Direction.Left;
|
||||
case None:
|
||||
return Direction.None;
|
||||
}
|
||||
return Direction.None;
|
||||
}
|
||||
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawBarrierPart(Graphics gr, int i, int j);
|
||||
protected abstract void DrawRoadPart(Graphics gr, int i, int j);
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
public enum Direction {
|
||||
Up(1),
|
||||
Down(2),
|
||||
Left(3),
|
||||
Right(4),
|
||||
None(0);
|
||||
Direction(int value){}
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right;
|
||||
}
|
||||
|
@ -2,13 +2,12 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingField extends JPanel{
|
||||
private final FormGasolineTanker Field;
|
||||
DrawingGasolineTanker _gasolineTanker=null;
|
||||
public class DrawingField extends JPanel {
|
||||
private final FormGasolineTanker field;
|
||||
DrawingGasolineTanker _gasolineTanker;
|
||||
public DrawingField(FormGasolineTanker field) {
|
||||
Field = field;
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
@ -17,47 +16,42 @@ public class DrawingField extends JPanel{
|
||||
_gasolineTanker.DrawTransport(g2);
|
||||
else return;
|
||||
}
|
||||
public void DirectionButtonAction(Direction side){
|
||||
if(_gasolineTanker == null)
|
||||
public void UpButtonAction(){
|
||||
if (_gasolineTanker!=null)
|
||||
_gasolineTanker.MoveTransport(Direction.Up);
|
||||
else
|
||||
return;
|
||||
_gasolineTanker.MoveTransport(side);
|
||||
}
|
||||
private void SetData() {
|
||||
Random rand=new Random();
|
||||
_gasolineTanker.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight());
|
||||
Field.SpeedLabel.setText("Speed: "+_gasolineTanker.getGasolineTanker().getSpeed());
|
||||
Field.WeightLabel.setText("Weight: "+_gasolineTanker.getGasolineTanker().getWeight());
|
||||
Field.BodyColorLabel.setText("Color: "+Integer.toHexString(_gasolineTanker.getGasolineTanker().getBodyColor().getRGB()).substring(2));
|
||||
public void DownButtonAction(){
|
||||
if (_gasolineTanker!=null)
|
||||
_gasolineTanker.MoveTransport(Direction.Down);
|
||||
else
|
||||
return;
|
||||
}
|
||||
public void RightButtonAction(){
|
||||
if (_gasolineTanker!=null)
|
||||
_gasolineTanker.MoveTransport(Direction.Right);
|
||||
else
|
||||
return;
|
||||
}
|
||||
public void LeftButtonAction(){
|
||||
if (_gasolineTanker!=null)
|
||||
_gasolineTanker.MoveTransport(Direction.Left);
|
||||
else
|
||||
return;
|
||||
}
|
||||
public void CreateButtonAction(){
|
||||
Random rand=new Random();
|
||||
Color color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
if(color1==null)
|
||||
color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
_gasolineTanker=new DrawingGasolineTanker(rand.nextInt(50)+10,rand.nextInt(3000)+20000,color1,rand.nextInt(3));
|
||||
SetData();
|
||||
}
|
||||
public void CreateModifButtonAction(){
|
||||
Random rand=new Random();
|
||||
Color color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
Color color2=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
if(color1==null)
|
||||
color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
if (color2==null)
|
||||
color2=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
_gasolineTanker = new DrawingImprovedGasolineTanker(rand.nextInt(50) + 10, rand.nextInt(3000) + 20000, color1,
|
||||
color2, rand.nextBoolean(), rand.nextBoolean(), rand.nextInt(3));
|
||||
SetData();
|
||||
Random rnd=new Random();
|
||||
_gasolineTanker=new DrawingGasolineTanker();
|
||||
_gasolineTanker.Init(rnd.nextInt(50)+10,rnd.nextInt(100)+500,new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256)));
|
||||
_gasolineTanker.SetPosition(rnd.nextInt(100)+10,rnd.nextInt(100)+10,getWidth(),getHeight());
|
||||
field.SpeedLabel.setText("Speed: "+_gasolineTanker.getGasolineTanker().getSpeed());
|
||||
field.WeightLabel.setText("Weight: "+_gasolineTanker.getGasolineTanker().getWeight());
|
||||
field.BodyColorLabel.setText("Color: "+Integer.toHexString(_gasolineTanker.getGasolineTanker().getBodyColor().getRGB()).substring(2));
|
||||
}
|
||||
public void ResizeField(){
|
||||
if (_gasolineTanker!=null)
|
||||
_gasolineTanker.ChangeBorders(getWidth(),getHeight());
|
||||
else return;
|
||||
}
|
||||
|
||||
public void Draw(Graphics2D graphics) {
|
||||
if (_gasolineTanker!=null)
|
||||
_gasolineTanker.DrawTransport(graphics);
|
||||
else return;
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +1,26 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingGasolineTanker {
|
||||
protected EntityGasolineTanker GasolineTanker;
|
||||
public EntityGasolineTanker getGasolineTanker(){
|
||||
public EntityGasolineTanker GasolineTanker;
|
||||
public EntityGasolineTanker getGasolineTanker() {
|
||||
return GasolineTanker;
|
||||
}
|
||||
protected IDrawningObjectWheels Wheels;
|
||||
private CountWheels _wheels;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
public DrawingWheels Wheels;
|
||||
private int _startPosX;
|
||||
private int _startPosY;
|
||||
private Integer _pictureWidth = null;
|
||||
private Integer _pictureHeight = null;
|
||||
private int _gasolineTankerWidth = 160;
|
||||
private int _gasolineTankerHeight = 70;
|
||||
private final int _gasolineTankerWidth = 160;
|
||||
private final int _gasolineTankerHeight = 55;
|
||||
|
||||
public DrawingGasolineTanker(int speed, float weight, Color bodyColor, int wheelsForm)
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
GasolineTanker = new EntityGasolineTanker(speed, weight, bodyColor);
|
||||
Wheels= GetFormOfWheels(wheelsForm);
|
||||
GasolineTanker = new EntityGasolineTanker();
|
||||
GasolineTanker.Init(speed, weight, bodyColor);
|
||||
Wheels = new DrawingWheels();
|
||||
Wheels.SetCountWheels((int)(2 + Math.random() + Math.random()*2));
|
||||
}
|
||||
|
||||
public IDrawningObjectWheels GetFormOfWheels(int FormOfWheel){
|
||||
OrnamentForm temp = null;
|
||||
for (OrnamentForm form:OrnamentForm.values()) {
|
||||
if(form.Value==FormOfWheel){
|
||||
temp = form;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(temp==null)
|
||||
return null;
|
||||
switch (temp){
|
||||
case NoneOrnament:
|
||||
return new DrawingWheels(_wheels);
|
||||
case GrayOrnament:
|
||||
return new DrawingOrnamentWheelsFirst(_wheels);
|
||||
case RedOrnament:
|
||||
return new DrawingOrnamentWheelsSecond(_wheels);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected DrawingGasolineTanker(int speed, float weight, Color bodyColor,int gasolineTankerWidth, int gasolineTankerHeight)
|
||||
{
|
||||
GasolineTanker = new EntityGasolineTanker(speed, weight, bodyColor);
|
||||
Wheels= new DrawingWheels(_wheels);
|
||||
Wheels.SetCountWheels((int)(2 + Math.random() + Math.random()*2));
|
||||
_gasolineTankerWidth=gasolineTankerWidth;
|
||||
_pictureHeight=gasolineTankerHeight;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (x >= 0 && x+_gasolineTankerWidth <= width && y >= 0 && y+_gasolineTankerHeight <= height)
|
||||
@ -100,7 +70,6 @@ public class DrawingGasolineTanker {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0 || _pictureHeight== null || _pictureWidth== null)
|
||||
@ -134,7 +103,6 @@ public class DrawingGasolineTanker {
|
||||
g2.drawRect(_startPosX + 120, _startPosY + 10, 25, 25);
|
||||
g2.fillRect(_startPosX + 120, _startPosY + 10, 25, 25);
|
||||
}
|
||||
|
||||
public void ChangeBorders(int width,int height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
@ -154,12 +122,4 @@ public class DrawingGasolineTanker {
|
||||
_startPosY = _pictureHeight - _gasolineTankerHeight;
|
||||
}
|
||||
}
|
||||
public float[] GetCurrentPosition() {
|
||||
float[] dim = new float[4];
|
||||
dim[0] = _startPosX;
|
||||
dim[1] =_startPosY;
|
||||
dim[2] = _startPosX + _gasolineTankerWidth;
|
||||
dim[3] = _startPosY + _gasolineTankerHeight;
|
||||
return dim;
|
||||
}
|
||||
}
|
||||
|
@ -1,50 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingImprovedGasolineTanker extends DrawingGasolineTanker {
|
||||
|
||||
public DrawingImprovedGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean antena,int wheelForm) {
|
||||
super(speed, weight, bodyColor, 160, 70);
|
||||
GasolineTanker=new EntityImprovedGasolineTanker(speed,weight,bodyColor,dopColor,bodyKit,antena);
|
||||
Wheels= GetFormOfWheels(wheelForm);
|
||||
Wheels.SetCountWheels((int)(2 + Math.random() + Math.random()*2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawTransport(Graphics g) {
|
||||
|
||||
if (! (GasolineTanker instanceof EntityImprovedGasolineTanker))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EntityImprovedGasolineTanker improvedGasolineTanker = (EntityImprovedGasolineTanker)GasolineTanker;
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
|
||||
int [] x1 ={_startPosX+25,_startPosX+65,_startPosX+75,_startPosX+25,_startPosX+25};
|
||||
int [] y1 ={_startPosY,_startPosY,_startPosY+5,_startPosY+5,_startPosY};
|
||||
int [] x2 ={_startPosX+25,_startPosX+75,_startPosX+65,_startPosX+25,_startPosX+25};
|
||||
int [] y2 ={_startPosY+45,_startPosY+45,_startPosY+50,_startPosY+50,_startPosY+45};
|
||||
|
||||
if (improvedGasolineTanker.BodyKit)
|
||||
{
|
||||
g2.setColor(improvedGasolineTanker.GetDopColor());
|
||||
g2.drawRect(_startPosX + 25, _startPosY + 5, 100, 35);
|
||||
g2.fillRect(_startPosX + 25, _startPosY + 5, 100, 35);
|
||||
|
||||
}
|
||||
|
||||
_startPosX += 10;
|
||||
_startPosY += 5;
|
||||
super.DrawTransport(g);
|
||||
_startPosX -= 10;
|
||||
_startPosY -= 5;
|
||||
|
||||
if (improvedGasolineTanker.Antena)
|
||||
{
|
||||
g2.setColor(Color.RED);
|
||||
g2.drawRect(_startPosX + 130, _startPosY + 5, 10, 5);
|
||||
g2.fillRect(_startPosX + 130, _startPosY + 5, 10, 5);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingMap extends JPanel {
|
||||
private final FormMap Map;
|
||||
private AbstractMap _abstractMap;
|
||||
BufferedImage bufferedImage;
|
||||
|
||||
public DrawingMap(FormMap map){
|
||||
Map=map;
|
||||
_abstractMap = new SimpleMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.drawImage(bufferedImage,0,0,null);
|
||||
}
|
||||
|
||||
private void SetData(DrawingGasolineTanker gasolineTanker) {
|
||||
Random rand=new Random();
|
||||
gasolineTanker.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight());
|
||||
Map.SpeedLabel.setText("Speed: "+gasolineTanker.getGasolineTanker().getSpeed());
|
||||
Map.WeightLabel.setText("Weight: "+gasolineTanker.getGasolineTanker().getWeight());
|
||||
Map.BodyColorLabel.setText("Color: "+Integer.toHexString(gasolineTanker.getGasolineTanker().getBodyColor().getRGB()).substring(2));
|
||||
bufferedImage = _abstractMap.CreateMap(700,550,new DrawingObjectGasolineTanker(gasolineTanker));
|
||||
}
|
||||
public void CreateButtonAction(){
|
||||
Random rand=new Random();
|
||||
Color color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
if(color1==null)
|
||||
color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
DrawingGasolineTanker gasolineTanker=new DrawingGasolineTanker(rand.nextInt(50)+10,rand.nextInt(3000)+20000,color1,rand.nextInt(3));
|
||||
SetData(gasolineTanker);
|
||||
}
|
||||
public void CreateModifButtonAction(){
|
||||
Random rand=new Random();
|
||||
Color color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
Color color2=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
if(color1==null)
|
||||
color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
if (color2==null)
|
||||
color2=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
DrawingGasolineTanker gasolineTanker = new DrawingImprovedGasolineTanker(rand.nextInt(50) + 10, rand.nextInt(3000) + 20000, color1,
|
||||
color2, rand.nextBoolean(), rand.nextBoolean(),rand.nextInt(3));
|
||||
SetData(gasolineTanker);
|
||||
}
|
||||
public void DirectionButtonAction(Direction side){
|
||||
if(_abstractMap != null){
|
||||
bufferedImage = _abstractMap.MoveObject(side);
|
||||
}
|
||||
}
|
||||
|
||||
public void ComboBoxSelectorMapAction(String name){
|
||||
switch (name){
|
||||
case "Simple map":
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case "Long map":
|
||||
_abstractMap = new LongMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawMap(Graphics g){
|
||||
g.drawImage(bufferedImage,0,0,null);
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingObjectGasolineTanker implements IDrawingObject {
|
||||
|
||||
private DrawingGasolineTanker _gasolineTanker=null;
|
||||
|
||||
public DrawingObjectGasolineTanker(DrawingGasolineTanker gasolineTanker)
|
||||
{
|
||||
_gasolineTanker= gasolineTanker;
|
||||
}
|
||||
|
||||
public float Step() {
|
||||
if(_gasolineTanker != null && _gasolineTanker.GasolineTanker != null)
|
||||
return _gasolineTanker.GasolineTanker.Step;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetObject(int x, int y, int width, int height) {
|
||||
_gasolineTanker.SetPosition(x,y,width,height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void MoveObject(Direction direction) {
|
||||
_gasolineTanker.MoveTransport(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawingObject(Graphics g) {
|
||||
_gasolineTanker.DrawTransport(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] GetCurrentPosition() {
|
||||
if(_gasolineTanker!=null)
|
||||
return _gasolineTanker.GetCurrentPosition();
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingOrnamentWheelsFirst implements IDrawningObjectWheels{
|
||||
private CountWheels _wheels;
|
||||
|
||||
public DrawingOrnamentWheelsFirst(CountWheels wheels){
|
||||
_wheels=wheels;
|
||||
}
|
||||
@Override
|
||||
public void SetCountWheels(int count) {
|
||||
for (CountWheels temp: CountWheels.values())
|
||||
if (temp.getCountWheels() == count){
|
||||
_wheels=temp;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawWheels(Graphics2D g, int _startPosX, int _startPosY) {
|
||||
if (_wheels.getCountWheels() == 2) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.setColor(Color.GRAY);
|
||||
g.drawOval(_startPosX + 130, _startPosY + 45, 20, 5);
|
||||
g.drawOval(_startPosX + 10, _startPosY + 45, 20, 5);
|
||||
}
|
||||
if (_wheels.getCountWheels() == 3) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||
g.setColor(Color.GRAY);
|
||||
g.drawOval(_startPosX + 130, _startPosY + 45, 20, 5);
|
||||
g.drawOval(_startPosX + 30, _startPosY + 45, 20, 5);
|
||||
g.drawOval(_startPosX + 10, _startPosY + 45, 20, 5);
|
||||
}
|
||||
if (_wheels.getCountWheels() == 4) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||
g.drawOval(_startPosX + 50, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 50, _startPosY + 35, 20, 20);
|
||||
g.setColor(Color.GRAY);
|
||||
g.drawOval(_startPosX + 130, _startPosY + 45, 20, 5);
|
||||
g.drawOval(_startPosX + 50, _startPosY + 45, 20, 5);
|
||||
g.drawOval(_startPosX + 30, _startPosY + 45, 20, 5);
|
||||
g.drawOval(_startPosX + 10, _startPosY + 45, 20, 5);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingOrnamentWheelsSecond implements IDrawningObjectWheels{
|
||||
private CountWheels _wheels;
|
||||
|
||||
public DrawingOrnamentWheelsSecond(CountWheels wheels){
|
||||
_wheels=wheels;
|
||||
}
|
||||
@Override
|
||||
public void SetCountWheels(int count) {
|
||||
for (CountWheels temp: CountWheels.values())
|
||||
if (temp.getCountWheels() == count){
|
||||
_wheels=temp;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawWheels(Graphics2D g, int _startPosX, int _startPosY) {
|
||||
|
||||
if (_wheels.getCountWheels() == 2) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.setColor(Color.GRAY);
|
||||
g.drawRect(_startPosX + 130, _startPosY + 45, 20, 5);
|
||||
g.drawRect(_startPosX + 10, _startPosY + 45, 20, 5);
|
||||
}
|
||||
if (_wheels.getCountWheels() == 3) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||
g.setColor(Color.GRAY);
|
||||
g.drawRect(_startPosX + 130, _startPosY + 45, 20, 5);
|
||||
g.drawRect(_startPosX + 30, _startPosY + 45, 20, 5);
|
||||
g.drawRect(_startPosX + 10, _startPosY + 45, 20, 5);
|
||||
}
|
||||
if (_wheels.getCountWheels() == 4) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||
g.drawOval(_startPosX + 50, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 50, _startPosY + 35, 20, 20);
|
||||
g.setColor(Color.GRAY);
|
||||
g.drawRect(_startPosX + 130, _startPosY + 45, 20, 5);
|
||||
g.drawRect(_startPosX + 50, _startPosY + 45, 20, 5);
|
||||
g.drawRect(_startPosX + 30, _startPosY + 45, 20, 5);
|
||||
g.drawRect(_startPosX + 10, _startPosY + 45, 20, 5);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,8 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingWheels implements IDrawningObjectWheels{
|
||||
public class DrawingWheels {
|
||||
|
||||
private CountWheels _wheels = null;
|
||||
|
||||
public DrawingWheels(CountWheels wheels) {
|
||||
_wheels=wheels;
|
||||
}
|
||||
private CountWheels _wheels;
|
||||
|
||||
public void SetCountWheels(int Count){
|
||||
for (CountWheels temp: CountWheels.values())
|
||||
@ -17,26 +13,29 @@ public class DrawingWheels implements IDrawningObjectWheels{
|
||||
}
|
||||
|
||||
public void DrawWheels(Graphics2D g,int _startPosX, int _startPosY) {
|
||||
if (_wheels.getCountWheels() == 2) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
}
|
||||
if (_wheels.getCountWheels() == 3) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||
}
|
||||
if (_wheels.getCountWheels() == 4){
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||
g.drawOval(_startPosX + 50, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 50, _startPosY + 35, 20, 20);
|
||||
switch (_wheels.getCountWheels())
|
||||
{
|
||||
case 2:
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
break;
|
||||
case 3:
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||
break;
|
||||
case 4:
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||
g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||
g.drawOval(_startPosX + 50, _startPosY + 35, 20, 20);
|
||||
g.fillOval(_startPosX + 50, _startPosY + 35, 20, 20);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,15 +14,15 @@ public class EntityGasolineTanker {
|
||||
public Color getBodyColor() {
|
||||
return BodyColor;
|
||||
}
|
||||
public int Step;
|
||||
public float Step;
|
||||
|
||||
public EntityGasolineTanker(int speed, float weight, Color bodyColor){
|
||||
public void Init(int speed, float weight, Color bodyColor){
|
||||
|
||||
Random rnd = new Random();
|
||||
Speed = speed <= 0 ? rnd.nextInt(50)+10 : speed;
|
||||
Weight = weight <= 0 ? rnd.nextInt(100)+500 : weight;
|
||||
BodyColor = bodyColor;
|
||||
Step = Speed * 5000/ (int)Weight;
|
||||
Step = Speed * 100/ (int)Weight;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,26 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityImprovedGasolineTanker extends EntityGasolineTanker{
|
||||
public Color DopColor;
|
||||
public Color GetDopColor() {
|
||||
return DopColor;
|
||||
}
|
||||
|
||||
public boolean BodyKit ;
|
||||
public boolean GetBodyKit () {
|
||||
return BodyKit ;
|
||||
}
|
||||
|
||||
public boolean Antena ;
|
||||
public boolean GetAntena () {
|
||||
return Antena ;
|
||||
}
|
||||
|
||||
public EntityImprovedGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean antena){
|
||||
super(speed,weight,bodyColor);
|
||||
DopColor = dopColor;
|
||||
BodyKit = bodyKit;
|
||||
Antena = antena;
|
||||
|
||||
}
|
||||
}
|
@ -1,160 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormGasolineTanker">
|
||||
<grid id="27dc6" binding="PictureBox" layout-manager="GridLayoutManager" row-count="3" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="572" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="1123e" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="f81fa" class="javax.swing.JLabel" binding="SpeedLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Speed:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="802bb">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="7d7fb" class="javax.swing.JLabel" binding="WeightLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Weight:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ea175" class="javax.swing.JLabel" binding="BodyColorLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Color:"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="8a6df" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="6c4ce" class="javax.swing.JButton" binding="ButtonCreate">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Create"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="76111" class="javax.swing.JButton" binding="ButtonCreateModif">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Improved create"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="39656" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="e39ac" class="javax.swing.JButton" binding="ButtonLeft">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c212c" class="javax.swing.JButton" binding="ButtonDown">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="1b9e6" class="javax.swing.JButton" binding="ButtonRight">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="39d04" class="javax.swing.JButton" binding="ButtonUp">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<vspacer id="74357">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<hspacer id="94433">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<grid id="d5026" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="bfaf3">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="b1e67" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="1fab3">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
@ -2,90 +2,134 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
||||
public class FormGasolineTanker extends JFrame{
|
||||
private int Width;
|
||||
private int Height;
|
||||
DrawingField field = new DrawingField(this);
|
||||
private JButton ButtonDown;
|
||||
private JButton ButtonRight;
|
||||
private JButton ButtonLeft;
|
||||
private JButton ButtonUp;
|
||||
private JButton ButtonCreate;
|
||||
private JButton ButtonCreateModif;
|
||||
public JLabel SpeedLabel;
|
||||
public JLabel WeightLabel;
|
||||
public JLabel BodyColorLabel;
|
||||
private JPanel PictureBox;
|
||||
|
||||
JPanel BottomPanel = new JPanel();
|
||||
JPanel CreatePanel = new JPanel();
|
||||
JPanel BottomAndCreatePanel = new JPanel();
|
||||
JPanel DimentionPanel = new JPanel();
|
||||
JPanel UPanel = new JPanel();
|
||||
JPanel DPanel = new JPanel();
|
||||
JPanel LRPanel = new JPanel();
|
||||
|
||||
JLabel SpeedLabel = new JLabel("Speed: ");
|
||||
JLabel WeightLabel = new JLabel("Weight: ");
|
||||
JLabel BodyColorLabel = new JLabel("Color: ");
|
||||
|
||||
DrawingField field = new DrawingField(this);
|
||||
|
||||
JButton ButtonCreate=new JButton("Create");
|
||||
|
||||
Icon iconUp = new ImageIcon("C:\\Users\\kashi\\OneDrive\\Материал\\KeyUp.png");
|
||||
JButton ButtonUp=new JButton(iconUp);
|
||||
|
||||
Icon iconDown = new ImageIcon("C:\\Users\\kashi\\OneDrive\\Материал\\KeyDown.png");
|
||||
JButton ButtonDown=new JButton(iconDown);
|
||||
|
||||
Icon iconRight = new ImageIcon("C:\\Users\\kashi\\OneDrive\\Материал\\KeyRight.png");
|
||||
JButton ButtonRight=new JButton(iconRight);
|
||||
|
||||
Icon iconLeft = new ImageIcon("C:\\Users\\kashi\\OneDrive\\Материал\\KeyLeft.png");
|
||||
JButton ButtonLeft=new JButton(iconLeft);
|
||||
public FormGasolineTanker(){
|
||||
super("Gasoline Tanker");
|
||||
setContentPane(PictureBox);
|
||||
setSize(1000,700);
|
||||
Width = getWidth();
|
||||
Height = getHeight();
|
||||
setSize(800,600);
|
||||
Width=getWidth();
|
||||
Height=getHeight();
|
||||
ShowWindow();
|
||||
field.setBounds(0,0,Width,Height);
|
||||
RefreshWindow();
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
}
|
||||
ImageIcon spriteUp =new ImageIcon((new ImageIcon("Material\\KeyUp.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
ImageIcon spriteDown =new ImageIcon((new ImageIcon("Material\\KeyDown.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
ImageIcon spriteLeft =new ImageIcon((new ImageIcon("Material\\KeyLeft.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
ImageIcon spriteRight =new ImageIcon((new ImageIcon("Material\\KeyRight.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
private void ShowWindow(){
|
||||
|
||||
ButtonCreate.addActionListener(e -> {
|
||||
public void ShowWindow(){
|
||||
|
||||
Dimension dimen=new Dimension(30,30);
|
||||
|
||||
ButtonUp.setPreferredSize(dimen);
|
||||
ButtonUp.addActionListener(e->{
|
||||
field.UpButtonAction();
|
||||
repaint();
|
||||
});
|
||||
|
||||
ButtonDown.setPreferredSize(dimen);
|
||||
ButtonDown.addActionListener(e->{
|
||||
field.DownButtonAction();
|
||||
repaint();
|
||||
});
|
||||
|
||||
ButtonRight.setPreferredSize(dimen);
|
||||
ButtonRight.addActionListener(e->{
|
||||
field.RightButtonAction();
|
||||
repaint();
|
||||
});
|
||||
|
||||
ButtonLeft.setPreferredSize(dimen);
|
||||
ButtonLeft.addActionListener(e->{
|
||||
field.LeftButtonAction();
|
||||
repaint();
|
||||
});
|
||||
|
||||
LRPanel.setLayout(new FlowLayout(FlowLayout.CENTER,50,0));
|
||||
LRPanel.setBackground(new Color(0,0,0,0));
|
||||
LRPanel.add(ButtonLeft);
|
||||
LRPanel.add(ButtonRight);
|
||||
|
||||
UPanel.setLayout(new FlowLayout());
|
||||
UPanel.setBackground(new Color(0,0,0,0));
|
||||
UPanel.add(ButtonUp);
|
||||
|
||||
DPanel.setLayout(new FlowLayout());
|
||||
DPanel.setBackground(new Color(0,0,0,0));
|
||||
DPanel.add(ButtonDown);
|
||||
|
||||
DimentionPanel.setLayout(new BoxLayout(DimentionPanel,BoxLayout.Y_AXIS));
|
||||
DimentionPanel.setBackground(new Color(0,0,0,0));
|
||||
DimentionPanel.add(UPanel);
|
||||
DimentionPanel.add(LRPanel);
|
||||
DimentionPanel.add(DPanel);
|
||||
add(DimentionPanel);
|
||||
|
||||
CreatePanel.setLayout(new FlowLayout());
|
||||
CreatePanel.setBackground(new Color(0,0,0,0));
|
||||
CreatePanel.add(ButtonCreate);
|
||||
ButtonCreate.addActionListener(e->{
|
||||
field.CreateButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
ButtonCreateModif.addActionListener(e -> {
|
||||
field.CreateModifButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
ButtonUp.setIcon(spriteUp);
|
||||
ButtonUp.addActionListener(e -> {
|
||||
field.DirectionButtonAction(Direction.Up);
|
||||
ReDraw();
|
||||
});
|
||||
ButtonLeft.setIcon(spriteLeft);
|
||||
ButtonLeft.addActionListener(e -> {
|
||||
field.DirectionButtonAction(Direction.Left);
|
||||
ReDraw();
|
||||
});
|
||||
ButtonRight.setIcon(spriteRight);
|
||||
ButtonRight.addActionListener(e -> {
|
||||
field.DirectionButtonAction(Direction.Right);
|
||||
ReDraw();
|
||||
});
|
||||
ButtonDown.setIcon(spriteDown);
|
||||
ButtonDown.addActionListener(e -> {
|
||||
field.DirectionButtonAction(Direction.Down);
|
||||
ReDraw();
|
||||
repaint();
|
||||
});
|
||||
|
||||
BottomPanel.setLayout(new FlowLayout());
|
||||
BottomPanel.setBackground(new Color(0,0,0,0));
|
||||
BottomPanel.add(SpeedLabel);
|
||||
BottomPanel.add(WeightLabel);
|
||||
BottomPanel.add(BodyColorLabel);
|
||||
|
||||
BottomAndCreatePanel.setLayout(new BoxLayout(BottomAndCreatePanel,BoxLayout.Y_AXIS));
|
||||
BottomAndCreatePanel.setBackground(new Color(0,0,0,0));
|
||||
BottomAndCreatePanel.add(CreatePanel);
|
||||
BottomAndCreatePanel.add(BottomPanel);
|
||||
|
||||
add(BottomAndCreatePanel);
|
||||
add(field);
|
||||
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e){
|
||||
public void componentResized(ComponentEvent e) {
|
||||
super.componentResized(e);
|
||||
Width=getWidth();
|
||||
Height=getHeight();
|
||||
|
||||
field.ResizeField();
|
||||
ReDraw();
|
||||
field.setBounds(0,0,Width,Height);
|
||||
repaint();
|
||||
RefreshWindow();
|
||||
}
|
||||
});
|
||||
}
|
||||
private void ReDraw()
|
||||
{
|
||||
Graphics2D graphics = (Graphics2D) PictureBox.getGraphics();
|
||||
graphics.clearRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||
PictureBox.paintComponents(graphics);
|
||||
field.Draw(graphics);
|
||||
public void RefreshWindow(){
|
||||
field.setBounds(0,0,Width,Height);
|
||||
BottomAndCreatePanel.setBounds(-220,Height-110,Width,80);
|
||||
DimentionPanel.setBounds(Width-170,Height-170,190,140);
|
||||
}
|
||||
}
|
||||
|
171
src/FormMap.form
171
src/FormMap.form
@ -1,171 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMap">
|
||||
<grid id="27dc6" binding="PictureBox" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="572" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="3d1ad" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="325b7" class="javax.swing.JLabel" binding="SpeedLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Speed:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="b7022">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="fead2" class="javax.swing.JLabel" binding="WeightLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Weight:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f9385" class="javax.swing.JLabel" binding="BodyColorLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Color:"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="86b55" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="cb255" class="javax.swing.JButton" binding="ButtonCreate">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Create"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="269f9" class="javax.swing.JButton" binding="ButtonCreateModif">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Improved create"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="53d05" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="b822e" class="javax.swing.JButton" binding="ButtonUp">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c8a05" class="javax.swing.JButton" binding="ButtonDown">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ee84a" class="javax.swing.JButton" binding="ButtonRight">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b182f" class="javax.swing.JButton" binding="ButtonLeft">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="5081d" class="javax.swing.JComboBox" binding="ComboBoxSelectorMap">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="Simple map"/>
|
||||
<item value="Long map"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="ee7b4">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<grid id="d0ad5" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="33887">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="a07b0" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="276f9">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
<hspacer id="7b3f3">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
@ -1,87 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FormMap extends JFrame {
|
||||
private int Width;
|
||||
private int Height;
|
||||
DrawingMap map = new DrawingMap(this);
|
||||
private JButton ButtonDown;
|
||||
private JButton ButtonRight;
|
||||
private JButton ButtonLeft;
|
||||
private JButton ButtonUp;
|
||||
private JButton ButtonCreate;
|
||||
private JButton ButtonCreateModif;
|
||||
public JLabel SpeedLabel;
|
||||
public JLabel WeightLabel;
|
||||
public JLabel BodyColorLabel;
|
||||
private JComboBox ComboBoxSelectorMap;
|
||||
private JPanel PictureBox;
|
||||
ImageIcon spriteUp =new ImageIcon((new ImageIcon("Material\\KeyUp.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
ImageIcon spriteDown =new ImageIcon((new ImageIcon("Material\\KeyDown.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
ImageIcon spriteLeft =new ImageIcon((new ImageIcon("Material\\KeyLeft.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
ImageIcon spriteRight =new ImageIcon((new ImageIcon("Material\\KeyRight.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
public FormMap(){
|
||||
super("Gasoline tanker");
|
||||
setContentPane(PictureBox);
|
||||
setSize(1000,700);
|
||||
Width = getWidth();
|
||||
Height = getHeight();
|
||||
ShowWindow();
|
||||
map.setBounds(0,0,Width,Height);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void ShowWindow(){
|
||||
ButtonCreate.addActionListener(e -> {
|
||||
map.CreateButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
ButtonCreateModif.addActionListener(e -> {
|
||||
map.CreateModifButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
ButtonUp.setIcon(spriteUp);
|
||||
ButtonUp.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Up);
|
||||
ReDraw();
|
||||
});
|
||||
ButtonLeft.setIcon(spriteLeft);
|
||||
ButtonLeft.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Left);
|
||||
ReDraw();
|
||||
});
|
||||
ButtonRight.setIcon(spriteRight);
|
||||
ButtonRight.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Right);
|
||||
ReDraw();
|
||||
});
|
||||
ButtonDown.setIcon(spriteDown);
|
||||
ButtonDown.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Down);
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
ComboBoxSelectorMap.addActionListener(e -> {
|
||||
map.ComboBoxSelectorMapAction(Objects.requireNonNull(ComboBoxSelectorMap.getSelectedItem()).toString());
|
||||
ReDraw();
|
||||
});
|
||||
}
|
||||
private void ReDraw()
|
||||
{
|
||||
Graphics2D graphics = (Graphics2D) PictureBox.getGraphics();
|
||||
graphics.clearRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||
PictureBox.paintComponents(graphics);
|
||||
map.DrawMap(graphics);
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawingObject {
|
||||
public float Step=0;
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
void MoveObject(Direction direction);
|
||||
void DrawingObject(Graphics g);
|
||||
float[] GetCurrentPosition();
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawningObjectWheels {
|
||||
void SetCountWheels(int count);
|
||||
void DrawWheels(Graphics2D g, int _startPosX, int _startPosY);
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class LongMap extends AbstractMap{
|
||||
@Override
|
||||
protected void GenerateMap()
|
||||
{
|
||||
_map = new int[100][100];
|
||||
_size_x = (float)_width / _map[0].length;
|
||||
_size_y = (float)_height / _map[1].length;
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map[0].length; ++i)
|
||||
{
|
||||
for (int j = 0; j < _map[1].length; ++j)
|
||||
{
|
||||
_map[i][j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 5)
|
||||
{
|
||||
int xStart = _random.nextInt(0, 100);
|
||||
int xEnd = _random.nextInt(80, 100);
|
||||
|
||||
for (int i = xStart; i <= xEnd; ++i)
|
||||
{
|
||||
_map[i] [xStart] = _barrier;
|
||||
}
|
||||
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics gr, int i, int j) {
|
||||
gr.setColor(Color.GRAY);
|
||||
gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics gr, int i, int j) {
|
||||
gr.setColor(Color.BLACK);
|
||||
gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
new FormMap();
|
||||
public static void main(String[] args){
|
||||
new FormGasolineTanker();
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
public enum OrnamentForm {
|
||||
NoneOrnament(0),
|
||||
GrayOrnament(1),
|
||||
RedOrnament(2);
|
||||
public final int Value;
|
||||
OrnamentForm(int i) {
|
||||
Value=i;
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class SimpleMap extends AbstractMap {
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics gr, int i, int j) {
|
||||
gr.setColor(Color.GRAY);
|
||||
gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics gr, int i, int j) {
|
||||
gr.setColor(Color.BLACK);
|
||||
gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void GenerateMap() {
|
||||
_map = new int[100][100];
|
||||
_size_x = (float) (_width / _map.length);
|
||||
_size_y = (float) (_height / _map[0].length);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.length; ++i) {
|
||||
for (int j = 0; j < _map[i].length; ++j) {
|
||||
_map[i][j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 50) {
|
||||
int x = _random.nextInt(99);
|
||||
int y = _random.nextInt(99);
|
||||
if (_map[x][y] == _freeRoad) {
|
||||
_map[x][y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user