프로그래밍

겜프 #1

juni929 2018. 6. 18. 22:51
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>
 
void gotoxy(int x, int y)
{
    COORD Pos = { x, y };
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
void textcolor(int color_number) {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color_number);
void removeCursor() { //콘솔에서 깜박이는 커서 삭제하는 함수
    CONSOLE_CURSOR_INFO curInfo;
    GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &curInfo);
    curInfo.bVisible = 0;
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &curInfo);
}
int Random(); //컴퓨터의 랜덤 값 출력
void game1(); // 가위바위보 게임 시작 함수
//void game2(); // 묵찌바 게임 시작 함수
void HOF(name, score); //명예의 전당 함수
void help(); //도움말 함수
 
 
int main()
{
    removeCursor();
    int number = 0;
    system("mode con cols=150 lines=50");
 
    textcolor(10);
    gotoxy(174);
    printf("  ●●●●●●●      ●       ●●●●●●●●●                          ●       ●●●●●●●●●           "); gotoxy(175);
    printf("              ●      ●           ●      ●           ●●●●●●       ●                       ●      "); gotoxy(176);
    printf("              ●      ●           ●      ●           ●                 ●       ●●●●●●●●●      "); gotoxy(177);
    printf("      ●●●●●  ●●●       ●●●●●●●●●       ●                 ●       ●                           "); gotoxy(178);
    printf("              ●      ●                                ●●●●●●   ●●●       ●●●●●●●●●     "); gotoxy(179);
    printf("                            ●●●●●●●●●●●●    ●                 ●     ●●●●●●●●●●●                       "); gotoxy(1711);
    printf("            ●●●●●●          ●        ●          ●                 ●        ●●●●●●●●                      "); gotoxy(1712);
    printf("            ●        ●          ●        ●          ●●●●●●       ●                      ●        "); gotoxy(1713);
    printf("            ●        ●          ●        ●                             ●        ●●●●●●●●         "); gotoxy(1714);
    printf("            ●        ●          ●        ●                             ●        ●                      "); gotoxy(1715);
    printf("            ●●●●●●          ●        ●                             ●        ●●●●●●●●         "); gotoxy(1819);
 
    printf("                       ●                              ●                               ● "); gotoxy(1820);
    printf("           ●●●      ●       ●●●●●●●●       ●          ●●●●●●●●●   ● "); gotoxy(1821);
    printf("          ●    ●     ●                     ●       ●                          ●   ● "); gotoxy(1822);
    printf("         ●      ●    ●                     ● ●●●●                          ●   ●"); gotoxy(1823);
    printf("        ●        ●   ●                     ●       ●          ●●●●●●●●●   ● "); gotoxy(1824);
    printf("       ●          ●  ●                     ●       ●          ●                   ●●● "); gotoxy(1825);
    printf("        ●        ●   ●                     ● ●●●●          ●                   ●  "); gotoxy(1826);
    printf("         ●      ●    ●                     ●       ●          ●●●●●●●●●   ● "); gotoxy(1827);
    printf("          ●    ●     ●                     ●       ●                               ● "); gotoxy(1828);
    printf("           ●●●      ●                              ●                               ●"); gotoxy(1829);
    printf("                       ●                              ●                               ● "); gotoxy(1830);
    printf("\n\n\n\n");
    Sleep(500);
    textcolor(8);
    gotoxy(5035);
    printf("[ 시작하려면 아무키나 누르세요 ]");
    Sleep(500);
    gotoxy(5045);
    printf("[ 시작하려면 아무키나 누르세요 ]");
    _getch();
 
    while (1)
    {
        textcolor(12);
        system("cls"); // 콘솔창 초기화
        printf("\n\n                            [ 메인메뉴 ]\n\n");
        printf("\n                            1. 가위바위보\n");
        printf("\n                            2. 묵찌빠(제작중)\n");
        printf("\n                            3. 게임방법\n");
        printf("\n                            4. 명예의 전당\n");
        printf("\n                            5. QUIT\n");
        printf("선택>");
        scanf("%d"&number);
 
        switch (number)
        {
        case 1:
            game1(); // 가위바위보 게임의 주 함수 호출 
            break;
        case 2:
            //game2(); // 묵찌빠 게임의 주 함수 호출 
            break;
        case 3:
            help(); // 도움말 출력 함수 호출
            break;
        case 4:
            HOF();    // 명예의 전당 점수표 확인
            break;
        case 5:
            system("Cls");
            printf("Play 해 주셔서 감사합니다. 다음에 또 놀러오세요!"); // 명예의 전당 점수표 확인
            return 0;
            break;
        default:
            gotoxy(7520);
            printf("이 프로그램을 하고 있는 분께.. 여러분 글씨를 제대로 읽을 수 있다면 왜 누르셨나요?? \n제대로 눌러주세요!!");
            _getch();// 그외 입력 무시
            break;
        }
    }
}
 
