지금 파이썬으로 간단한 게임으로 10x10의 공간을 두고 0,0에서 9,9로 가면 엔딩을 보는 게임을 만드는 중입니다. 그런데 지금 if player_turn 부터 오류가 나는데 definded라고 나오면서 정상 실행이 안되고 있습니다. 제가 짠 부분중 어디가 틀려있나요?
##함수
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()
if player_turn == "1" :
print("system > Restart the Game")
DrawTitle()
if player_turn == "2" :
print("system > Program End")
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()
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
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
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
a=="1"이건 파이썬뿐만아니라 c/c++에서도 적용이안됨
숫자 1이랑 같은걸 표현하고 싶으면 a==1이렇게 해야한다는 ㅇ말임
https://ideone.com/11JYpf
확인해봐
뭔가 컴퓨터 언어 자체의미만 봤을 때는 될 거 같은데 안되는게 신기하네. 근데 따지고보면 "1"이나 1이나 같은의미아닌가?
아스키코드를 원하는 거면 '1'이렇게
그럼 지금은 메인코드 쪽은 ""만 없애면 되나요?
너때메 나도햇갈렷네 '1' '2' 이렇게 해보든가 니가 잘못확인한거아님?
혹시 디코로 자세히 보시겠어요?
ㅇㅇ 문자로 정의한거면 '1' '2' 이렇게 하고, 숫자로 정의 한거면 1 2 이렇게 하셈 근데 '1'이랑 1이랑 같아서 의미차이없음
cout<<"1"; 은 1을 문자열로 표현한건데 문자열타입을 if문에서 구분한다는건 좀 문제가 있지
#include using namespace std; int main() { cout<<65<<" "<<"A"<<" "<<'A'<<"\n"; cout<<(int)65<<" "<<" "<<(int)'A'; // cout<<(int)56<<" "<<(int)"A"<<" "<<(int)'A'; }
include 옆은 iostream이고, 주석 빼고 확인해보셈. 오류가 뜰거임 "A"는 문자열인데 정수로 나타내기 힘들지 문자 하나면 아스키코드라 바로됨
" " 이건 문자열 ' '이건 문자
https://drive.google.com/drive/folders/1fkJKIM9dwMXuhKwVnjpmPnPZmrVWZgjw?usp=sharing
지금 다 "를 '로 고쳤는데 이따구에요 살려주세요
player_turn을 정의 해야됨 player_input 같은 경우는 = DrawTitle() 로 정의 되어있잖아 마찬가지로, player_turn 도 함수안에서 정의하면 될거같은데
def DrawGameturn() 여기안에 정의 되어있으니까 꺼내오면됨
player_turn=DrawGameturn()
이걸 input밑에 넣어
나 이제 바쁘니까 알고리즘 하러감 남은 건 님이 알아서 해보셈 교수님이 일부러 공부하라고 주신것 같은데, 이제부터는 님이 직접해주는 것도 좋을 것 같음. 다 알려주면 음... 님 실력이 안 늘것같음. 제가 알려준 것도 왜 그런지 코드를 직접 읽어보시면 아실꺼임
아마 님이 뜨는 오류는 제 생각에 의도적으로 교수님이 넣어주신 오류같음 왜냐면 player_turn 같은 경우만 해도, 코드를 조금만 바꾸면 완성되는 코드임 안된다고 생각하지 말고, 교수님이 일부러 어떻게 바꾸셧을까를 생각하시면 다 가능하실듯
그나저나 게임 만들 때 저런식으로 만드는구나 조금 흥미로웠던 코드다 내가 전에 봤던 language c언어 소스랑 비슷하네 ㅇㅅㅇ
지금 보니까 말씀하신건 c언어인거 같네요. 비슷은 하니까 다행이도 도움이 됩네요. 감사합니다