Class: BrainSnap::Game
- Inherits:
-
Object
- Object
- BrainSnap::Game
- Defined in:
- lib/brainsnap.rb
Instance Attribute Summary collapse
-
#current_card ⇒ Object
Returns the value of attribute current_card.
-
#dealer ⇒ Object
Returns the value of attribute dealer.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #end_game ⇒ Object
-
#initialize ⇒ Game
constructor
A new instance of Game.
- #mark_correct(card_obj) ⇒ Object
- #mark_incorrect(card_obj) ⇒ Object
- #next_card ⇒ Object
- #play ⇒ Object
- #play_game ⇒ Object
- #start_menu ⇒ Object
Constructor Details
#initialize ⇒ Game
Returns a new instance of Game.
12 13 14 15 16 17 18 19 |
# File 'lib/brainsnap.rb', line 12 def initialize # something to generate new cards @user = nil @current_card = nil @score = 0 @correctly_answered = [] @incorrectly_answered = [] end |
Instance Attribute Details
#current_card ⇒ Object
Returns the value of attribute current_card.
10 11 12 |
# File 'lib/brainsnap.rb', line 10 def current_card @current_card end |
#dealer ⇒ Object
Returns the value of attribute dealer.
10 11 12 |
# File 'lib/brainsnap.rb', line 10 def dealer @dealer end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
9 10 11 |
# File 'lib/brainsnap.rb', line 9 def score @score end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
9 10 11 |
# File 'lib/brainsnap.rb', line 9 def user @user end |
Class Method Details
.user ⇒ Object
21 22 23 |
# File 'lib/brainsnap.rb', line 21 def self.user @user end |
Instance Method Details
#end_game ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/brainsnap.rb', line 105 def end_game View.show_results(@correctly_answered.length, @incorrectly_answered.length) highscore = HighScores.new(@user, @score) highscore.players highscore.changeScore View.show_scores(highscore.sort_players) View.again? input = View.user_input if input == "y" || input == "yes" @incorrectly_answered = [] play else exit end end |
#mark_correct(card_obj) ⇒ Object
121 122 123 |
# File 'lib/brainsnap.rb', line 121 def mark_correct(card_obj) @correctly_answered << card_obj end |
#mark_incorrect(card_obj) ⇒ Object
125 126 127 |
# File 'lib/brainsnap.rb', line 125 def mark_incorrect(card_obj) @incorrectly_answered << card_obj end |
#next_card ⇒ Object
101 102 103 |
# File 'lib/brainsnap.rb', line 101 def next_card @current_card = dealer.load_card end |
#play ⇒ Object
129 130 131 |
# File 'lib/brainsnap.rb', line 129 def play self. end |
#play_game ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/brainsnap.rb', line 63 def play_game View.clear # show current card's category and question View.category_screen(current_card.category) View.show_card(current_card.question) # get user input from the View # TODO: prompt user for answer in View guess = View.user_input.downcase if guess == 'quit' end_game else # define flow of game based on user input (case statement) # use View to print returns from Model # define how the game ends if dealer.check(@current_card.answer, guess) # is this bad design? View.correct mark_correct(@current_card) @score+=1 sleep 1.5 else View.incorrect(@current_card.answer) mark_incorrect(@current_card) if @incorrectly_answered.length >=3 end_game end sleep 1.5 end if next_card next_card play_game else end_game end end end |
#start_menu ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/brainsnap.rb', line 26 def View.clear View.enter_username input = View.user_input @user = input.capitalize if input == 'quit' exit elsif input.length > 0 View.choose_category case View.user_input when '1' input = 'Animals' when '2' input = 'Food' when '3' input = 'Computers' when '4' input = 'Sports' when '5' input = 'Ruby' when 'quit' exit else puts "Choosing random category..." sleep 1.5 input = ['Animals','Food','Computers','Sports','Ruby'].sample end config_path = File.("../game_questions.csv", __FILE__) @dealer = Dealer.new(config_path, input) next_card play_game else end end |