Compare commits
2 Commits
bf246e17d4
...
400672b6dd
Author | SHA1 | Date | |
---|---|---|---|
400672b6dd | |||
18a72916b6 |
@ -3,7 +3,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
class DrawningLocomotive {
|
class DrawningLocomotive {
|
||||||
public EntityLocomotive Locomotive;
|
public EntityLocomotive Locomotive;
|
||||||
public ExtraWheelsDraw extraWheelsDraw;
|
public IDrawningExtra[] drawningExtra;
|
||||||
/// Левая координата отрисовки локомотива
|
/// Левая координата отрисовки локомотива
|
||||||
protected float _startPosX;
|
protected float _startPosX;
|
||||||
/// Верхняя координата отрисовки локомотива
|
/// Верхняя координата отрисовки локомотива
|
||||||
@ -20,7 +20,10 @@ class DrawningLocomotive {
|
|||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
public DrawningLocomotive(int speed, float weight, Color bodyColor)
|
public DrawningLocomotive(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
extraWheelsDraw = new ExtraWheelsDraw(random.nextInt(3), bodyColor);
|
int randExtra = random.nextInt(3);
|
||||||
|
drawningExtra = new IDrawningExtra[2];
|
||||||
|
drawningExtra[0] = new ExtraWheelsDraw(randExtra, bodyColor);
|
||||||
|
drawningExtra[1] = random.nextBoolean() ? new ExtraRoundWheelDraw(randExtra) : new ExtraStarWheelDraw(randExtra);
|
||||||
Locomotive = new EntityLocomotive(speed, weight, bodyColor);
|
Locomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,18 +102,20 @@ class DrawningLocomotive {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//тело
|
//тело
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawRect((int)_startPosX , (int)_startPosY, 110 - 10, 50 - 10);
|
|
||||||
//окна
|
|
||||||
g.setColor(Locomotive.getBodyColor());
|
g.setColor(Locomotive.getBodyColor());
|
||||||
|
g.fillRect((int)_startPosX , (int)_startPosY, 110 - 10, 50 - 10);
|
||||||
|
//окна
|
||||||
|
g.setColor(Color.BLUE);
|
||||||
g.fillRect((int)_startPosX + 10, (int)_startPosY + 10, 10, 10);
|
g.fillRect((int)_startPosX + 10, (int)_startPosY + 10, 10, 10);
|
||||||
g.fillRect((int)_startPosX + 30, (int)_startPosY + 10, 10, 10);
|
g.fillRect((int)_startPosX + 30, (int)_startPosY + 10, 10, 10);
|
||||||
g.fillRect((int)_startPosX + 80, (int)_startPosY + 10, 10, 10);
|
g.fillRect((int)_startPosX + 80, (int)_startPosY + 10, 10, 10);
|
||||||
//дверь
|
//дверь
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
g.drawRect( (int)_startPosX + 50, (int)_startPosY + 10, 10, 20);
|
g.fillRect( (int)_startPosX + 50, (int)_startPosY + 10, 10, 20);
|
||||||
//колеса
|
//колеса
|
||||||
extraWheelsDraw.DrawWheels((int)_startPosX, (int)_startPosY, g);
|
drawningExtra[0].DrawExtra((int)_startPosX, (int)_startPosY, g);
|
||||||
|
//extra
|
||||||
|
drawningExtra[1].DrawExtra((int)_startPosX, (int)_startPosY, g);
|
||||||
//движок
|
//движок
|
||||||
g.setColor(Locomotive.getBodyColor());
|
g.setColor(Locomotive.getBodyColor());
|
||||||
g.fillRect((int)_startPosX + 100, (int)_startPosY + 10, 10, 30);
|
g.fillRect((int)_startPosX + 100, (int)_startPosY + 10, 10, 30);
|
||||||
|
@ -23,7 +23,7 @@ public class DrawningWarmlyLocomotive extends DrawningLocomotive{
|
|||||||
|
|
||||||
if (warmlyLocomotive.FuelStorage)
|
if (warmlyLocomotive.FuelStorage)
|
||||||
{
|
{
|
||||||
g.fillRect((int)_startPosX + 110, (int)_startPosY + 10, 10, 50);
|
g.fillRect((int)_startPosX + 120, (int)_startPosY + 10, 10, 50);
|
||||||
g.fillRect((int)_startPosX + 110, (int)_startPosY + 40, 20, 20);
|
g.fillRect((int)_startPosX + 110, (int)_startPosY + 40, 20, 20);
|
||||||
g.fillRect((int)_startPosX + 110, (int)_startPosY, 30, 10);
|
g.fillRect((int)_startPosX + 110, (int)_startPosY, 30, 10);
|
||||||
}
|
}
|
||||||
|
40
ExtraRoundWheelDraw.java
Normal file
40
ExtraRoundWheelDraw.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class ExtraRoundWheelDraw implements IDrawningExtra{
|
||||||
|
private WheelsCount wheelsCount = WheelsCount.Two;
|
||||||
|
public void setExtraNum(int num) {
|
||||||
|
switch (num) {
|
||||||
|
case 0: {
|
||||||
|
wheelsCount = WheelsCount.Three;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 1: {
|
||||||
|
wheelsCount = WheelsCount.Four;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExtraRoundWheelDraw (int num) {
|
||||||
|
setExtraNum(num);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawExtra(int startPosX, int startPosY, Graphics2D g) {
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.fillOval(startPosX + 5, startPosY + 35, 10, 10);
|
||||||
|
g.fillOval(startPosX + 95, startPosY + 35, 10, 10);
|
||||||
|
switch (wheelsCount) {
|
||||||
|
case Four: {
|
||||||
|
g.fillOval(startPosX + 75, startPosY + 35, 10, 10);
|
||||||
|
}
|
||||||
|
case Three: {
|
||||||
|
g.fillOval(startPosX + 25, startPosY + 35, 10, 10);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
47
ExtraStarWheelDraw.java
Normal file
47
ExtraStarWheelDraw.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class ExtraStarWheelDraw implements IDrawningExtra{
|
||||||
|
private WheelsCount wheelsCount = WheelsCount.Two;
|
||||||
|
public void setExtraNum(int num) {
|
||||||
|
switch (num) {
|
||||||
|
case 0: {
|
||||||
|
wheelsCount = WheelsCount.Three;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 1: {
|
||||||
|
wheelsCount = WheelsCount.Four;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExtraStarWheelDraw (int num) {
|
||||||
|
setExtraNum(num);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawExtra(int startPosX, int startPosY, Graphics2D g) {
|
||||||
|
DrawStarOnWheel(startPosX, startPosY + 30, g);
|
||||||
|
DrawStarOnWheel(startPosX + 90, startPosY + 30, g);
|
||||||
|
switch (wheelsCount) {
|
||||||
|
case Four: {
|
||||||
|
DrawStarOnWheel(startPosX + 70, startPosY + 30, g);
|
||||||
|
}
|
||||||
|
case Three: {
|
||||||
|
DrawStarOnWheel(startPosX + 20, startPosY + 30, g);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawStarOnWheel(int startPosX, int startPosY, Graphics2D g) {
|
||||||
|
g.drawLine(startPosX + 10, startPosY, startPosX + 15, startPosY + 17);
|
||||||
|
g.drawLine(startPosX + 10, startPosY, startPosX + 5, startPosY + 17);
|
||||||
|
g.drawLine(startPosX + 15, startPosY + 17, startPosX + 2, startPosY + 8);
|
||||||
|
g.drawLine(startPosX + 5, startPosY + 17, startPosX + 18, startPosY + 8);
|
||||||
|
g.drawLine(startPosX + 2, startPosY + 8, startPosX + 18, startPosY + 8);
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class ExtraWheelsDraw {
|
public class ExtraWheelsDraw implements IDrawningExtra{
|
||||||
private WheelsCount wheelsCount = WheelsCount.Two;
|
private WheelsCount wheelsCount = WheelsCount.Two;
|
||||||
public void setWheelsNum(int num) {
|
public void setExtraNum(int num) {
|
||||||
switch (num) {
|
switch (num) {
|
||||||
case 0: {
|
case 0: {
|
||||||
wheelsCount = WheelsCount.Three;
|
wheelsCount = WheelsCount.Three;
|
||||||
@ -19,20 +19,28 @@ public class ExtraWheelsDraw {
|
|||||||
private Color color;
|
private Color color;
|
||||||
|
|
||||||
public ExtraWheelsDraw(int num, Color color) {
|
public ExtraWheelsDraw(int num, Color color) {
|
||||||
setWheelsNum(num);
|
setExtraNum(num);
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawWheels(int startPosX, int startPosY, Graphics2D g) {
|
public void DrawExtra(int startPosX, int startPosY, Graphics2D g) {
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawOval(startPosX, startPosY + 30, 20, 20);
|
||||||
|
g.drawOval(startPosX + 90, startPosY + 30, 20, 20);
|
||||||
g.setColor(color);
|
g.setColor(color);
|
||||||
g.drawOval(startPosX, startPosY + 40, 10, 10);
|
g.fillOval(startPosX, startPosY + 30, 20, 20);
|
||||||
g.drawOval(startPosX + 90, startPosY + 40, 10, 10);
|
g.fillOval(startPosX + 90, startPosY + 30, 20, 20);
|
||||||
switch (wheelsCount) {
|
switch (wheelsCount) {
|
||||||
case Four: {
|
case Four: {
|
||||||
g.drawOval(startPosX + 70, startPosY + 40, 10, 10);
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawOval(startPosX + 70, startPosY + 30, 20, 20);
|
||||||
|
g.setColor(color);
|
||||||
|
g.fillOval(startPosX + 70, startPosY + 30, 20, 20);
|
||||||
}
|
}
|
||||||
case Three: {
|
case Three: {
|
||||||
g.drawOval(startPosX + 20, startPosY + 40, 10, 10);
|
g.fillOval(startPosX + 20, startPosY + 30, 20, 20);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawOval(startPosX + 20, startPosY + 30, 20, 20);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
6
IDrawningExtra.java
Normal file
6
IDrawningExtra.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public interface IDrawningExtra {
|
||||||
|
void setExtraNum(int num);
|
||||||
|
void DrawExtra(int startPosX, int startPosY, Graphics2D g);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user