Skip to content

Start Developing

Ta Van Dung edited this page Jun 9, 2016 · 1 revision

After setup the project done, you have enough libraries now, lets continues.

Step 1. Add application entry point class.

To run an application on smartfox server environment we need an application entry point, you can create its like this:

import com.tvd12.ezyfox.core.annotation.AppContextConfiguration;
import com.tvd12.ezyfox.sfs2x.extension.ZoneExtension;

@AppContextConfiguration(clazz = AppConfig.class)
public class GameApplication extends ZoneExtension {
}
import com.tvd12.ezyfox.core.annotation.PackagesScan;

@PackagesScan(packages = "com.tvd12.videopoker")
public class AppConfig {
}

[Ezyfox] (https://github.com/youngmonkeys/ezyfox-core) will use packages to scan all component needed in runtime.

Step 2. Create User and Room agent classes.

Difference from smartfox, [Ezyfox] (https://github.com/youngmonkeys/ezyfox-core) doesn't use key-value object, we use [POJO] (https://en.wikipedia.org/wiki/Plain_Old_Java_Object), so to describe User agent and Room agent, we need create two class like this:

import com.lagente.videopoker.model.Game;
import com.tvd12.ezyfox.core.annotation.UserAgent;
import com.tvd12.ezyfox.core.annotation.Variable;
import com.tvd12.ezyfox.core.model.ApiUser;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@UserAgent
@EqualsAndHashCode(callSuper = false)
public class VideoPokerUser extends ApiUser {

    @Variable(name = "1", visible = true)
    private long money = 200000; 
    
    @Variable(name ="2", visible = true)
    private long gameMoney = 0;
    
    private Game game;
    
    public void increaseMoney(long offset) {
        setMoney(getMoney() + offset);
    }
    
    public void decreaseMoney(long offset) {
        setMoney(getMoney() - offset);
    }
    
    public void increaseGameMoney(long offset) {
        setGameMoney(getGameMoney() + offset);
    }
    
    public void resetGameMoney() {
        setGameMoney(0);
    }
    
    public Game newGame() {
        setGame(new Game());
        return getGame();
    }
}
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.lagente.videopoker.builder.PackMatcherChain;
import com.lagente.videopoker.card.Card;
import com.lagente.videopoker.model.PayTable;
import com.lagente.videopoker.server.model.AppSingleton;
import com.lagente.videopoker.server.model.BettingType;
import com.tvd12.ezyfox.core.annotation.ResponseParam;
import com.tvd12.ezyfox.core.annotation.ResponseParams;
import com.tvd12.ezyfox.core.annotation.RoomAgent;
import com.tvd12.ezyfox.core.annotation.Variable;
import com.tvd12.ezyfox.core.model.ApiRoom;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@RoomAgent
@ResponseParams
@ToString
@JsonIgnoreProperties(ignoreUnknown = true)
public class VideoPokerRoom extends ApiRoom {

    @Setter @Getter
    public int typeId = 0;
    
    @Variable(name = "1", visible = true)
    @Setter @Getter
    private long jackpotMoney = 100000;

    @ResponseParam("1")
    @Setter @Getter
    private PayTable payTable;
    
    @Getter
    @JsonIgnore
    private Map<Integer, BettingType> bettingTypes;
    
    @ResponseParam("2")
    public Set<Integer> bettingTypeIds() {
        return bettingTypes.keySet();
    }
    
    @JsonProperty("bettingTypes")
    public void setBettingTypes(BettingType[] types) {
        bettingTypes = new HashMap<>();
        for(BettingType type : types)
            bettingTypes.put(type.getId(), type);
    }
    
    public BettingType getBettingType(int id) {
        return bettingTypes.get(id);
    }
    
    public PackMatcherChain matcherChain() {
        return AppSingleton.chain(payTable);
    }
    
    public List<Card> cardPack() {
        return AppSingleton.cardPack(typeId);
    }
    
    public void increaseJackpotMoney(long offset) {
        setJackpotMoney(getJackpotMoney() + offset);
    }
    
    public void resetJackpotMoney() {
        setJackpotMoney(0);
    }
}

And now you can [deploy the application to smartfox]

Hello World

Clone this wiki locally