int Random() // 반환하는 값은 정수형이다.
{
    int RD = 0;
 
    srand(time(NULL)); // 랜덤 값을 시간으로 설정한다.
    RD = rand() % 3 + 1// RD에 3으로 나눈 나머지 + 1 즉, 1~3까지의 값
 
    return RD; // 정수형 RD를 반환 한다.
}
 
void game1()
{
    int person;
    int computer;
    int score = 1;
    int life = 3;
    char name[6];
    system("cls");
    printf("가위바위보를 시작합니다.\n");
 
    while (1)
    {
        printf("\n가위바위 보!");
        scanf("%d"&person);
        computer = Random();
 
        if (person == 1)
        {
            if (computer == 1)
            {
                printf("도전자 : 가위 \n 컴퓨터 : 가위\n\n무승부!!!");
                score += 30;
            }
            else if (computer == 2)
            {
                printf("도전자 : 가위 \n 컴퓨터 : 주먹\n\n졌따..");
                life -= 1;
            }
            else if (computer == 3)
            {
                printf("도전자 : 가위 \n 컴퓨터 : 보\n\n이겼따..");
                score += 100;
            }
        }
        else if (person == 2)
        {
            if (computer == 1)
            {
                printf("도전자 : 주먹 \n 컴퓨터 : 가위\n\n이겼따!");
                score += 100;
            }
            else if (computer == 2)
            {
                printf("도전자 : 주먹 \n 컴퓨터 : 주먹\n\n무승부!!..");
                score += 30;
            }
            else if (computer == 3)
            {
                printf("도전자 : 주먹 \n 컴퓨터 : 보\n\n졋네용..");
                life -= 1;
            }
        }
        else if (person == 3)
        {
            if (computer == 1)
            {
                printf("도전자 : 보 \n 컴퓨터 : 가위\n\n졋네용..");
                life -= 1;
            }
            else if (computer == 2)
            {
                printf("도전자 : 보 \n 컴퓨터 : 주먹\n\n이겼다!");
                score += 100;
 
            }
            else if (computer == 3)
            {
                printf("도전자 : 보 \n 컴퓨터 : 보\n\n무승부..");
                score += 30;
            }
        }
        else
            printf("제대로 입력해 시키야");
        if (life == 3)
            printf("재도전 횟수 3번 남았습니다.");
        else if (life == 2)
            printf("재도전 횟수 2번 남았습니다.");
        else if (life == 1)
            printf("재도전 횟수 1번 남았습니다.");
        else
        {
            printf("이름을 입력해주세요\n입력>");
            scanf("%s", name);
            printf("받은 점수는 %d점입니다.", score);
            printf("5초뒤에 메인화면으로 넘어갑니다");
            Sleep(5000);
            HOF(name, score);
            return main();
        }
    }
}
/*void game2() {
    int person;
    int computer;
    int turn;
    int life = 3;
    system("cls");
    printf("게임을 시작합니다!!");
    while (1) 
    {
        printf("선공을 정합니다!");
        scanf("%d", &person);
        computer = Random();
        if (person == 1) {
            if (computer == 1) 
            {
                printf("다시 해주세요!!");
            }
            else if (computer == 2) 
            {
                printf("컴퓨터가 공격합니다.");
            }
            else if (computer == 3)
            {
                printf("오! 선공입니다.!");
            }
        }
        if (person == 2) {
            if (computer == 1)
            {
                printf("오! 선공입니다.!");
            }
            else if (computer == 2)
            {
                printf("다시 해주세요!!");
            }
            else if (computer == 3)
            {
                printf("컴퓨터가 공격합니다.");
            }
        }
        if (person == 3) {
            if (computer == 1)
            {
                printf("컴퓨터가 공격합니다.");
            }
            else if (computer == 2)
            {
                printf("오! 선공입니다.!");
            }
            else if (computer == 3)
            {
                printf("다시 해주세요!!");
            }
        }
    }
    */
 
void HOF(name, score) {
 
    system("cls");
    printf("〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓  〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n");
    printf("     명예의 전당                                                     \n\n");
 
    printf("%s님은 %d의 점수로 명예의 전당에 오르신걸 다시 한번 인증합니다.", name, score);
    Sleep(5000);
    return main();
}
 
void help()
{
    printf("이 게임은 컴퓨터와 가위바위보, 묵찌바 대결을 하여 점수를 얻는 게임입니다.\n");
    printf("게임은 가위바위보, 묵찌바로 이루어져 있으며 3번 컴퓨터에게 패배시 종료되게 됩니다.\n");
    printf("조작법은 1은 '가위' 2은 '주먹' 3은 '보자기'입니다. 즐겁게 게임하세요!!\n");
    printf("명예의 전당 수록방법 700점이 넘을시 순위대로 이름과 같이 오르게 됩니다.");
    _getch();
}
    
cs

수정해야될 것 묵찌바 게임 완성, 명예의 전당 700점이상이후에 등재 순위 매김,