+ 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?

25th Jan 2020, 8:55 PM
Jester Ruhiel Rocton
Jester Ruhiel Rocton - avatar
6 Respuestas
+ 3
The monsters would be two objects built from the monster class.
26th Jan 2020, 5:08 AM
Sonic
Sonic - avatar
+ 2
when user clicks punch call punch function, which will reduce second user's hp by given points. same for kick 😁😁
25th Jan 2020, 10:14 PM
Amar
Amar - avatar
+ 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?
25th Jan 2020, 10:44 PM
Jester Ruhiel Rocton
Jester Ruhiel Rocton - avatar
+ 1
monsters would be objects, with total hp and current hp as attriubutes. and punch and kick would be methods as you just said 😁
26th Jan 2020, 5:16 AM
Amar
Amar - avatar
+ 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
26th Jan 2020, 5:18 AM
Amar
Amar - avatar
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 💪
26th Jan 2020, 8:37 PM
Jester Ruhiel Rocton
Jester Ruhiel Rocton - avatar