//wincommon.c
//wincommon.c
//wincommon.c 공통라이브러리
#include "wincommon.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 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 언어 > 중급과정' 카테고리의 다른 글
구조체 정렬 크기조정하기(structure padding) (0) | 2019.10.31 |
---|---|
LINUX, char *strtok_r(char *str, const char *delim, char **saveptr); (0) | 2019.10.31 |
WINDOWS, WIN, HEXA프로그램(헤더) (0) | 2019.10.31 |
WINDOWS, WIN, HEXA프로그램(메인) (0) | 2019.10.31 |
WINDOSW, CMD, HEXA프로그램(공통) (0) | 2019.10.31 |