파이썬에서 지뢰 찾기를 다시 만들려고합니다. 그리고 IDLE에서 코드를 실행하려고합니다. 이제 내 질문은 어떻게 작성해야합니까? 사용자가 좌표를 입력 할 때 위치를 어떻게 지정합니까? 위치가 "X"에서 빈 타일 인 "-"로 바뀝니다. 또한 내 코드를 개선하는 방법에 대한 조언도 신경 쓰지 않습니다. 감사!파이썬으로 지뢰 찾기를 만들고 도움이 필요합니다.
import random
Field = [
LA=["X","X","X","X","X","X","X"],
LB=["X","X","X","X","X","X","X"],
LC=["X","X","X","X","X","X","X"],
LD=["X","X","X","X","X","X","X"],
LE=["X","X","X","X","X","X","X"],
LF=["X","X","X","X","X","X","X"],
LG=["X","X","X","X","X","X","X"]
]
print (Feild)
print("Select row starting from top = 1 and column from left = 0")
numa = random.randint(1,7)
numb = random.randint(0,6)
MINE = "O"
row=9
column = 9
one = "1"
blank = "-"
while row != numa and column != numb:
print (Field)
print("Enter a row")
row = raw_input('Please select a row from rows 1 - 7: ')
column = raw_input('Please enter a column from columns 1 - 7: ')
columA = int(column) + 1
columB = int(column) - 1
rowA = row + 1
rowB = row - 1
if rowA == numa and column == numb:
if row == 1:
del LA[column]
LA.insert(column, one)
if row == 2:
del LB[column]
LB.insert(column, one)
if row == 3:
del LC[column]
LC.insert(column, one)
if row == 4:
del LD[column]
LD.insert(column, one)
if row == 5:
del LE[column]
LE.insert(column, one)
if row == 6:
del LF[column]
LF.insert(column, one)
if row == 7:
del LG[column]
LG.insert(column, one)
elif rowB == numa and column == numb:
if row == 1:
del LA[column]
LA.insert(column, one)
if row == 2:
del LB[column]
LB.insert(column, one)
if row == 3:
del LC[column]
LC.insert(column, one)
if row == 4:
del LD[column]
LD.insert(column, one)
if row == 5:
del LE[column]
LE.insert(column, one)
if row == 6:
del LF[column]
LF.insert(column, one)
if row == 7:
del LG[column]
LG.insert(column, one)
elif row == numa and columA == numb:
if row == 1:
del LA[column]
LA.insert(column, one)
if row == 2:
del LB[column]
LB.insert(column, one)
if row == 3:
del LC[column]
LC.insert(column, one)
if row == 4:
del LD[column]
LD.insert(column, one)
if row == 5:
del LE[column]
LE.insert(column, one)
if row == 6:
del LF[column]
LF.insert(column, one)
if row == 7:
del LG[column]
LG.insert(column, one)
elif row == numa and columB == numb:
if row == 1:
del LA[column]
LA.insert(column, one)
if row == 2:
del LB[column]
LB.insert(column, one)
if row == 3:
del LC[column]
LC.insert(column, one)
if row == 4:
del LD[column]
LD.insert(column, one)
if row == 5:
del LE[column]
LE.insert(column, one)
if row == 6:
del LF[column]
LF.insert(column, one)
if row == 7:
del LG[column]
LG.insert(column, one)
else:
if row == 1:
del LA[column]
LA.insert(column, blank)
if row == 2:
del LB[column]
LB.insert(column, blank)
if row == 3:
del LC[column]
LC.insert(column, blank)
if row == 4:
del LD[column]
LD.insert(column, blank)
if row == 5:
del LE[column]
LE.insert(column, blank)
if row == 6:
del LF[column]
LF.insert(column, blank)
if row == 7:
del LG[column]
LG.insert(column, blank)
if row == 1:
del LA[column]
LA.insert(column, MINE)
if row == 2:
del LB[column]
LB.insert(column, MINE)
if row == 3:
del LC[column]
LC.insert(column, MINE)
if row == 4:
del LD[column]
LD.insert(column, MINE)
if row == 5:
del LE[column]
LE.insert(column, MINE)
if row == 6:
del LF[column]
LF.insert(column, MINE)
if row == 7:
del LG[column]
LG.insert(column, MINE)
print (Field)
print("Game over")
'print' 명령문이 너무 많지 않게하려면 목록을 사용하는 것이 좋습니다 ('for i in lst_of_lsts : print i'). –
이것에 대해 디버깅을하고 질문의 범위를 좁힐 수 있습니까 – Greg
@ F3AR3DLEGEND 감사합니다. – AAA