Class: BoardgameEngine::Game
- Inherits:
-
Object
- Object
- BoardgameEngine::Game
- Defined in:
- lib/boardgame_engine/boardgame.rb
Overview
Class representing the game loop. It contains the tutorial sequence and information about the core gameplay loop
Direct Known Subclasses
Constant Summary collapse
- PLAY_INSTRUCTIONS =
''- GAME_NAME =
'Boardgame'- NUM_PLAYERS =
2
Class Method Summary collapse
-
.start(do_onboarding: true) ⇒ void
Begins a round of the Game.
Instance Method Summary collapse
-
#onboarding ⇒ void
Execute onboarding sequence where the player is asked if they want a tutorial.
-
#play(turn = ) ⇒ void
Play the game.
-
#to_s ⇒ String
String representation of the game.
Class Method Details
.start(do_onboarding: true) ⇒ void
This method returns an undefined value.
Begins a round of the Game
onboarding
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/boardgame_engine/boardgame.rb', line 40 def self.start(do_onboarding: true) names = [] self::NUM_PLAYERS.times do |i| puts "What is Player #{i}'s name?" names.push(gets.chomp) end @game = new(names) puts "Welcome to #{@game}!" @game.onboarding if do_onboarding puts "Starting #{@game}..." @game.play end |
Instance Method Details
#onboarding ⇒ void
This method returns an undefined value.
Execute onboarding sequence where the player is asked if they want a tutorial
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/boardgame_engine/boardgame.rb', line 59 def onboarding puts "Would you like a tutorial on how to play on this program? \n(y, n)" case gets.chomp when 'y' tutorial when 'n' puts 'Skipping Tutorial' else puts 'Please answer either "y" or "n"' onboarding end end |
#play(turn = ) ⇒ void
This method returns an undefined value.
Play the game
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/boardgame_engine/boardgame.rb', line 78 def play(turn = @players[0]) @turn = turn @board.display until @winner play_turn @board.display change_turn end puts "#{@winner} wins!" end |
#to_s ⇒ String
String representation of the game
92 93 94 |
# File 'lib/boardgame_engine/boardgame.rb', line 92 def to_s "#{self.class::GAME_NAME} between #{@players.join(', ')}" end |