difficult

This commit is contained in:
Timourka 2023-10-09 21:18:09 +04:00
parent ae7baff597
commit ab1835aec7
6 changed files with 205 additions and 9 deletions

View File

@ -7,7 +7,7 @@ import javax.swing.Timer;
import java.awt.event.*;
public class DrawingTrain {
protected WheelDrawing wheelDrawing;
protected IWheelDrawing wheelDrawing;
/// <summary>
/// Класс-сущность
/// </summary>
@ -51,7 +51,21 @@ public class DrawingTrain {
if (_pictureHeight < _locoHeight || _pictureWidth < _locoWidth)
return;
EntityTrain = new EntityTrain(speed, weight, bodyColor, _numWheel);
wheelDrawing = new WheelDrawing();
Random random = new Random();
switch(random.nextInt(0, 3)){
case 0:
wheelDrawing = new WheelDrawingSimple();
break;
case 1:
wheelDrawing = new WheelDrawingBalls();
break;
case 2:
wheelDrawing = new WheelDrawingDavidStar();
break;
default:
wheelDrawing = new WheelDrawingSimple();
break;
}
wheelDrawing.setNumWheel(_numWheel);
}
/// <summary>
@ -188,6 +202,6 @@ _startPosY+12,_startPosY+12,_startPosY+30,_startPosY+30
g2d.drawRect(_startPosX + 72, _startPosY + 12, 6, 7);
//wheels
wheelDrawing.Draw(_startPosX, _startPosY, false, null, g2d);
wheelDrawing.Draw(_startPosX, _startPosY, false, EntityTrain.BodyColor, g2d);
}
}

View File

