//공통 라이브러리 함수(LINK시에 함께 컴파일)
//공통 라이브러리 함수(LINK시에 함께 컴파일)
//공통 라이브러리 함수(LINK시에 함께 컴파일)
//gcc -c mainsrc.c
//gcc -c common.c
//gcc main_exe_filename main.o common.o
//gcc main_exe_filename main.o common.o
//gcc main_exe_filename main.o common.o
#include "common.h"
extern char design[6][2+1];
int f_rightkey(int hexa[MAPY][MAPX], int *x, int *y, int __des[3])
{
if(check(hexa, *x + 1, *y, 0) == 1)
{
hexa[*y+0][*x] = 0;
hexa[*y+1][*x] = 0;
hexa[*y+2][*x] = 0;
*x = *x + 1;
hexa[*y+0][*x] = __des[0];
hexa[*y+1][*x] = __des[1];
hexa[*y+2][*x] = __des[2];
return 1;
}
else
{
return 0;
}
}
int f_leftkey(int hexa[MAPY][MAPX], int *x, int *y, int __des[3])
{
if(check(hexa, *x - 1, *y, 0) == 1)
{
hexa[*y+0][*x] = 0;
hexa[*y+1][*x] = 0;
hexa[*y+2][*x] = 0;
*x = *x - 1;
hexa[*y+0][*x] = __des[0];
hexa[*y+1][*x] = __des[1];
hexa[*y+2][*x] = __des[2];
return 1;
}
else
{
return 0;
}
}
int f_downkey(int hexa[MAPY][MAPX], int *x, int *y, int __des[3])
{
if(check(hexa, *x, *y + 1, 1)==1)
{
hexa[*y+0][*x] = 0;
hexa[*y+1][*x] = 0;
hexa[*y+2][*x] = 0;
*y = *y + 1;
hexa[*y+0][*x] = __des[0];
hexa[*y+1][*x] = __des[1];
hexa[*y+2][*x] = __des[2];
return 1;
}
else
{
return 0;
}
}
int f_enterkey(int hexa[MAPY][MAPX], int *x, int *y, int __des[3])
{
return 1;
}
int f_spacekey(int hexa[MAPY][MAPX], int *x, int *y, int __des[3])
{
int tmp;
tmp = __des[0];
__des[0] = __des[1];
__des[1] = __des[2];
__des[2] = tmp;
hexa[*y+0][*x] = __des[0];
hexa[*y+1][*x] = __des[1];
hexa[*y+2][*x] = __des[2];
return 1;
}
void f_quitmsg(int idx)
{
printf(
"----------------------------------------------------------------------\n"
"MinGW provides a complete Open Source programming tool set \n"
"which is suitable for the development of native MS-Windows appications\n"
"and which do not depend on any 3rd-party C-Runtime DLLs. \n"
"(It does depend on a number of DLLs provided by Microsoft themselves, \n"
"as components of the operating system; most notable among these is MSV\n"
"the Microsoft C runtime library. Additionally, threaded applications m\n"
"with a freely distributable thread support DLL, provided as part of Mi\n"
" \n"
"MinGW compilers provide access to the functionality of the Microsoft C\n"
"and some language-specific runtimes. MinGW, being Minimalist, \n"
"does not, and never will, attempt to provide a POSIX runtime environme\n"
"for POSIX application deployment on MS-Windows. \n"
"If you want POSIX application deployment on this platform, please cons\n"
"DATE : \n"
"AUTHOR : \n"
"SCORE :[%.4d] \n"
"SCORE :[%.4d] \n"
"SCORE :[%.4d] \n"
"SCORE :[%.4d] \n"
"SCORE :[%.4d] \n"
"SCORE :[%.4d] \n"
"SCORE :[%.4d] \n"
"----------------------------------------------------------------------\n", idx, idx, idx, idx, idx, idx, idx);
}
int check(int hexa[MAPY][MAPX], int x, int y, int idx)
{
int result;
result = 0;
if(idx == 0)
{
if(hexa[y+0][x]>0) result = 1;
if(hexa[y+1][x]>0) result = 1;
if(hexa[y+2][x]>0) result = 1;
}
if(idx == 1)
{
if(hexa[y+2][x] >0) result = 1;
}
if(result == 1) return -1;
return 1;
}
void gotoxy(int x, int y)
{
COORD Pos = {x - 1, y - 1};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
void f_display_all(int hexa[MAPY][MAPX])
{
int i, k;
for(i=0; i<MAPY; i++)
{
for(k=0; k<MAPX; k++)
{
if(hexa[i][k] == 10)
{
continue;
}
else if(hexa[i][k] == 0)
{
gotoxy(k * 2 + 1, i + 2);
printf("□");
}
else
{
gotoxy(k * 2 + 1, i + 2);
printf("%s", design[ hexa[i][k] ]);
}
}
}
}
void f_display(int hexa[MAPY][MAPX], int x, int y)
{
int i, k;
/*
hexa[y-1][x]
hexa[y+0][x]
hexa[y+1][x]
hexa[y+2][x]
hexa[y-1][x+1]
hexa[y+0][x+1]
hexa[y+1][x+1]
hexa[y+2][x+1]
hexa[y-1][x-1]
hexa[y+0][x-1]
hexa[y+1][x-1]
hexa[y+2][x-1]
*/
for(i=-1; i < 3; i++)
{
if(y + i> MAPY -1) continue;
if(y + i < 0) continue;
if(x < 0) continue;
if(x > MAPX - 1) continue;
if(hexa[y + i][x] == 10) continue;
else if(hexa[y + i][x] == 0)
{
gotoxy(x * 2 + 1, y + i + 2);
printf("□");
}
else
{
gotoxy(x * 2 + 1, y + i + 2);
printf("%s", design[ hexa[y + i][x] ]);
}
}
for(i=-1; i < 3; i++)
{
if(y + i> MAPY -1) continue;
if(y + i < 0) continue;
if(x + 1 < 0) continue;
if(x + 1 > MAPX - 1) continue;
if(hexa[y + i][x + 1] == 10) continue;
else if(hexa[y + i][x + 1] == 0)
{
gotoxy( (x + 1) * 2 + 1, y + i + 2);
printf("□");
}
else if(hexa[y + i][x + 1] == 1)
{
gotoxy( (x + 1) * 2 + 1, y + i + 2);
printf("%s", design[ hexa[y + i][x + 1] ]);
}
}
for(i=-1; i < 3; i++)
{
if(y + i> MAPY -1) continue;
if(y + i < 0) continue;
if(x - 1 < 0) continue;
if(x - 1 > MAPX - 1) continue;
if(hexa[y + i][x - 1] == 10) continue;
else if(hexa[y + i][x - 1] == 0)
{
gotoxy( (x - 1) * 2 + 1, y + i + 2);
printf("□");
}
else
{
gotoxy( (x - 1) * 2 + 1, y + i + 2);
printf("%s", design[ hexa[y + i][x - 1] ]);
}
}
}
void init(int hexa[MAPY][MAPX], int *x, int *y, int __des[3])
{
int i, k;
//char design[6][2+1] = {"", "●","◆","■","◀","▶"};
strcpy(design[0], "");
strcpy(design[5], "●");
strcpy(design[1], "◆");
strcpy(design[2], "■");
strcpy(design[3], "◀");
strcpy(design[4], "▶");
for(i=0; i<MAPY; i++)
{
for(k=0; k<MAPX; k++)
{
hexa[i][k] = 0;
}
}
for(i=0; i<MAPY; i++)
{
hexa[i][0] = 10;
hexa[i][MAPX-1] = 10;
}
for(k=0; k<1 + MAPX + 1; k++)
{
hexa[MAPY-1][k] = 10;
}
*x = MAPX / 2;
*y = 0;
__des[0] = 1 + ( rand() % 5 );
__des[1] = 1 + ( rand() % 5 );
__des[2] = 1 + ( rand() % 5 );
hexa[*y+0][*x] = __des[0];
hexa[*y+1][*x] = __des[1];
hexa[*y+2][*x] = __des[2];
}
void f_delete_column( int hexa[MAPY][MAPX], int x, int y )
{
int k;
for(k = y; k >= 1; k--)
{
hexa[ k][ x ] = hexa[ ( k - 1 ) ][ x ];
}
}
int f_check_horizontal(int hexa[MAPY][MAPX], int *sc)
{
int i, k, j, idx;
for(i = 0; i <MAPY - 1; i++ )
{
for(k = 1; k <MAPX - 3; k++ )
{
idx = 0;
while( 1 )
{
if( hexa[ i][ k + idx ] != 0 )
{
if( hexa[ i][ k + idx ] == hexa[ i][ k + idx + 1 ] )
{
idx = idx + 1;
}
else break;
}
else break;
}
if( idx >= 2 )
{
(*sc)++;
for( j = k; j <= k + idx; j++ )
{
f_delete_column( hexa, j, i );
}
return 1;
}
}
}
return 0;
}
int f_check_vertical(int hexa[MAPY][MAPX], int *sc)
{
int i, k, j, idx;
for( k = 1; k < MAPX - 1; k++ )
{
for( i = MAPY - 2; i >= 0; i-- )
{
idx = 0;
while( 1 )
{
if( hexa[ ( i - idx )][k ] != 0 )
{
if( hexa[ ( i - idx )][k ] == hexa[ ( i - idx - 1 )][k ] )
{
idx = idx + 1;
}
else break;
}
else break;
}
if( idx >= 2 )
{
(*sc)++;
for( j = i; j >= i - idx; j-- )
{
f_delete_column( hexa, k, i );
}
return 1;
}
}
}
return 0;
}
int f_check_left_to_right(int hexa[MAPY][MAPX], int *sc)
{
int i, k, j, idx;
for(k = 1; k <MAPX - 1; k++ )
{
for(i = 0; i <MAPY - 1; i++ )
{
idx = 0;
while( 1 )
{
if( hexa[ ( i + idx ) ][k + idx ] != 0 )
{
if( hexa[ ( i + idx )][( k + idx ) ] == hexa[ ( i + idx + 1 )][( k + idx + 1 ) ] )
{
idx = idx + 1;
}
else break;
}
else break;
}
if( idx >= 2 )
{
(*sc)++;
for( j = 0; j <= idx; j++ )
{
f_delete_column( hexa, k + j, i + j );
}
return 1;
}
}
}
return 0;
}
int f_check_right_to_left(int hexa[MAPY][MAPX], int *sc)
{
int i, k, j, idx;
for(k = MAPX - 2; k >= 1; k--)
{
for(i = 0; i < MAPY - 1; i++)
{
idx = 0;
while( 1 )
{
if( hexa[ (i + idx )][k - idx ] != 0 )
{
if( hexa[ (i + idx )][(k - idx ) ] == hexa[ (i + idx + 1 )][(k - idx - 1 ) ] )
{
idx = idx + 1;
}
else break;
}
else break;
}
if( idx >= 2 )
{
(*sc)++;
for( j = 0; j <= idx; j++ )
{
f_delete_column(hexa, k - j, i + j );
}
return 1;
}
}
}
return 0;
}
'c 언어 > 중급과정' 카테고리의 다른 글
WINDOWS, WIN, HEXA프로그램(헤더) (0) | 2019.10.31 |
---|---|
WINDOWS, WIN, HEXA프로그램(메인) (0) | 2019.10.31 |
WINDOWS, CMD, HEXA프로그램(메인소스) (0) | 2019.10.31 |
WINDOWS, CMD, HEXA프로그램(헤더) (0) | 2019.10.31 |
엔디안 (0) | 2019.10.30 |