Commencé à implémenter les plis

This commit is contained in:
julien committed 2026-10-06 15:54:57 +02:00
1 parent 3cdcec55b2
commit de4c374f33
4 files changed
+22 -16

No files matched your search

+17 -6
View File
@@ -60,12 +60,12 @@ class Game
@deck.cards @deck.cards
end end
def play_trick def play_trick(lead_player, follow_player)
lead_card = @ui.choose_card(player1) lead_card = @ui.choose_card(lead_player)
follow_card = @ui.choose_card(player2) follow_card = @ui.choose_card(follow_player)
player1.play lead_player.play(lead_card)
player2.play follow_player.play(follow_card)
if lead_card.suit != follow_card.suit && follow_card.suit != @trump_suit if lead_card.suit != follow_card.suit && follow_card.suit != @trump_suit
@trick_winner = @player1 @trick_winner = @player1
@@ -76,12 +76,23 @@ class Game
end end
@trick_winner.add_point @trick_winner.add_point
@ui.display_trick_winner(trick_winner)
end
def other_player(player)
player == @player1 ? @player2 : @player1
end end
def play def play
lead_player = @non_dealer
follow_player = @dealer
5.times do 5.times do
play_round play_trick(lead_player, follow_player)
end end
lead_player = @trick_winner
follow_player = other_player(lead_player)
end end
def game_winner def game_winner
+2 -2
View File
@@ -15,8 +15,8 @@ class Player
@hand.clear @hand.clear
end end
def play def play(card)
@hand.pop @hand.delete(card)
end end
def add_point def add_point
+2
View File
@@ -2,6 +2,7 @@ class TerminalUI
def choose_card(player) def choose_card(player)
player.hand.each_with_index do |card, index| player.hand.each_with_index do |card, index|
puts "#{index + 1}. #{card}" puts "#{index + 1}. #{card}"
puts
end end
print "Choose a card: " print "Choose a card: "
@@ -12,6 +13,7 @@ class TerminalUI
def display_trick_winner(player) def display_trick_winner(player)
puts "#{player.name} wins the trick." puts "#{player.name} wins the trick."
puts
end end
def debug_game(game) def debug_game(game)
+1 -8
View File
@@ -11,15 +11,8 @@ game.determine_dealer
game.deal game.deal
# Première manche # Première manche
# Premier pli
ui.debug_game(game) ui.debug_game(game)
game.play_trick game.play
ui.display_trick_winner(game.trick_winner)
# Second pli
ui.debug_game(game)
game.play_trick
ui.display_trick_winner(game.trick_winner)
# Nouvelle manche # Nouvelle manche
# game.change_dealer # game.change_dealer