« first day (4 days earlier)    last day (15 days later) » 

7:14 PM
Sorry to drop off on this, busy lately. Don't worry that your questions are basic, I'm a noob too with a lot of JS stuff.
I'm going to try to clarify a bit but this is a complex subject. You'll need to put in your own legwork by studying books and other materials. Here's a good selection of options: medium.com/javascript-scene/…
Some of these books are available free online. Here's another one that might be particularly relevant: github.com/getify/You-Dont-Know-JS/tree/master/…
So when I say "central object", architecturally I mean this: conceptually, you'd like to have a Game object that takes parameters to initialize a new instance of it. Inside that object, you store the state of the game (abstractly) and ways that it receives user input (events from the DOM) and interacts with a display output (in this case, an instance of Processing which gives you tools to draw to a canvas element).
User events cause changes in the state of the Game object instance, and when that state changes, you draw to the canvas using the Processing object instance. One direction of data flow makes things much clearer, as does separating these three parts, and keeping their scopes separate.
So in your game logic file, you'd have something like:
function Game(parameters) {
// assign internal properties, for example:
this.turns_played = 0;
// assign methods:
this.calculate_damage = function (attacker, attackee) { /* stuff */ };
this.draw = function () { /* you might have a this.canvas reference which points to a Processing instance, so you call this.canvas.draw(), for example */ }
}
and so on
I've never really tried explaining any of this to anyone so I'm not sure if it puts you on the right track but hopefully you get some of an idea. And with all this, it's important to understand what the scope is at each point.
You might look at the source of a small library which is architected in this way to help understand. Here's a resource I really like, if you can dissect it and understand it all then you'll be able to use the same patterns, or even improve on them: underscorejs.org/docs/underscore.html
 
 
2 hours later…
9:43 PM
I think I understand what you mean
But I'm not sure if I should store the ways the game receives user input inside the object, because I'm using Processing.js's functionality for that. But I think I understand what you want me to do. I should basically turn my program into an Object type, and add all the information that it needs into properties, and it's execution (when it draws to the canvas) inside a method. Then I should just create a new Game and use game.play
Is that right or am I missing something?
 

« first day (4 days earlier)    last day (15 days later) »