document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <windows.h>
  5.  
  6. #define RED 12
  7. #define WHITE 15
  8.  
  9. #define LINE 6           // 라인수를 증가 시킬 수 있습니다.
  10. #define MAX (LINE*4)
  11.  
  12. void textcolor(int color_number); // 텍스트 칼라 출력
  13. void gotoxy(int x, int y); // 좌표 이동
  14. int baserand(int x, int y); // 랜덤 범위 지정
  15.  
  16. void VerticalSet(int MAP[20][MAX]);
  17. void HorizonSet(int MAP[20][MAX]);
  18.  
  19. void PrintLine(int MAP[20][MAX]);
  20.  
  21. void LadderStart( int MAP[20][MAX] , int Select );
  22.  
  23. int main(void){
  24.  
  25.     int MAP[20][MAX];
  26.     int Select;
  27.     printf("출발점 설정 ( 1 ~ %d ) : ",LINE);
  28.     scanf("%d",&Select);
  29.     Select--;
  30.     system("pause");
  31.     system("cls"); 
  32.    
  33.     // 세로선 설정
  34.     VerticalSet(MAP);
  35.     // 가로선 설정
  36.     HorizonSet(MAP);
  37.    
  38.     PrintLine(MAP);    
  39.  
  40.     LadderStart(MAP,Select);   
  41.  
  42.     return 0;
  43. }
  44.  
  45. // 텍스트 칼라 출력
  46. void textcolor(int color_number)
  47. {
  48.  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),color_number);
  49. };
  50. // 좌표 이동
  51. void gotoxy(int x, int y)
  52. {
  53.      COORD Cur;
  54.      Cur.X=x;
  55.      Cur.Y=y;
  56.      SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Cur);
  57. }
  58. // 랜덤 범위 지정
  59. int baserand(int x, int y){
  60.  
  61.     static int z = 0;
  62.     int tmp;
  63.     if(z==0){
  64.         srand((int)time(NULL));
  65.         rand();rand();rand();rand();
  66.         srand(rand());
  67.         z=1;
  68.     }
  69.  
  70.     tmp = rand()%(y-x+1)+x;
  71.     return tmp;
  72. }
  73.  
  74. void VerticalSet(int MAP[20][MAX]){
  75.     int i,j;
  76.     // 직선 긋기
  77.     for(i=0;i<20;i++){
  78.         for(j=0;j<MAX;j++){
  79.             if( (j%4 ==0) ){
  80.                 MAP[i][j] = 5;    
  81.             }else{
  82.                 MAP[i][j] = 0;
  83.             }
  84.         }
  85.     }
  86. }
  87. void HorizonSet(int MAP[20][MAX]){
  88.     int i,j;   
  89.     int x,y;
  90.     for(i=0;i<20;i++){
  91.         // 선 긋기
  92.         x = baserand(0,LINE-2)*4;
  93.         y = baserand(1,19);  
  94.         if( MAP[y][x+4] == 5 && MAP[y][x-4] == 5 ){
  95.             j=x;
  96.             MAP[y][j++] = 25;
  97.             for(;j<x+4;j++){
  98.                 MAP[y][j] = 6;
  99.             }
  100.  
  101.             MAP[y][j] = 23;
  102.         }
  103.     }
  104. }
  105.  
  106. void PrintLine(int MAP[20][MAX]){
  107.     int i,j;
  108.     for(i=0;i<20;i++){
  109.         for(j=0;j<MAX;j++){
  110.             switch(MAP[i][j]){
  111.             case 0:
  112.                 printf(" ");
  113.                 break;
  114.             case 6:
  115.                 printf("%c",MAP[i][j]);        
  116.                 break;    
  117.             default:
  118.                 printf("%c",MAP[i][j]);
  119.             }
  120.         }
  121.         printf("\\n");
  122.     }
  123.     printf("\\n");
  124.     for(i=1;i<LINE+1;i++){
  125.         printf("%-4d",i);
  126.     }
  127.     printf("\\n\\n");
  128. }
  129.  
  130. void LadderStart( int MAP[20][MAX] , int Select ){
  131.     int i;
  132.     int x,y;
  133.     x = Select*4,y= 0;
  134.     for(y=0;y<20;y++){
  135.         if( MAP[y][x] == 25 ){
  136.             for(i = x; i < x + 4; i++){
  137.                 Sleep(200);
  138.                 gotoxy(i,y);
  139.                 textcolor(RED);
  140.                 printf("%c",MAP[y][i]);
  141.             }
  142.             x = i;
  143.         }else if( MAP[y][x] == 23 ){
  144.             for(i = x; i > x - 4; i--){
  145.                 Sleep(200);
  146.                 gotoxy(i,y);
  147.                 textcolor(RED);
  148.                 printf("%c",MAP[y][i]);
  149.             }
  150.             x = i;
  151.         }
  152.         Sleep(200);
  153.         gotoxy(x,y);
  154.         textcolor(RED);
  155.         printf("%c",MAP[y][x]);
  156.     }
  157.  
  158.     textcolor(WHITE);
  159.     gotoxy(0,22);
  160.     printf("%d 번 당첨 \\n",(x/4)+1);
  161. }
');