【发布时间】:2019-03-21 05:23:06
【问题描述】:
我正在用 ruby 实现一个 TIC TAC TOE 游戏。我希望用户能够通过使用键盘的箭头来选择他想要放置十字架的方格。因此,我必须为他进入的方格着色(使用宝石“粉彩”),以便他知道自己的位置。
到目前为止,我已经使用了这部分代码:
@position = 0
@pastel = Pastel.new
@board = Board.new
def self.show_single_key
c = self.read_char
case c
when "\r"
puts "RETURN"
when "\e[A"
@position > 5 ? @position : @position -= 3
when "\e[B"
@position < 3 ? @position : @position += 3
when "\e[C"
@position == 8 ? @position : @position += 1
when "\e[D"
@position == 0 ? @position : @position -= 1
end
p @position
$cases[@position].value = @pastel.on_green($cases[@position].value)
$cases[@position].value = $cases[@position].value
@board.print_board
end
结果是:this
您能帮我弄清楚如何将绿色方块变为原来的黑色状态吗?
感谢您的帮助
【问题讨论】:
标签: ruby colors terminal background-color tic-tac-toe