이 페이지는 코딩도장 데이터의 읽기 전용 정적 보관본입니다.

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

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

조건 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

2023/05/16 17:37

insperChoi

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줄 출력하게 합니다] 이게 무슨뜻인지는 잘 이해가 안되네요ㅠ

2023/05/02 15:23

HoHyeon Kim

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 자릿수 입니다. 첫 번째 숫자: 넓이가 40cm² 이고 높이가 10cm 일때 밑변의 길이 두 번째 숫자: 2³ x -3³ + 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

2023/10/28 21:37

Hyunpung Park

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

2024/02/12 20:39

이용호

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!')

2024/03/23 15:12

라구리

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!')

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

2024/04/22 20:20

예즤YeZ

import random
passward = random.randint(100, 999)
input_int = []
print_list = ['첫', '두', '세']
for i in print_list:
    num = int(input(f'{i}번째 자리수를 입력해주세요.'))
    input_int.append(num)

result = int(''.join(map(str, input_int)))
if result == passward:
    print('성공')
else:
    print('실패')
    print(passward)

2024/06/18 20:51

조건우

import random
a=[random.randrange(0,9) for _ in range(3)]
b=""
for i in a:
    b=b+str(i)
passkey=1
n=1
while passkey <= 3:
    key=int(input("비밀번호를 입력하시오(0-9):"))
    if key==a[0]:
        print(passkey,"번째 키",key,"를 맞추었습니다")
        passkey+=1
        a.pop(0)
        n+=1
        continue
    if key<a[0]:
        print("비밀번호 보다 작습니다")
    if key>a[0]:
        print("비밀번호 보다 큽니다")
    n+=1
print("비밀번호",b,"를 ",n,"회 시도 후 찾았습니다")

2024/07/20 21:42

Dr.Choi

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int main() {
    srand(time(0));
    int pw[3], input, count = 0;
    for (int i = 0; i < 3; i++) 
        pw[i] = rand() % 10;

    for (int i = 0; i < 3; i++) {
        do {
            cout << i + 1 << "번째 비밀번호를 입력하시오: ";
            cin >> input;
            count++;
            cout << (input == pw[i] ? "" : input > pw[i] ? "작습니다\n" : "큽니다\n");
        } while (input != pw[i]);
    }

    cout << "맞습니다! 비밀번호는 " << pw[0] << pw[1] << pw[2] << "입니다.\n";
    cout << "시도횟수: " << count << endl;
    return 0;
}

2024/09/30 19:25

아드구

import random

def genPwd() -> list[int]:
  return [random.randrange(100, 1000) for _ in range(10)]

def checkNum(numPosition: int, checkNum, pwd: int) -> bool:
  return checkNum == str(pwd)[numPosition-1]

if __name__ == '__main__':
    print('start escape room')
    pwds = genPwd()
    print(pwds)

    for i, pwd in enumerate(pwds):
      roomIdx = i + 1
      print(f'{roomIdx}번째 방 패스워드 맞추기를 시작합니다.')
      sHint = random.randrange(100, pwd)
      eHint = random.randrange(pwd, 1000)
      print(f'패스워드 힌트는 {sHint} ~ {eHint} 사이의 3자리 숫자입니다.')

      isPass = False
      positionIdx = 1
      while not isPass:
        num = input(f'{positionIdx}번째 자리 숫자를 입력하세요.(0~9)')
        if checkNum(positionIdx, num, pwd):
          positionIdx += 1
        else:
          positionIdx = 1
          print(f'틀렸습니다. 처음부터 다시 입력하세요.')

        if positionIdx == 4:
          isPass = True
          print('정답입니다.')
          break

2025/01/17 13:57

JI HOON Yang

목록으로