Auf Thema antworten

Hi.

Ich stehe grad aufm Schlauch. Ich möchte meinem zweidimensionalem Array (Spielfeld) eine Startposition vorgeben.

Das Brett initialisiere ich hier.

Es wird eine 8x8 Matrix erstellt die zu Anfang Leer ist.

Ich möchte Allerdings in Zeile 0 und 1 überall ein '+' haben.

Normalerweise würde ich mein Array so befühlen

[code=Java]

static final char A = '+'; // Figur Spieler FIGUR_A

    static final char B = 'o'; // Figur Spieler Figur_B

    static final char N = '.'; // Feld leer


    public static void main(String[] args) {

        char[][] spielfeld = { { A, A, A, A, A, A, A, A },

                { A, A, A, A, A, A, A, A }, { N, N, N, N, N, N, N, N },

                { N, N, N, N, N, N, N, N }, { N, N, N, N, N, N, N, N },

                { B, B, B, B, B, B, B, B }, { B, B, B, B, B, B, B, B } };


[/code]


Aber da ich hier nicht imperativ arbeite fällt mir das komplizierter da er immer meckert " cannot convert from char to ..Figur " oder so ähnlich

Wie implementiere ich hier z.b das oben beschriebene Array ?

[code=Java]

class BTSpielbrett{

    final static int n= 8;

    final static BTFigur START = null;

   

    BTFigur[][] brett;

   

   

    BTSpielbrett(){

        this.brett=new BTFigur[n][n];

        for ( int i=0;i<n;i++)

            for ( int j=0;j<n;j++)

                this.brett[i][j]=null;

       

    }




class BTFigur{

final static char KREUZ='x';

final static char KREIS='o';

final static char LEER='.';


boolean aOderB;

int zeile,spalte;

boolean istLeer;

 BTFigur(boolean aOderB, int zeile,int spalte,boolean istLeer){

     this.aOderB =aOderB;

     this.zeile= zeile;

     this.spalte=spalte;

     this.istLeer=istLeer;

 }

 boolean istAFigur(){

     return this.aOderB;

 }

 

 boolean istBFigur() {

        return !this.istAFigur();

 }

 int getZeile() {

        return this.zeile;

    }


    int getSpalte() {

        return this.spalte;

    }

   

  public char getAFigur() {

        return KREUZ;

    }


  public char getBFigur() {

        return KREIS;

}

  public char getLeer(){

       return LEER;

   }

}

[/code]



lg

Flo



Oben