학교에서 프로젝트 작업 중입니다. 저는 프로그래밍 초보자이며 버블 슈터 제작에 큰 문제가 있습니다. 이전에지도의 모든 공을 가져와야합니다. map2로 변경.Java Greenfoot, 파일간에 메소드를 연결할 수 없습니다.
모든 볼을 나열하려고했지만 프로그램이 첫 번째지도의 끝에 충돌하고 음수 값을로드 할 수 없다는 오류보고가 표시됩니다. 나는 그것이 총을 적재하려고 할 때이고, "allowedBallTypes! = null"또는 0 일 수도 있다고 말하면서 총을 적재해야하는 것보다 if-statement를 넣고 싶다고 생각했습니다.
기호를 찾을 수 없습니다. - getAllowedBallTypes(); greenfoot 자바 방법 클래스
bubbleworld 클래스 :
public BubbleWorld()
{
super(Map.MAX_WIDTH*Map.COLUMN_WIDTH, Map.MAX_HEIGHT*Map.ROW_HEIGHT, 1,false);
// Max speed. We use time-based animation so this is purely for smoothness,
// because Greenfoot is plain stupid. I can't find a way to get 60 Hz so this is
// what we have to do. Note: Exporting the game seems to cap this to some value < 100. :(
Greenfoot.setSpeed(100);
// Load the map.
map = new Map(this, testMap1);
// Update the allowed ball types. (i.e. we don't want to spawn a
// certain color of balls if the map doesn't contain them!)
map.updateAllowedBallTypes();
// Create the cannon.
Cannon cannon = new Cannon();
addObject(cannon, getWidth()/2, getHeight());
지도 클래스 :
public int[] getAllowedBallTypes()
{
return allowedBallTypes;
}
public void updateAllowedBallTypes()
{
int allowedCount = 0;
boolean[] allowed = new boolean[Ball.typeCount];
// Only ball types that exist in the map RIGHT NOW as attached balls will be allowed.
for(Cell c : cells)
{
if(c != null && c.getBall() != null && c.isAttached())
{
int type = c.getBall().getType();
if(!allowed[type])
allowedCount++;
allowed[type] = true;
}
}
allowedBallTypes = new int[allowedCount];
int writeIndex = 0;
for(int type = 0; type < Ball.typeCount; ++type)
{
if(allowed[type])
{
allowedBallTypes[writeIndex++] = type;
}
}
}
대포 클래스 : 코드를 기반으로
private void prepareBall()
{
// Get a random ball type from the list of allowed ones. Only balls currently in the map
// will be in the list.
int[] allowedBallTypes = ((BubbleWorld)getWorld()).getMap().getAllowedBallTypes();
int type = allowedBallTypes[Greenfoot.getRandomNumber(allowedBallTypes.length)];
// Create it and add it to the world.
ball = new Ball(type);
getWorld().addObject(ball, getX(), getY());
}
심볼을 찾을 수 없습니다. - 메서드 getAllowedBallTypes() –
저는이 프로젝트를 도와주었습니다.하지만 전에 JAVA 나이 프로그램을 건드리지 않았으므로 여기에서 물어볼 것이라고 제안했습니다. –
저는 초급자이고 클래스 레벨 변수 선언으로 무엇을 의미하는지 확신 할 수 없으므로 저에게 설명해주십시오 :) –