코딩도장

방탈출 게임 만들기 (간단)

방탈출 게임을 만들려면 기본적인 맵을 구상하는게 좋습니다.

조건 1. 10줄 출력하게 합니다.

방탈출이기 때문에 힌트는 하나라도 있어야 합니다.

그다음에는 비밀번호를 만듭니다.

조건 1. 비밀번호는 3자리로 한다. 2. 비밀번호를 1자리씩 입력하게 한다. (1개 입력하고 엔터 누르는 식) 3. 비밀번호가 틀리면 처음부터 다시 입력하게 한다. 4. 비밀번호가 맞으면 성공 메시지를 출력한다.

2023年04月22日 18:06

고양이 푸딩

(追記) (追記ここまで)
댓글 작성은 로그인이 필요합니다.
(注記) 상대에게 상처를 주기보다 서로에게 도움이 될 수 있는 댓글을 달아 주세요.
풀이 보기 (14개의 풀이가 있습니다)
import random
password = [random.randint(0, 9) for _ in range(3)]
idx = 0
while True:
 if idx == 3:
 print('3개의 비번을 맞추었습니다.!!')
 break
 num = int(input('1자리 정수을 입력하세요(0, 1, 2, . . , 9): '))
 if num != password[idx]:
 if num > password[idx]:
 print('작은 수를 입력하세요')
 else:
 print('더 큰 수를 입력하세요.')
 print('처음 부터 다시 숫자를 입력하세요.')
 idx = 0
 else:
 idx += 1
댓글 작성은 로그인이 필요합니다.
(注記) 상대에게 상처를 주기보다 서로에게 도움이 될 수 있는 댓글을 달아 주세요.
import random
def make_num():
 return [random.randrange(0, 9) for i in range(3)]
secret_num = make_num()
t_num = 1
while True:
 if t_num == 4:
 print("성공\n게임종료")
 break
 input_num = input("{}자리 비밀번호 입력 : ".format(t_num))
 if str(secret_num[t_num-1]) == input_num:
 t_num += 1
 else:
 t_num = 1

비밀번호부분만 짜봤습니다.

[조건 1. 10줄 출력하게 합니다] 이게 무슨뜻인지는 잘 이해가 안되네요ᅲ

댓글 작성은 로그인이 필요합니다.
(注記) 상대에게 상처를 주기보다 서로에게 도움이 될 수 있는 댓글을 달아 주세요.
import random
number = random.randrange(100, 1000)
number_first = str(number)[0]
number_second = str(number)[1]
done = False
while not done:
 print('첫번째 수와 두번째 수의 합은 {0}'.format(int(number_first) + int(number_second)))
 answer = int(input('답을 입력해주세요: '))
 if answer == number:
 print('성공!')
 done = True
 else:
 print('틀림...')

2023年05月07日 12:34

pizza

댓글 작성은 로그인이 필요합니다.
(注記) 상대에게 상처를 주기보다 서로에게 도움이 될 수 있는 댓글을 달아 주세요.
/*
조건 1. 비밀번호는 3자리로 한다. 
2. 비밀번호를 1자리씩 입력하게 한다. (1개 입력하고 엔터 누르는 식) 
3. 비밀번호가 틀리면 처음부터 다시 입력하게 한다. 
4. 비밀번호가 맞으면 성공 메시지를 출력한다.
*/
import java.util.Scanner;
class Door {
 //field
 private int password;
 //constractor
 public Door() {
 this.setPassword(new java.util.Random().nextInt(1000));
 }
 //getter setter
 public void setPassword(int password) {
 this.password = password;
 }
 public int getPassword() {
 return this.password;
 }
 //methed
 public boolean check(int password) {
 if(password == this.getPassword()) {
 return true;
 } else {
 return false;
 }
 }
}
public class Main {
 public static void main(String[] args) {
 Door door = new Door();
 Scanner sc = new Scanner(System.in);
 String ans = "";
 int intAns = 0;
 while (true) {
 ans = "";
 try {
 for (int i = 0; i < 3; i++) {
 System.out.print("숫자를 1개 입력해주세요:");
 ans += sc.next();
 }
 } catch (Exception e) { }
 try {
 intAns = Integer.parseInt(ans);
 } catch (Exception e) {
 System.err.println(e.toString());
 System.out.println("숫자를 정확히 입력해주세요");
 continue;
 }
 if (door.check(intAns)) { 
 System.out.println("정답입니다!");
 break; 
 }
 System.out.println((door.getPassword() - intAns) > 0 ? "틀렸습니다. 더 높은 숫자로 다시 입력해주세요":"틀렸습니다. 더 낮은 숫자로 다시 입력해주세요"); 
 }
 }
}

2023年06月15日 22:49

赤野冬樹

댓글 작성은 로그인이 필요합니다.
(注記) 상대에게 상처를 주기보다 서로에게 도움이 될 수 있는 댓글을 달아 주세요.

힌트:비밀번호 는 3 자릿수 입니다. 첫 번째 숫자: 넓이가 40cm2 이고 높이가 10cm 일때 밑변의 길이 두 번째 숫자: 23 x -33 + 217 세 번째 숫자: 169.9 - 정사각형의 한 각도 ÷ 10 - 0.99){.python} a = int(input()) if a == 4: pass else: print("처음부터 다시 입력 하세요") continue b = int(input()) if b == 1: pass else: print("처음부터 다시 입력 하세요") continue c = int(input()) if c == 7: pass else: print("처음부터 다시 입력 하세요") continue

