+ 1
how would I code an health point system?
lets say I have a monster named "mon1" and another monster named "mon2".they both have 100 health points. how could I make mon1 do damage to decrease mon2 health? or vice versa. lets say they both, only have 2 attacks called, "punch" and "kick" punch does 20 damage and kick does 30 damage. and the user can choose which attack they want to use to deal damage to the other monster. can anyone give me a general idea on how this would be written in ruby code?
6 Réponses
+ 3
The monsters would be two objects built from the monster class.
+ 2
when user clicks punch call punch function, which will reduce second user's hp by given points.
same for kick 😁😁
+ 2
so basically punch and kick would be methods aka (.punch) and (.kick) and I would have to specify how much hp they reduce. hp would stay as a variable.
so would the monsters count as classes then?
+ 1
monsters would be objects, with total hp and current hp as attriubutes.
and punch and kick would be methods as you just said 😁
+ 1
i never wrote code in ruby so I'm talking in general, it could be applied to most oop languages, so probably works for ruby too
0
thank you guys so much. I feel like I have basic information on objects but I may have to do a bit more studying to really understand everything. but im getting there 💪