Class: GitGameShow::GameState
- Inherits:
-
Object
- Object
- GitGameShow::GameState
- Defined in:
- lib/git_game_show/core/game_state.rb
Overview
Manages the state of the game
Instance Attribute Summary collapse
-
#current_mini_game ⇒ Object
readonly
Returns the value of attribute current_mini_game.
-
#current_question_id ⇒ Object
readonly
Returns the value of attribute current_question_id.
-
#current_question_index ⇒ Object
readonly
Returns the value of attribute current_question_index.
-
#current_round ⇒ Object
readonly
Returns the value of attribute current_round.
-
#player_answers ⇒ Object
readonly
Returns the value of attribute player_answers.
-
#question_already_evaluated ⇒ Object
readonly
Returns the value of attribute question_already_evaluated.
-
#question_start_time ⇒ Object
readonly
Returns the value of attribute question_start_time.
-
#round_questions ⇒ Object
readonly
Returns the value of attribute round_questions.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#total_rounds ⇒ Object
readonly
Returns the value of attribute total_rounds.
Instance Method Summary collapse
- #current_question ⇒ Object
- #end_game ⇒ Object
- #ended? ⇒ Boolean
-
#initialize(total_rounds) ⇒ GameState
constructor
A new instance of GameState.
- #last_question_in_round? ⇒ Boolean
- #last_round? ⇒ Boolean
- #lobby? ⇒ Boolean
- #mark_question_evaluated ⇒ Object
- #move_to_next_question ⇒ Object
- #playing? ⇒ Boolean
- #prepare_next_question ⇒ Object
- #record_player_answer(player_name, answer, time_taken, correct = nil, points = 0) ⇒ Object
- #reset_game ⇒ Object
- #set_round_questions(questions) ⇒ Object
- #start_game ⇒ Object
- #start_next_round(mini_game) ⇒ Object
Constructor Details
#initialize(total_rounds) ⇒ GameState
Returns a new instance of GameState.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/git_game_show/core/game_state.rb', line 8 def initialize(total_rounds) @total_rounds = total_rounds @current_round = 0 @state = :lobby # :lobby, :playing, :ended @current_mini_game = nil @round_questions = [] @current_question_index = 0 @question_start_time = nil @player_answers = {} @current_question_id = nil @question_already_evaluated = false @used_mini_games = [] # Track which mini-games have been used @available_mini_games = [] # Mini-games still available in the current cycle end |
Instance Attribute Details
#current_mini_game ⇒ Object (readonly)
Returns the value of attribute current_mini_game.
4 5 6 |
# File 'lib/git_game_show/core/game_state.rb', line 4 def current_mini_game @current_mini_game end |
#current_question_id ⇒ Object (readonly)
Returns the value of attribute current_question_id.
6 7 8 |
# File 'lib/git_game_show/core/game_state.rb', line 6 def current_question_id @current_question_id end |
#current_question_index ⇒ Object (readonly)
Returns the value of attribute current_question_index.
5 6 7 |
# File 'lib/git_game_show/core/game_state.rb', line 5 def current_question_index @current_question_index end |
#current_round ⇒ Object (readonly)
Returns the value of attribute current_round.
4 5 6 |
# File 'lib/git_game_show/core/game_state.rb', line 4 def current_round @current_round end |
#player_answers ⇒ Object (readonly)
Returns the value of attribute player_answers.
6 7 8 |
# File 'lib/git_game_show/core/game_state.rb', line 6 def player_answers @player_answers end |
#question_already_evaluated ⇒ Object (readonly)
Returns the value of attribute question_already_evaluated.
6 7 8 |
# File 'lib/git_game_show/core/game_state.rb', line 6 def question_already_evaluated @question_already_evaluated end |
#question_start_time ⇒ Object (readonly)
Returns the value of attribute question_start_time.
5 6 7 |
# File 'lib/git_game_show/core/game_state.rb', line 5 def question_start_time @question_start_time end |
#round_questions ⇒ Object (readonly)
Returns the value of attribute round_questions.
5 6 7 |
# File 'lib/git_game_show/core/game_state.rb', line 5 def round_questions @round_questions end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
4 5 6 |
# File 'lib/git_game_show/core/game_state.rb', line 4 def state @state end |
#total_rounds ⇒ Object (readonly)
Returns the value of attribute total_rounds.
4 5 6 |
# File 'lib/git_game_show/core/game_state.rb', line 4 def total_rounds @total_rounds end |
Instance Method Details
#current_question ⇒ Object
87 88 89 90 |
# File 'lib/git_game_show/core/game_state.rb', line 87 def current_question return nil if @current_question_index >= @round_questions.size @round_questions[@current_question_index] end |
#end_game ⇒ Object
45 46 47 48 |
# File 'lib/git_game_show/core/game_state.rb', line 45 def end_game @state = :ended true end |
#ended? ⇒ Boolean
31 32 33 |
# File 'lib/git_game_show/core/game_state.rb', line 31 def ended? @state == :ended end |
#last_question_in_round? ⇒ Boolean
98 99 100 |
# File 'lib/git_game_show/core/game_state.rb', line 98 def last_question_in_round? @current_question_index >= @round_questions.size - 1 end |
#last_round? ⇒ Boolean
102 103 104 |
# File 'lib/git_game_show/core/game_state.rb', line 102 def last_round? @current_round >= @total_rounds end |
#lobby? ⇒ Boolean
23 24 25 |
# File 'lib/git_game_show/core/game_state.rb', line 23 def lobby? @state == :lobby end |
#mark_question_evaluated ⇒ Object
116 117 118 |
# File 'lib/git_game_show/core/game_state.rb', line 116 def mark_question_evaluated @question_already_evaluated = true end |
#move_to_next_question ⇒ Object
92 93 94 95 96 |
# File 'lib/git_game_show/core/game_state.rb', line 92 def move_to_next_question @current_question_index += 1 @player_answers = {} @question_already_evaluated = false end |
#playing? ⇒ Boolean
27 28 29 |
# File 'lib/git_game_show/core/game_state.rb', line 27 def @state == :playing end |
#prepare_next_question ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/git_game_show/core/game_state.rb', line 77 def prepare_next_question return false if @current_question_index >= @round_questions.size @question_already_evaluated = false @current_question_id = "#{@current_round}-#{@current_question_index}" @question_start_time = Time.now @player_answers = {} true end |
#record_player_answer(player_name, answer, time_taken, correct = nil, points = 0) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/git_game_show/core/game_state.rb', line 106 def record_player_answer(player_name, answer, time_taken, correct = nil, points = 0) @player_answers[player_name] = { answer: answer, time_taken: time_taken, answered: true, correct: correct, points: points } end |
#reset_game ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/git_game_show/core/game_state.rb', line 50 def reset_game @state = :lobby @current_round = 0 @current_mini_game = nil @round_questions = [] @current_question_index = 0 @question_already_evaluated = false @player_answers = {} true end |
#set_round_questions(questions) ⇒ Object
71 72 73 74 75 |
# File 'lib/git_game_show/core/game_state.rb', line 71 def set_round_questions(questions) @round_questions = questions @current_question_index = 0 true end |
#start_game ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/git_game_show/core/game_state.rb', line 35 def start_game return false unless @state == :lobby @state = :playing @current_round = 0 # Reset the mini-game tracking for a new game @used_mini_games = [] @available_mini_games = [] true end |
#start_next_round(mini_game) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/git_game_show/core/game_state.rb', line 61 def start_next_round(mini_game) @current_round += 1 # Reset question evaluation flag for the new round @question_already_evaluated = false # Set the current mini-game @current_mini_game = mini_game true end |