【发布时间】:2013-12-06 16:36:27
【问题描述】:
我在 Ruby 中创建了一个井字游戏程序。我对允许游戏以平局结束的代码部分有问题。
我编写了一个 if 语句来检查玩家何时赢得游戏。这是我的 else 条件。当我尝试运行程序时出现错误。怎么了?
else
while @turn == "x" or "o"
@square_count -= 1 # I set empty_count to 9 in the initialize of the class
# of this program. This would minus 1 from empty) count_each every turn
end
if @square_count == 0 #when all the slots are taken, its a tie game
puts "Tie game!"
return true #this makes the program end
end
我得到的错误是:
tac.rb:89: warning: string literal in condition
tac.rb:88:in `block in check_win': undefined method `-' for nil:NilClass (NoMethodError)
from tac.rb:77:in `each'
from tac.rb:77:in `check_win'
from tac.rb:108:in `<class:Game>'
from tac.rb:1:in `<main>'
【问题讨论】:
-
你得到什么错误信息?
标签: ruby