Developing TicToe HTML5/Implementing Client Entities: Difference between revisions

Content deleted Content added
imported>Hendrik Brummermann
Created page with "{{Navigation TicToe HTML5}}__NOTOC__ After drawing a rough entity class diagram in the previous article, we are now going to implement the client side. We need to start with a h..."
imported>Hendrik Brummermann
No edit summary
Line 24:
</source>
 
== Implementing the entitiesentity hierarchy ==
 
In Java we would implement a class per entity type. JavaScript, however, is not class but prototype based.
 
In the later live game, Marauroa has to create the objects based on the information it gets from the server. In order to store the prototpyes it has a factory called marauroa.rpobjectFactory.
 
As a first step, we setup our inheritance hierarchy. Entity is the class at the root. Gameboard, Token and Player are specializations:
 
<source lang="html4strict">
/** Abstract entity */
marauroa.rpobjectFactory.entity = marauroa.util.fromProto(marauroa.rpobjectFactory._default);
 
/** game board */
marauroa.rpobjectFactory.gameboard = marauroa.util.fromProto(marauroa.rpobjectFactory.entity);
 
/** token */
marauroa.rpobjectFactory.token = marauroa.util.fromProto(marauroa.rpobjectFactory.entity);
 
/** player */
marauroa.rpobjectFactory.player = marauroa.util.fromProto(marauroa.rpobjectFactory.entity);
</source>