reducing repetitive code
This commit is contained in:
parent
29e3f74627
commit
bcf703d795
@ -26,71 +26,28 @@ public class DrawningPortholesCircle implements IDrawningPortholes {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawPortholes(Graphics2D g, int posX, int posY){
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(posX, posY, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawOval(posX, posY, 3, 3);
|
||||
}
|
||||
public void Draw (Graphics2D g, int _startPosX, int _startPosY) {
|
||||
g.setColor(Color.BLACK);
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
drawPortholes(g, _startPosX + 19 + i * 8, _startPosY + 21);
|
||||
}
|
||||
if (_porthole == CountPortholes.Ten) {
|
||||
// цикл
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
drawPortholes(g, _startPosX + 15 + i * 5, _startPosY + 26);
|
||||
drawPortholes(g, _startPosX + 70 + i * 5, _startPosY + 26);
|
||||
}
|
||||
if (_porthole == CountPortholes.Twenty) {
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawOval(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawOval(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (_porthole == CountPortholes.Thirty){
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawOval(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawOval(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
|
||||
}
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(_startPosX + 19 + i*8, _startPosY+31, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawOval(_startPosX + 19 + i*8, _startPosY+31, 3, 3);
|
||||
}
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
drawPortholes(g, _startPosX + 19 + i * 8, _startPosY + 31);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,75 +4,10 @@ import Entities.CountPortholes;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningPortholesHeart implements IDrawningPortholes {
|
||||
private CountPortholes _porthole;
|
||||
|
||||
public CountPortholes getCount()
|
||||
{
|
||||
return _porthole;
|
||||
}
|
||||
public void SetCount (int count) {
|
||||
switch (count) {
|
||||
case 10:
|
||||
_porthole = CountPortholes.Ten;
|
||||
break;
|
||||
case 20:
|
||||
_porthole = CountPortholes.Twenty;
|
||||
break;
|
||||
case 30:
|
||||
_porthole = CountPortholes.Thirty;
|
||||
break;
|
||||
default:
|
||||
_porthole = CountPortholes.Ten;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw (Graphics2D g, int _startPosX, int _startPosY) {
|
||||
g.setColor(Color.BLACK);
|
||||
if (_porthole == CountPortholes.Ten) {
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
drawHeart(g, _startPosX + 19 + i*8, _startPosY + 20);
|
||||
}
|
||||
}
|
||||
if (_porthole == CountPortholes.Twenty) {
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
drawHeart(g, _startPosX + 19 + i*8, _startPosY + 20);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
drawHeart(g, _startPosX + 12 + i*6, _startPosY + 26);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
drawHeart(g, _startPosX + 70 + i*6, _startPosY + 26);
|
||||
}
|
||||
}
|
||||
if (_porthole == CountPortholes.Thirty){
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
drawHeart(g, _startPosX + 19 + i*8, _startPosY + 20);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
drawHeart(g, _startPosX + 12 + i*6, _startPosY + 26);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
drawHeart(g, _startPosX + 70 + i*6, _startPosY + 26);
|
||||
}
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
drawHeart(g, _startPosX + 19 + i*8, _startPosY+32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawHeart(Graphics2D g, int _startPosX, int _startPosY){
|
||||
int[] HeartX = {_startPosX+2, _startPosX, _startPosX, _startPosX+1, _startPosX+2, _startPosX+3, _startPosX+5, _startPosX+5};
|
||||
int[] HeartY = {_startPosY+4, _startPosY+2, _startPosY, _startPosY, _startPosY+1, _startPosY, _startPosY, _startPosY+2};
|
||||
public class DrawningPortholesHeart extends DrawningPortholesCircle {
|
||||
protected void drawPortholes(Graphics2D g, int posX, int posY) {
|
||||
int[] HeartX = {posX + 2, posX, posX, posX + 1, posX + 2, posX + 3, posX + 5, posX + 5};
|
||||
int[] HeartY = {posY + 4, posY + 2, posY, posY, posY + 1, posY, posY, posY + 2};
|
||||
g.setColor(Color.cyan);
|
||||
g.fillPolygon(HeartX, HeartY, HeartX.length);
|
||||
g.setColor(Color.black);
|
||||
|
@ -4,94 +4,11 @@ import Entities.CountPortholes;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningPortholesSquare implements IDrawningPortholes {
|
||||
private CountPortholes _porthole;
|
||||
|
||||
public CountPortholes getCount()
|
||||
{
|
||||
return _porthole;
|
||||
}
|
||||
public void SetCount (int count) {
|
||||
switch (count) {
|
||||
case 10:
|
||||
_porthole = CountPortholes.Ten;
|
||||
break;
|
||||
case 20:
|
||||
_porthole = CountPortholes.Twenty;
|
||||
break;
|
||||
case 30:
|
||||
_porthole = CountPortholes.Thirty;
|
||||
break;
|
||||
default:
|
||||
_porthole = CountPortholes.Ten;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw (Graphics2D g, int _startPosX, int _startPosY) {
|
||||
g.setColor(Color.BLACK);
|
||||
if (_porthole == CountPortholes.Ten) {
|
||||
// цикл
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
}
|
||||
}
|
||||
if (_porthole == CountPortholes.Twenty) {
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
|
||||
}
|
||||
}
|
||||
if (_porthole == CountPortholes.Thirty){
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
|
||||
}
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(_startPosX + 19 + i*8, _startPosY+31, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 19 + i*8, _startPosY+31, 3, 3);
|
||||
}
|
||||
}
|
||||
public class DrawningPortholesSquare extends DrawningPortholesCircle {
|
||||
protected void drawPortholes(Graphics2D g, int posX, int posY){
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(posX, posY, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(posX, posY, 3, 3);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user