-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed impressive level of duplication #2
- Loading branch information
1 parent
883c47d
commit f3ec811
Showing
20 changed files
with
1,881 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main.java.drawing; | ||
|
||
import javax.swing.*; | ||
|
||
import main.java.control.ViewGame; | ||
|
||
import java.awt.*; | ||
|
||
/** | ||
* CisternDraw class | ||
*/ | ||
public class CisternDraw extends Drawable { | ||
JButton cistern = new JButton(); | ||
JButton cisternB = new JButton(); | ||
|
||
/** | ||
* CisternDraw constructor | ||
* @param tmpX | ||
* @param tmpY | ||
*/ | ||
public CisternDraw(int tmpX, int tmpY) { | ||
x = tmpX; | ||
y = tmpY; | ||
cistern.setVisible(true); | ||
cistern.setBackground(new Color(150, 75, 0)); | ||
|
||
ViewGame.buttonToElement.put(cisternB, this); | ||
cisternB.addActionListener(ViewGame.selectListener); | ||
} | ||
|
||
/** | ||
* Draw method | ||
* @param panel | ||
* @param g | ||
*/ | ||
@Override | ||
public void Draw(JPanel panel, Graphics2D g) { | ||
cistern.setBounds(x, y, 50, 50); | ||
cistern.setBorder(BorderFactory.createLineBorder(Color.blue, 5)); | ||
|
||
if(ViewGame.getChosen()) { | ||
cisternB.setVisible(true); | ||
cisternB.setBackground(new Color(255, 0, 0)); | ||
cisternB.setBounds(x, y, 50, 50); | ||
cisternB.setBorder(BorderFactory.createLineBorder(Color.blue, 5)); | ||
panel.add(cisternB); | ||
} else { | ||
cisternB.setVisible(false); | ||
panel.remove(cisternB); | ||
} | ||
|
||
panel.add(cistern); | ||
panel.repaint(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main.java.drawing; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
|
||
/** | ||
* Drawable class | ||
*/ | ||
public abstract class Drawable { | ||
protected int x; | ||
protected int y; | ||
|
||
/** | ||
* Get X method | ||
* @return | ||
*/ | ||
public int getX() { | ||
return x; | ||
} | ||
|
||
/** | ||
* Get Y method | ||
* @return | ||
*/ | ||
public int getY() { | ||
return y; | ||
} | ||
|
||
/** | ||
* Draw method | ||
* @param panel | ||
* @param g | ||
*/ | ||
public void Draw(JPanel panel, Graphics2D g) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package main.java.drawing; | ||
|
||
import main.java.control.Controller; | ||
import main.java.control.ViewGame; | ||
import main.java.fields.Field; | ||
import main.java.fields.Pipe; | ||
import main.java.fields.activefields.Cistern; | ||
import main.java.fields.activefields.Pump; | ||
import main.java.fields.activefields.Spring; | ||
import main.java.players.Mechanic; | ||
import main.java.players.Player; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.util.ArrayList; | ||
|
||
/** | ||
* Class for drawing the mechanic. | ||
* */ | ||
public class MechanicDraw extends Drawable { | ||
String mecName = ""; | ||
JButton mec = new JButton(); | ||
|
||
/** | ||
* Constructor for the mechanic. | ||
* @param tmpX X coordinate of the mechanic. | ||
* @param tmpY Y coordinate of the mechanic. | ||
* */ | ||
public MechanicDraw(int tmpX, int tmpY) { | ||
x = tmpX; | ||
y = tmpY; | ||
mec.setVisible(true); | ||
} | ||
|
||
/** | ||
* Draw method for the mechanic. | ||
* @param panel | ||
* @param g | ||
*/ | ||
@Override | ||
public void Draw(JPanel panel, Graphics2D g) { | ||
Mechanic m = (Mechanic)ViewGame.objectDrawNames.get(this); | ||
Player current = Controller.getActivePlayer(); | ||
mecName = Controller.objectReverseNames.get(m); | ||
mec.setText(mecName); | ||
Field f = m.getStandingField(); | ||
if (f instanceof Pipe) { | ||
PipeDraw pd = (PipeDraw)ViewGame.objectDrawReverseNames.get(f); | ||
ArrayList<Player> players = f.getPlayers(); | ||
int i = players.indexOf(m); | ||
x = (pd.getxFrom()+pd.getxTo())/2-25; | ||
y = (pd.getYFrom()+pd.getYTo())/2 - (i+1)*25; | ||
} | ||
else if (f instanceof Pump) { | ||
PumpDraw pd = (PumpDraw)ViewGame.objectDrawReverseNames.get(f); | ||
ArrayList<Player> players = f.getPlayers(); | ||
int i = players.indexOf(m); | ||
x = pd.getX(); | ||
y = pd.getY() - (i+1)*25; | ||
} | ||
else if (f instanceof Cistern) { | ||
CisternDraw pd = (CisternDraw)ViewGame.objectDrawReverseNames.get(f); | ||
ArrayList<Player> players = f.getPlayers(); | ||
int i = players.indexOf(m); | ||
x = pd.getX(); | ||
y = pd.getY() - (i+1)*25; | ||
} | ||
else if (f instanceof Spring) { | ||
SpringDraw pd = (SpringDraw)ViewGame.objectDrawReverseNames.get(f); | ||
ArrayList<Player> players = f.getPlayers(); | ||
int i = players.indexOf(m); | ||
x = pd.getX(); | ||
y = pd.getY() - (i+1)*25; | ||
} | ||
mec.setBounds(x, y, 50, 20); | ||
if (m.equals(current)) mec.setBorder(BorderFactory.createLineBorder(Color.green, 5)); | ||
else mec.setBorder(BorderFactory.createLineBorder(Color.red, 5)); | ||
panel.add(mec); | ||
panel.repaint(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package main.java.drawing; | ||
|
||
import javax.swing.*; | ||
|
||
import main.java.control.ViewGame; | ||
|
||
import java.awt.*; | ||
|
||
/** | ||
* PipeDraw class | ||
*/ | ||
public class PipeDraw extends Drawable { | ||
private int xFrom; | ||
private int xTo; | ||
private int yFrom; | ||
private int yTo; | ||
JButton pipeB = new JButton(); | ||
|
||
/** | ||
* Getters | ||
* @return xFrom, xTo, yFrom, yTo | ||
*/ | ||
public int getxFrom() { return xFrom; } | ||
public int getxTo() { return xTo; } | ||
public int getYFrom() { return yFrom; } | ||
public int getYTo() { return yTo; } | ||
|
||
/** | ||
* Constructor for PipeDraw | ||
* @param x1 | ||
* @param y1 | ||
* @param x2 | ||
* @param y2 | ||
*/ | ||
public PipeDraw(int x1, int y1, int x2, int y2) { | ||
xFrom = x1; | ||
yFrom = y1; | ||
xTo = x2; | ||
yTo = y2; | ||
|
||
ViewGame.buttonToElement.put(pipeB, this); | ||
pipeB.addActionListener(ViewGame.selectListener); | ||
} | ||
public void setCoords(Drawable pumpFrom, Drawable pumpTo) { | ||
int fromX; | ||
int toX; | ||
int fromY; | ||
int toY; | ||
|
||
fromX = pumpFrom.getX(); | ||
fromY = pumpFrom.getY(); | ||
toX = pumpTo.getX(); | ||
toY = pumpTo.getY(); | ||
|
||
//A cél pumpa | ||
if(toY < fromY) { | ||
//felettünk van | ||
toY += 50; | ||
} else if(toY > fromY) { | ||
//alattunk | ||
fromY += 50; | ||
} else { | ||
//velünk egy magasságban | ||
toY += 25; | ||
fromY += 25; | ||
|
||
} | ||
if(toX < fromX) { | ||
//balra | ||
toX += 50; | ||
} else if(fromX > toX) { | ||
//jobbra | ||
fromX += 50; | ||
} else { | ||
//egy oszlopban | ||
toX += 25; | ||
fromX += 25; | ||
} | ||
setCoords(fromX, fromY, toX, toY); | ||
|
||
|
||
} | ||
public void setCoords(int x1, int y1, int x2, int y2) { | ||
xFrom = x1; | ||
yFrom = y1; | ||
xTo = x2; | ||
yTo = y2; | ||
} | ||
|
||
/** | ||
* Draw method | ||
* @param panel | ||
* @param g2d | ||
*/ | ||
@Override | ||
public void Draw(JPanel panel, Graphics2D g2d) { | ||
|
||
if(ViewGame.getChosen()) { | ||
pipeB.setVisible(true); | ||
pipeB.setBackground(new Color(255, 0, 0)); | ||
pipeB.setBounds(xFrom + (xTo - xFrom) / 2 - 25, yFrom + (yTo - yFrom) / 2 - 12, 50, 25); | ||
pipeB.setBorder(BorderFactory.createLineBorder(Color.black, 5)); | ||
panel.add(pipeB); | ||
} else { | ||
pipeB.setVisible(false); | ||
panel.remove(pipeB); | ||
} | ||
|
||
panel.repaint(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main.java.drawing; | ||
|
||
import main.java.control.ViewGame; | ||
import main.java.fields.activefields.Pump; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
|
||
/** | ||
* Class for drawing the mechanic. | ||
* */ | ||
public class PumpDraw extends Drawable { | ||
JButton pump = new JButton(); | ||
JButton pumpB = new JButton(); | ||
/** | ||
* Constructor for the mechanic. | ||
* @param tmpX X coordinate of the mechanic. | ||
* @param tmpY Y coordinate of the mechanic. | ||
* */ | ||
public PumpDraw(int tmpX, int tmpY) { | ||
x = tmpX; | ||
y = tmpY; | ||
pump.setVisible(true); | ||
pump.setBackground(new Color(150, 75, 0)); | ||
|
||
ViewGame.buttonToElement.put(pumpB, this); | ||
pumpB.addActionListener(ViewGame.selectListener); | ||
} | ||
/** | ||
* Draws the mechanic. | ||
* @param panel The panel to draw on. | ||
* @param g The graphics to draw with. | ||
* */ | ||
@Override | ||
public void Draw(JPanel panel, Graphics2D g) { | ||
pump.setBounds(x, y, 50, 50); | ||
Pump p = (Pump)ViewGame.objectDrawNames.get(this); | ||
|
||
if (p.isBroken()) pump.setBorder(BorderFactory.createDashedBorder(Color.black, 5, 2, 2, false)); | ||
else pump.setBorder(BorderFactory.createLineBorder(Color.black, 5)); | ||
|
||
if(ViewGame.getChosen()) { | ||
pumpB.setVisible(true); | ||
pumpB.setBackground(new Color(255, 0, 0)); | ||
pumpB.setBounds(x, y, 50, 50); | ||
if (p.isBroken()) pumpB.setBorder(BorderFactory.createDashedBorder(Color.black, 5, 2, 2, false)); | ||
else pumpB.setBorder(BorderFactory.createLineBorder(Color.black, 5)); | ||
panel.add(pumpB); | ||
} else { | ||
pumpB.setVisible(false); | ||
panel.remove(pumpB); | ||
} | ||
|
||
panel.add(pump); | ||
panel.repaint(); | ||
} | ||
} |
Oops, something went wrong.