@ -11,7 +11,7 @@ public class FormTrain{
private AbstractStrategy abstractStrategy;
Canvas canv;
static int pictureBoxWidth = 980;
static int pictureBoxHeight = 560;
static int pictureBoxHeight = 580;
public void Draw(){
canv.repaint();
@ -127,8 +127,8 @@ public class FormTrain{
random.nextInt(1000, 3000),
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
random.nextInt(2, 5),
1000,
560);
pictureBoxWidth,
pictureBoxHeight);
_drawingTrain.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
canv._drawingTrain = _drawingTrain;
Draw();

View File

@ -0,0 +1,15 @@
package laba1Loco;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.event.*;
public interface IWheelDrawing{
public NumWheel getNumWheel();
public void setNumWheel(int kwheel);
public void Draw(int _startPosX, int _startPosY, boolean fuelTank, Color color, Graphics2D g2d);
}

View File

@ -0,0 +1,80 @@
package laba1Loco;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.event.*;
public class WheelDrawingBalls implements IWheelDrawing{
private NumWheel numWheel;
public NumWheel getNumWheel() {
return numWheel;
}
public void setNumWheel(int kwheel){
switch(kwheel){
case 2:
numWheel = NumWheel.TwoWheel;
break;
case 3:
numWheel = NumWheel.ThreeWheel;
break;
case 4:
numWheel = NumWheel.FourWheel;
break;
default:
numWheel = NumWheel.TwoWheel;
System.out.println("ВСё плохо, колво колёс почему то не соответтвовало критериям, количество колёс:" + Integer.toString(kwheel) + "но вывели мы как будто их было 2");
break;
}
}
private void DrawWheel(int _startPosX, int _startPosY, Color color, Graphics2D g2d){
g2d.setColor(color);
g2d.fillOval(_startPosX, _startPosY, 8, 8);
g2d.setColor(Color.PINK);
g2d.fillOval( _startPosX+3, _startPosY+1, 2, 3);
g2d.fillOval( _startPosX+1, _startPosY+4, 2, 2);
g2d.fillOval( _startPosX+6, _startPosY+4, 2, 2);
}
public void Draw(int _startPosX, int _startPosY, boolean fuelTank, Color color, Graphics2D g2d){
DrawWheel(_startPosX + 3, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 26, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 46, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 72, _startPosY + 34, color, g2d);
if (numWheel == NumWheel.TwoWheel){
DrawWheel(_startPosX + 14, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 59, _startPosY + 34, color, g2d);
}
if (numWheel == NumWheel.FourWheel){
DrawWheel(_startPosX + 11, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 18, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 55, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 63, _startPosY + 34, color, g2d);
}
if (fuelTank){
DrawWheel(_startPosX + 3+85, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 26+85, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 46+85, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 72+85, _startPosY + 34, color, g2d);
if (numWheel == NumWheel.TwoWheel){
DrawWheel(_startPosX + 14+85, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 59+85, _startPosY + 34, color, g2d);
}
if (numWheel == NumWheel.FourWheel){
DrawWheel(_startPosX + 11+85, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 18+85, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 55+85, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 63+85, _startPosY + 34, color, g2d);
}
}
}
}

View File

@ -0,0 +1,87 @@
package laba1Loco;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.event.*;
public class WheelDrawingDavidStar implements IWheelDrawing{
private NumWheel numWheel;
public NumWheel getNumWheel() {
return numWheel;
}
public void setNumWheel(int kwheel){
switch(kwheel){
case 2:
numWheel = NumWheel.TwoWheel;
break;
case 3:
numWheel = NumWheel.ThreeWheel;
break;
case 4:
numWheel = NumWheel.FourWheel;
break;
default:
numWheel = NumWheel.TwoWheel;
System.out.println("ВСё плохо, колво колёс почему то не соответтвовало критериям, количество колёс:" + Integer.toString(kwheel) + "но вывели мы как будто их было 2");
break;
}
}
private void DrawWheel(int _startPosX, int _startPosY, Color color, Graphics2D g2d){
g2d.setColor(color);
g2d.fillOval(_startPosX, _startPosY, 8, 8);
g2d.setColor(Color.WHITE);
g2d.drawPolygon(new int[]{
_startPosX + 1, _startPosX + 7, _startPosX + 3
}, new int[]{
_startPosY + 2, _startPosY + 2, _startPosY + 7
}, 3);
g2d.drawPolygon(new int[]{
_startPosX + 1, _startPosX + 7, _startPosX + 4
}, new int[]{
_startPosY + 6, _startPosY + 6, _startPosY + 1
}, 3);
}
public void Draw(int _startPosX, int _startPosY, boolean fuelTank, Color color, Graphics2D g2d){
DrawWheel(_startPosX + 3, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 26, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 46, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 72, _startPosY + 34, color, g2d);
if (numWheel == NumWheel.TwoWheel){
DrawWheel(_startPosX + 14, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 59, _startPosY + 34, color, g2d);
}
if (numWheel == NumWheel.FourWheel){
DrawWheel(_startPosX + 11, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 18, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 55, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 63, _startPosY + 34, color, g2d);
}
if (fuelTank){
DrawWheel(_startPosX + 3+85, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 26+85, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 46+85, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 72+85, _startPosY + 34, color, g2d);
if (numWheel == NumWheel.TwoWheel){
DrawWheel(_startPosX + 14+85, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 59+85, _startPosY + 34, color, g2d);
}
if (numWheel == NumWheel.FourWheel){
DrawWheel(_startPosX + 11+85, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 18+85, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 55+85, _startPosY + 34, color, g2d);
DrawWheel(_startPosX + 63+85, _startPosY + 34, color, g2d);
}
}
}
}

View File

@ -6,10 +6,10 @@ import javax.swing.*;
import javax.swing.Timer;
import java.awt.event.*;
public class WheelDrawing{
public class WheelDrawingSimple implements IWheelDrawing{
private NumWheel numWheel;
public NumWheel getSomeProperty() {
public NumWheel getNumWheel() {
return numWheel;
}
@ -31,7 +31,7 @@ public class WheelDrawing{
}
}
void Draw(int _startPosX, int _startPosY, boolean fuelTank, Color color, Graphics2D g2d){
public void Draw(int _startPosX, int _startPosY, boolean fuelTank, Color color, Graphics2D g2d){
g2d.setColor(color);