June is Combung

숫자이동[2단계] 본문

python/리스트

숫자이동[2단계]

june__Park 2021. 2. 28. 00:34
# 숫자이동[2단계]
# 1. 숫자2는 캐릭터이다.
# 2. 숫자1을 입력하면, 캐릭터가 왼쪽으로
# 	 숫자2를 입력하면, 캐릭터가 오른쪽으로 이동한다.
# 3. 단, 좌우 끝에 도달했을 때, 예외처리를 해야한다.
# 4. 숫자 1은 벽이다. 벽을 만나면 이동할 수 없다.
# 5. 단, 숫자3을 입력하면, 벽을 격파할 수 있다.

game = [0, 0, 1, 0, 2, 0, 0, 1, 0]

player = 4

while True:
    game[player] = 2
    print(game)
    me = int(input("1) left, 2) right, 0) exit >>"))

    if me == 1:
        if player == 0:
            print("끝에 도달하여 이동할 수 없습니다.")
            continue
        
        if game[player-1] == 1:
            wall = int(input("벽이 있어 이동불가. 격파하시겠습니까? 격파하려면 3을 누르세요."))
            if wall == 3:
                print("격파완료.")
            else:
                continue
        game[player] = 0
        player -= 1

    elif me == 2:
        if player == 8:
            print("끝에 도달하여 이동할 수 없습니다.")
            continue
        if game[player+1] == 1:
            wall = int(input("벽이 있어 이동불가. 격파하시겠습니까? 격파하려면 3을 누르세요."))
            if wall == 3:
                print("격파완료.")
            else:
                continue
        game[player] = 0
        player += 1

    elif me == 0:
        print("exit.")
        break

'python > 리스트' 카테고리의 다른 글

중복숫자 금지[2단계]  (0) 2021.02.28
EXIT 게임  (0) 2021.02.28
1 to 50[2단계]  (0) 2021.02.28
OMR카드(리스트 함수 적용)  (0) 2021.02.28
함수  (0) 2021.02.28
Comments