2015-01-27 4 views
-1

이 버그는 그리드에서 단독으로 제거 할 수없는 것으로 간주됩니다. ConnorBug가 원래 버그 클래스에서 removeSelfFromGrid()를 수행하고 실제로 그리드에서 버그를 없애는 방법이 있습니까?수퍼 클래스에서 메서드를 호출하는 방법은 무엇입니까?

public class ConnorBug extends Bug 
{ 
    public static int MyNewCounter = 0; 
    public ConnorBug() 
    { 
     setColor(null); 
    } 
    public void removeSelfFromGrid() 
    { 
     Location loc = getLocation(); 
     Grid<Actor> gr = getGrid(); 
     Location next = loc.getAdjacentLocation(getDirection()); 
     if(gr.isValid(next)) 
     { 

      this.move(); 
     } 
     else{ 
      this.setDirection(getDirection()-180); 
      this.move(); 
     } 
     for(int c=0; c<8; c++) 
     { 

      Location thatLoc = getLocation(); 
      Location thatNext = thatLoc.getAdjacentLocation((0+(45*c))); 
      if(gr.isValid(thatNext)&&!(gr.get(thatNext) instanceof ConnorRock)&&!(gr.get(thatNext) instanceof ConnorBug)) 
      { 

       ConnorRock something = new ConnorRock(); 
       something.putSelfInGrid(gr,thatNext); 
      } 
     } 
    } 

} 

답변

0

당신은 사용할 필요가 :

super.<method name>(); 

함수가 정적 인 경우 어느, 당신은 단지

+0

Bug.<method name>(); 그래서 또 다른 버그는 대한 ' .super.removeSelfFromGrid을() 것 수 ConnorBug는 슈퍼 클래스에서 removeSelfFromGrid()를 올바르게 수행합니까? –

+0

가끔은 env에서 자신을 테스트하는 것이 좋습니다. 이런 종류의 작업에서는이 문제를 더 잘 배웁니다. – roeygol

관련 문제