|
|
@ -27,7 +27,8 @@ public class Cell extends JButton { |
|
|
|
type = _type; |
|
|
|
cord = _cord; |
|
|
|
playfield = _playfield; |
|
|
|
|
|
|
|
|
|
|
|
setBackground(Color.white); |
|
|
|
addActionListener(new ActionListener() { |
|
|
|
@Override |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
@ -48,18 +49,30 @@ public class Cell extends JButton { |
|
|
|
} |
|
|
|
|
|
|
|
protected void OnMouseClick() { |
|
|
|
if (type != CellType.Bomb) { |
|
|
|
flood(); |
|
|
|
} else { |
|
|
|
playfield.reset(); |
|
|
|
if (!flagged) { |
|
|
|
if (type != CellType.Bomb) { |
|
|
|
flood(); |
|
|
|
} else { |
|
|
|
playfield.reset(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected void OnMouseRightClick() { |
|
|
|
if (flagged) { |
|
|
|
flagged = false; |
|
|
|
} else { |
|
|
|
flagged = true; |
|
|
|
if (isEnabled()) { |
|
|
|
if (flagged) { |
|
|
|
flagged = false; |
|
|
|
|
|
|
|
if (type == CellType.Number) { |
|
|
|
setBackground(Color.gray); |
|
|
|
} else { |
|
|
|
setBackground(Color.red); |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
flagged = true; |
|
|
|
setBackground(Color.cyan); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -75,9 +88,11 @@ public class Cell extends JButton { |
|
|
|
if (type == CellType.Bomb) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
setBackground(Color.LIGHT_GRAY); |
|
|
|
setEnabled(false); |
|
|
|
playfield.cellFlooded(); |
|
|
|
|
|
|
|
if (value == 0) { |
|
|
|
if (cord.y > 0) { |
|
|
|
if (playfield.cells[cord.y - 1][cord.x].type == CellType.Number |
|
|
|