작동시키면 저따구로 나오는데 원래대로라면 영어를 선택해서 system > You choose the Englich. Enjoy the game. 이런식으로 나와야하는데 어째선지 맨처음에 2를 입력했을때 나올게 나오네요. 코드는 여기 적겠습니다. 참고로 visual studio로 파이썬 한겁니다.
##함수
def DrawTitle() :
is_loop = 1
while is_loop == 1 :
print("****************************************")
print("* WELCOME TO THE GAME! *")
print("****************************************")
print("1. GAME START")
print("2. GAME EXIT")
player_input = input("Please enter(1~2) : ")
if player_input == '1' :
is_loop = 0
elif player_input == '2' :
is_loop = 0
else :
print("system > Not correct answer. Please select again.")
return player_input
def DrawGameturn() :
is_loop = 1
while is_loop == 1 :
print("system > Would you like to run the game?")
print("system > 1. Restart 2.End The Game")
player_turn = input("system > Please enter(1~2) : ")
if player_turn == '1' :
is_loop = 0
elif player_turn == '2' :
is_loop = 0
else :
print("system > Not correct answer. Please select again.")
return player_turn
def DrawLanguage() :
is_loop = 1
while is_loop == 1 :
player_language = input("Please enter(1~3) : ")
if player_language == '1' :
is_loop = 0
elif player_language == '2' :
is_loop = 0
elif player_language == '3' :
is_loop = 0
else :
print("system > Not Correct Answer. Please select again.")
return player_language
def DrawMainGameKo() :
is_loop = 1
while is_loop == 1 :
player_moveko = input("system > 움직일 방향을 입력해주세요(1~4) : ")
if player_moveko == '1' :
print("위로 한 칸")
is_loop = 0
elif player_moveko == '2' :
print("아래로 한 칸")
is_loop = 0
elif player_moveko == '3' :
print("왼쪽으로 한 칸")
is_loop = 0
elif player_moveko == '4' :
print("오른쪽으로 한 칸")
is_loop = 0
else :
print("없는 동작입니다. 다시 해주세요.")
return player_move
def DrawMainGameEn() :
is_loop = 1
while is_loop == 1 :
player_moveen = input("system > Please enter the direction to move(1~4) : ")
if player_moveen == '1' :
print("One space up")
is_loop = 0
elif player_moveen == '2' :
print("One space down")
is_loop = 0
elif player_moveen == '3' :
print("One space to the left")
is_loop = 0
elif player_moveen == '4' :
print("One space to the right")
else :
print("This is no behavior. Please do it again.")
return player_move
def DrawMainGameJa() :
is_loop = 1
while is_loop == 1 :
player_moveja = input("system > 移動方向を入力してください(1~4) : ")
if player_moveja == '1' :
print("上した1カーン")
is_loop = 0
elif player_moveja == '2' :
print("下に1カーン")
is_loop = 0
elif player_moveja == '3' :
print("左に1カーン")
is_loop = 0
elif player_moveja == '4' :
print("右に1カーン")
is_loop = 0
else :
print("ない動作です。再びください。")
return player_move
##맵
def DrawMap(g_map, g_player) :
a = 0
while i<10:
if g_player == i :
print('P', end = '')
else :
print(g_map[i], end = '')
a = a + 1
def DrawMap(g_map, g_player) :
b = 0
while i<10:
if g_player == i :
print('P', end = '')
else :
print(g_map[i], end = '')
b = b + 1
## 메인코드
player_input = DrawTitle()
if player_input == "1" :
print("Choose the language")
print("1. Engilsh")
print("2. 한국어")
print("3. 日本語")
DrawLanguage()
if player_input == "2" :
print("system > Exit The Game")
DrawGameturn()
player_turn = DrawGameturn()
if player_turn == "1" :
print("system > Restart the Game")
DrawTitle()
if player_turn == "2" :
print("system > Program End")
player_language = DrawLanguage()
if player_language == "1" :
print("system > You choose the Englich. Enjoy the game.")
DrawMainGameEn()
if plyer_language == "2" :
print("system > 한국어를 선택하셨습니다. 즐거운 게임되세요.")
DrawMainGameKo()
if player_language == "3" :
print("system > 日本語を選択した。楽しいゲームになれます。")
DrawMainGameJa()
player_moveko = DrawMainGameKo()
if player_moveko == "1" :
b = b + 1
if player_moveko == "2" :
b = b - 1
if player_moveko == "3" :
a = a + 1
if player_moveko == "4" :
a = a - 1
player_moveen = DrawMainGameEn()
if player_moveen == "1" :
b = b + 1
if player_moveen == "2" :
b = b - 1
if player_moveen == "3" :
a = a + 1
if player_moveen == "4" :
a = a - 1
player_moveja = DrawMainGameJa()
if player_moveja == "1" :
b = b + 1
if player_moveja == "2" :
b = b - 1
if player_moveja == "3" :
a = a + 1
if player_moveja == "4" :
a = a - 1
님아
You choose the 문장을 각 함수 제일 상단에 넣어 바보야
def DrawMainGameEn() : is_loop = 1 while is_loop == 1 : print("system > You choose the Englich. Enjoy the game.") player_moveen = input("system > Please enter the direction to move(1~4) : ") 이런식으로요?
ㅇㅇ 근데 저 오류는 그거 때문은 아닐 수도 있어 보인다
아니 지 while 실행보단 위로 넣어야지
ef DrawMainGameEn() : print("system > You choose the Englich. Enjoy the game.") is_loop = 1 while is_loop == 1 : 이렇게요?
ㅇㅇ 일단 그렇게 하는게 좀 더 낫지 않나 싶음
근데 왜 언어 선택했는데 DrawGameturn 함수가 실행이 될까요....?
이제 그 이유를 찾아봐야죠
음 대충 다시 봤는데 elif를 왜 안씀?
어...썻는데 잘못 썻나요.......?
사실 너무 중구난방이라 저도 잘 모르겠음
if player_language == '1' : is_loop = 0 elif player_language == '2' : is_loop = 0 elif player_language == '3' : is_loop = 0 else : 이런식으로 쓰면 되는거 아니에요?
그 부분 말고 메인쪽 말한건데 다시 보다보니 이유를 알거 같음. 랭귀지에서 리턴한 값을 받아주지 않네
if player_input == "1" : print("Choose the language") print("1. Engilsh") print("2. 한국어") print("3. 日本語") player_input = DrawLanguage() 이렇게 해야 하지 않음?
player_input 대신에 player_language 라고 해놨어요
아 한참 밑에 있구나 근데 그럼 왜 바로 밑에 DrawGameturn()가 있음?
그건 처음에 게임 종료 눌렀을때 확실히 게임을 종료하겠냐 아님 다시 실행하겠냐 그거 묻기용
그냥 실행되고 있는데?
https://drive.google.com/file/d/1fRFxIEm_GlEVas5JLtAcMk39BbzSkKIR/view?usp=sharing
이거 보심 뭐가 문제인지 아실수 있을꺼에요
코드가 바뀌었는지 어떤지도 잘 모르겠고 스샷만 봐선 저도 잘 모름...아무튼 드리고 싶은 말은 일단 메인에서는 로직은 최대한 배제하고 함수 갔다가 리턴 받는 식으로 라인을 줄여보셈. 죄다 함수쪽으로 빼 놓으면 이해가 더 쉬워질거임
메인에 입출력 if가 너무 많으니까 꼬인게 어디인지 못찾는거라
다시 처음부터 할까요
아예 처음부터 짜기는 좀 너무 많이 왔고 리팩토링부터 함 해보셈
메인의 이상적인 모습은 a(); b(); c(); 이런 식으로 함수만 주르륵 실행되는거임
아래 함수에 대응하는 애들을 다시 할까요 아님 함수를 할까요
제가 말한 식으로 메인 리팩토링 하면 대충 어디가 잘못된건지 보일거임