구조체 배열 질문
민G
질문 제목 : 구조체 배열저 소스중에서
int i,j;
int map[max][max2]={
{brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick},
{brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick},
{brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick},
{brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick}
};
이 부분만 전역변수 구조체로 뺄수없나요 ? 저 배열을 그대로 구조체로빼니까 못쓰던데. 저런식의 배열은
초기화는 어떻게해야돼고 구조체로 어떻게빼야됍니까?질문 내용 : #include stdio.h
#include windows.h
#define left 75
#define right 77
#define brick 1
#define max 4
#define max2 34
struct bal{
int x,y;
int dir[10];
};
gotoxy(int x, int y)
{
coord pos = {x, y};
setconsolecursorposition(getstdhandle(std_output_handle), pos);
}
void textcolor(int color_number)
{
setconsoletextattribute(getstdhandle(std_output_handle),color_number);
}
struct bal ba={33,15};
map();
ball();
character();
int c_x=32;
int c_y=23;
main(){
system(mode con cols=70 lines=25);
map();
while(1){
character();
ball();
}
sleep(50);
}
map(){
int i,j;
int map[max][max2]={
{brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick},
{brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick},
{brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick},
{brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick,brick}
};
for(i=0;imax;i++){
for(j=0;jmax2;j++){
if(map[i][j]==brick)
{
printf(■);
}
}
printf(\n);
}
}
character(){
int key;
gotoxy(c_x,c_y);
printf(ㅡㅡㅡㅡ);
if(kbhit()){
key=getch();
gotoxy(c_x,c_y);
printf( );
switch(key){
case left:
if(c_x0)
c_x--;
break;
case right:
if(c_x62)
c_x++;
break;
}
gotoxy(c_x,c_y);
printf(ㅡㅡㅡㅡ);
}
gotoxy(20,20);
printf(%d %d,c_x,c_y);
}
ball(){
ba.dir[0]=1; // ↗
ba.dir[1]=2; // ↘
ba.dir[2]=3; // ↙
ba.dir[3]=4; // ↖
if(ba.yc_y){
while(ba.y!=23){
character();
gotoxy(ba.x,ba.y);
printf(ⓢ);
gotoxy(ba.x,ba.y);
printf( );
ba.y++;
gotoxy(ba.x,ba.y);
printf(ⓢ);
&nbbr /sleep(50);
}
}
if(ba.y==c_y){
for(;c_x==ba.x || c_x==ba.x-1 || c_x==ba.x-2 || c_x==ba.x-3 || c_x==ba.x-4 || c_x==ba.x-5 || c_x==ba.x-6 || c_x==ba.x+1;){
character();
if(ba.y23)
gotoxy(ba.x,ba.y);
printf( );
gotoxy(ba.x,ba.y);
printf(ⓢ);
gotoxy(ba.x,ba.y);
printf( );
ba.y--;
gotoxy(ba.x,ba.y);
printf(ⓢ);
sleep(50);
gotoxy(33,16);
printf(%d %d,ba.x,ba.y);
if(ba.y==3)
break;
}
if(c_x!=ba.x && c_x!=ba.x-1 && c_x!=ba.x-2 && c_x!=ba.x-3 && c_x!=ba.x-4 && c_x!=ba.x-5 && c_x!=ba.x-6 && c_x!=ba.x+1 && ba.y==23){
printf(으악 !);
system(pausenul);
system(cls);
gotoxy(30,12);
printf(game over\n\n\n\n\n\n\n\n);
system(pausenul);
exit(1);
}
}
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2676182 | 숫자 순서대로 배열하는법 | 권뉴 | 2024-11-24 |
2676152 | 기본적인거 하나 질문드립니다. | 개미 | 2024-11-24 |
2676124 | 함수선언관련 질문이에요~...털썩..수정완료 (2) | 가지 | 2024-11-24 |
2676092 | C언어 책 (2) | 아서 | 2024-11-24 |
2676065 | 웹사이트 또는 메신저 등에서 원하는 텍스트를 검사하는방법?? (1) | 모든 | 2024-11-23 |
2676033 | 배열 기초연습중 발생하는 에러 ㅠㅜ... | Creative | 2024-11-23 |
2676005 | keybd_event 게임 제어 | 영글 | 2024-11-23 |
2675900 | 진짜기본적인질문 | 글길 | 2024-11-22 |
2675845 | 수정좀해주세요ㅠㅠㅠ | 해골 | 2024-11-21 |
2675797 | 병합 정렬 소스 코드 질문입니다. (2) | 도래솔 | 2024-11-21 |
2675771 | 큐의 활용이 정확히 어떻게 되죠?? | 해긴 | 2024-11-21 |
2675745 | 도서관리 프로그램 질문이요 | 도리도리 | 2024-11-20 |
2675717 | 2진수로 변환하는것! (3) | 동생몬 | 2024-11-20 |
2675599 | for문 짝수 출력하는 법 (5) | 널위해 | 2024-11-19 |
2675575 | Linux 게시판이 없어서.. | 첫삥 | 2024-11-19 |
2675545 | 구조체 이용할 때 함수에 자료 넘겨주는 것은 어떻게 해야 하나요? | 아연 | 2024-11-19 |
2675518 | 사각형 가로로 어떻게 반복해서 만드는지좀.. 내용 | 신당 | 2024-11-18 |
2675491 | !느낌표를 입력하는것은 어떻게합니까~~?ㅠㅠ (5) | 사지타리우스 | 2024-11-18 |
2675411 | 파일입출력으로 받아온 파일의 중복문자열을 제거한 뒤 파일출력 | 앨버트 | 2024-11-17 |
2675385 | 링크드리스트 주소록 질문드립니다. (1) | 겨루 | 2024-11-17 |