Compare commits
No commits in common. "LabWork01" and "main" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,4 @@
|
|||||||
# ---> VisualStudioCode
|
# ---> VisualStudioCode
|
||||||
*.class
|
|
||||||
.vscode/*
|
.vscode/*
|
||||||
!.vscode/settings.json
|
!.vscode/settings.json
|
||||||
!.vscode/tasks.json
|
!.vscode/tasks.json
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
public enum DirectionType {
|
|
||||||
Up, Down, Right, Left
|
|
||||||
}
|
|
@ -1,143 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
|
|
||||||
public class DrawingWarmlyLocomotive {
|
|
||||||
|
|
||||||
private EntityWarmlyLocomotive EntityWarmlyLocomotive;
|
|
||||||
public EntityWarmlyLocomotive getEntityWarmlyLocomotive(){ return EntityWarmlyLocomotive; }
|
|
||||||
|
|
||||||
private Integer _pictureWidth;
|
|
||||||
private Integer _pictureHeight;
|
|
||||||
private Integer _startPosX;
|
|
||||||
private Integer _startPosY;
|
|
||||||
private final int _drawningLocomotiveWidth = 150;
|
|
||||||
private final int _drawningLocomotiveHeight = 100;
|
|
||||||
|
|
||||||
|
|
||||||
public void Init(int speed, double weight, Color bodyColor,
|
|
||||||
Color additionalColor, boolean tube, boolean fuelTank)
|
|
||||||
{
|
|
||||||
EntityWarmlyLocomotive = new EntityWarmlyLocomotive();
|
|
||||||
EntityWarmlyLocomotive.Init(speed, weight, bodyColor, additionalColor,
|
|
||||||
tube, fuelTank);
|
|
||||||
_pictureWidth = null;
|
|
||||||
_pictureHeight = null;
|
|
||||||
_startPosX = null;
|
|
||||||
_startPosY = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean SetPictureSize(int width, int height)
|
|
||||||
{
|
|
||||||
if (width >= _drawningLocomotiveWidth && height >= _drawningLocomotiveHeight) {
|
|
||||||
_pictureWidth = width;
|
|
||||||
_pictureHeight = height;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetPosition(int x, int y){
|
|
||||||
if (_pictureHeight.equals(null) || _pictureWidth.equals(null)){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((y + _drawningLocomotiveHeight) > _pictureHeight){
|
|
||||||
_startPosY = y - _drawningLocomotiveHeight;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
_startPosY = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((x + _drawningLocomotiveWidth) > _pictureWidth){
|
|
||||||
_startPosX = x - _drawningLocomotiveWidth;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
_startPosX = x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean MoveTransport(DirectionType direction){
|
|
||||||
if (EntityWarmlyLocomotive.equals(null) || _startPosX.equals(null) || _startPosY.equals(null)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
switch (direction)
|
|
||||||
{
|
|
||||||
case Up:
|
|
||||||
{
|
|
||||||
if (_startPosY - EntityWarmlyLocomotive.Step() > 0){
|
|
||||||
_startPosY -= (int)EntityWarmlyLocomotive.Step();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case Left:
|
|
||||||
{
|
|
||||||
if (_startPosX - EntityWarmlyLocomotive.Step() > 0){
|
|
||||||
_startPosX -= (int)EntityWarmlyLocomotive.Step();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case Right:
|
|
||||||
{
|
|
||||||
if (_startPosX + EntityWarmlyLocomotive.Step() + _drawningLocomotiveWidth < _pictureWidth){
|
|
||||||
_startPosX += (int)EntityWarmlyLocomotive.Step();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case Down:
|
|
||||||
{
|
|
||||||
if (_startPosY + EntityWarmlyLocomotive.Step() + _drawningLocomotiveHeight < _pictureHeight){
|
|
||||||
_startPosY += (int)EntityWarmlyLocomotive.Step();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DrawTransport(Graphics g){
|
|
||||||
if (EntityWarmlyLocomotive.equals(null) || _startPosX.equals(null) || _startPosY.equals(null))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
if (EntityWarmlyLocomotive.getTube())
|
|
||||||
{
|
|
||||||
g.drawRect(_startPosX + 40, _startPosY, 20, 30);
|
|
||||||
g.setColor(EntityWarmlyLocomotive.getAdditionColor());
|
|
||||||
g.fillRect(_startPosX + 40, _startPosY, 20, 40);
|
|
||||||
}
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawRect(_startPosX, _startPosY + 60, 140, 20);
|
|
||||||
g.setColor(EntityWarmlyLocomotive.getBodyColor());
|
|
||||||
g.fillRect(_startPosX, _startPosY + 60, 140, 20);
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
Polygon body = new Polygon();
|
|
||||||
body.addPoint(_startPosX, _startPosY + 60);
|
|
||||||
body.addPoint(_startPosX + 20, _startPosY + 30);
|
|
||||||
body.addPoint(_startPosX + 140, _startPosY + 30);
|
|
||||||
body.addPoint(_startPosX + 140, _startPosY + 60);
|
|
||||||
g.drawPolygon(body);
|
|
||||||
g.setColor(EntityWarmlyLocomotive.getBodyColor());
|
|
||||||
g.fillPolygon(body);
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawRect(_startPosX + 140, _startPosY + 40, 10, 40);
|
|
||||||
g.setColor(EntityWarmlyLocomotive.getBodyColor());
|
|
||||||
g.fillRect(_startPosX + 140, _startPosY + 40, 10, 40);
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawOval(_startPosX, _startPosY + 80, 20, 20);
|
|
||||||
g.fillOval(_startPosX, _startPosY + 80, 20, 20);
|
|
||||||
g.drawOval(_startPosX + 30, _startPosY + 80, 20, 20);
|
|
||||||
g.fillOval(_startPosX + 30, _startPosY + 80, 20, 20);
|
|
||||||
g.drawOval(_startPosX + 90, _startPosY + 80, 20, 20);
|
|
||||||
g.fillOval(_startPosX + 90, _startPosY + 80, 20, 20);
|
|
||||||
g.drawOval(_startPosX + 120, _startPosY + 80, 20, 20);
|
|
||||||
g.fillOval(_startPosX + 120, _startPosY + 80, 20, 20);
|
|
||||||
|
|
||||||
if (EntityWarmlyLocomotive.getFuelTank()){
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawRect(_startPosX + 80, _startPosY + 40, 50, 40);
|
|
||||||
g.setColor(EntityWarmlyLocomotive.getAdditionColor());
|
|
||||||
g.fillRect(_startPosX + 80, _startPosY + 40, 50, 40);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
import java.awt.Color;
|
|
||||||
|
|
||||||
public class EntityWarmlyLocomotive {
|
|
||||||
|
|
||||||
private int Speed;
|
|
||||||
public int getSpeed() { return Speed; }
|
|
||||||
|
|
||||||
private double Weight;
|
|
||||||
public double getWeight() { return Weight; }
|
|
||||||
|
|
||||||
private Color BodyColor;
|
|
||||||
public Color getBodyColor() { return BodyColor; }
|
|
||||||
|
|
||||||
private Color AdditionalColor;
|
|
||||||
public Color getAdditionColor() { return AdditionalColor; }
|
|
||||||
|
|
||||||
private boolean Tube;
|
|
||||||
public boolean getTube() { return Tube; }
|
|
||||||
|
|
||||||
private boolean FuelTank;
|
|
||||||
public boolean getFuelTank() { return FuelTank; }
|
|
||||||
|
|
||||||
public double Step() {
|
|
||||||
return Speed * 100 / Weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color
|
|
||||||
additionalColor, boolean tube, boolean fuelTank)
|
|
||||||
{
|
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
|
||||||
Tube = tube;
|
|
||||||
FuelTank = fuelTank;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,107 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
public class FormWarmlyLocomotive extends JFrame {
|
|
||||||
DrawingWarmlyLocomotive _drawningWarmlyLocomotive;
|
|
||||||
JPanel pictureBox;
|
|
||||||
|
|
||||||
public void Initialize(){
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
setSize(900, 500);
|
|
||||||
setVisible(true);
|
|
||||||
setTitle("Тепловоз");
|
|
||||||
setResizable(false);
|
|
||||||
|
|
||||||
//pictireBox
|
|
||||||
pictureBox = new JPanel();
|
|
||||||
pictureBox.setSize(getWidth(), getHeight());
|
|
||||||
pictureBox.setLayout(null);
|
|
||||||
|
|
||||||
//createButton
|
|
||||||
JButton createButton = new JButton("Создать");
|
|
||||||
createButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
createButton_Click();
|
|
||||||
//repaint();
|
|
||||||
System.out.println("helpmepls");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
//createButton.setBounds(10, 420, 90, 30);
|
|
||||||
createButton.setSize(90, 30);
|
|
||||||
createButton.setLocation(10, 420);
|
|
||||||
pictureBox.add(createButton);
|
|
||||||
|
|
||||||
|
|
||||||
//upButton
|
|
||||||
JButton upButton = new JButton();
|
|
||||||
ImageIcon imgUp = new ImageIcon("Resources\\UpArrow.png");
|
|
||||||
upButton.setIcon(imgUp);
|
|
||||||
upButton.setSize(30,30);
|
|
||||||
upButton.setLocation(810,385);
|
|
||||||
pictureBox.add(upButton);
|
|
||||||
|
|
||||||
//downButton
|
|
||||||
JButton downButton = new JButton();
|
|
||||||
ImageIcon imgDn = new ImageIcon("Resources\\DownArrow.png");
|
|
||||||
downButton.setIcon(imgDn);
|
|
||||||
downButton.setSize(30 ,30);
|
|
||||||
downButton.setLocation(810, 420);
|
|
||||||
pictureBox.add(downButton);
|
|
||||||
|
|
||||||
//rightButton
|
|
||||||
JButton rightButton = new JButton();
|
|
||||||
ImageIcon imgRt = new ImageIcon("Resources\\RightArrow.png");
|
|
||||||
rightButton.setIcon(imgRt);
|
|
||||||
rightButton.setSize(30, 30);
|
|
||||||
rightButton.setLocation(845, 420);
|
|
||||||
pictureBox.add(rightButton);
|
|
||||||
|
|
||||||
//downButton
|
|
||||||
JButton leftButton = new JButton();
|
|
||||||
ImageIcon imgLt = new ImageIcon("Resources\\LeftArrow.png");
|
|
||||||
leftButton.setIcon(imgLt);
|
|
||||||
leftButton.setSize(30, 30);
|
|
||||||
leftButton.setLocation(775, 420);
|
|
||||||
pictureBox.add(leftButton);
|
|
||||||
repaint();
|
|
||||||
add(pictureBox);
|
|
||||||
|
|
||||||
Graphics g = pictureBox.getGraphics();
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.fillRect(100, 100, 100, 100);
|
|
||||||
repaint();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// private void Draw()
|
|
||||||
// {
|
|
||||||
// if (_drawningWarmlyLocomotive.equals(null))
|
|
||||||
// {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// BufferedImage bmp = new BufferedImage(getWidth(), getHeight(), 1);
|
|
||||||
// Graphics gr = bmp.getGraphics();
|
|
||||||
// _drawningWarmlyLocomotive.DrawTransport(gr);
|
|
||||||
// repaint();
|
|
||||||
// }
|
|
||||||
|
|
||||||
private void createButton_Click(){
|
|
||||||
Random random = new Random();
|
|
||||||
_drawningWarmlyLocomotive = new DrawingWarmlyLocomotive();
|
|
||||||
_drawningWarmlyLocomotive.Init(
|
|
||||||
random.nextInt(200) + 100,
|
|
||||||
random.nextInt(2000) + 1000,
|
|
||||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
|
||||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
|
||||||
random.nextInt(2) != 0, random.nextInt(2) != 0);
|
|
||||||
_drawningWarmlyLocomotive.SetPictureSize(getWidth(), getHeight());
|
|
||||||
_drawningWarmlyLocomotive.SetPosition(random.nextInt(90) + 10, random.nextInt(90) + 10);
|
|
||||||
_drawningWarmlyLocomotive.DrawTransport(getGraphics());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,5 @@
|
|||||||
|
|
||||||
public class Program {
|
public class Program {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
FormWarmlyLocomotive form = new FormWarmlyLocomotive();
|
System.out.println("Hello, World!");
|
||||||
form.Initialize();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 933 B |
Binary file not shown.
Before Width: | Height: | Size: 907 B |
Binary file not shown.
Before Width: | Height: | Size: 922 B |
Binary file not shown.
Before Width: | Height: | Size: 989 B |
Loading…
Reference in New Issue
Block a user