2014-10-29 1 views
-2

안녕하세요. 저는 작은 루비 프로그램을 가지고 있습니다. 모든 일은 문법 오류를 제외하고는 훌륭합니다. 왜냐하면 저의 삶은 디버깅 할 수 없기 때문입니다. 내 프로그램이 실행 중이기 때문에 실행 중이기 때문에.Ruby 오류 : keyword_end를 (를) 기대 하시겠습니까?

아래 코드는 어떤 도움을 주시면 감사하겠습니다!

def print_game_header 
    # Print Header 
    print "\n" 
    print "Welcome to Math Buddy\n" 
    print "\n" 

end 

def make_game_array game_array 
    for x in 0..4 
     for y in 0..4 
      game_array[x][y] = "*" 
     end 
    end 
end 

def make_mines game_array 
    for x in 0..4 
      game_array[x][rand(0..4)] = '!' 
     end 
    end 

def print_game_board game_array 
    for x in 0..4 
     for y in 0..4 
     game_array[x][rand(0..4)]="!" 
    end 
end 

def print_game_board game_array 
    for x in 0..4 
     for y in 0..4 
      print game_array[x][y]    
      end 
      print "\n" 
     end 
end 

def compute_results game_array 

     print "\nFor this 5x5 grid above, please give your guesses for the location of the mines in the following format #,#,#,#,# where # is a value of 1 through 5: " 
     game_array = gets.chomp.split(',') 

     print "\n" 
     the_Guess = 0 
     hits = 0 
     for x in 0..4 
      if game_array[x][guess_array[the_Guess].to_i-1] == '!' 
       print "[#{x+1},#{guess_array[the_Guess]}] was a HIT!\n" 
     else 
      print "[#{x+1},#{guess_array[the_Guess]}] was a MISS!\n" 
     end 
     the_Guess+=1 
    end 
    if hits > 0 
     print "\nYour hit rate was ", (hits.to_f/5*100).to_s, "%\n" 
    else 
     print "\nYour hit rate was 0%\n" 
    end 
end 

columns, rows = 5, 5 
game_array = [] 
rows.times { game_array << Array.new(columns) } 

print_game_header 
make_game_array game_array 
print_game_board game_array 
make_mines game_array 
compute_results 

print "\nHere are the actual locations of the mines:\n\n" 
print_game_board game_array 
+0

"구문 오류를 제외한 모든 것이 훌륭하다는 것을 어떻게 알 수 있습니까?" 들여 쓰기를 정정하면 오류를 빠르게 디버그합니다. –

+0

팁 : 코드를 올바르게 들여 쓰고 오류가 사라질 때까지 비트 단위로 코드를 제거하십시오. –

답변

1

print_game_board의 첫 번째 정의가 누락되어 end.

참고 :이 방법을 두 번 정의하십시오.

관련 문제