Android Open Source - memorygame Player






From Project

Back to project page memorygame.

License

The source code is released under:

MIT License

If you think the Android project memorygame listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gustavoparreira.realtimetile;
//from www .jav  a 2s.  c  o  m
import java.util.LinkedHashMap;

import co.realtime.storage.ItemAttribute;
import co.realtime.storage.ItemRef;
import co.realtime.storage.StorageRef;
import co.realtime.storage.TableRef;
import co.realtime.storage.ext.OnError;
import co.realtime.storage.ext.OnItemSnapshot;

public class Player {

    public String gameID;
    public String playerID;
    public String name;
    public int score;
    TableRef gameTableRef;

    public Player(StorageRef storage, String _gameID, String _playerID, String _name, int _score) {
        gameID= _gameID;
        playerID = _playerID;
        name = _name;
        score = _score;
        gameTableRef = storage.table("Game").equals("gameID", new ItemAttribute(gameID));
    }

    public void update(final OnItemSnapshot finish) {

        ItemAttribute primaryKey = new ItemAttribute(gameID);
        ItemAttribute secondaryKey = new ItemAttribute(playerID);

        LinkedHashMap<String, ItemAttribute> playerInfo = new LinkedHashMap<String, ItemAttribute>();
        playerInfo.put("gameID", primaryKey);
        playerInfo.put("playerID", secondaryKey);
        playerInfo.put("playerName", new ItemAttribute(name));
        playerInfo.put("score", new ItemAttribute(score));

        gameTableRef.push(playerInfo, finish, new OnError() {
            @Override
            public void run(Integer code, String errorMessage) {
                System.out.println(String.format("Player update:: error %d (%s)", code, errorMessage));
                if(finish != null) {
                    finish.run(null);
                }
            }
        });
    }

    public void leaveGame() {
        ItemAttribute primaryKey = new ItemAttribute(gameID);
        ItemAttribute secondaryKey = new ItemAttribute(playerID);
        ItemRef player = gameTableRef.item(primaryKey, secondaryKey);
        player.del(null, null);
    }
}




Java Source Code List

com.gustavoparreira.realtimetile.ApplicationTest.java
com.gustavoparreira.realtimetile.Game.java
com.gustavoparreira.realtimetile.JoinGame.java
com.gustavoparreira.realtimetile.MainMenu.java
com.gustavoparreira.realtimetile.NewGame.java
com.gustavoparreira.realtimetile.Player.java
com.gustavoparreira.realtimetile.Tile.java