有人可以向新手解释为什么我得到错误的参数数量错误?如何正确传递new_game对象的参数?
load 'admin_logic.rb'
load 'computer_logic.rb'
load 'user_logic.rb'
class TicTacToe
admin_object = Admin.new
computer_object = ComputerLogic.new
user_object = UserLogic.new
new_game = TicTacToe.new(admin_object, computer_object, user_object)
puts "Hello, I\'m " + new_game.computer_name + ", let\'s play Tic Tac Toe! What is your name?"
puts "Great " + new_game.user_name + ", you\'ll be " + new_game.user_sign + ". Please choose where you want to go."
puts 'The game board is the following, please remember!'
puts ' a1 | a2 | a3'
puts " --- --- ---"
puts ' b1 | b2 | b3'
puts " --- --- ---"
puts ' c1 | c2 | c3'
new_game.user_sign
new_game.computer_sign
new_game.game_board
new_game.winning_propositions
while new_game .computer_win != true do
new_game.user_turn
new_game.draw_game_outcome
new_game.player_first_turn_check?
new_game.draw_game_outcome
end
end
答案 0 :(得分:1)
TicTacToe.new(admin_object, computer_object, user_object)
这就是问题所在。
您的TicTacToe
类目前没有构造函数。要添加一个,请执行类似
def initialize(var1, var2, var3)
# do something with your variables.
end
您也不能像目前一样在对象(class
)内编写代码。对象的目的是成为彼此相关的数据的集合。它意味着是一组变量和方法,它们彼此交互,而不是充当脚本。