2014-10-29 49 views
-2

嘿所以我有一個我寫的小ruby程序,除了語法錯誤,我對我的生活無法調試,一切都很好。顯然,因爲這個,我的程序也沒有運行。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

你怎麼知道「除語法錯誤外,一切都很好」? 更正您的縮進,您將快速調試錯誤。 – 2014-10-29 14:22:36

+0

重要提示:正確縮進代碼,然後逐個刪除代碼,直到錯誤消失 – 2014-10-29 14:24:44

回答

1

print_game_board的第一個定義缺失和end

注意:您可以定義此方法兩次。

相關問題