처리 중에 ArrayList의 초기 요소 수가 가변적이지만 (코드에서 변경하지 않음) Number와 Number를 변경하도록 IntList의 ArrayList를 만들려고합니다. IntList의 요소 중 초기 값은 0이지만 코드에서 추가되고 편집됩니다. 내 코드의 ArrayList를 각각의 사다리의 Y 위치에 대응 INT 구성 요소 "렁"을 함유하는 IntList를 있고, 래더 인 일본 래더 게임이다. "인쇄 (사다리);" IntList의 ArrayList에서 삽입 부분 수정
ArrayList <IntList> Ladders = new ArrayList <IntList>();
IntList temp = new IntList();
void setup()
{
for(int i=0;i<numRails-1;i++)
{
Ladders.add(new IntList());
temp.clear();
temp.append(0);
Ladders.set(i,temp);
}
}
void addRung (int spot)
{
temp.clear();
temp = Ladders.get(spot);
temp.append(50);
//note that 50 is an arbitrary number, it would be given by MouseY
Ladders.set(spot,temp);
print(Ladders);
//I have also tried...
Ladders.get(spot).append(50);
}
그래서 내 문제는 addRung()는 모든 단일 ArrayList에 적힌 요소와 50를 추가하는 것이다 outputs ...
[IntList size=1 [ 50 ], IntList size=1 [ 50 ], IntList size=1 [ 50 ], IntList size=1 [ 50 ], IntList size=1 [ 50 ], IntList size=1 [ 50 ], IntList size=1 [ 50 ], IntList size=1 [ 50 ], IntList size=1 [ 50 ]]
이 문제를 완전히 해결할 수있는 좋은 방법이 있습니까? 아니면 잘못된 것입니까?
나는 내 코드가 출력되는 것을의 이미지 ... It should be a single rung at location 50 but it is 9 rungs at 50.
당신은 ArrayList를로 50 회를 추가 한 IntList를을 만들고 있습니다. 50 가지 IntLists가 필요합니다. –
addRung() 함수를 작성하려면 어떻게해야합니까? –