|
@ -1,7 +1,10 @@ |
|
|
package solitaer; |
|
|
package solitaer; |
|
|
|
|
|
|
|
|
|
|
|
import java.awt.Graphics; |
|
|
|
|
|
import java.awt.Image; |
|
|
import java.util.Objects; |
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.ImageIcon; |
|
|
import javax.swing.JPanel; |
|
|
import javax.swing.JPanel; |
|
|
|
|
|
|
|
|
enum Symbol { |
|
|
enum Symbol { |
|
@ -19,10 +22,21 @@ public class Card extends JPanel { |
|
|
|
|
|
|
|
|
private boolean faceUp; |
|
|
private boolean faceUp; |
|
|
|
|
|
|
|
|
|
|
|
private Image Up; |
|
|
|
|
|
private Image back; |
|
|
|
|
|
|
|
|
public Card(int nr, Symbol symbol, boolean faceUp) { |
|
|
public Card(int nr, Symbol symbol, boolean faceUp) { |
|
|
|
|
|
this.setSize(72,96); |
|
|
this.nr = nr; |
|
|
this.nr = nr; |
|
|
this.symbol = symbol; |
|
|
this.symbol = symbol; |
|
|
this.faceUp = faceUp; |
|
|
this.faceUp = faceUp; |
|
|
|
|
|
|
|
|
|
|
|
String cardName = "" + getFileNr() + getFileSymbole(); |
|
|
|
|
|
ImageIcon iiup = new ImageIcon(getClass().getResource("images/" + cardName + ".png")); |
|
|
|
|
|
Up = iiup.getImage(); |
|
|
|
|
|
|
|
|
|
|
|
ImageIcon iiback = new ImageIcon(getClass().getResource("images/back.png")); |
|
|
|
|
|
back = iiback.getImage(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public boolean isFaceUp() { |
|
|
public boolean isFaceUp() { |
|
@ -37,10 +51,41 @@ public class Card extends JPanel { |
|
|
return nr; |
|
|
return nr; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String getFileNr() { |
|
|
|
|
|
if (this.nr < 10) { |
|
|
|
|
|
return "0" + this.nr; |
|
|
|
|
|
} else { |
|
|
|
|
|
return "" + this.nr; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public Symbol getSymbol() { |
|
|
public Symbol getSymbol() { |
|
|
return symbol; |
|
|
return symbol; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String getFileSymbole() { |
|
|
|
|
|
switch (this.symbol) { |
|
|
|
|
|
case Herz: |
|
|
|
|
|
return "Herz"; |
|
|
|
|
|
case Karo: |
|
|
|
|
|
return "Karo"; |
|
|
|
|
|
case Pik: |
|
|
|
|
|
return "Pik"; |
|
|
|
|
|
case Kreuz: |
|
|
|
|
|
return "Kreuz"; |
|
|
|
|
|
default: |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Image getImage() { |
|
|
|
|
|
if (faceUp) { |
|
|
|
|
|
return Up; |
|
|
|
|
|
} else { |
|
|
|
|
|
return back; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public String toString() { |
|
|
public String toString() { |
|
|
return "Card [nr=" + nr + ", symbol=" + symbol + ", faceUp=" + faceUp + "]"; |
|
|
return "Card [nr=" + nr + ", symbol=" + symbol + ", faceUp=" + faceUp + "]"; |
|
@ -63,6 +108,11 @@ public class Card extends JPanel { |
|
|
return faceUp == other.faceUp && nr == other.nr && symbol == other.symbol; |
|
|
return faceUp == other.faceUp && nr == other.nr && symbol == other.symbol; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
protected void paintComponent(Graphics g) { |
|
|
|
|
|
// TODO Auto-generated method stub |
|
|
|
|
|
super.paintComponent(g); |
|
|
|
|
|
g.drawImage(getImage(), 0, 0, this.getWidth(), this.getHeight(), this); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |