Добавление новых классов и их заполнение

This commit is contained in:
Senju 2022-09-23 11:35:42 +04:00
parent 5606591132
commit b5be809757
4 changed files with 103 additions and 7 deletions

8
src/Direction.java Normal file
View File

@ -0,0 +1,8 @@
package src;
public enum Direction {
Up,
Down,
Left,
Right;
}

86
src/DrawingWarship.java Normal file
View File

@ -0,0 +1,86 @@
package src;
import java.awt.*;
public class DrawingWarship {
private EntityWarship Warship;
public EntityWarship GetWarship(){return Warship;}
private float _startPosX;
private float _startPosY;
private Integer _pictureWidth = null;
private Integer _pictureHeight = null;
private final int _warshipWidth = 94;
private final int _warshipHeight = 40;
public void Init(int speed, float weight, Color bodyColor)
{
Warship = new EntityWarship();
Warship.Init(speed, weight, bodyColor);
}
public void SetPosition(int x, int y, int width, int height)
{
if (width >= x + _warshipWidth && height >= y + _warshipHeight && x >= 0 && y >= 0)
{
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
}
}
public void MoveTransport(Direction direction)
{
if (_pictureWidth == null || _pictureHeight == null)
{
return;
}
switch (direction)
{
// вправо
case Right:
if (_startPosX + _warshipWidth + Warship.Step < _pictureWidth)
{
_startPosX += Warship.Step;
}
break;
//влево
case Left:
if(_startPosX - Warship.Step > 0)
{
_startPosX -= Warship.Step;
}
break;
//вверх
case Up:
if (_startPosY - Warship.Step > 0)
{
_startPosY -= Warship.Step;
}
break;
//вниз
case Down:
if (_startPosY + _warshipHeight + Warship.Step < _pictureHeight)
{
_startPosY += Warship.Step;
}
break;
}
}
public void DrawTransport(Graphics g){
if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null)
{
return;
}
Graphics2D g2 = (Graphics2D) g;
float[] pointXWarship = {_startPosX + 4, _startPosX + 94, _startPosX + 114, _startPosX + 94, _startPosX + 4};
float[] pointYWarship = {_startPosY, _startPosY, _startPosY + 20, _startPosY + 40, _startPosY + 40};
}
}

View File

@ -5,16 +5,16 @@ import java.util.Random;
public class EntityWarship {
private int Speed;
private void setSpeed(int speed){this.Speed = speed;}
public int getSpeed(){return Speed;}
private void SetSpeed(int speed){this.Speed = speed;}
public int GetSpeed(){return Speed;}
private float Weight;
private void setWeight(float weight){this.Weight = weight;}
public float getWeight(){return Weight;}
private void SetWeight(float weight){this.Weight = weight;}
public float GetWeight(){return Weight;}
private Color BodyColor ;
private void setBodyColor (Color bodyColor){this.BodyColor = bodyColor;}
public Color getBodyColor (){return BodyColor;}
private void SetBodyColor (Color bodyColor){this.BodyColor = bodyColor;}
public Color GetBodyColor (){return BodyColor;}
public float Step;
public void Init(int speed, float weight, Color bodyColor)

View File

@ -1,5 +1,7 @@
package src;
public class FormWarship {
import javax.swing.*;
public class FormWarship extends JFrame{
}