PIbd-22. Shabunov O.A. Lab work 02 (Hard) #2

Closed
olshab wants to merge 4 commits from Lab2 into Lab1
5 changed files with 151 additions and 8 deletions
Showing only changes of commit 4d2ce83547 - Show all commits

View File

@ -1,6 +1,5 @@
package AirBomber.Rendering;
import AirBomber.*;
import AirBomber.Entities.*;
import AirBomber.MovementStrategy.*;
import java.awt.*;
@ -22,7 +21,7 @@ public class BomberRendererBase
public int PosX() { return _startPosX; }
public int PosY() { return _startPosY; }
public EngineRenderer EngineRenderer;
public IEngineRenderer EngineRenderer;
public int EntityWidth() { return _bomberWidth; }
public int EntityHeight() { return _bomberHeight; }
@ -37,9 +36,27 @@ public class BomberRendererBase
EntityBomber = new BomberEntityBase(Speed, Weight, BodyColor);
EngineRenderer = new EngineRenderer();
Random Random = new Random();
/** Создание прорисовщика дополнительных элементов */
int EngineRendererVariant = Random.nextInt(1, 4);
switch (EngineRendererVariant) {
case 1:
EngineRenderer = new EngineRenderer();
break;
case 2:
EngineRenderer = new RectangleEngineRenderer();
break;
case 3:
EngineRenderer = new TriangleEngineRenderer();
break;
default:
break;
}
EngineRenderer.SetAmount(Random.nextInt(1, 7));
}
@ -56,9 +73,27 @@ public class BomberRendererBase
EntityBomber = new BomberEntityBase(Speed, Weight, BodyColor);
EngineRenderer = new EngineRenderer();
Random Random = new Random();
/** Создание прорисовщика дополнительных элементов */
int EngineRendererVariant = Random.nextInt(1, 4);
switch (EngineRendererVariant) {
case 1:
EngineRenderer = new EngineRenderer();
break;
case 2:
EngineRenderer = new RectangleEngineRenderer();
break;
case 3:
EngineRenderer = new TriangleEngineRenderer();
break;
default:
break;
}
EngineRenderer.SetAmount(Random.nextInt(1, 7));
}

View File

@ -1,8 +1,9 @@
package AirBomber;
package AirBomber.Rendering;
import java.awt.*;
import AirBomber.EnginesAmount;
public class EngineRenderer
public class EngineRenderer implements IEngineRenderer
{
private EnginesAmount Amount;

View File

@ -0,0 +1,10 @@
package AirBomber.Rendering;
import java.awt.*;
public interface IEngineRenderer
{
public void SetAmount(int Amount);
public void DrawEngines(Graphics g, Color BodyColor, int StartPosX, int StartPosY);
}

View File

@ -0,0 +1,41 @@
package AirBomber.Rendering;
import java.awt.*;
import AirBomber.EnginesAmount;
public class RectangleEngineRenderer implements IEngineRenderer
{
private EnginesAmount Amount;
public void SetAmount(int Amount)
{
if (Amount <= 2)
this.Amount = EnginesAmount.Two;
else if (Amount > 2 && Amount <= 4)
this.Amount = EnginesAmount.Four;
else
this.Amount = EnginesAmount.Six;
}
public void DrawEngines(Graphics g, Color BodyColor, int _startPosX, int _startPosY)
{
g.setColor(BodyColor);
g.fillRect(_startPosX + 83, _startPosY + 50, 30, 15);
g.fillRect(_startPosX + 83, _startPosY + 135, 30, 15);
if (Amount == EnginesAmount.Two)
return;
g.fillRect(_startPosX + 83, _startPosY + 30, 30, 15);
g.fillRect(_startPosX + 83, _startPosY + 155, 30, 15);
if (Amount == EnginesAmount.Four)
return;
g.fillRect(_startPosX + 83, _startPosY + 10, 30, 15);
g.fillRect(_startPosX + 83, _startPosY + 175, 30, 15);
}
}

View File

@ -0,0 +1,56 @@
package AirBomber.Rendering;
import java.awt.*;
import AirBomber.EnginesAmount;
public class TriangleEngineRenderer implements IEngineRenderer
{
private EnginesAmount Amount;
public void SetAmount(int Amount)
{
if (Amount <= 2)
this.Amount = EnginesAmount.Two;
else if (Amount > 2 && Amount <= 4)
this.Amount = EnginesAmount.Four;
else
this.Amount = EnginesAmount.Six;
}
public void DrawEngines(Graphics g, Color BodyColor, int _startPosX, int _startPosY)
{
g.setColor(BodyColor);
int[] FirstTopX = { _startPosX + 83, _startPosX + 113, _startPosX + 83 };
int[] FirstTopY = { _startPosY + 50, _startPosY + 57, _startPosY + 65 };
g.fillPolygon(FirstTopX, FirstTopY, 3);
int[] FirstBottomX = { _startPosX + 83, _startPosX + 113, _startPosX + 83 };
int[] FirstBottomY = { _startPosY + 135, _startPosY + 142, _startPosY + 150 };
g.fillPolygon(FirstBottomX, FirstBottomY, 3);
if (Amount == EnginesAmount.Two)
return;
int[] SecondTopX = { _startPosX + 83, _startPosX + 113, _startPosX + 83 };
int[] SecondTopY = { _startPosY + 30, _startPosY + 37, _startPosY + 45 };
g.fillPolygon(SecondTopX, SecondTopY, 3);
int[] SecondBottomX = { _startPosX + 83, _startPosX + 113, _startPosX + 83 };
int[] SecondBottomY = { _startPosY + 155, _startPosY + 162, _startPosY + 170 };
g.fillPolygon(SecondBottomX, SecondBottomY, 3);
if (Amount == EnginesAmount.Four)
return;
int[] ThirdTopX = { _startPosX + 83, _startPosX + 113, _startPosX + 83 };
int[] ThirdTopY = { _startPosY + 10, _startPosY + 17, _startPosY + 25 };
g.fillPolygon(ThirdTopX, ThirdTopY, 3);
int[] ThirdBottomX = { _startPosX + 83, _startPosX + 113, _startPosX + 83 };
int[] ThirdBottomY = { _startPosY + 175, _startPosY + 182, _startPosY + 190 };
g.fillPolygon(ThirdBottomX, ThirdBottomY, 3);
}
}