Developing TicToe HTML5/Implementing Server Entities

From Arianne
Revision as of 00:17, 21 December 2011 by imported>Hendrik Brummermann (Created page with "{{Navigation TicToe HTML5}}__NOTOC__ Now we have a user interface on the client side. Lets have a look at the server. The server is the place where all the interesting logic wil...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Development log of TicToe HTML5

Now we have a user interface on the client side. Lets have a look at the server. The server is the place where all the interesting logic will happen. But before we can start coding the game rules, we need to implement the entities.

As we are using different programming languages for the client and the server, we have to do this again.

We start with a stub for the Entity class, which we will put into the folder net/sf/arianne/tictoe/server/entity. The prefix is generated by reversing our domain name arianne.sf.net to ensure a unique name space.


Entity class

We define two constructors: A simple one without parameters that is used by our code to create a new Entity. And a second one with an RPObject as parameter. This one is used when Marauroa creates an Entity based on information stored in the database:

<source lang="java"> package net.sf.arianne.tictoe.server.entity;

import marauroa.common.game.Definition.Type; import marauroa.common.game.RPClass; import marauroa.common.game.RPObject;

/**

* the abstract base class of all Entities
*
* @author hendrik
*/

public abstract class Entity extends RPObject {

/** * creates a new Entity. */ public Entity() { // default constructor }

/** * creates a new Entity based on the provided RPObject * * @param object RPObject */ public Entity(RPObject object) { super(object); } } </source>

Now we need to tell Marauroa which attributes our entity class will have. Depending on the flags they will be sent to the client and/or stored to the database. For now, we use the x, y, z coordinates without any special flags:

<source lang="java"> /** * generates the RPClass */ public static void generateRPClass() { RPClass clazz = new RPClass("entity"); clazz.addAttribute("x", Type.INT); clazz.addAttribute("y", Type.INT); clazz.addAttribute("z", Type.INT); } </source>

It is a good design to make the interface of a class explicit. Therefore we define get- and set- method for those attributes:

<source lang="java"> /** * gets the x-coordinate * * @return x-coordinate */ public int getX() { return super.getInt("x"); }

/** * gets the y-coordinate * * @return y-coordinate */ public int getY() { return super.getInt("y"); }

/** * gets the z-coordinate * * @return z-coordinate */ public int getZ() { return super.getInt("z"); }

/** * sets the x coordinate * * @param x x-coordinate */ public void setX(int x) { super.put("x", x); }

/** * sets the y coordinate * * @param y y-coordinate */ public void setY(int y) { super.put("y", y); }

/** * sets the z coordinate * * @param z z-coordinate */ public void setZ(int z) { super.put("z", z); } </source>

These simple methods may seem like a waste of space, but they will make things a lot easier later.

Gameboard class

TODO: Write this section

Token class

TODO: Write this section

Player class

TODO: Write this section