Created
December 25, 2024 21:14
-
-
Save AndyObtiva/f76d930e8d910d9714136773ab63a704 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: https://github.com/AndyObtiva/glimmer_hangman/blob/master/app/glimmer_hangman/view/hangman_guess.rb | |
require 'glimmer_hangman/model/game' | |
class GlimmerHangman | |
module View | |
class HangmanGuess | |
include Glimmer::LibUI::CustomShape | |
option :game | |
option :size, default: 480 | |
option :thickness, default: 2 | |
option :font_size, default: 33 | |
body { | |
text(size*0.1, size*0.8, size*0.8) { | |
default_font family: 'Courier New', size: font_size | |
content(game, computed_by: [:guess, :incorrect_guess_count]) do | |
game.guess.size.times do |letter_index| | |
letter = rendered_letter(letter_index) | |
string(letter) { | |
color string_color(letter_index) | |
} | |
string(' ') | |
end | |
end | |
} | |
} | |
private | |
def rendered_letter(letter_index) | |
letter = game.lost? ? game.word[letter_index] : game.guess[letter_index] | |
letter = '_' if letter == ' ' | |
letter.upcase | |
end | |
def string_color(letter_index) | |
if game.lost? && !game.guessed_letter_at_index?(letter_index) | |
:green | |
else | |
:black | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment