Séparé les classes dans des fichiers
This commit is contained in:
1 parent
87e89775cc
commit
3fcc1b5318
3 files changed
+43
-20
No files matched your search
@@ -1,5 +1,6 @@
|
||||
require_relative "deck"
|
||||
require_relative "player"
|
||||
require_relative "terminal_ui"
|
||||
|
||||
class Game
|
||||
attr_reader :player1, :player2, :dealer, :non_dealer,
|
||||
@@ -14,6 +15,7 @@ class Game
|
||||
@upcard = nil
|
||||
@trump_suit = nil
|
||||
@round_winner = nil
|
||||
@ui = TerminalUI.new
|
||||
end
|
||||
|
||||
def determine_dealer
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
class TerminalUI
|
||||
def choose_card(player)
|
||||
player.hand.each_with_index do |card, index|
|
||||
puts "#{index + 1}. #{card}"
|
||||
end
|
||||
|
||||
print "Choose a card: "
|
||||
choice = gets.chomp.to_i
|
||||
|
||||
player.hand[choice - 1]
|
||||
end
|
||||
|
||||
def debug_game(game)
|
||||
puts "Dealer: #{game.dealer.name}"
|
||||
puts "Non-dealer: #{game.non_dealer.name}"
|
||||
puts
|
||||
|
||||
puts "#{game.player1.name} has:"
|
||||
puts game.player1.hand
|
||||
puts
|
||||
|
||||
puts "#{game.player2.name} has:"
|
||||
puts game.player2.hand
|
||||
puts
|
||||
|
||||
puts "Upcard: #{game.upcard}"
|
||||
puts "Trump suit: #{game.trump_suit}"
|
||||
puts
|
||||
|
||||
puts "Stock:"
|
||||
puts game.stock
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,33 +1,20 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require_relative "lib/game"
|
||||
require_relative "lib/terminal_ui"
|
||||
|
||||
# Instance du jeu
|
||||
game = Game.new("Alice", "Bob")
|
||||
ui = TerminalUI.new
|
||||
|
||||
game.determine_dealer
|
||||
puts "The dealer is #{game.dealer.name}."
|
||||
game.deal
|
||||
puts "#{game.player1.name} has #{game.player1.hand.count} cards."
|
||||
puts "#{game.player2.name} has #{game.player2.hand.count} cards."
|
||||
puts "The stock has #{game.stock.length} cards."
|
||||
puts
|
||||
ui.debug_game(game)
|
||||
|
||||
game.change_dealer
|
||||
puts "The dealer is #{game.dealer.name}."
|
||||
game.deal
|
||||
puts "#{game.player1.name} has #{game.player1.hand.count} cards."
|
||||
puts "#{game.player2.name} has #{game.player2.hand.count} cards."
|
||||
puts "The stock has #{game.stock.length} cards."
|
||||
ui.debug_game(game)
|
||||
|
||||
# Mise en place du jeu
|
||||
# puts "#{game.player1.name} has :"
|
||||
# puts
|
||||
# puts "#{game.player2.name} has :"
|
||||
# puts game.player2.hand
|
||||
# puts
|
||||
# puts "Upcard is #{game.upcard} so the trump suit is #{game.trump_suit}."
|
||||
# puts
|
||||
# puts "The stock has #{game.stock.length} cards :"
|
||||
# puts
|
||||
# puts game.stock
|
||||
# card = ui.choose_card(game.player1)
|
||||
# puts "#{game.player1.name} chose #{card}."
|
||||
|
||||
Reference in new issue
Block a user