Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## got to using a binding.pry
- class Player
- attr_accessor :name, :prompt, :score, :lives
- def initialize
- @score = 0
- @lives = 3
- end
- def get_name
- puts "Which player are you - 1 or 2?"
- self.name = gets.chomp().to_s
- end
- def gain_a_point
- self.score += 1
- end
- def lose_a_life
- self.lives -= 1
- end
- end
- class Game
- attr_accessor :players
- attr_accessor :active_player
- attr_accessor :game_question
- attr_accessor :answer
- attr_accessor :point
- def initialize
- # @turn = ""
- # @question = ""
- # @answer = ""
- self.players = []
- 2.times { players << Player.new }
- self.active_player = players[0]
- end
- # def game_question
- # Question.new.equation
- # end
- def run_the_game
- loop do
- ask = Question.new
- ask.equation
- answer = gets.chomp().to_i
- if ask.check_answer(answer)
- puts "That is correct - switch player"
- active_player.gain_a_point
- else
- puts "Sorry, wrong answer - switch player"
- active_player.lose_a_life
- end
- if game_over
- break
- end
- end
- end
- def game_over
- active_player.lives == 0 || active_player.score == 8
- # game has a loser || game has a winner
- end
- end
- class Question
- attr_accessor :num1
- attr_accessor :num2
- attr_accessor :equation
- def initialize
- @equation = "i + i"
- @ask_question = ""
- get_random_numbers
- end
- def get_random_numbers
- self.num1 = rand(1..20)
- self.num2 = rand(1..20)
- end
- def equation
- puts "What is #{num1} + #{num2}?"
- end
- def check_answer(user_answer)
- answer = num1 + num2
- user_answer == answer
- end
- end
- Player.new.get_name
- Game.new.run_the_game
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement