嘿,所以我写了一个小的ruby程序,我写的一切都很好,除了语法错误,我为我的生活无法调试。显然,因为这个我的程序也没有运行。
我的代码如下,任何帮助都将不胜感激!
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 :(得分:1)
缺少print_game_board
的第一个定义end
。
注意:您可以定义此方法两次。