C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[59312] 블럭에대해.. 정말모르겠씁니다 도와주세요!!!!!!!!!!
제룽뎅이 [] 1135 읽음    2009-12-03 15:16
#include <stdio.h>

#include <stdlib.h>
#include <conio.h>
#include <windows.h>

#define box_length 15
#define box_height 15

void intro_game(void);
void game_control(void);
void gotoxy(int x, int y);
int left_right_move(void);
void move_down(int x);
void draw_rectangle(int c, int r);
int max_block(void);

int block_stack[box_length*2+1]={0}; // 해당위치의 블록을 누적

int main(void)
{
    intro_game();
    game_control();
    gotoxy(1, box_height+3);
    printf("game이 종료되었습니다.                 \n");
    return 0;
}

void intro_game(void)
{
    system("cls");
    printf("블록쌓기 \n\n");
    printf("블록이 좌우로 움직일때 스페이스키를 누르면\n");
    printf("블록이 떨어져 바닥에 쌓입니다.\n\n");
    printf("아무키나 누르면 게임을 시작합니다. \n");
    getch();
}

void game_control(void)
{
    int x, count=0;
    system("cls");
    draw_rectangle(box_length, box_height);
    gotoxy(box_length*2+5,3);
    printf("블록의 개수: %2d", box_height);
    gotoxy(1, box_height+3);
    printf("스페이스키를 누르면 블록이 떨어지고\n");
    printf("바닥에 쌓입니다. \n");
    while(count<box_height)
    {
        gotoxy(box_length*2+5,4);
        printf("시도한 횟수: %2d", count+1);
        gotoxy(box_length*2+5,5);
        printf("쌓인 블록수: %2d", max_block());
        x=left_right_move();
        move_down(x);
        count++;
        getch();
    }
}

int max_block(void)
{
    int i, max=0;
    for(i=1;i<box_height*2+1;i++)
    {
        if (max<=block_stack[i])
            max=block_stack[i];
    }
    return max;
}


int left_right_move(void)
{
    int x=3, y=2, temp=2;
    do
    {
        x+=temp;
        if (x>(box_length*2)) //x방향 최대값 설정
            temp=-2;
        if (x<3)
        {
            x=3;
            temp=2;
        }

        gotoxy(x, y);
        printf("□");
        Sleep(50); //블록이 좌우로 움직이는 속도를 조절
        gotoxy(x, y);
        printf("  ");

    }while(!kbhit());
    block_stack[x]+=1;
    return x;
}

void move_down(int x)
{
    int y;
    for(y=2;y<box_height+2-block_stack[x];y+=1)
    {
        gotoxy(x, y);
        printf("□");
        Sleep(20);
        gotoxy(x, y);
        printf("  ");
        Sleep(10);
    }
    gotoxy(x,box_height+2-block_stack[x]);
    printf("□");
}

void gotoxy(int x, int y)
{
   COORD Pos = {x - 1, y - 1};
   SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}

void draw_rectangle(int r, int c)
{

    int i, j;
    unsigned char a=0xa6;
    unsigned char b[7];

    for(i=1;i<7;i++)
        b[i]=0xa0+i;

    printf("%c%c",a, b[3]);
    for(i=0;i<r;i++)
        printf("%c%c", a, b[1]);
    printf("%c%c", a, b[4]);
    printf("\n");

    for(i=0;i<c;i++)
    {
        printf("%c%c", a, b[2]);
        for(j=0;j<r;j++)
            printf("  ");
        printf("%c%c",a, b[2]);
        printf("\n");
    }
    printf("%c%c", a, b[6]);
    for(i=0;i<r;i++)
        printf("%c%c", a, b[1]);
    printf("%c%c", a, b[5]);
    printf("\n");
}

-----------------------------------------------------------
태트리스를처럼 완벽히 원하진않습니다
하지만..........
아님 한줄이 다 맞춰지면 없어지는것처럼
하려고하는데 소스를뭘넣어야할지모르겠습니다
도와주세요!!!!!!!!!!!!!!!!!!!!
그리고 15개만 블럭이내려오는데
무한으로내려와서
계속할수있게끔은 어캐해야하는겁니까?
무한...................댓글부탁드립니다
1. 테트리스처럼 한줄이완성되면 없어지는거처럼하는 경우
   소스는 무엇입니까?
2. 블럭이무제한나오게해주시게해주세요
소스는 무엇이죠?

부탁드립니다.........ㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜ

+ -

관련 글 리스트
59312 블럭에대해.. 정말모르겠씁니다 도와주세요!!!!!!!!!! 제룽뎅이 1135 2009/12/03
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.