2012-03-28 7 views
1

간단한 지뢰 찾기 게임을 파이썬으로 만들려고했지만 한 가지 문제가 있습니다. 나는 x의 7x7 보드를 가지고 있으며 플레이어가 행과 열을 입력하면 열을 삭제하고 -로 바꿉니다. 플레이어가 한 칸 떨어진 곳을 추측 할 경우에도 1을 표시하려고했지만 작동하지 않는 이유를 알 수 없습니다. 대신 루프를 종료합니다. 아래는 내가 한 일이다. 그것의 아마 간단한 수정 그러나 나는 그것을 볼 수 없습니다. 도와 주셔서 감사합니다!간단한 지뢰 찾기 게임을 파이썬으로 만들려고 시도합니다.

import random 

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("", LA, "\n" , LB, "\n" , LC, "\n" , LD, "\n" , LE, "\n" , 
     LF, "\n" , LG, "\n") 
print("\n 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("", LA, "\n" , LB, "\n" , LC, "\n" , LD, "\n" , LE, "\n" , 
     LF, "\n" , LG, "\n") 
    #cheeter 
    print(numa , "" , numb) 
    row = int(input("\nEnter row")) 
    column = int(input("\nEnter column")) 
    columA = column + 1 
    columB = 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("", LA, "\n" , LB, "\n" , LC, "\n" , LD, "\n" , LE, "\n" , 
     LF, "\n" , LG, "\n") 
print("Game over") 

input("Press enter to quit") 
+0

코드에서 '....'은 무엇입니까? – Amber

+0

if row == 2 : then row == 3 ... 행까지 == 7 반복적으로. –

+1

점을 수정 해달라고 요청하는 경우이 질문이 너무 현지화되어 있다고 말할 수 있습니다. 대신에 오류가 있거나 어떤 점에 처해 있다면 그것에 대해 물어보십시오. 질문을 편집하고 개선 할 수 있습니다. - 추신 안녕하세요.에 오신 것을 환영합니다. [faq]를 읽는 것을 잊지 마십시오. –

답변

2

("지뢰 찾기/N에 오신 것을 환영합니다") 인쇄 나는 당신의 문제가 루프 상태에 생각 : 에는 광산이없는 경우에만 루프를 입력합니다

while row != numa and column != numb: 

행 또는 열. 당신은하지와 함께하고, 그들을 결합하거나 할 필요가 : 행과 열이 모두 광산이 켜져 위치에 해당하지 않는 한

while row != numa or column != numb: 

이 방법은 루프를 입력합니다.

+0

고마워. 이제 작동합니다! –

관련 문제