#include"Turboc.h"
#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
#define ESC 27
#define BX 3
#define BY 2
#define BW 10
#define BH 30
struct Point
{
int x, y;
};
Point Shape[][4][4] = {
{ { 0, 0, 1, 0, 2, 0, -1, 0 }, { 0, 0, 0, 1, 0, -1, 0, -2 }, { 0, 0, 1, 0, 2, 0, -1, 0 }, { 0, 0, 0, 1, 0, -1, 0, -2 } },
{ { 0, 0, 1, 0, 0, 1, 1, 1 }, { 0, 0, 1, 0, 0, 1, 1, 1 }, { 0, 0, 1, 0, 0, 1, 1, 1 }, { 0, 0, 1, 0, 0, 1, 1, 1 } },
{ { 0, 0, -1, 0, 0, -1, 1, -1 }, { 0, 0, 0, 1, -1, 0, -1, -1 }, { 0, 0, -1, 0, 0, -1, 1, -1 }, { 0, 0, 0, 1, -1, 0, -1, -1 } },
{ { 0, 0, -1, -1, 0, -1, 1, 0 }, { 0, 0, -1, 0, -1, 1, 0, -1 }, { 0, 0, -1, -1, 0, -1, 1, 0 }, { 0, 0, -1, 0, -1, 1, 0, -1 } },
{ { 0, 0, -1, 0, 1, 0, -1, -1 }, { 0, 0, 0, -1, 0, 1, -1, 1 }, { 0, 0, -1, 0, 1, 0, 1, 1 }, { 0, 0, 0, -1, 0, 1, 1, -1 } },
{ { 0, 0, 1, 0, -1, 0, 1, -1 }, { 0, 0, 0, 1, 0, -1, -1, -1 }, { 0, 0, 1, 0, -1, 0, -1, 1 }, { 0, 0, 0, -1, 0, 1, 1, 1 } },
{ { 0, 0, -1, 0, 1, 0, 0, 1 }, { 0, 0, 0, -1, 0, 1, 1, 0 }, { 0, 0, -1, 0, 1, 0, 0, -1 }, { 0, 0, -1, 0, 0, -1, 0, 1 } },
};
enum {EMPTY,BRICK, WALL};
char *arTile[] = { ". ", "??quot;, "??quot; };
char board[BW][BH] = { 0 };
int ch;
int block, turn;
int dx, dy;
int nframe;
BOOL exist;
BOOL GetAround(int nx, int ny, int nturn);
BOOL CreateBlock();
void MoveBlock(BOOL boolean);
void ProcessKey();
void StackBrick();
int main(void)
{
int i, j;
for (i = 0; i < BH; i++)
{
gotoxy(BX, BY);
puts(arTile[BRICK]);
if (i == 0 || i == BH - 1)
puts(arTile[EMPTY]);
puts(arTile[BRICK]);
}
randomize();
while (1)
{
if (exist == FALSE)
if (!CreateBlock())
break;
ProcessKey();
nframe--;
delay(20);
if ((nframe <= 0) && (GetAround(dx, dy, turn)))
{
MoveBlock(FALSE);
dy++;
MoveBlock(TRUE);
}
else
StackBrick();
}
}
BOOL GetAround(int nx, int ny, int nturn)
{
int i;
for (i = 0; i < 4; i++)
if (board[nx + Shape[block][nturn][i].x][ny + Shape[block][nturn][i].y] != EMPTY)
{
putch('\a');
return FALSE;
}
return TRUE;
}
BOOL CreateBlock()
{
block = random(4) % 4;
turn = random(7) % 7;
dx = BX + 5;
dy = BY + 4;
nframe = 50;
if (!GetAround(dx, dy, turn))
return FALSE;
return TRUE;
}
BOOL GetAround(int nx,int ny,int nturn)
{
int i;
for (i = 0; i < 4;i++)
if (board[nx + Shape[block][nturn][i].x][ny + Shape[block][nturn][i].y] != EMPTY)
{
putch('\a');
return FALSE;
}
return TRUE;
}
void MoveBlock(BOOL boolean)
{
int i;
for (i = 0; i < 4; i++)
{
board[Shape[block][turn][i].x][Shape[block][turn][i].y] = boolean ? BRICK : EMPTY;
gotoxy(Shape[block][turn][i].x + 1, Shape[block][turn][i].y + 1);
puts(arTile[board[Shape[block][turn][i].x][Shape[block][turn][i].y]]);
}
}
void ProcessKey()
{
ch = getch();
if (ch == 0xE0 || ch == 0)
{
ch = getch();
switch (ch)
{
case UP:
if (GetAround(dx, dy, (turn + 1) % 4))
{
MoveBlock(FALSE);
turn = (turn + 1) % 4;
MoveBlock(TRUE);
}
break;
case DOWN:
if (GetAround(dx, dy+1, turn))
{
MoveBlock(FALSE);
dy++;
MoveBlock(TRUE);
}
break;
case LEFT:
if (GetAround(dx-1, dy, turn))
{
MoveBlock(FALSE);
dx--;
MoveBlock(TRUE);
}
break;
case RIGHT:
if (GetAround(dx+1, dy, turn))
{
MoveBlock(FALSE);
dx++;
MoveBlock(TRUE);
}
break;
}
}
if (ch == ' ')
{
MoveBlock(FALSE);
while (GetAround(dx, dy+1, turn))
{
dy++;
}
MoveBlock(TRUE);
StackBrick();
}
}
void StackBrick()
{
int i;
for (i = 0; i < 4; i++)
{
board[dx + Shape[block][turn][i].x][dy + Shape[block][turn][i].y] = BRICK;
}
exist = FALSE;
}
아래의 코드는 헤더파일 코드입니다.
현재 콘솔화면에서 플레이하는 테트리스를 만드는 중입니다.
그래도 어케되는지 궁금해서 컴파일을 시켜봤더니 전혀 예상치 못한곳에서 에러가 발생....
1>d:\하정해\해킹\c++공부\tetrisgame.c\tetrisgame.c\tetrisgame.cpp(199): error C3861: 'GetAround': identifier not found
1>d:\하정해\해킹\c++공부\tetrisgame.c\tetrisgame.c\tetrisgame.cpp(208): error C3861: 'GetAround': identifier not found
1>d:\하정해\해킹\c++공부\tetrisgame.c\tetrisgame.c\tetrisgame.cpp(218): error C3861: 'GetAround': identifier not found
1>d:\하정해\해킹\c++공부\tetrisgame.c\tetrisgame.c\tetrisgame.cpp(227): error C3861: 'GetAround': identifier not found
1>d:\하정해\해킹\c++공부\tetrisgame.c\tetrisgame.c\tetrisgame.cpp(241): error C3861: 'GetAround': identifier not found
전부다 ProcessKey함수안에 있는 GetAround함수에서 나온 에러구요 식별자를 찾을수가 없다고 나오네요...
main 함수 안에있는 GetAround 에서는 아무런 에러도 발생하지 않는데 대체 뭐가 문제인건지....