Computer Science Canada RPG Classes (Cervantes come see) |
Author: | Clayton [ Sat Sep 02, 2006 4:59 pm ] |
Post subject: | RPG Classes (Cervantes come see) |
here is my basic (note: basic) class heirarchy (sp?) for my hopefully, in time to come, rpg. right now ive just got the basic stuff happening here (characters and weapons. the item class and its children to come soon), but none of the battle engine or anything intertwined yet, ive got a folder attached to show what you can do with a character (its just taking the stats from a file right now) and displays its traits, however, i hope that it will be much more in the future ![]() |
Author: | TheOneTrueGod [ Sun Sep 03, 2006 5:32 pm ] | ||
Post subject: | |||
Nice, more people starting to learn classes ![]() -First thing I see: exporting variables. You shouldn't do this... All the variables should be managed inside the class. If you absolutely must get the value from inside the class, make a function called "Get*****" (Where ***** is the name of whatever you want to 'get'). If you have a lot of variables that you plan on exporting this way, I generally make a "GetVar (s : string)" type of funciton, and the parameter is which one I want to 'get'. -Can't really comment on the inheritance as not much is being done with it...
First thing that comes to mind here is: what happens if they have an item in the highest slot, but not in the second highest? Also, when you actually do add the item, its really inefficient (what happens if you have 200 items? and you get, say, 5 from battle? lag...) and hard-coded. You should go from 0 to upper(item_inventory), not 0 to 3... though there is probably a better (more efficient) way of doing that anyways. -When you move on, change the display procedure so it is less hard-coded. -Your dmg function is also kinda hard-coded. What happens if you want to have intelligence used for damage? (Just something to think about, this one isn't really that much of an issue) -Overall, however, this is a good job. The fun part is going to be when you start getting the player to equip weapons -- This didn't work out too great for me, for various coding reasons. Hope you get it done better than I did ![]() Good job superfreak. ![]() |
Author: | Clayton [ Mon Sep 04, 2006 9:26 am ] |
Post subject: | |
right now the item idea is kind of in limbo of having only four items to be carried (about 85% sure on that one), um the way the item_inventory is (supposed) to work, is that it will fill up from 0..3, then it will empty out and all items will be shifted down in the array (eg. if item 2 is discarded or used up, then item 3 will move down to element 2). The display procedure was just a kind of way of testing right now to make sure i can get things from my files etc. I believe that my damage formula is pretty much where i want to keep it (with the stats etc.) Another thing, why cant i export those couple of variables (especially since they arent exported as var)? Is it really worth making extra functions for them? Thanks for the feedback TOTG ![]() |
Author: | Mad_CatMk2 [ Mon Oct 16, 2006 10:52 am ] |
Post subject: | Cool |
Nice class action going there. Since im still getting accustomed to somewhat object oriented programming (java in this case), looking at your simple code gave me an idea to do OOT. Btw, I do have a bigass RPG-type game wip but its a personal project and its VERY structured oriented. However, it does include graphics, movement etc n stuff and I woudln't mind sharing it ![]() Keep it going! |
Author: | Cervantes [ Mon Oct 16, 2006 3:06 pm ] | ||
Post subject: | |||
I'm really, truly sorry I haven't commented on this yet. I had intended to, but then it slipped my mind. Now, I've got a midterm in a few hours, but I'm going to comment now anyways, because I know if I don't it'll slip my mind again. ![]() First, a comment on TheOneTrueGod's comments: TheOneTrueGod wrote: -First thing I see: exporting variables. You shouldn't do this... All the variables should be managed inside the class. If you absolutely must get the value from inside the class, make a function called "Get*****" (Where ***** is the name of whatever you want to 'get'). If you have a lot of variables that you plan on exporting this way, I generally make a "GetVar (s : string)" type of funciton, and the parameter is which one I want to 'get'. Exporting variables is essentially the same as creating reader methods for them. In a good language, the shortcut used would be fine. Turing, however, has an inconsistency in that exporting a variable in read-only scope doesn't actually prevent one from getting write access to that variable. Rather, Turing will complain (give a warning) if you try to write to a "read only variable", but it will do it. So, in the case of Turing, writing your own getVar type functions would be good. I would highly recommend you stay away from a generic getVar(s : string) type function, though. The reason being that this function contains within it the code that determines which variables are made accessable. Then how would you document it? We should know exactly which properties of our objects are readable from the outside world, and this approach to creating reader-methods undermines that because it is hard to document. On the other hand, we don't even need any documentation if you use methods like getX and getHealth. Another bonus is that some languages (Ruby, for example) provide a method that will return an array of all the methods associated with an object. This would allow us to see all the getX, getHealth type methods, and we don't even need to go to the documentation at all! Now, here's something in your code to clean up: Look at the Non_Mage_Enemy and Mage_Enemy classes (that right there is an issue, actually: you should follow a consistant style within your code. You've got some classes in lower case with underscores, some with first letter of each word in upper case with underscores... I suggest DoingAllClassNamesLikeThis, method_names_like_this, vars_like_this, CONSTANTS_LIKE_THIS). Anyways, looking at the Non_Mage_Enemy and Mage_Enemy classes, you've got a level_up procedure that looks mighty similar. It looks the same, to me. The only way the level ups could differ is with different values for the variables skill_chance, speed_chance, etc. But you can change those variables' values for each object. Take this example:
In this code, Foo is your Enemy class, and Bar is a Mage_Enemy. So you can see that changing the variables value within a child object will indeed modify the behaviour of that object's methods. And so it should. As already mentioned, the inventory system needs some work. That checking the 0..3 slots is a problem. Hardcoding is bad, for many reasons. One such reason is because I, the reader of your code, don't immediately know if you even are checking all the slots, or if there are more slots you aren't checking there. |