Lets program a roleplaying game together. Each post must contain either a new function or an edited version of an old function in psudocode. I will start:
int dealDamage(int hp, int damage){
return hp - damage;
}
Name:
Anonymous2010-10-29 15:48
>>1
Now rewrite that function to return 0 if its negative without using an if statement!
Name:
Anonymous2010-10-29 15:50
Easy.
int dealDamage(int hp, int damage){
hp -= damage;
while(hp > 0)
return hp;
return 0;
}
you guys can optimize it,add to it and define the other functions in it
Name:
Anonymous2010-10-29 17:32
Here's some ENTERPRISE Common Lisp RPG skeleton I wrote in the last 15 minutes:
(defclass damageable-mixin ()
((damage-accumulated :accessor total-damage :initform 0)))
(defgeneric damage (object &key)
(:documentation "Inflict damage upon an object in some way"))
;; item may not have hp, but it can still accumulate damage,
;; it may break eventually depending on item's implementation
(defclass item (damageable-mixin) ())
(defmethod damage :before ((player player-character) &key amount)
(format t "You received ~A damage.~&" amount))
(defmethod heal :before ((player player-character) amount)
(format t "You were healed by ~A hitpoints.~&" amount))
(defmethod show-hitpoints ((player player-character))
(format t "You now have ~A hitpoints.~&" (hitpoints player)))
(let ((player (make-instance 'player-character :hitpoints 100)))
(damage player :amount 10)
(heal player 9.99))
;; Outputs:
;You received 10 damage.
;You now have 90 hitpoints.
;You were healed by 9.99 hitpoints.
;You now have 99.99 hitpoints.
It's overengineered, however it is imagined to allow one to define all kinds of things that can be damaged, and thigns that have HPs, each with more general and more specific behaviours as the game designer wishes. Items are meant to be able to receive damage, but they don't have to have a set HP, instead how damage is handled is left to the developer. Playable and non-playable characters do have HP and the damage is reflected by changing the HP, however such behaviour can be easily overridden by defining more specific methods on the characters.
>>14-16
This is meant to be pseudocode, you brain-damaged idiots; code written for the entertainment of the readers, nothing more. >>2-6 and others are also missing the point entirely.
>>17
Who cares, I never write psuedocode most of the time, unless the language is braindead, I can just express myself in it without the need of an extra translation step.
>>19
But then there are retards like >>14 writing function definitions. >>15-16 are nice and all but we were going to write it together and end up having humorous game logic or something not totally boring.
And >>2-6 just spewed their Asperger's all over the place.
>>26
What are you on about? Expressions are always better than statements. Its syntax in C may suck, but it's still superior to the normal statements semantically, at least when it comes to usefulness.