Начало
@ -1,192 +0,0 @@
|
||||
package DrawningObjects;
|
||||
import java.awt.*;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import Directions.Direction;
|
||||
import Entities.EntityMonorail;
|
||||
|
||||
import java.util.Random;
|
||||
import java.lang.*;
|
||||
|
||||
public class DrawningMonorail extends JPanel {
|
||||
private EntityMonorail entity;
|
||||
private int pictureWidth;
|
||||
private int pictureHeight;
|
||||
private int _countWheels;
|
||||
private int _startPosX;
|
||||
private int _startPosY ;
|
||||
private int relWidth = 150;
|
||||
private final int relHeight = 46;
|
||||
Random rd = new Random();
|
||||
private DrawingWheels _drawingWheels;
|
||||
|
||||
public boolean init(int wheelCount ,int speed, double weight, Color bodyColor, Color additionalColor,
|
||||
boolean monorails, boolean secondCabin, int width, int height) {
|
||||
if (0 + relWidth >= width || 0 + relHeight >= height) {
|
||||
return false;
|
||||
}
|
||||
_countWheels = wheelCount;
|
||||
pictureWidth = width;
|
||||
pictureHeight = height;
|
||||
entity = new EntityMonorail();
|
||||
entity.init(wheelCount, speed, weight, bodyColor, additionalColor, monorails, secondCabin);
|
||||
_drawingWheels = new DrawingWheels(entity.getBodyColor(), _countWheels);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setPosition(int x, int y) {
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
public void moveTransport(Direction dr) {
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
switch (dr) {
|
||||
case LEFT:
|
||||
if (_startPosX - entity.getStep() > 0) {
|
||||
_startPosX -= entity.getStep();
|
||||
}
|
||||
break;
|
||||
case RIGHT:
|
||||
if (_startPosX + entity.getStep() < pictureWidth - relWidth) {
|
||||
_startPosX += entity.getStep();
|
||||
}
|
||||
break;
|
||||
case UP:
|
||||
if (_startPosY - entity.getStep() > 0) {
|
||||
_startPosY -= entity.getStep();
|
||||
}
|
||||
break;
|
||||
case DOWN:
|
||||
if (_startPosY + entity.getStep() < pictureHeight - relHeight) {
|
||||
_startPosY += entity.getStep();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void drawMonorail(Graphics g) {
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
relWidth = 150;
|
||||
//Колёса
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 22, _startPosY + 36, 40, 8);
|
||||
g.drawRect(_startPosX+82, _startPosY + 36, 40, 8);
|
||||
g.drawOval(_startPosX + 3, _startPosY + 37, 30, 8);
|
||||
g.drawOval(_startPosX + 110, _startPosY + 37, 29, 8);
|
||||
|
||||
g.fillRect(_startPosX + 22, _startPosY + 36, 40, 8);
|
||||
g.fillRect(_startPosX + 82, _startPosY + 36, 40, 8);
|
||||
g.fillOval( _startPosX + 3, _startPosY + 37, 30, 8);
|
||||
g.fillOval( _startPosX + 110, _startPosY + 37, 29, 8);
|
||||
_drawingWheels.Draw(g, _startPosX, _startPosY);
|
||||
|
||||
//Кабина
|
||||
g.setColor(entity.getBodyColor());
|
||||
g.fillRect(_startPosX + 10, _startPosY + 20, 120, 16);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 10, _startPosY + 20, 120, 16);
|
||||
|
||||
int[] xp1 = new int[]{_startPosX+10,_startPosX+130,_startPosX+130,_startPosX+13};
|
||||
int[] yp1 = new int[]{_startPosY + 20,_startPosY + 20,_startPosY + 5,_startPosY + 5};
|
||||
Polygon pol1 = new Polygon(xp1, yp1, yp1.length);
|
||||
|
||||
g.setColor(entity.getBodyColor());
|
||||
g.fillPolygon(pol1);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(pol1);
|
||||
|
||||
//Дверь
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(_startPosX + 49, _startPosY + 9, 12, 22);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 49, _startPosY + 9, 12, 22);
|
||||
|
||||
//Окна и прочее
|
||||
g.setColor(Color.CYAN);
|
||||
g.drawRect(_startPosX + 20, _startPosY + 8, 10, 10);
|
||||
g.drawRect(_startPosX + 35, _startPosY + 8, 10, 10);
|
||||
g.drawRect(_startPosX + 117, _startPosY + 8, 10, 10);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 130, _startPosY + 10, 2, 22);
|
||||
g.fillRect(_startPosX + 130, _startPosY + 10, 2, 22);
|
||||
|
||||
//Магнитная рельса
|
||||
|
||||
if(entity.getMonorails())
|
||||
{
|
||||
g.drawRect(_startPosX, _startPosY + 50, 140, 10);
|
||||
g.fillRect(_startPosX, _startPosY + 50, 140, 10);
|
||||
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(_startPosX + 5, _startPosY + 53, 130, 5);
|
||||
}
|
||||
|
||||
if (entity.getSecondCabin())
|
||||
{
|
||||
relWidth = 290;
|
||||
//низ
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 162, _startPosY + 36, 40, 8);
|
||||
g.drawRect(_startPosX + 222, _startPosY + 36, 40, 8);
|
||||
g.drawOval(_startPosX + 143, _startPosY + 37, 30, 8);
|
||||
g.drawOval(_startPosX + 250, _startPosY + 37, 29, 8);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillRect(_startPosX + 162, _startPosY + 36, 40, 8);
|
||||
g.fillRect(_startPosX + 222, _startPosY + 36, 40, 8);
|
||||
g.fillOval(_startPosX + 143, _startPosY + 37, 30, 8);
|
||||
g.fillOval(_startPosX + 250, _startPosY + 37, 29, 8);
|
||||
|
||||
//_drawingWheels = new DrawingWheels(g, _startPosX + 140, _startPosY,
|
||||
//entity.getAdditionalColor(), _countWheels);
|
||||
_drawingWheels.Draw(g, _startPosX + 140, _startPosY);
|
||||
if (entity.getMonorails())
|
||||
{
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 140, _startPosY + 50, 145, 10);
|
||||
g.fillRect(_startPosX + 140, _startPosY + 50, 145, 10);
|
||||
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(_startPosX + 135, _startPosY + 53, 145, 5);
|
||||
}
|
||||
|
||||
//Кабина
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 150, _startPosY + 20, 120, 16);
|
||||
|
||||
g.fillRect(_startPosX + 150, _startPosY + 20, 120, 16);
|
||||
|
||||
int[] xp2 = new int[]{_startPosX + 150,_startPosX + 270,_startPosX + 267,_startPosX + 150};
|
||||
int[] yp2 = new int[] {_startPosY + 20, _startPosY + 20, _startPosY + 5, _startPosY + 6};
|
||||
Polygon pol2 = new Polygon(xp2, yp2, yp2.length);
|
||||
|
||||
g.setColor(entity.getAdditionalColor());
|
||||
g.fillPolygon(pol2);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(pol2);
|
||||
|
||||
|
||||
//дверь
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(_startPosX + 189, _startPosY + 9, 12, 22);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 189, _startPosY + 9, 12, 22);
|
||||
|
||||
//Окна и прочее
|
||||
g.setColor(Color.CYAN);
|
||||
g.drawRect(_startPosX + 160, _startPosY + 8, 10, 10);
|
||||
g.drawRect(_startPosX + 175, _startPosY + 8, 10, 10);
|
||||
g.drawRect(_startPosX + 257, _startPosY + 8, 10, 10);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 270, _startPosY + 10, 2, 22);
|
||||
g.fillRect(_startPosX + 270, _startPosY + 10, 2, 22);
|
||||
}
|
||||
}
|
||||
}
|
0
.gitignore → Monorail/.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
package Directions;
|
||||
package Monorail.Directions;
|
||||
public enum CountWheels{
|
||||
Min(2),
|
||||
Mid(3),
|
@ -1,6 +1,6 @@
|
||||
package Directions;
|
||||
|
||||
enum Direction{
|
||||
public enum Direction{
|
||||
UP(1),
|
||||
DOWN(2),
|
||||
LEFT(3),
|
@ -1,3 +1,4 @@
|
||||
package DrawningObjects;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
170
Monorail/DrawningObjects/DrawningMonorail.java
Normal file
@ -0,0 +1,170 @@
|
||||
package DrawningObjects;
|
||||
import java.awt.*;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import Directions.Direction;
|
||||
import Entities.EntityMonorail;
|
||||
import Entities.EntitySecondMonorail;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawningMonorail extends JPanel {
|
||||
private EntityMonorail entity;
|
||||
private int pictureWidth;
|
||||
private int pictureHeight;
|
||||
private int _startPosX;
|
||||
private int _startPosY ;
|
||||
private int relWidth = 150;
|
||||
private int relHeight = 46;
|
||||
Random rd = new Random();
|
||||
private DrawingWheels _drawingWheels;
|
||||
public DrawningMonorail(int wheelCount ,int speed, double weight, Color bodyColor, int width, int height){
|
||||
if (relWidth >= width || relHeight >= height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureWidth = width;
|
||||
pictureHeight = height;
|
||||
entity = new EntityMonorail(wheelCount, speed, weight, bodyColor);
|
||||
_drawingWheels = new DrawingWheels(entity.getBodyColor(), wheelCount);
|
||||
}
|
||||
|
||||
public EntityMonorail getEntityMonorail(){
|
||||
return entity;
|
||||
}
|
||||
protected void setEntityMonorail(int wheelCount, int speed, double weight,
|
||||
Color bodyColor, Color additionalColor, boolean monorails, boolean secondCabin){
|
||||
entity = new EntitySecondMonorail(wheelCount, speed, weight, bodyColor,
|
||||
additionalColor, monorails, secondCabin);
|
||||
}
|
||||
|
||||
protected DrawningMonorail(int wheelCount, int speed, double weight, Color bodyColor, int width,
|
||||
int height, int carWidth, int carHeight){
|
||||
if (relWidth >= width || relHeight >= height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureWidth = width;
|
||||
pictureHeight = height;
|
||||
relWidth = carWidth;
|
||||
relHeight = carHeight;
|
||||
entity = new EntityMonorail(wheelCount, speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
public void setPosition(int x, int y) {
|
||||
if (x < 0 || x > pictureWidth - relWidth)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0 || y > pictureHeight - relHeight)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
public void moveTransport(Direction dr) {
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
switch (dr) {
|
||||
case LEFT:
|
||||
_startPosX -= (int)entity.getStep();
|
||||
break;
|
||||
case RIGHT:
|
||||
_startPosX += (int)entity.getStep();
|
||||
break;
|
||||
case UP:
|
||||
_startPosY -= (int)entity.getStep();
|
||||
break;
|
||||
case DOWN:
|
||||
_startPosY += (int)entity.getStep();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public int getPosX(){
|
||||
return _startPosX;
|
||||
}
|
||||
public int getPosY(){
|
||||
return _startPosY;
|
||||
}
|
||||
public int getHeight(){
|
||||
return relHeight;
|
||||
}
|
||||
public int getWidth(){
|
||||
return relWidth;
|
||||
}
|
||||
|
||||
public boolean CanMove(Direction direction)
|
||||
{
|
||||
if (entity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction) {
|
||||
case LEFT:
|
||||
return _startPosX - entity.getStep() > 0;
|
||||
case UP:
|
||||
return _startPosY - entity.getStep() > 0;
|
||||
case RIGHT:
|
||||
return _startPosX + entity.getStep() < pictureWidth - relWidth;
|
||||
case DOWN:
|
||||
return _startPosY + entity.getStep() < pictureHeight - relHeight;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics g) {
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
relWidth = 150;
|
||||
//Колёса
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 22, _startPosY + 36, 40, 8);
|
||||
g.drawRect(_startPosX+82, _startPosY + 36, 40, 8);
|
||||
g.drawOval(_startPosX + 3, _startPosY + 37, 30, 8);
|
||||
g.drawOval(_startPosX + 110, _startPosY + 37, 29, 8);
|
||||
|
||||
g.fillRect(_startPosX + 22, _startPosY + 36, 40, 8);
|
||||
g.fillRect(_startPosX + 82, _startPosY + 36, 40, 8);
|
||||
g.fillOval( _startPosX + 3, _startPosY + 37, 30, 8);
|
||||
g.fillOval( _startPosX + 110, _startPosY + 37, 29, 8);
|
||||
_drawingWheels.Draw(g, _startPosX, _startPosY);
|
||||
|
||||
//Кабина
|
||||
g.setColor(entity.getBodyColor());
|
||||
g.fillRect(_startPosX + 10, _startPosY + 20, 120, 16);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 10, _startPosY + 20, 120, 16);
|
||||
|
||||
int[] xp1 = new int[]{_startPosX+10,_startPosX+130,_startPosX+130,_startPosX+13};
|
||||
int[] yp1 = new int[]{_startPosY + 20,_startPosY + 20,_startPosY + 5,_startPosY + 5};
|
||||
Polygon pol1 = new Polygon(xp1, yp1, yp1.length);
|
||||
|
||||
g.setColor(entity.getBodyColor());
|
||||
g.fillPolygon(pol1);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(pol1);
|
||||
|
||||
//Дверь
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(_startPosX + 49, _startPosY + 9, 12, 22);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 49, _startPosY + 9, 12, 22);
|
||||
|
||||
//Окна и прочее
|
||||
g.setColor(Color.CYAN);
|
||||
g.drawRect(_startPosX + 20, _startPosY + 8, 10, 10);
|
||||
g.drawRect(_startPosX + 35, _startPosY + 8, 10, 10);
|
||||
g.drawRect(_startPosX + 117, _startPosY + 8, 10, 10);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 130, _startPosY + 10, 2, 22);
|
||||
g.fillRect(_startPosX + 130, _startPosY + 10, 2, 22);
|
||||
|
||||
}
|
||||
}
|
93
Monorail/DrawningObjects/DrawningSecondMonorail.java
Normal file
@ -0,0 +1,93 @@
|
||||
package DrawningObjects;
|
||||
import java.awt.*;
|
||||
|
||||
import Entities.EntitySecondMonorail;
|
||||
|
||||
public class DrawningSecondMonorail extends DrawningMonorail{
|
||||
public DrawningSecondMonorail(int wheelCount, int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, boolean monorails, boolean secondCabin, int width, int height){
|
||||
super(wheelCount, speed, weight, bodyColor, width, height, 110, 60);
|
||||
if (getEntityMonorail() != null)
|
||||
{
|
||||
setEntityMonorail(wheelCount, speed, weight, bodyColor, additionalColor, monorails, secondCabin);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void DrawTransport(Graphics g){
|
||||
super.DrawTransport(g);
|
||||
if (!(getEntityMonorail() instanceof EntitySecondMonorail secondMonorail)) {
|
||||
return;
|
||||
}
|
||||
//Магнитная рельса
|
||||
|
||||
if(secondMonorail.getMonorails())
|
||||
{
|
||||
g.drawRect(_startPosX, _startPosY + 50, 140, 10);
|
||||
g.fillRect(_startPosX, _startPosY + 50, 140, 10);
|
||||
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(_startPosX + 5, _startPosY + 53, 130, 5);
|
||||
}
|
||||
|
||||
if (entity.getSecondCabin())
|
||||
{
|
||||
relWidth = 290;
|
||||
//низ
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 162, _startPosY + 36, 40, 8);
|
||||
g.drawRect(_startPosX + 222, _startPosY + 36, 40, 8);
|
||||
g.drawOval(_startPosX + 143, _startPosY + 37, 30, 8);
|
||||
g.drawOval(_startPosX + 250, _startPosY + 37, 29, 8);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillRect(_startPosX + 162, _startPosY + 36, 40, 8);
|
||||
g.fillRect(_startPosX + 222, _startPosY + 36, 40, 8);
|
||||
g.fillOval(_startPosX + 143, _startPosY + 37, 30, 8);
|
||||
g.fillOval(_startPosX + 250, _startPosY + 37, 29, 8);
|
||||
|
||||
_drawingWheels.Draw(g, _startPosX + 140, _startPosY);
|
||||
if (entity.getMonorails())
|
||||
{
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 140, _startPosY + 50, 145, 10);
|
||||
g.fillRect(_startPosX + 140, _startPosY + 50, 145, 10);
|
||||
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(_startPosX + 135, _startPosY + 53, 145, 5);
|
||||
}
|
||||
|
||||
//Кабина
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 150, _startPosY + 20, 120, 16);
|
||||
|
||||
g.fillRect(_startPosX + 150, _startPosY + 20, 120, 16);
|
||||
|
||||
int[] xp2 = new int[]{_startPosX + 150,_startPosX + 270,_startPosX + 267,_startPosX + 150};
|
||||
int[] yp2 = new int[] {_startPosY + 20, _startPosY + 20, _startPosY + 5, _startPosY + 6};
|
||||
Polygon pol2 = new Polygon(xp2, yp2, yp2.length);
|
||||
|
||||
g.setColor(entity.getAdditionalColor());
|
||||
g.fillPolygon(pol2);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(pol2);
|
||||
|
||||
|
||||
//дверь
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(_startPosX + 189, _startPosY + 9, 12, 22);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 189, _startPosY + 9, 12, 22);
|
||||
|
||||
//Окна и прочее
|
||||
g.setColor(Color.CYAN);
|
||||
g.drawRect(_startPosX + 160, _startPosY + 8, 10, 10);
|
||||
g.drawRect(_startPosX + 175, _startPosY + 8, 10, 10);
|
||||
g.drawRect(_startPosX + 257, _startPosY + 8, 10, 10);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 270, _startPosY + 10, 2, 22);
|
||||
g.fillRect(_startPosX + 270, _startPosY + 10, 2, 22);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -12,7 +12,7 @@ public class EntityMonorail {
|
||||
return (double) speed * 130 / weight;
|
||||
}
|
||||
|
||||
public void init(int wheelCount, int speed, double weight, Color bodyColor) {
|
||||
public EntityMonorail(int wheelCount, int speed, double weight, Color bodyColor) {
|
||||
setSpeed(speed);
|
||||
setWeight(weight);
|
||||
setBodyColor(bodyColor);
|
@ -1,11 +1,13 @@
|
||||
package Entities;
|
||||
import java.awt.*;
|
||||
|
||||
public class EntitySecondMonorail {
|
||||
public class EntitySecondMonorail extends EntityMonorail{
|
||||
private Color additionalColor;
|
||||
private boolean monorails;
|
||||
private boolean secondCabin;
|
||||
public EntitySecondMonorail(Color additionalColor, boolean monorails, boolean secondCabin){
|
||||
public EntitySecondMonorail(int wheelCount, int speed, double weight,
|
||||
Color bodyColor, Color additionalColor, boolean monorails, boolean secondCabin){
|
||||
super(wheelCount, speed,weight, bodyColor);
|
||||
setAdditionalColor(additionalColor);
|
||||
setMonorails(monorails);
|
||||
setSecondCabin(secondCabin);
|
@ -1,3 +1,4 @@
|
||||
package Monorail;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
Before Width: | Height: | Size: 281 B After Width: | Height: | Size: 281 B |
Before Width: | Height: | Size: 265 B After Width: | Height: | Size: 265 B |
Before Width: | Height: | Size: 224 B After Width: | Height: | Size: 224 B |
Before Width: | Height: | Size: 264 B After Width: | Height: | Size: 264 B |