SORU
27 Kasım 2013, ÇARŞAMBA


Kapsayan sınıfı bir Java değil

Tetris bir oyun yapmaya çalışıyorum ve "Şekli kapsayan bir sınıf değil." ben bir nesne oluşturmak için deneyin . alıyorum

public class Test {
    public static void main(String[] args) {
        Shape s = new Shape.ZShape();
    }
}

Her şekil için iç sınıflar kullanıyorum. İşte benim kod parçası

public class Shape {

    private String shape;
    private int[][] coords;
    private int[][] noShapeCoords = { { 0, 0 },   { 0, 0 },   { 0, 0 },   { 0, 0 } };
    private int[][] zShapeCoords = { { 0, -1 },  { 0, 0 },   { -1, 0 },  { -1, 1 } };
    private int[][] sShapeCoords = { { 0, -1 },  { 0, 0 },   { 1, 0 },   { 1, 1 } };
    private int[][] lineShapeCoords = { { 0, -1 },  { 0, 0 },   { 0, 1 },   { 0, 2 } };
    private int[][] tShapeCoords = { { -1, 0 },  { 0, 0 },   { 1, 0 },   { 0, 1 } };
    private int[][] squareShapeCoords = { { 0, 0 },   { 1, 0 },   { 0, 1 },   { 1, 1 }   };
    private int[][] lShapeCoords = { { -1, -1 }, { 0, -1 },  { 0, 0 },   { 0, 1 } };
    private int[][] mirroredLShapeCoords = { { 1, -1 },  { 0, -1 },  { 0, 0 },   { 0, 1 } };

    public Shape(){
        int[][] coords =  noShapeCoords;
        shape = "NoShape";
    }

    class ZShape{
        int[][] coords =  zShapeCoords;
        String shape = "ZShape";
    }

    class SShape{
        int[][] coords = sShapeCoords;
        String shape = "SShape";
    }

 //etc
}

Neyi yanlış yapıyorum ?

CEVAP
27 Kasım 2013, ÇARŞAMBA


ZShape dış sınıfının bir örneğini gerektirir bu yüzden statik değil.

En basit çözüm eğer yapabilirsen ZShape ve herhangi bir iç içe geçmiş sınıf static yapmaktır.

Ayrıca herhangi bir alan da olabilir final static final yapmak istiyorum.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Megan Parken

    Megan Parken

    19 Temmuz 2009
  • SuppressedStorm

    SuppressedSt

    11 AĞUSTOS 2013
  • William Hyde

    William Hyde

    23 HAZİRAN 2008