4 ms·
Cool idea, but I don't think it makes sense for there to be both a Player class and a warrior object. They seem like they are/should be one in the same. At th
by matthuggins 13y ago
Cool idea, but I don't think it makes sense for there to be both a Player class and a warrior object. They seem like they are/should be one in the same. At the very least, I think behind the scenes, the Player class should look more like this such that the warrior object is always available, and I don't need to pass it around from method to method that I define. e.g.:
class Player
attr_reader :warrior
def initialize(warrior)
@warrior = warrior
end
def play_turn
# I can now access `warrior` here or in any other methods I write
end
end
- snikch 13y agoThe player object would represent the current person playing the game, i.e. you. The warrior represents the object on the screen. The player tells the warrior to take actions, so it makes sense that they're different objects. If there were multiple warriors then your code would no longer make sense, as the control logic would have to be changing the player_instance.warrior object.
- xentronium 13y ago> If there were multiple warriors then your code would no longer make sense, as the control logic would have to be changing the player_instance.warrior object. You need to keep previous state about warrior. E.g. delta health.
- stormbrew 13y agoYou could always just do that.