00001 package dionarap;
00002
00003 import java.awt.Color;
00004 import java.awt.Dimension;
00005 import java.awt.GridLayout;
00006
00007 import javax.swing.JLabel;
00008 import javax.swing.JPanel;
00009
00010 import de.fhwgt.dionarap.model.objects.AbstractPawn;
00011 import de.fhwgt.dionarap.model.objects.Ammo;
00012 import de.fhwgt.dionarap.model.objects.Destruction;
00013 import de.fhwgt.dionarap.model.objects.Obstacle;
00014 import de.fhwgt.dionarap.model.objects.Opponent;
00015 import de.fhwgt.dionarap.model.objects.Player;
00016 import de.fhwgt.dionarap.model.objects.Vortex;
00017
00025 public class Spielfeld extends JPanel {
00026
00030 private static final long serialVersionUID = 5715276577498012282L;
00031
00035 private JLabel schachBrett[][];
00036
00040 private GameStatus status = GameStatus.game;
00041
00048 public Spielfeld( int felderX, int felderY ) {
00049 JPanel panel = new JPanel( new GridLayout( felderX, felderY ) );
00050 this.add(panel);
00051
00052 this.schachBrett = new JLabel[felderX][felderY];
00053
00054 for( int reihe = 0; reihe < felderX; ++reihe ) {
00055 for( int spalte = 0; spalte < felderY; ++spalte ) {
00056 schachBrett[reihe][spalte] = new JLabel();
00057 schachBrett[reihe][spalte].setPreferredSize(new Dimension(50,50));
00058
00059 if( reihe % 2 == 0 ) {
00060 if( spalte % 2 == 0 )
00061 schachBrett[reihe][spalte].setBackground(Color.white);
00062 else
00063 schachBrett[reihe][spalte].setBackground(Color.black);
00064 } else {
00065 if( spalte % 2 == 0 )
00066 schachBrett[reihe][spalte].setBackground(Color.black);
00067 else
00068 schachBrett[reihe][spalte].setBackground(Color.white);
00069 }
00070
00071 schachBrett[reihe][spalte].setOpaque(true);
00072 panel.add( schachBrett[reihe][spalte] );
00073 }
00074 }
00075 }
00076
00085 public void updateStatus(GameStatus status)
00086 {
00087 if (this.status == GameStatus.game) {
00088 this.status = status;
00089 }
00090 }
00091
00097 public void setPawn(AbstractPawn pawn)
00098 {
00099 JLabel feld = this.schachBrett[pawn.getY()][pawn.getX()];
00100 Artwork artwork = Artwork.getTheme();
00101
00102 if (pawn instanceof Obstacle) {
00103 feld.setIcon(artwork.getObstacleIcon());
00104 }
00105 if (pawn instanceof Opponent) {
00106 feld.setIcon(artwork.getOpponentIcon());
00107 }
00108 if (pawn instanceof Ammo) {
00109 feld.setIcon(artwork.getAmmoIcon());
00110 }
00111 if (pawn instanceof Player) {
00112 if (this.status == GameStatus.gameover) {
00113 feld.setIcon(artwork.getGameOverIcon());
00114 } else if (this.status == GameStatus.gamewon) {
00115 feld.setIcon(artwork.getGameWonIcon());
00116 } else {
00117 Player p = (Player)pawn;
00118 feld.setIcon(artwork.getPlayerIcon(p.getViewDirection()));
00119 }
00120 }
00121 if (pawn instanceof Destruction) {
00122 feld.setIcon(artwork.getDestructionIcon());
00123 }
00124 if (pawn instanceof Vortex) {
00125 feld.setIcon(artwork.getVortexIcon());
00126 }
00127 }
00128
00133 public void cleanupSpielfeld() {
00134 for (int y = 0; y < this.schachBrett.length; y++) {
00135 for (int x = 0; x < this.schachBrett[y].length; x++) {
00136 JLabel feld = this.schachBrett[y][x];
00137 feld.setIcon(null);
00138 }
00139 }
00140 }
00141
00142 }