게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
(질문)콘솔 화면에서 실행하는 테트리스 만드는 중인데 질문점..
게시물ID : programmer_13241짧은주소 복사하기
작성자 : 우와우와우왕
추천 : 0
조회수 : 437회
댓글수 : 2개
등록시간 : 2015/09/12 16:51:47
옵션
  • 본인삭제금지
#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;
}
 
#ifndef TURBOC_HEADER

#define TURBOC_HEADER



#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

#include <time.h>

#include <windows.h>



typedef enum { NOCURSOR, SOLIDCURSOR, NORMALCURSOR } CURSOR_TYPE;

void clrscr();

void gotoxy(int x, int y);

int wherex();

int wherey();

void setcursortype(CURSOR_TYPE c);



#define delay(n) Sleep(n)                              // n/1000珥덈쭔???쒓컙 ??/span>

#define randomize() srand((unsigned)time(NULL))         // ?쒖닔 諛쒖깮湲?珥덇린??/span>

#define random(n) (rand() % (n))                        //0~n源뚯????쒖닔 諛쒖깮



// ??ㅽ겕濡쒓? ?뺤쓽?섏뼱 ?덉쑝??⑥닔???먰삎??좎뼵?섍퀬 ?뺤쓽???섏? ?딅뒗??

#ifndef TURBOC_PROTOTYPE_ONLY



// ?붾㈃??⑤몢 ?대떎.

void clrscr()

{

    system("cls");

}



// 而ㅼ꽌瑜?x,y醫뚰몴濡??대룞?쒗궓??

void gotoxy(int x, int y)

{

    COORD Cur;

    Cur.X = x;

    Cur.Y = y;

    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Cur);

}



// 而ㅼ꽌??x 醫뚰몴瑜?議곗궗?쒕떎.

int wherex()

{

    CONSOLE_SCREEN_BUFFER_INFO BufInfo;



    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &BufInfo);

    return BufInfo.dwCursorPosition.X;

}



// 而ㅼ꽌??y醫뚰몴瑜?議곗궗?쒕떎.

int wherey()

{

    CONSOLE_SCREEN_BUFFER_INFO BufInfo;



    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &BufInfo);

    return BufInfo.dwCursorPosition.Y;

}



// 而ㅼ꽌瑜??④린嫄곕굹 ?ㅼ떆 ?쒖떆?쒕떎.

void setcursortype(CURSOR_TYPE c)

{

    CONSOLE_CURSOR_INFO CurInfo;



    switch (c) {

    case NOCURSOR:

        CurInfo.dwSize = 1;

        CurInfo.bVisible = FALSE;

        break;

    case SOLIDCURSOR:

        CurInfo.dwSize = 100;

        CurInfo.bVisible = TRUE;

        break;

    case NORMALCURSOR:

        CurInfo.dwSize = 20;

        CurInfo.bVisible = TRUE;

        break;

    }

    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &CurInfo);

}



 
 
위의 코드는 테트리스 코드이고
 
아래의 코드는 헤더파일 코드입니다.
 
 
 
현재 콘솔화면에서 플레이하는 테트리스를 만드는 중입니다.
 
일단 지금 만들고 있는 중이라 이대로 실행해도 제대로 작동 안될껀 뻔하지만
 
그래도 어케되는지 궁금해서 컴파일을 시켜봤더니 전혀 예상치 못한곳에서 에러가 발생....
 
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함수에서 나온 에러구요 식별자를 찾을수가 없다고 나오네요...
 
msdn에서 찾아봐도 c3861은 함수를 선언하지 않고 사용할 경우에 뜨는 에러라고 하는데
 
위에서 보시다시피 함수의 선언과 정의 둘다 해놓았고
 
main 함수 안에있는 GetAround 에서는 아무런 에러도 발생하지 않는데 대체 뭐가 문제인건지....
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호