【问题标题】:How to remove color from text background in the terminal unsig ruby?如何从终端 unsig ruby​​ 中的文本背景中删除颜色?
【发布时间】: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


    【解决方案1】:

    您需要“重新绘制”整个游戏。或受影响的线路(至少)。这样,您可以将“非活动”字段绘制为白色(或任何其他颜色),将活动字段绘制为绿色。您不能更改颜色。 检查可用的“进度条”宝石之一。比如这个——https://github.com/paul/progress_bar/blob/master/lib/progress_bar.rb

    在这里您可以找到更多想法Printing an ASCII spinning "cursor" in the console

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-06
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多