Tag: attr

Ruby OOP tic-tac-toe hash / conditional / itiration

试图在Ruby中创建一个经典的tic tac toe OOP但是我的game_results()方法遇到了麻烦。 我意识到这不是很完整,需要更多的function,但是现在我只是试图用我从用户输入的对象填充我的电路板并输出填充板和赢家。 当我在我的主板上看到我们有一个胜利者时,我呼吁使用game_results()方法并且它给了我正确的赢家,但是每当发生平局游戏时,我都会收到错误。 有人对操作员的错误有什么想法或解决方案吗? 顺便说一下,我知道这一切都很混乱,但我是初学者。 #require “pry” class Game attr_reader :turn def initialize @turn = 1 @board = { a1: ” “, a2: ” “, a3: ” “, b1: ” “, b2: ” “, b3: ” “, c1: ” “, c2: ” “, c3: ” ” } end # def start_game # […]