2023年08月16日 11:02

hehe

댓글 작성은 로그인이 필요합니다.
(注記) 상대에게 상처를 주기보다 서로에게 도움이 될 수 있는 댓글을 달아 주세요.
import random
first = random.randint(0, 9)
second = random.randint(0, 9)
third = random.randint(0, 9)
password = [first, second, third]
n = 1
while True:
 request = int(input(f'{n}단계 암호를 입력: '))
 if request == password[n-1]:
 n = n + 1
 if n == 4:
 break
 else:
 print(f'다시 시도하세요. (힌트: 암호와의 절댓값 차이는 {abs(request - password[n-1])})')
 n = 1
print('성공!')

2023年09月30日 04:24

천성

댓글 작성은 로그인이 필요합니다.
(注記) 상대에게 상처를 주기보다 서로에게 도움이 될 수 있는 댓글을 달아 주세요.
import random
ans = random.randint(0,999)
while True:
 a=input("1st num: ")
 b=input("2nd num: ")
 c=input("3rd num: ")
 inNum = int(a+b+c)
 print(inNum)
 diff = ans -inNum
 if diff >0 :
 print ("guess higher")
 elif diff<0:
 print ("guess lower")
 else:
 print("good") 
 break
댓글 작성은 로그인이 필요합니다.
(注記) 상대에게 상처를 주기보다 서로에게 도움이 될 수 있는 댓글을 달아 주세요.
import random
right_answer = random.choices(range(1,10), k=3)
print(right_answer)
answer = []
while right_answer != answer: 
 try:
 input_n1 = int(input("첫 번째 자리를 입력하세요: "))
 if input_n1 == right_answer[0]: 
 answer.append(input_n1)
 input_n2 = int(input("두 번째 자리를 입력하세요: "))
 if input_n2 == right_answer[1]:
 answer.append(input_n2)
 input_n3 = int(input("세 번째 자리를 입력하세요: "))
 if input_n3 == right_answer[2]:
 answer.append(input_n3) 
 else:
 answer = []
 except Exception as e:
 continue
댓글 작성은 로그인이 필요합니다.
(注記) 상대에게 상처를 주기보다 서로에게 도움이 될 수 있는 댓글을 달아 주세요.
code1 = 1
code2 = 2
code3 = 3
print("비밀번호는 연속된 세 자리 수 입니다.") #힌트
while True:
 y_code = int(input('첫 번째 비밀번호를 입력하세요 :')) 
 if y_code != code1:
 continue
 your_code = int(input('두번째 비밀번호를 입력하세요 :'))
 if your_code != code2:
 continue
 your_code = int(input('세번째 비밀번호를 입력하세요 :'))
 if your_code != code3:
 continue
print('clear!')
댓글 작성은 로그인이 필요합니다.
(注記) 상대에게 상처를 주기보다 서로에게 도움이 될 수 있는 댓글을 달아 주세요.
from random import randint
'''generating password'''
def generate_password():
 password = []
 print('YOUR PASSWORD IS 3-DIGITS NUMBER(there\'s no repetition)\n')
 while len(password) < 3:
 num = randint(0, 9)
 if num not in password:
 password.append(num)
 return password
'''input password'''
def user_input():
 guess = []
 print('ENTER PASSWORD')
 while len(guess) < 3:
 num = int(input())
 guess.append(num)
 return guess
'''check'''
def check(answer, user):
 right = 0
 for i in range(0, 3):
 if user[i] in answer:
 right += 1
 print('{} of them is/are right\n'.format(right))
'''start'''
ANSWER = generate_password()
while True:
 user_guess = user_input()
 check(user_guess, ANSWER)
 if user_guess == ANSWER:
 break
print('UNLOCKED!')

온라인 강의에서 배운 코드를 변형해서 해봤습니다

댓글 작성은 로그인이 필요합니다.
(注記) 상대에게 상처를 주기보다 서로에게 도움이 될 수 있는 댓글을 달아 주세요.

풀이 작성

(注記) 풀이작성 안내
  • 본문에 코드를 삽입할 경우 에디터 우측 상단의 "코드삽입" 버튼을 이용 해 주세요.
  • 마크다운 문법으로 본문을 작성 해 주세요.
  • 풀이를 읽는 사람들을 위하여 풀이에 대한 설명도 부탁드려요. (아이디어나 사용한 알고리즘 또는 참고한 자료등)
  • 작성한 풀이는 다른 사람(빨간띠 이상)에 의해서 내용이 개선될 수 있습니다.
풀이 작성은 로그인이 필요합니다.
목록으로
코딩도장

코딩도장은 프로그래밍 문제풀이를 통해서 코딩 실력을 수련(Practice)하는 곳입니다.


언어별 풀이 현황
전 체 x 14
python x 10
java x 1
기 타 x 2
cpp x 1
코딩도장 © 2014 · 문의 [email protected]
피드백 · 개인정보취급방침 · RSS

AltStyle によって変換されたページ (->オリジナル) /