테트리스 벽돌생성 과정중 질문입니다.
글쓴이: ch0nn0m / 작성시간: 일, 2010/09/26 - 5:09오후
배경과 블럭만 출력해보는 과정인데요
error C2061: syntax error : identifier 'block'
error C2059: syntax error : ';'
error C2059: syntax error : '['
error C2065: 'block' : undeclared identifier
error C2109: subscript requires array or pointer type
error C2109: subscript requires array or pointer type
error C2109: subscript requires array or pointer type
error C2224: left of '.y' must have struct/union type
이러한 에러들이 나오는데...어디서 잘못된건지..?
#include<stdio.h> #include<time.h> #include <windows.h> void Map(); //맵출력함수 void Rand(); //랜덤함수 void gotoxy(int x, int y); void Block(); void gotoxy(int x, int y) { COORD pos={x, y}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); } int shape; //블럭 모양 struct XY { int x,y; }; void Rand() //랜덤함수 { srand(time(0)); shape = rand() % 7; //블럭 모양랜덤 생성 } int p[22][25]= //배경[세로][가로] { //0, 1, 2, 3, 4, 5, 6, 7, 8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //0 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //1 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //2 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //3 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //4 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //5 {1, 0, 0, 0, 0, 0, 0, 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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //19 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //20 {1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1} //21 }; XY block[8][4][4] //[벽돌번호][회전번호][일련번호] ={ { {0,0,2,0,4,0,-2,0}, {0,0,0,1,0,-1,0,-2}, {0,0,2,0,4,0,-2,0}, {0,0,0,1,0,-1,0,-2} }, //━ { {0,0,2,0,0,1,2,1}, {0,0,2,0,0,1,2,1}, {0,0,2,0,0,1,2,1}, {0,0,2,0,0,1,2,1} }, //□ { {0,0,-2,0,0,-1,2,-1}, {0,0,0,1,-2,0,-2,-1}, {0,0,-2,0,0,-1,2,-1}, {0,0,0,1,-2,0,-2,-1} }, // ┗┒ { {0,0,-2,-1,0,-1,2,0}, {0,0,-2,0,-2,1,0,-1}, {0,0,-2,-1,0,-1,2,0}, {0,0,-2,0,-2,1,0,-1} }, //┎┚ { {0,0,-2,0,2,0,-2,-1}, {0,0,0,-1,0,1,-2,1}, {0,0,-2,0,2,0,2,1}, {0,0,0,-1,0,1,2,-1} }, //┗ { {0,0,-2,0,2,0,0,1}, {0,0,0,-1,0,1,2,0}, {0,0,-2,0,2,0,0,-1}, {0,0,-2,0,0,-1,0,1} }, //┻ { {0,0,2,0,-2,0,2,-1}, {0,0,0,1,0,-1,-2,-1}, {0,0,2,0,-2,0,-2,1}, {0,0,0,-1,0,1,2,1} }, //┛ { {0,0,0,0, 0,0,0, 0}, {0,0,0,0,0, 0, 0, 0}, {0,0,0,0, 0,0, 0,0}, {0,0,0, 0,0,0,0,0} } /*예비블럭*/}; void Map() { int i,j; for(i=0 ; i<22 ; i++) { for(j=0 ; j<25 ; j=j+2) { if(p[i][j]==0) { gotoxy(j, i); printf("."); } if (p[i][j]==1) { gotoxy(j, i); printf("□"); } if (p[i][j]==2) //블럭을 출력시킨다 { gotoxy(j, i); printf("■"); } } } } void Block() //블럭함수 { int z; for(z=0 ; z<4 ; z++) { p[1+block[shape][0][z].y][12+block[shape][0][z].x]=2; //┗1은 처음 시작 y좌표값┗12은 처음 시작 x좌표값 } } void main() { Rand(); //랜덤함수 Block(); //블럭 함수 Map(); //맵출력함수 }
Forums:
XY block[8][4][4]
XY block[8][4][4] //[벽돌번호][회전번호][일련번호]
={
이부분이.. 문제인 것 같은데
XY block[8][4][4] ={
이렇게..하셔야 하지 않을까요?
웬지 줄 내린게 문제가 될 것 같은;;
──────────────────────────────────
──────────────────────────────────
block선언시
XY block[][][] 대신 struct XY block이라고 해 보세요. C++컴파일러면 뭐 이게 문제는 아니겠지만...
댓글 달기