walkerb,

Read a post last night asking about making a python class use different code for different things. It was in the context of a game, so extending the ability of the class with different objects.

It interested me so I thought I'd play with the idea this lunchtime.

Here we have a player object (apologies to Steve Jackson / Ian Livingston for appropriating their combat system) with name, skill, stamina and the weapon and armor they have.

The weapons and armor are defined in different classes as functions representing the damage they do, or absorb.

They are passed into the player object by assigning them.

Then battle commences...

Fun little lunchtime code illustrating the power of object oriented code.

https://github.com/nakedmcse/PyRPGCombat/blob/main/PyRPGCombat.py

image/png
image/png

davidr,
@davidr@hachyderm.io avatar

@walkerb If I understand what you mean "use different code", first class functions are probably a clearer example of this.

walkerb,

@davidr yeah I kind of butchered the description.

It was for a game and the guy was trying to plugable weapon functions.

This was supposed to show that and grouping the weapons and armor in their own classes.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • python
  • tacticalgear
  • thenastyranch
  • ethstaker
  • everett
  • Durango
  • rosin
  • InstantRegret
  • DreamBathrooms
  • magazineikmin
  • Youngstown
  • mdbf
  • slotface
  • GTA5RPClips
  • kavyap
  • megavids
  • modclub
  • cisconetworking
  • cubers
  • ngwrru68w68
  • khanakhh
  • tester
  • anitta
  • normalnudes
  • Leos
  • osvaldo12
  • provamag3
  • JUstTest
  • lostlight
  • All magazines