본문 바로가기

공부/컴퓨터

[공학프로그램] 사다리 타기 소스 ^_^

반응형


001: #include <stdio.h>
002: #include <conio.h>
003:
004: #define DOWN 1
005: #define LEFT 2
006: #define RIGHT 3
007:
008:
009: int get_start_position();
010: void check();
011: void go();
012: int end_check();
013: void show_point();
014: void show_array();
015:
016:
017: int now_row=1;
018: int now_col=0;
019:
020: int dir=0;
021:
022: char array[15][7] = {
023: { '1' , ' ' ,'2' ,' ' ,'3' ,' ' ,'4' } ,
024: { '|' , ' ' ,'|' ,' ' ,'|' ,' ' ,'|' } ,
025: { '|' , ' ' ,'+' ,'-' ,'+' ,' ' ,'|' } ,
026: { '|' , ' ' ,'|' ,' ' ,'+' ,'-' ,'+' } ,
027: { '|' , ' ' ,'|' ,' ' ,'|' ,' ' ,'|' } ,
028: { '+' , '-' ,'+' ,' ' ,'|' ,' ' ,'|' } ,
029: { '|' , ' ' ,'|' ,' ' ,'|' ,' ' ,'|' } ,
030: { '+' , '-' ,'+' ,' ' ,'+' ,'-' ,'+' } ,
031: { '|' , ' ' ,'|' ,' ' ,'|' ,' ' ,'|' } ,
032: { '|' , ' ' ,'+' ,'-' ,'+' ,' ' ,'|' } ,
033: { '|' , ' ' ,'|' ,' ' ,'|' ,' ' ,'|' } ,
034: { '+' , '-' ,'+' ,' ' ,'|' ,' ' ,'|' } ,
035: { '|' , ' ' ,'|' ,' ' ,'+' ,'-' ,'+' } ,
036: { '|' , ' ' ,'|' ,' ' ,'|' ,' ' ,'|' } ,
037: { 'A' , ' ' ,'B' ,' ' ,'C' ,' ' ,'D' }
038: };
039:
040:
041: void main()
042: {
043: int startx;
044:
045: show_array();
046:
047: startx = get_start_position();
048: now_col = startx;
049:
050: go();
051:
052:
053: }
054:
055: void show_array()
056: {
057: int i = 0;
058: int j = 0;
059:
060: for ( i =0 ; i < 15 ; i++ ) {
061: for ( j = 0 ; j < 7 ;j++ ) {
062: gotoxy(j+2,i+2); printf("%c",array[i][j]);
063: }
064: }
065: }
066:
067:
068:
069: int get_start_position(){
070: int t;
071: printf("

번호 입력 : "
);
072: scanf("%d",&t);
073:
074: while(t < 1 || t > 4 ) {
075: printf("제대로 입력해 주세요 :");
076: scanf("%d",&t);
077: }
078:
079: return (t-1)*2;
080: }
081:
082:
083: void go()
084: {
085: show_point();
086:
087: check();
088:
089: if ( dir == DOWN ) now_row++;
090: else if ( dir == LEFT ) now_col--;
091: else if ( dir == RIGHT ) now_col++;
092:
093: if ( !end_check() ) go();
094:
095: }
096:
097:
098: void check() {
099:
100: if ( array[now_row][now_col] == '|' ) dir = DOWN;
101: else if ( array[now_row][now_col] == '+' ) {
102: if ( dir == LEFT || dir == RIGHT ) dir = DOWN;
103: else if ( now_col == 0 ) dir = RIGHT;
104: else if ( now_col == 6 ) dir = LEFT;
105: else {
106:
107: if ( array[now_row][now_col-1] == '-' ) dir = LEFT;
108: else dir = RIGHT;
109: }
110: }
111:
112: }
113:
114:
115:
116: void show_point()
117: {
118:
119: long int i=0;
120: gotoxy(now_col+2, now_row+2); printf("*");
121: for (i=0; i< 10000000 ; i++);
122: //getch();

123:
124: }
125:
126:
127:
128: int end_check()
129: {
130: if ( array[now_row][now_col] == 'A' ||
131: array[now_row][now_col] == 'B' ||
132: array[now_row][now_col] == 'C' ||
133: array[now_row][now_col] == 'D'
134: )
135: {
136:
137: gotoxy( 30,20 ); printf("%c 에 도착했습니다.",array[now_row][now_col]);
138: return 1;
139: }
140: else return 0;
141: }
142:




반응형