Developing TicToe HTML5/Implementing Server Entities: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
imported>Hendrik Brummermann added missing setRPClass class in constructors |
imported>Hendrik Brummermann No edit summary |
||
| (5 intermediate revisions by the same user not shown) | |||
| Line 280: | Line 280: | ||
<source lang="ini"> |
<source lang="ini"> |
||
factory_implementation=net.sf.arianne.tictoe.server.core.TicToeObjectFactory |
factory_implementation=net.sf.arianne.tictoe.server.core.TicToeObjectFactory |
||
</source> |
|||
== Rule Processor == |
|||
The last basic class is the Rule Processor. It will receive all events from Marauroa and act in a game specific manner. We will register it in server.ini as: |
|||
<source lang="ini"> |
|||
ruleprocessor=net.sf.arianne.tictoe.server.core.TicToeRule |
|||
</source> |
|||
It is a singleton class, and therefore has to implement a get-method for the instance: |
|||
<source lang="java"> |
|||
package net.sf.arianne.tictoe.server.core; |
|||
import marauroa.common.game.RPObject; |
|||
import marauroa.server.game.rp.IRPRuleProcessor; |
|||
import marauroa.server.game.rp.RPRuleProcessorImpl; |
|||
import net.sf.arianne.tictoe.server.entity.Entity; |
|||
import net.sf.arianne.tictoe.server.entity.Gameboard; |
|||
import net.sf.arianne.tictoe.server.entity.Player; |
|||
import net.sf.arianne.tictoe.server.entity.Token; |
|||
/** |
|||
* provides the rules of the game. |
|||
*/ |
|||
public class TicToeRule extends RPRuleProcessorImpl { |
|||
private static RPRuleProcessorImpl instance; |
|||
/** |
|||
* gets the Rule singleton object |
|||
* |
|||
* @return Rule |
|||
*/ |
|||
public static IRPRuleProcessor get() { |
|||
if (instance == null) { |
|||
instance = new TicToeRule(); |
|||
} |
|||
return instance; |
|||
} |
|||
</source> |
|||
The constructor of the rule processor is a good place, to define the RPClasses: |
|||
<source lang="java"> |
|||
/** |
|||
* creates the rule processor |
|||
*/ |
|||
public TicToeRule() { |
|||
Entity.generateRPClass(); |
|||
Player.generateRPClass(); |
|||
Gameboard.generateRPClass(); |
|||
Token.generateRPClass(); |
|||
} |
|||
</source> |
|||
We override the method createCharacterObject, to tell Marauroa, that newly created character objects should use the class "Player": |
|||
<source lang="java"> |
|||
/** |
|||
* Creates an new character object that will used by createCharacter |
|||
* |
|||
* @param username the username who owns the account of the character to be added. |
|||
* @param character the character to create |
|||
* @param template the desired values of the avatar representing the character. |
|||
* @return RPObject |
|||
*/ |
|||
@SuppressWarnings("unused") |
|||
@Override |
|||
protected RPObject createCharacterObject(String username, String character, RPObject template) { |
|||
Player player = new Player(); |
|||
player.setPlayerName(character); |
|||
return player; |
|||
} |
|||
} |
|||
</source> |
</source> |
||