Stephen68 Posted March 17, 2009 Share Posted March 17, 2009 Not sure if this belongs where or not, I thought there was a OOP section but I could not find it. I was reading up on OOP and PHP and I think I can get a small grasp on it. In this article I he tells you you should draw diagrams of your objects, make boxes for each object that you create. So lets say that I want to make a web based game, would this be the right idea for a start. Box 1.) Object name game - would contain gameStartSpot(), gameStartRations(), gameAttack(), gameMove(),ect... Box 2.) Object name Players - would contain playerName(),playerProfile(),playerSig(), ... ect Box 3.) Object name stats - would contain statsRank(),statsArmySize(),statsAllianceRank(), ... ect Box 4.) Object name DB - would contain my database connection and query's calls/returns. Is this the right way to go about something like this? or would an I way off on my thinking? Any suggestions would be greatly appreciated, thanks for your help and time. Stephen Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted March 17, 2009 Share Posted March 17, 2009 Not sure if this belongs where or not, I thought there was a OOP section but I could not find it. I was reading up on OOP and PHP and I think I can get a small grasp on it. In this article I he tells you you should draw diagrams of your objects, make boxes for each object that you create. So lets say that I want to make a web based game, would this be the right idea for a start. Box 1.) Object name game - would contain gameStartSpot(), gameStartRations(), gameAttack(), gameMove(),ect... Box 2.) Object name Players - would contain playerName(),playerProfile(),playerSig(), ... ect Box 3.) Object name stats - would contain statsRank(),statsArmySize(),statsAllianceRank(), ... ect Box 4.) Object name DB - would contain my database connection and query's calls/returns. Is this the right way to go about something like this? or would an I way off on my thinking? Any suggestions would be greatly appreciated, thanks for your help and time. Stephen Without knowing what you want your game to be and how it should run, then yes, in a general sense, you're on the right track. The key, like with everything else, is to try to have a good idea of all the system's participants before diving into coding. Changes to your design will inevitably happen, but you should still know what you want to do even if how it is actually done is not in line with your original setup. Also, keep in mind that the first 'O' in OOP is 'Object.' A lot of new OOP learners try to stuff as much functionality into as few objects as possible, which runs counter to the entire point of OOP. It's better to have many simple objects than one big, complex object. Why? Because objects can (and should) be used in combination to create larger system components. This grants us flexibility. So, objects can (and should) be used as properties of other objects. And objects can (and should) be passed to another object's methods. And, simple data structures (like arrays) can contain objects as well. That's about all I can say without knowing anything else about your project. I hope it helps somewhat. Quote Link to comment Share on other sites More sharing options...
Stephen68 Posted March 17, 2009 Author Share Posted March 17, 2009 Thanks for the help, I have not really set in stone what I am going to do. I do have some ideas that I think would be cool to do and learn from at the same time. Once I have the full idea down on paper I could run it past you and see what you think, if you would like that is. Stephen Quote Link to comment Share on other sites More sharing options...
Stephen68 Posted March 18, 2009 Author Share Posted March 18, 2009 So basically it's should go something like this I have an Object that I call game and in the game object I have a method for moving a until around the playing board. I also have a Object called unit that has all the different units I can move. In stead of making a method called move for each unit (different speeds for each) I make a call to the move method in the game Object only passing the speed property for that unit. Is this right? seems there should be lots of thinking before ever writing code, I think I understand the reason the author suggests that I write it down on paper. Thanks for your help Stephen Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted March 18, 2009 Share Posted March 18, 2009 So basically it's should go something like this I have an Object that I call game and in the game object I have a method for moving a until around the playing board. I also have a Object called unit that has all the different units I can move. In stead of making a method called move for each unit (different speeds for each) I make a call to the move method in the game Object only passing the speed property for that unit. Is this right? seems there should be lots of thinking before ever writing code, I think I understand the reason the author suggests that I write it down on paper. Thanks for your help Stephen That should work. You could also give each unit their own Move method and pass into it an object representing the game world/level, which could then return the unit's new position. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.