첫 번째 응답은 'wtf, arraylists를 사용하지 마십시오!'라고 확신하지만, 실제로는 가능한 모든 방식으로이 작업을 수행하려고합니다.ArrayList 내 ArrayList에 대한 액세스 얻기
기본적으로 일치하는 3 경기를위한 '경기 찾는 사람'입니다. 성냥 목록에서 성냥 데이터에 액세스하는 데 문제가 있습니다. 아래를 참조하십시오.
public void FindAndRemoveMatches() {
ArrayList foundMatches = LookForMatches();
//just checking if we're getting the right amount for now
Debug.Log("We found " + foundMatches.Count + " 'Match 3's");
foreach(Object el in foundMatches){
// Debug.Log(el.ToString());
}
}
ArrayList LookForMatches(){
//List<int> matchList = new List<int>();
ArrayList matchList = new ArrayList();
// search for horizontal matches
// note that we're subtracting two rows here.
// We don't need to check the last two rows because we're matching 3.
for (int i = 0; i < BOARD_WIDTH; i++){
for (int j = 0; j < BOARD_HEIGHT-2; j++){
ArrayList match = GetMatchHoriz(i,j);
if (match.Count > 2) {
matchList.Add(match);
i += match.Count-1;
}
}
}
// search for vertical matches
for (int i = 0; i < BOARD_WIDTH; i++){
for (int j = 0; j < BOARD_HEIGHT-2; j++){
ArrayList match = GetMatchVert(i,j);
if (match.Count > 2) {
matchList.Add(match);
j += match.Count-1;
}
}
}
return matchList;
}
// look for horizontal matches starting at this point
ArrayList GetMatchHoriz(int col,int row){
ArrayList match = new ArrayList();
match.Add(mBoard[col,row]);
for(int i = 1; (col+i)<8; i++) {
if (mBoard[col,row] == mBoard[col+i,row]) {
if(mBoard[col+i,row] > mPieces.GetNumPieceTypes()) match.Add(mBoard[col+i,row]);
} else {
return match;
}
}
return match;
}
// look for horizontal matches starting at this point
ArrayList GetMatchVert(int col,int row){
ArrayList match = new ArrayList();
match.Add(mBoard[col,row]);
for(int i = 1; (row+i)<8; i++) {
if (mBoard[col,row] == mBoard[col,row+i]) {
if(mBoard[col,row+i] > mPieces.GetNumPieceTypes()) match.Add(mBoard[col,row+i]);
} else {
return match;
}
}
return match;
}
좋은 소식은 정확하게 일치를 찾는 것입니다. 디버그 로그를 사용하여 찾은 일치 항목의 수는 화면의 상황과 관련이 있습니다. 예! 그러나 보드 (mBoard [col, row])와 비교하여 게임 보드에서 해당 데이터를 제거 할 수 있도록 해당 데이터에 액세스해야합니다.
findandremovematches의 'foreach'루프가 캐스팅에 대한 오류를 제공합니다. 어떤 도움이 필요합니까?
감사합니다.
정확한 오류 메시지가 나타나는 데 도움이됩니다. – mobiGeek
첫 번째 응답에 대해 틀 렸습니다 :) –
wtf, arraylists를 사용하지 마십시오! –