다운로드 링크가 정상적으로 보이지 않는 경우 애드블록을 해제해 주세요.
본문 바로가기
  • 혜음우리말화연구소
잘 사용하지 않는 카테고리/c++ 공략하기

c언어 bomblink 1

by WindowsTiger 2015. 6. 20.

이상하게 폭탄터트리게하는 재귀함수 부분에서 튕기네요

그래서 주석처리






#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

#include <Windows.h>

#include <time.h>


#define BLACK 0

#define DARK_BLUE 1

#define DARK_GREEN 2

#define DARK_SKY 3

#define DARK_RED 4

#define DARK_PUPPLE 5

#define DARK_YELLOW 6

#define GRAY 7

#define DARK_GRAY 8

#define BLUE 9

#define GREEN 10

#define SKY 11

#define RED 12

#define PUPPLE 13

#define YELLOW 14

#define WHITE 15


    int bombs_a[10][5]={0};

    int bombs_b[10][5]={0};

    int bombs_c[10][5]={0};

    int bombs_ab[6]={0};

    int bombs_bb[6]={0};

    int fire_left=0;

    int fire_right=0;

    int icon_x=3;

    int icon_y=7;


void color(int background, int text) /*색깔 함수*/

{

SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), background*16+text);

}


void cursor(int x, int y) /*커서이동 함수 부분*/

{

 COORD XY = {x, y};

 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), XY);

}




int countdown=0;


void fire()

{

int i;


    if(countdown==0)

    {

    if(fire_left==15&&fire_right==15)

    {

        i=rand()%2;

        if(i==0)

            fire_left=0;

        else

            fire_right=0;

        countdown=500;

    }

    else if(fire_left<15)

        {

        fire_left++;

        countdown=50;

        }

    else if(fire_right<15)

        {

        fire_right++;

        countdown=50;

        }

    }

    else

        countdown--;

}

void up()

{

    int k,j;

    for(j=1; j<=5; j++)

    {

        if(bombs_a[1][j]=!0)

    {

        //gameover();

    }

    }

    for(k=1; k<=10; k++)

    {

        for(j=0; j<=5; j++)

            if(bombs_a[k+1][j]>0)

            {

                bombs_a[k][j]=bombs_a[k+1][j];

                bombs_b[k][j]=bombs_b[k+1][j];

                bombs_a[k+1][j]=0;

                bombs_b[k+1][j]=0;

            }

        }


    for(j=0; j<=5; j++)

    {

        bombs_a[11][j]=bombs_ab[j];

        bombs_b[11][j]=bombs_bb[j];

    }

    for(j=0; j<=5; j++)

        {

            bombs_ab[j]=rand()%5;

            bombs_bb[j]=1;

        }

        for(j=0; j<=5; j++)

        {

            if(bombs_ab[j]==0)

                bombs_bb[j]=0;


        }

}

void moving()

{

    int control;

    if(kbhit()){

    control = getche();

    if(control=='a'){

        icon_x--;


        if(icon_x<=0){

            icon_x++;


        }

    }

    else if(control=='d'){

        icon_x++;


        if(icon_x>=6)

            icon_x--;


        }

    else if(control=='w'){

        icon_y--;


        if(icon_y<=0)

            icon_y++;


    }

    else if(control=='s'){

        icon_y++;


        if(icon_y>=11)

            icon_y--;


        }


    else if(control==' '){

        if(bombs_b[icon_y][icon_x]==1)

        {

            bombs_a[icon_y][icon_x]--;

            if(bombs_a[icon_y][icon_x]<=0)

                bombs_a[icon_y][icon_x]+=4;

        }


        }

        else if(control=='r'){

        up();


        }

    }


}

int gravitycount=50;


void gravity()

{

    int i, j;

    if(gravitycount==0)

    {

    for(i=10; i>=1; i--)

    {

        for(j=1; j<=5; j++)

            if(bombs_a[i][j]==0)

        {

            if(bombs_a[i-1][j]>0)

            {

                bombs_a[i][j]=bombs_a[i-1][j];

                bombs_b[i][j]=bombs_b[i-1][j];

                if(bombs_a[i][j]==4)

                {

                    bombs_a[i][j]=2;

                }

                else if(bombs_a[i][j]==2)

                {

                    bombs_a[i][j]=4;

            }

                bombs_a[i-1][j]=0;

                bombs_b[i-1][j]=0;

            }

        }

    }

    gravitycount=50;

    }

    else

        gravitycount--;

}

/*int bombing(int n)

{

    int i,j,k=0;

    for(i=10; i>=1; i--)

    {

        for(j=1; j<=5; j++)

        {

            if(bombs_c[i][j]==n)

            {

                k++;

                if(bombs_a[i-1][j]==1&&i!=1);

                    bombs_c[i-1][j]=n+1;

                if(bombs_a[i+1][j]==3&&i!=5);

                    bombs_c[i+1][j]=n+1;

                if(bombs_a[i][j-1]==4&&j!=1);

                    bombs_c[i][j-1]=n+1;

                if(bombs_a[i][j+1]==2&&j!=5);

                    bombs_c[i][j+1]=n+1;


                k++;


            }

        }

    }

   // if(k!=0)

      //  bombing(n+1);


}

*/

int main ()

{

    int i, j;

    srand(time(NULL));


    for(i=8; i<=10; i++)

    {

        for(j=1; j<=6; j++)

        {

            bombs_a[i][j]=rand()%5;

        }

    }

    for(i=8; i<=10; i++)

    {

        for(j=1; j<=6; j++)

        {

            bombs_b[i][j]=1;

        }

    }

    for(j=1; j<=6; j++)

        {

            bombs_ab[j]=rand()%5;

            bombs_bb[j]=1;

        }

for(j=1; j<=6; j++)

        {

            if(bombs_a[i][j]==0)

                bombs_b[i][j]=0;

        }

while(1)

{

     for(i=10; i>=1; i--)

    {

        for(j=1; j<=6; j++)

        {

            if(bombs_a[i][j]==0)

                bombs_b[i][j]=0;

                if(bombs_b[i][j]==0)

                bombs_a[i][j]=0;


        }

    }



    for(i=1; i<=10; i++)

    {

        cursor(3,i+2);

        color(BLACK,BLACK);

        printf(" ");

        color(YELLOW,RED);


        if(fire_left==i)

            printf("▲");

        else

            printf("  ");


        for(j=1; j<=5; j++)

        {

            //bombs_c[i][j]=0;

            color(SKY,SKY);

            if(bombs_b[i][j]==1)

            color(SKY,BLUE);

            if(j==icon_x&&i==icon_y)

            color(YELLOW,SKY);

            if(j==icon_x&&i==icon_y&bombs_b[i][j]==1)

            color(YELLOW,BLUE);

            if(bombs_a[i][j]==0)

                printf("  ");

            if(bombs_a[i][j]==1)

                printf("▶");

            if(bombs_a[i][j]==2)

                printf("▲");

            if(bombs_a[i][j]==3)

                printf("◀");

            if(bombs_a[i][j]==4)

                printf("▼");

           // printf("%d",bombs_c[i][j]);

        }

        color(YELLOW,RED);

        if(fire_right==i)

            printf("▲");

        else

            printf("  ");

        printf("\n");

    }


        fire();

        moving();

        gravity();

        /*if(bombs_a[fire_left][1]==3)

            {

            bombs_c[fire_left][1]=1;

            bombing(1);

            }

         if(bombs_a[fire_right][5]==1)

            {

            bombs_c[fire_right][5]=1;

            bombing(1);

            }*/

    //cursor(0,0);


}

    //system("pause");


}

 




댓글