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 | 31 |
Tags
- GetAxis()메서드
- 문자 분류
- 반사 벡터
- 미리 컴파일된 헤더 사용안함
- 전처리기 정의
- UnityHub
- ASCII CODE TABLE
- Axes
- scanf 오류
- time.h
- 2차원 배열
- 키입력값 받기
- 난수 값 맞추기 게임
- C 언어
- round()함수
- Logic Gates
- 유니티허브
- AWS Discovery Book
- 개인 정리
- 프로젝트 목록 제거
- 기호 상수
- Unity
- 두 수 크기 비교 함수
- 유니티
- C언어
- 극장 예약 프로그램
- 두 값 교체하기
- 배열 사용X
- 소스코드 하이라이팅
- 논리 게이트
Archives
- Today
- Total
flrto
C언어 보물찾기 본문
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 | #include <stdio.h> #include <Windows.h> #include <limits.h> #include <stdlib.h> #include <time.h> #include <conio.h> const int SIZE_X = 20; const int SIZE_Y = 10; const int MapWall = 1; const int Player = 2; const int Star = 3; int StarX = 0; int StarY = 0; int PlayerX = 0; int PlayerY = 0; int AutoX = 0; int AutoY = 0; int MO = 0; int AutoFlag = 0; int list[SIZE_Y][SIZE_X] = { { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } }; void KeyChk(); void DrawWindow(); void Init(); void Mission(); void Auto(); int main(void) { Init(); while (MO != 1) { DrawWindow(); KeyChk(); Mission(); Auto(); } return 0; } void Init() { PlayerX = 5; PlayerY = 5; list[PlayerY][PlayerX] = 2; srand(time(NULL)); while (list[StarY][StarX] != 3) { StarX = rand() % SIZE_X; StarY = rand() % SIZE_Y; if (list[StarY][StarX] != MapWall && list[StarY][StarX] != Player) { list[StarY][StarX] = Star; } } } void Auto() { if (AutoFlag == 1) { Sleep(100); if (AutoX != 0) { if (AutoX > 0) { PlayerX++; AutoX--; } if (AutoX < 0) { PlayerX--; AutoX++; } } if (AutoX == 0 && AutoY != 0) { if (AutoY > 0) { PlayerY++; AutoY--; } if (AutoY < 0) { PlayerY--; AutoY++; } } } } void Mission() { if (StarX == PlayerX && StarY == PlayerY) { MO = 1; } if (MO == 1) { system("cls"); printf("보물을 찾았습니다.\n"); } } void DrawWindow() { system("cls"); for (int y = 0; y < SIZE_Y; y++) { for (int x = 0; x < SIZE_X; x++) { if (list[y][x] == 1) printf("#"); else if (PlayerX == x && PlayerY == y) printf("$"); else if (list[y][x] == 3) printf("*"); else printf(" "); } printf("\n"); } printf("\nStarX : %d\tStarY : %d\nPlayerX : %d\tPlayerY : %d", StarX, StarY, PlayerX, PlayerY, AutoX, AutoY); } void KeyChk() { if (AutoFlag != 1) { char ch; ch = _getch(); switch (ch) { case 'w'/*119*/: printf("\n위로\n"); if (list[--PlayerY][PlayerX] == 1) PlayerY++; break; case 's'/*97*/: printf("\n밑으로\n"); if (list[++PlayerY][PlayerX] == 1) PlayerY--; break; case 'a'/*100*/: printf("\n왼쪽으로\n"); if (list[PlayerY][--PlayerX] == 1) PlayerX++; break; case 'd'/*115*/: printf("\n오른쪽으로\n"); if (list[PlayerY][++PlayerX] == 1) PlayerX--; break; case 'p'/*115*/: AutoX = StarX - PlayerX; AutoY = StarY - PlayerY; AutoFlag = 1; break; } } } | cs |
'C > Academy' 카테고리의 다른 글
C언어 간단한 로그인 프로그램 (1) | 2019.06.25 |
---|---|
문제 (0) | 2019.06.20 |
C 언어 로또(배열 사용 X) (0) | 2019.06.14 |
C 언어 두 수 크기 비교 함수 (0) | 2019.06.14 |
C 언어 난수 값 맞추기 게임 (0) | 2019.06.13 |
Comments