|
@ -169,13 +169,13 @@ public class GameLogic extends JPanel { |
|
|
JLabel matchfieldLabel = new JLabel("Spielfeld"); |
|
|
JLabel matchfieldLabel = new JLabel("Spielfeld"); |
|
|
gameInfoContentPanel.add(matchfieldLabel); |
|
|
gameInfoContentPanel.add(matchfieldLabel); |
|
|
|
|
|
|
|
|
matchfieldValue = new JLabel("Eigenes"); |
|
|
|
|
|
|
|
|
matchfieldValue = new JLabel("-"); |
|
|
gameInfoContentPanel.add(matchfieldValue); |
|
|
gameInfoContentPanel.add(matchfieldValue); |
|
|
|
|
|
|
|
|
JLabel moveLabel = new JLabel("Am Zug"); |
|
|
JLabel moveLabel = new JLabel("Am Zug"); |
|
|
gameInfoContentPanel.add(moveLabel); |
|
|
gameInfoContentPanel.add(moveLabel); |
|
|
|
|
|
|
|
|
moveValue = new JLabel("Du"); |
|
|
|
|
|
|
|
|
moveValue = new JLabel("-"); |
|
|
gameInfoContentPanel.add(moveValue); |
|
|
gameInfoContentPanel.add(moveValue); |
|
|
|
|
|
|
|
|
for (int x = 0; x < 10; x++) { |
|
|
for (int x = 0; x < 10; x++) { |
|
@ -194,9 +194,14 @@ public class GameLogic extends JPanel { |
|
|
field.addMouseListener(new MouseAdapter() { |
|
|
field.addMouseListener(new MouseAdapter() { |
|
|
|
|
|
|
|
|
public void mouseClicked(MouseEvent e) { |
|
|
public void mouseClicked(MouseEvent e) { |
|
|
field.setBackground(Color.RED); |
|
|
|
|
|
field.revalidate(); |
|
|
|
|
|
field.repaint(); |
|
|
|
|
|
|
|
|
if (!playerMove) |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
int[] coords = getCoordinateFromLabel(field); |
|
|
|
|
|
int coordX = coords[0]; |
|
|
|
|
|
int coordY = coords[1]; |
|
|
|
|
|
|
|
|
|
|
|
// TODO add shoot function |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
@ -248,12 +253,19 @@ public class GameLogic extends JPanel { |
|
|
return enemy5Ship; |
|
|
return enemy5Ship; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void updateField(boolean playerMove, Matchfield matchfield) { |
|
|
|
|
|
for (JPanel coordinatePanel : this.fields) { |
|
|
|
|
|
String panelName = coordinatePanel.getName(); |
|
|
|
|
|
|
|
|
private int[] getCoordinateFromLabel(JPanel panel) { |
|
|
|
|
|
String panelName = panel.getName(); |
|
|
String[] panelNameSplit = panelName.split(":"); |
|
|
String[] panelNameSplit = panelName.split(":"); |
|
|
int coordX = Integer.parseInt(panelNameSplit[0]); |
|
|
int coordX = Integer.parseInt(panelNameSplit[0]); |
|
|
int coordY = Integer.parseInt(panelNameSplit[1]); |
|
|
int coordY = Integer.parseInt(panelNameSplit[1]); |
|
|
|
|
|
return new int[] { coordX, coordY }; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void updateField(boolean playerMove, Matchfield matchfield) { |
|
|
|
|
|
for (JPanel coordinatePanel : this.fields) { |
|
|
|
|
|
int[] coords = this.getCoordinateFromLabel(coordinatePanel); |
|
|
|
|
|
int coordX = coords[0]; |
|
|
|
|
|
int coordY = coords[1]; |
|
|
|
|
|
|
|
|
// reset field |
|
|
// reset field |
|
|
coordinatePanel.setBackground(null); |
|
|
coordinatePanel.setBackground(null); |
|
@ -278,6 +290,15 @@ public class GameLogic extends JPanel { |
|
|
coordinatePanel.revalidate(); |
|
|
coordinatePanel.revalidate(); |
|
|
coordinatePanel.repaint(); |
|
|
coordinatePanel.repaint(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// set game infos |
|
|
|
|
|
if (this.playerMove) { |
|
|
|
|
|
this.getMatchfieldValue().setText("Gegner"); |
|
|
|
|
|
this.getMoveValue().setText("Du"); |
|
|
|
|
|
} else { |
|
|
|
|
|
this.getMatchfieldValue().setText("Eigenes"); |
|
|
|
|
|
this.getMoveValue().setText("Gegner"); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|