I am creating a Monopoly game. I searched for a way to create a take_turn method (or a Class) so I can switch automatically between player1 and player2 (and in the future player3 etc.).
Looked for answers here and also found this full-on PDF on OOP for developing games but haven't found the answer to this specific question.
Here's the code I' TDDed and built with several other objects. All works well at the moment for just player1, I would just like to automatically repeat those steps for player1 then player2 automatically without having to do it manually (DRY).
class Engine
attr_reader :dice, :player1, :player2, :move, :board
def initialize
@player1 = Player.new
@board = Board.new
@player2 = Player.new
@dice = Dice.new
@move = Move.new
end
def run
3.times do
roll_and_move
print_current_balance
player_action
end
end
def roll_and_move
dice.roll
move.move(player1, board, dice.value)
end
def print_current_balance
player1.balance
end
def player_action
player1.buy(board.tile(player1.position))
end
end