Re: Procedural design patterns?
- Posted by mattlewis (admin) Sep 26, 2013
- 2096 views
Of course, I did not mean such a trivial example. Let x is the level of force of an object in the game (the hero, the monsters, the boss). Pseudo-OOP-Eu:
hero = clone(person) hero.lifepoints = 100 for i = 1 to 100 do monsters[i] = clone(hero) end for boss = clone(hero) boss.lifepoints *= 10 --------------------- if monsters.count = 0 then attack_boss() if boss.lifepoints = 0 then puts(1, "You saves FairyLand!") else puts(1, "Boss eats you! :(") end if end if
Sure. That doesn't seem much different than using sequences. So, boss.lifepoints becomes, say, boss[LIFEPOINTS].
How to automate reading and writing multiple parameters of the same type? Use a sequence where the first integer is hero's lifepoints, the next 100 - monsters' lifepoints, and 102nd is the boss?
sequence LifePoints = repeat(100, 101) & 1000 export fuction hit(integer who) LifePoints[who] -= 1 end function
Thank you. I'd rather look into the OOP.
There are multiple ways to do this. You could keep parallel sequences for lifepoints and whatever else you need. Alternatively, you could store each entity as an element in the sequence, so you might end up with something like:
sequence Characters = repeat(100, 101) & 1000 export fuction hit(integer who) Characters[who][LIFEPOINTS] -= 1 end function
These issues don't go away with OOP. Also, the new scoping for 4.0 facilitates similar functions to inheritance and encapsulation. So, you might have a base module, character.e that deals with common attributes of different kind of characters, (heroes, monsters, etc). And then various files that handle the more specific aspects of types of characters. The basic API could be exposed as public, with helper methods inside of character.e meant to be used by hero.e, monster.e as exports.
You could register routine_ids for the various routines that need to be specific for different types. This gives you some of the benefits of typical OOP polymorphism.
Matt