Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 기호 상수
- Logic Gates
- 유니티
- 난수 값 맞추기 게임
- 프로젝트 목록 제거
- ASCII CODE TABLE
- scanf 오류
- time.h
- 문자 분류
- Axes
- 키입력값 받기
- round()함수
- 소스코드 하이라이팅
- 논리 게이트
- 두 수 크기 비교 함수
- 극장 예약 프로그램
- 배열 사용X
- GetAxis()메서드
- Unity
- 2차원 배열
- C 언어
- 개인 정리
- UnityHub
- 반사 벡터
- 미리 컴파일된 헤더 사용안함
- 두 값 교체하기
- C언어
- 유니티허브
- 전처리기 정의
- AWS Discovery Book
Archives
- Today
- Total
flrto
텍스트 게임 본문
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 | #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> #include <stdlib.h> #include <Windows.h> #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <time.h> struct Ability { int hp; int damage; }; const int d_USER = 0; const int d_MON = 1; const int d_BOSS = 2; struct Player { int type; char name[50]; Ability ab; }; Player g_user; Player g_mon; int g_step = 0; int DodgeChance = 0; //15흰색 12,9,10 rgb void color(int a) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), a); } void Init() { g_user.type = d_USER; g_user.ab.hp = 100; g_user.ab.damage = 10; g_step = 0; } void MonInit() { g_mon.type = -1; g_mon.ab.hp = 0; g_mon.ab.damage = 0; } void Combat() { int Choice = 0; int RandNumber = 0; RandNumber = rand() % 4 + 1; // 1 2 3 4 // 1 -> 0 = 100 % // 2 -> 0, 1 = 50 % // 3 -> 0, 1, 2 = 33% // 4 -> 0, 1, 2, 3 = 25% if (g_mon.ab.hp > 0) { while (g_mon.ab.hp > 0 && g_user.ab.hp > 0) { DodgeChance = rand() % RandNumber; Sleep(1000); system("cls"); color(10); printf("\n┏───────────────┓\n│ 플레이어\t┃\n│ HP : %d\t┃\n│ 공격력 : %d\t┃\n┗───────────────┛\n", g_user.ab.hp, g_user.ab.damage); color(13); printf("\n┏───────────────┓\n│ %s\t┃\n│ HP : %d\t┃\n│ 공격력 : %d\t┃\n┗───────────────┛\n", g_mon.name, g_mon.ab.hp, g_mon.ab.damage); color(14); printf("\n행동을 결정하세요!\n1.공격.\n2.도망간다.\n"); color(11); printf("\n도망 확률 %d%%\n", (100 / RandNumber)); scanf("%d", &Choice); switch (Choice) { case 1: color(8); printf("\n┏──────────────────────────────┓\n│ 서로 공격을 주고 받았습니다 !┃\n┗──────────────────────────────┛\n"); g_user.ab.hp -= g_mon.ab.damage; g_mon.ab.hp -= g_user.ab.damage; break; case 2: if (DodgeChance == 0) { color(3); printf("\n┏─────────────────────┓\n│ 도망에 성공했습니다!┃ \n┗─────────────────────┛\n"); color(15); MonInit(); break; } else { color(4); printf("\n┏─────────────────────┓\n│ 도망에 실패했습니다!┃ \n┗─────────────────────┛\n"); g_user.ab.hp -= g_mon.ab.damage; break; } } if (g_mon.ab.hp <= 0 && g_mon.type != -1) { color(14); printf("%s를 처치 했습니다.\n", g_mon.name); if (g_mon.type == 1) { printf("능력치가 오릅니다. HP + 10 Damage + 1"); g_user.ab.hp += 10; g_user.ab.damage += 1; } else if (g_mon.type == 2) { printf("능력치가 오릅니다. HP + 50 Damage + 20"); g_user.ab.hp += 50; g_user.ab.damage += 20; color(11); printf("\n진행률이 초기화 됩니다."); g_step = 0; } MonInit(); break; } } } } void MonsterSpawn() { if (g_step < 100) { g_mon.type = d_MON; strcpy(g_mon.name, "몬스터"); g_mon.ab.hp = rand() % 30 + 10; g_mon.ab.damage = rand() % 6 + 5; } else if (g_step >= 100) { g_mon.type = d_BOSS; strcpy(g_mon.name, "보스 "); g_mon.ab.hp = rand() % 100 + 10; g_mon.ab.damage = rand() % 20 + 5; } } void main() { Init(); srand(time(NULL)); while (g_user.ab.hp > 0) { color(15); printf("진행률 : %d%%\n", g_step); int randVal = rand() % 10; //몬스터 등장 if (g_step >= 100) { MonsterSpawn(); color(12); printf("[[[[[[%s출현]]]]]]\n", g_mon.name); Combat(); } else if (randVal == 0 && g_step < 100) { MonsterSpawn(); color(12); printf("[[[[[[%s출현]]]]]]\n", g_mon.name); Combat(); } //그냥 진행 else { color(15); printf("아무일도 없었습니다\n"); } g_step++; printf("\n\n\n"); system("pause"); system("cls"); } printf("당신은 죽었습니다...\n"); } | cs |
Comments