Add seed to generate combats

pull/1/head
Karim Bogtob 2 years ago
parent e0b3f6cfbe
commit 84692f1cc1

@ -5,6 +5,11 @@ class Combat < ApplicationRecord
belongs_to :right_fighter, class_name: 'Creature'
belongs_to :winner, class_name: 'Creature', optional: true
def to_label
return "Invalid combat" unless valid?
"Combat '#{name}' entre #{left_fighter.name} et #{right_fighter.name}"
end
def baston!
return if left_fighter.nil? || right_fighter.nil?

@ -14,4 +14,13 @@ nb_creatures.times do
c = Creature.create(name: rng.compose(nb_syllables), health_points: rand(6..50))
puts "Création de #{c.to_label}"
end
3.times do |i|
combat = Combat.new(left_fighter: Creature.alive.first, right_fighter: Creature.alive.last, name: "Auto-généré #{i + 1}")
combat.baston!
combat.left_fighter.save!
combat.right_fighter.save!
combat.save!
puts combat.to_label
end
Loading…
Cancel
Save