PIbd-22. Bulatova K.R. LabWork_01 HARD #1
@ -1,12 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AutoImportSettings">
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="1966194d-7a0e-41b7-8248-e72d6d03a650" name="Changes" comment="" />
|
||||
<list default="true" id="1966194d-7a0e-41b7-8248-e72d6d03a650" name="Changes" comment="Создание проекта">
|
||||
<change afterPath="$PROJECT_DIR$/src/CountDecks.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/Direction.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/DrawingDecks.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/EntityShip.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/FormWarmlyShip.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Main.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Enum" />
|
||||
<option value="Class" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
@ -16,12 +35,17 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true"
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true"
|
||||
}
|
||||
}]]></component>
|
||||
}</component>
|
||||
<component name="RecentsManager">
|
||||
<key name="MoveFile.RECENT_KEYS">
|
||||
<recent name="C:\Users\midni\IdeaProjects\WarmlyShip_HARD\src" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
@ -31,6 +55,18 @@
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1700585370664</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Создание проекта">
|
||||
<created>1700585393019</created>
|
||||
<option name="number" value="00001" />
|
||||
<option name="presentableId" value="LOCAL-00001" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1700585393019</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="2" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="Создание проекта" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Создание проекта" />
|
||||
</component>
|
||||
</project>
|
5
src/CountDecks.java
Normal file
5
src/CountDecks.java
Normal file
@ -0,0 +1,5 @@
|
||||
public enum CountDecks {
|
||||
OneDeck,
|
||||
TwoDecks,
|
||||
ThreeDecks
|
||||
}
|
6
src/Direction.java
Normal file
6
src/Direction.java
Normal file
@ -0,0 +1,6 @@
|
||||
public enum Direction {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right
|
||||
}
|
41
src/DrawingDecks.java
Normal file
41
src/DrawingDecks.java
Normal file
@ -0,0 +1,41 @@
|
||||
import java.awt.*;
|
||||
public class DrawingDecks {
|
||||
private CountDecks countDecks;
|
||||
private int NumberDecks;
|
||||
public void SetCountDecks(int value){
|
||||
NumberDecks = value;
|
||||
switch (value){
|
||||
case 2:
|
||||
countDecks = CountDecks.TwoDecks;
|
||||
break;
|
||||
case 3:
|
||||
countDecks = CountDecks.ThreeDecks;
|
||||
break;
|
||||
default:
|
||||
countDecks = CountDecks.OneDeck;
|
||||
}
|
||||
};
|
||||
public void DrawDeck(int x, int y, int width, int heght, Graphics g, Color BodyColor){
|
||||
g.setColor(BodyColor);
|
||||
g.fillRect(x, y, width, heght);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(x, y, width, heght);
|
||||
}
|
||||
|
||||
public void DrawingDecks(int _startPosX, int _startPosY, Color BodyColor, Graphics g){
|
||||
switch (countDecks){
|
||||
case OneDeck:
|
||||
DrawDeck(_startPosX + 25, _startPosY + 80, 130, 30, g, BodyColor);
|
||||
break;
|
||||
case TwoDecks:
|
||||
DrawDeck(_startPosX + 25, _startPosY + 80, 130, 30, g, BodyColor);
|
||||
|
||||
DrawDeck(_startPosX + 40, _startPosY + 55, 100, 25, g, BodyColor);
|
||||
break;
|
||||
case ThreeDecks:
|
||||
DrawDeck(_startPosX + 25, _startPosY + 80, 130, 30, g, BodyColor);
|
||||
eegov
commented
Имеется дублирующийся код Имеется дублирующийся код
|
||||
DrawDeck(_startPosX + 40, _startPosY + 55, 100, 25, g, BodyColor);
|
||||
DrawDeck(_startPosX + 45, _startPosY + 30, 75, 25, g, BodyColor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
57
src/EntityShip.java
Normal file
57
src/EntityShip.java
Normal file
@ -0,0 +1,57 @@
|
||||
import java.awt.*;
|
||||
public class EntityShip {
|
||||
private int Speed;
|
||||
public int GetSpeed(){
|
||||
return Speed;
|
||||
}
|
||||
private void SetSpeed(int speed){
|
||||
Speed = speed;
|
||||
}
|
||||
private double Weight;
|
||||
public double GetWeight(){
|
||||
return Weight;
|
||||
}
|
||||
private void SetWeight(int weight){
|
||||
Weight = weight;
|
||||
}
|
||||
private Color BodyColor;
|
||||
public Color GetBodyColor(){
|
||||
return BodyColor;
|
||||
}
|
||||
private void SetBodyColor(Color bodyColor){
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
private Color AdditionlaColor;
|
||||
public Color GetAddColor(){
|
||||
return AdditionlaColor;
|
||||
}
|
||||
private void SetAddColor(Color addColor){
|
||||
AdditionlaColor = addColor;
|
||||
}
|
||||
private boolean Pipes;
|
||||
public boolean GetPipes(){
|
||||
return Pipes;
|
||||
}
|
||||
private void SetPipes(boolean pipes){
|
||||
Pipes = pipes;
|
||||
}
|
||||
private boolean Section;
|
||||
public boolean GetSection(){
|
||||
return Section;
|
||||
}
|
||||
private void SetSection(boolean section){
|
||||
Section = section;
|
||||
}
|
||||
private double Step;
|
||||
public double GetStep() {
|
||||
return (double)Speed * 100 / Weight;
|
||||
}
|
||||
public void Init(int speed, double weight, Color bodyColor, Color addColor, boolean pipes, boolean section){
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionlaColor = addColor;
|
||||
Pipes = pipes;
|
||||
Section = section;
|
||||
}
|
||||
}
|
116
src/FormWarmlyShip.java
Normal file
116
src/FormWarmlyShip.java
Normal file
@ -0,0 +1,116 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.*;
|
||||
|
||||
public class FormWarmlyShip{
|
||||
private DrawingShip _drawingShip;
|
||||
Canvas canv;
|
||||
public void Draw(){
|
||||
canv.repaint();
|
||||
}
|
||||
public FormWarmlyShip(){
|
||||
JFrame frame = new JFrame("Warmly Ship");
|
||||
JButton buttonCreate = new JButton("Создать");
|
||||
buttonCreate.setFocusPainted(false);
|
||||
buttonCreate.setContentAreaFilled(false);
|
||||
JButton buttonUp = new JButton();
|
||||
buttonUp.setFocusPainted(false); //контур вокруг текста
|
||||
buttonUp.setContentAreaFilled(false); //раскраска конпки
|
||||
buttonUp.setName("up"); //имя кнопки при обработке нажания
|
||||
buttonUp.setIcon(new ImageIcon(((new ImageIcon("resources/upper-arrow.png")).getImage()).getScaledInstance(35, 35, java.awt.Image.SCALE_SMOOTH)));
|
||||
JButton buttonDown = new JButton();
|
||||
buttonDown.setFocusPainted(false);
|
||||
buttonDown.setContentAreaFilled(false);
|
||||
buttonDown.setName("down");
|
||||
buttonDown.setIcon(new ImageIcon(((new ImageIcon("resources/down-arrow.png")).getImage()).getScaledInstance(35, 35, java.awt.Image.SCALE_SMOOTH)));
|
||||
JButton buttonLeft = new JButton();
|
||||
buttonLeft.setFocusPainted(false);
|
||||
buttonLeft.setContentAreaFilled(false);
|
||||
buttonLeft.setName("left");
|
||||
buttonLeft.setIcon(new ImageIcon(((new ImageIcon("resources/left-arrow.png")).getImage()).getScaledInstance(35, 35, java.awt.Image.SCALE_SMOOTH)));
|
||||
JButton buttonRight = new JButton();
|
||||
buttonRight.setFocusPainted(false);
|
||||
buttonRight.setContentAreaFilled(false);
|
||||
buttonRight.setName("right");
|
||||
buttonRight.setIcon(new ImageIcon(((new ImageIcon("resources/right-arrow.png")).getImage()).getScaledInstance(35, 35, java.awt.Image.SCALE_SMOOTH)));
|
||||
buttonCreate.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println(e.getActionCommand());
|
||||
Random random = new Random();
|
||||
_drawingShip = new DrawingShip();
|
||||
_drawingShip.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.nextBoolean(), random.nextBoolean(), 900, 460, random.nextInt(3) + 1);
|
||||
_drawingShip.SetPosition(random.nextInt(90) + 10, random.nextInt(90) + 10);
|
||||
canv._drawingShip = _drawingShip;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
);
|
||||
ActionListener actionListener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println(((JButton)(e.getSource())).getName());
|
||||
if (_drawingShip == null){
|
||||
return;
|
||||
}
|
||||
switch ((((JButton)(e.getSource())).getName())){
|
||||
case "up":
|
||||
_drawingShip.MoveTransport(Direction.Up);
|
||||
break;
|
||||
case "down":
|
||||
_drawingShip.MoveTransport(Direction.Down);
|
||||
break;
|
||||
case "left":
|
||||
_drawingShip.MoveTransport(Direction.Left);
|
||||
break;
|
||||
case "right":
|
||||
_drawingShip.MoveTransport(Direction.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
};
|
||||
buttonUp.addActionListener(actionListener);
|
||||
buttonDown.addActionListener(actionListener);
|
||||
buttonLeft.addActionListener(actionListener);
|
||||
buttonRight.addActionListener(actionListener);
|
||||
frame.setSize(920, 500);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setLayout(null);
|
||||
canv = new Canvas();
|
||||
canv.setBounds(0, 0, 900, 500);
|
||||
buttonCreate.setBounds(10, 400, 100, 40);
|
||||
buttonUp.setBounds(800, 360, 40, 40);
|
||||
buttonDown.setBounds(800, 400, 40, 40);
|
||||
buttonLeft.setBounds(760, 400, 40, 40);
|
||||
buttonRight.setBounds(840, 400, 40, 40);
|
||||
frame.add(canv);
|
||||
frame.add(buttonCreate);
|
||||
frame.add(buttonUp);
|
||||
frame.add(buttonDown);
|
||||
frame.add(buttonLeft);
|
||||
frame.add(buttonRight);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
class Canvas extends JComponent{
|
||||
public DrawingShip _drawingShip;
|
||||
public Canvas(){}
|
||||
|
||||
public void paintComponent(Graphics g){
|
||||
if (_drawingShip == null){
|
||||
return;
|
||||
}
|
||||
super.paintComponents(g);
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
_drawingShip.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello world!");
|
||||
new FormWarmlyShip();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user
Имеется дублирующийся код