I am implementing a TIC TAC TOE game in ruby. I want the user to be able to select the square he wants to put his crosses in, by using the arrows of the keyboard. Therefor I have to colorize (using the gem 'pastel') the squares he goes into, in order for him to know his position.
So far I have used this portion of code :
@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
The result is :this
Could you help me figure out how I take the green squares to their original black state ?
Thank you for your help