Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Spiel;
- import java.awt.Color;
- import java.awt.Point;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- /**
- *
- * @author Crushpest
- */
- public class Feld extends JButton{
- //<editor-fold defaultstate="collasped" desc="Definiere Globale Variablen">
- public enum FeldStatus {
- OFFEN, ZU, LEER
- };
- private int minenAußenrum = 0; //Wieviele Minen außenrum liegen
- private FeldStatus status = FeldStatus.ZU;
- private boolean mine = false; //Beinhaltet mine
- private Point point; //Koordinaten im Array
- private Color hintergrundGrau = new Color(189, 189, 189);
- private ImageIcon bildMinen = new ImageIcon(Feld.class.getResource("/IconBilder/bildMinen.png"));
- private ImageIcon bildEntschaerft = new ImageIcon(Feld.class.getResource("/IconBilder/bildEntschaerft.png"));
- private ImageIcon bildFragezeichen = new ImageIcon(Feld.class.getResource("/IconBilder/bildFragezeichen.png"));
- //</editor-fold>
- //Konstruktoren
- public Feld(int x, int y) {
- super();
- this.point = new Point(x, y);
- }
- //Gebe Koordinaten zurueck
- public Point getPointer() {
- return point;
- }
- //Gebe FeldStatus zurueck
- public FeldStatus getStatus(){
- return status;
- }
- //Setzte anzahl der Minen Außenrum
- public void setMinenAußenrum(int anzahl){
- minenAußenrum = anzahl;
- }
- //Decke dieses Feld auf. Gibt ZU zurueck wenn Mine getroffen!
- public FeldStatus aufdecken() {
- if (status == FeldStatus.ZU) {
- if (minenAußenrum == 0) {
- status = FeldStatus.LEER;
- } else if (mine) {
- this.setBackground(hintergrundGrau);
- this.setIcon(bildMinen);
- } else {
- this.setIcon(null);//Hier eigentlich minenAnzeige hochzählen, da eventuell schon entschaerft gewesen
- this.setBackground(hintergrundGrau);
- this.setText("" + minenAußenrum + "");
- status = FeldStatus.OFFEN;
- }
- } else if (status == FeldStatus.LEER) {
- this.setIcon(null);//Hier eigentlich minenAnzeige hochzählen, da eventuell schon entschaerft gewesen
- this.setBackground(hintergrundGrau);
- status = FeldStatus.OFFEN;
- }
- return status;
- }
- //Setzte Mine
- public void setMine() {
- mine = true;
- }
- //Gebe zurueck ob Feld eine Mine ist
- public boolean isMine(){
- return mine;
- }
- //Setzte Icon und gebe boolean zurueck ob Entschaerft
- public boolean feldEntschaerfen() {
- if (status == FeldStatus.ZU) {
- if (this.getIcon() == null) {
- this.setIcon(bildEntschaerft);
- return true;
- } else if (this.getIcon() == bildEntschaerft) {
- this.setIcon(bildFragezeichen);
- return true;
- } else if (this.getIcon() == bildFragezeichen) {
- this.setIcon(null);
- return false;
- }
- }
- return false;//Sollte niemals auftretten!
- }
- //Setzte dieses Feld zurueck
- public void reset() {
- minenAußenrum = 0;
- mine = false;
- this.setIcon(null);
- this.setText("");
- this.setBackground(null);
- status = FeldStatus.ZU;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement