• Advertisement
Sign in to follow this  

Javascript / angularJS OO and Code Separation Techniques

This topic is 1238 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey All,

 

I'll be the first to admit I don't know much about javascript programming but I did use it to create my entry of the week of awesome 2  competition. Now that competition is close I'd like to continue developing my game but before I continue to build on to what I've already got I'm looking for advice on how to better structure my code base. As how things currently stand I have one js file consisting of a 1000+ line controller.

 

Its made up of several sections:

  • Game Data - Holding all the variable related to the current game state.
  • Actions Lits - These are list of all the available actions in each room, along with descriptions of the actions, whether they are enabled, how many times its been called and a maximum number of times it can be called, not relevant to every action.
  • Story Data - This is just arrays containing text displayed at different times to the user, and any accompanying image data to go with the text.
  • Action Methods - There is a set methods that deal with performing an action, enabling, and disabling actions, and resolving the action and whatever the success and failure results.
  • Popup methods - These methods deal with displaying and handling input from popup boxes displayed to the user.
  • Combat methods - The methods that deal with combat.
  • Stat Change methods - This is set of methods that wrap the common functionality around changing any of the main character stats.

 

If I was doing this c# or java I'd be able to break all of those into different classes or spread the functionality across multiple partial files without a problem.  But when using them inside an angularJS controller I haven't go a scooby as to how to go about it.

 

Any good tips on how to proceed?  I don't want to end up with one file that's over 5000 lines long.

 

Share this post


Link to post
Share on other sites
Advertisement

I'm also doing myself questions about that. My problem stems from the fact to have private methods you have to use closures but at that point everything must be there.

 

I tried to refactor in helper objects as much as possible but I'm not currently satisfied.

 

Watching.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement