문서의 선택한 두 판 사이의 차이를 보여줍니다.
다음 판 | 이전 판 | ||
wiki:ai:python:타이핑_게임_제작_기본 [2020/06/30 18:50] hylee 만듦 |
wiki:ai:python:타이핑_게임_제작_기본 [2023/01/13 18:44] (현재) |
||
---|---|---|---|
줄 9: | 줄 9: | ||
===== 타이핑 게임 제작 (기본) ===== | ===== 타이핑 게임 제작 (기본) ===== | ||
- | ==== 준비 사항 ==== | + | ==== 준비사항 ==== |
- | + | > 아래 파일을 받아 resource 폴더 안에 넣어주고 실행하면 됩니다.\\ | |
- | {{ : | + | {{ : |
+ | \\ | ||
==== 예제 코드 ==== | ==== 예제 코드 ==== | ||
<code python> | <code python> | ||
+ | # Section13-1 | ||
+ | # 업그레이드 타이핑 게임 제작 | ||
+ | # 타이핑 게임 제작 및 기본완성 | ||
+ | |||
+ | import random | ||
+ | import time | ||
+ | |||
+ | words = [] # 영어 단어 리스트(1000개 로드) | ||
+ | |||
+ | n = 1 # 게임 시도 횟수 | ||
+ | cor_cnt = 0 # 정답 개수 | ||
+ | |||
+ | with open(' | ||
+ | for c in f: | ||
+ | words.append(c.strip()) | ||
+ | |||
+ | print(words) | ||
+ | |||
+ | input(" | ||
+ | |||
+ | start = time.time() | ||
+ | |||
+ | while n <= 5: # 5회 반복 | ||
+ | random.shuffle(words) | ||
+ | q = random.choice(words) | ||
+ | |||
+ | print() | ||
+ | print(" | ||
+ | print(q) | ||
+ | |||
+ | x = input() | ||
+ | |||
+ | | ||
+ | if str(q).strip() == str(x).strip(): | ||
+ | print(" | ||
+ | cor_cnt += 1 # 정답 개수 카운트 | ||
+ | else: | ||
+ | print(" | ||
+ | |||
+ | n += 1 # 다음 문제 전환 | ||
+ | |||
+ | end = time.time() | ||
+ | et = end - start # 총 게임 시간 | ||
+ | |||
+ | et = format(et, " | ||
+ | |||
+ | if cor_cnt >= 3: # 3개 이상 합격 | ||
+ | print(" | ||
+ | else: | ||
+ | print(" | ||
+ | | ||
+ | # 수행 시간 출력 | ||
+ | print(" | ||
+ | |||
+ | # 시작지점 | ||
+ | if __name__ == ' | ||
+ | pass | ||
줄 22: | 줄 80: | ||
<code console> | <code console> | ||
+ | Ready? Press Enter Key! | ||
+ | |||
+ | *Question # 1 | ||
+ | irs | ||
+ | irs | ||
+ | Pass! | ||
+ | |||
+ | *Question # 2 | ||
+ | displaying | ||
+ | s | ||
+ | Wrong! | ||
+ | |||
+ | *Question # 3 | ||
+ | roll | ||
+ | d | ||
+ | Wrong! | ||
+ | |||
+ | *Question # 4 | ||
+ | anyway | ||
+ | anyway | ||
+ | Pass! | ||
+ | |||
+ | *Question # 5 | ||
+ | zu | ||
+ | zu | ||
+ | Pass! | ||
+ | 결과 : 합격 | ||
+ | 게임 시간 : 17.357 초 정답 개수 : 3 | ||
</ | </ | ||