Hello,
I’ve got a web application that should simulate different activities as
follows:
- User1 and User2 teamed up for an activity called Activity1.
- Users have skills: skill1, skill2
def simulate_activity
a = Activity.find(params[:id])
return execute_1 a if a.activity_type == “1”
return execute_2 a if a.activity_type == “2”
end
def execute_1 act
report = “”
if(calculate_chance(user1.skill1) && calculate_chance(user2.skill1)
report += “Users successully blah”
act.status = “succeeded”
else
report += “Users did not manage to blah”
act.status = “failed”
end
report
end
def execute_2 act
report = “”
if(calculate_chance(user1.skill2) && calculate_chance(user2.skill2)
report += “Users successully blah”
act.status = “succeeded”
else
report += “Users did not manage to blah”
act.status = “failed”
end
report
end
I hope you get what I mean. My only problem is that I don’t really like
the way it’s programmed above. Does anyone know a better way to
“simulate” these kind of activities so it’s no mess when it gets more
complex etc.?