Added ExtraObjects & their Init.
This commit is contained in:
parent
18a72916b6
commit
400672b6dd
@ -3,7 +3,7 @@ import java.util.Random;
|
||||
|
||||
class DrawningLocomotive {
|
||||
public EntityLocomotive Locomotive;
|
||||
public ExtraWheelsDraw extraWheelsDraw;
|
||||
public IDrawningExtra[] drawningExtra;
|
||||
/// Левая координата отрисовки локомотива
|
||||
protected float _startPosX;
|
||||
/// Верхняя координата отрисовки локомотива
|
||||
@ -20,7 +20,10 @@ class DrawningLocomotive {
|
||||
private final Random random = new Random();
|
||||
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);
|
||||
}
|
||||
|
||||
@ -99,18 +102,20 @@ class DrawningLocomotive {
|
||||
return;
|
||||
}
|
||||
//тело
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect((int)_startPosX , (int)_startPosY, 110 - 10, 50 - 10);
|
||||
//окна
|
||||
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 + 30, (int)_startPosY + 10, 10, 10);
|
||||
g.fillRect((int)_startPosX + 80, (int)_startPosY + 10, 10, 10);
|
||||
//дверь
|
||||
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.DrawExtra((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.fillRect((int)_startPosX + 100, (int)_startPosY + 10, 10, 30);
|
||||
|
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);
|
||||
}
|
||||
}
|
@ -24,15 +24,23 @@ public class ExtraWheelsDraw implements IDrawningExtra{
|
||||
}
|
||||
|
||||
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.drawOval(startPosX, startPosY + 40, 10, 10);
|
||||
g.drawOval(startPosX + 90, startPosY + 40, 10, 10);
|
||||
g.fillOval(startPosX, startPosY + 30, 20, 20);
|
||||
g.fillOval(startPosX + 90, startPosY + 30, 20, 20);
|
||||
switch (wheelsCount) {
|
||||
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: {
|
||||
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;
|
||||
}
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user