コード例 #1
0
        public void renderNewBoard(BoardUpdate board)
        {
            foreach (MapObj obj in board.currentMap)
            {
                if (obj.type == BombermanObjType.Player)
                {
                    players [obj.color].moveToPos(floatArrayToVec(obj.pos), floatArrayToVec(obj.targetPos));
                }
            }

            foreach (BoardAction a in board.currentActions)
            {
                if (a.type == ActionType.BombSpawn)
                {
                    spawnBomb(a);
                }
                if (a.type == ActionType.BombExplosion)
                {
                    explodeBomb(a);
                }
                if (a.type == ActionType.PlayerDeath)
                {
                    playerDeath(a);
                }
            }
        }
コード例 #2
0
        private void broadcastBoard(Action <int, BoardUpdate> sendFunc)
        {
            List <MapObj>      currentMap     = formatMapObjects();
            List <BoardAction> currentActions = flushBoardActions();
            BoardUpdate        b = new BoardUpdate(currentMap, currentActions, PlayerColor.None, updateID);

            foreach (ConnectedPlayer p in players)
            {
                try{
                    b.color = p.color;
                    sendFunc(gameMaster.getMatchingPlayer(p.color).client.peerID, b);
                }catch (Exception e) { Debug.LogError("Failed Send: " + e.Message); }
            }
        }
コード例 #3
0
        // NOTE
        // Inheritence in the classes ParsedMapObj & ParsedPlayerObj seems to not be working correctly?!?
        // Look into this later


        public static string parseBoard(BoardUpdate b)
        {
            List <ParseBombObj>    parsedObjs    = new List <ParseBombObj> ();
            List <ParsedPlayerObj> parsedPlayers = new List <ParsedPlayerObj> ();

            foreach (MapObj obj in b.currentMap)
            {
                if (obj.type == BombermanObjType.Player)
                {
                    string          type = obj.color == b.color ? "Player" : "Enemy";
                    ParsedPlayerObj temp = new ParsedPlayerObj(type, obj.pos, obj.bombsLeft);
                    parsedPlayers.Add(temp);

                    if (type == "Player" && b.color == Game.PlayerColor.Blue)
                    {
                        //Debug.Log ("Blue Player: " + temp.Pos [0]);
                    }
                }

                if (obj.type == BombermanObjType.Bomb)
                {
                    string       type = "Bomb";
                    float        dur  = (float)decimal.Round((decimal)obj.explodeDuration, 2);
                    ParseBombObj temp = new ParseBombObj(type, obj.pos, dur);
                    parsedObjs.Add(temp);
                }
            }

            List <JSONObject> mapObjs = new List <JSONObject> ();

            foreach (ParsedPlayerObj obj in parsedPlayers)
            {
                mapObjs.Add(new JSONObject(JsonUtility.ToJson(obj)));
            }
            foreach (ParseBombObj obj in parsedObjs)
            {
                mapObjs.Add(new JSONObject(JsonUtility.ToJson(obj)));
            }


            JSONObject board = new JSONObject();

            foreach (JSONObject jObj in mapObjs)
            {
                board.Add(jObj);
            }

            return(board.ToString());
        }
コード例 #4
0
        public void initBoard(BoardUpdate board)
        {
            foreach (MapObj obj in board.currentMap)
            {
                if (obj.type == BombermanObjType.Player)
                {
                    GameObject tempObj = Instantiate(playerPrefab, Vector3.zero, Quaternion.identity, mapObjectsParent);
                    tempObj.transform.localPosition = BombermanOverlord.FArrayToVec(obj.pos);

                    VisualPlayer tempPlayer = tempObj.GetComponent <VisualPlayer> ();
                    tempPlayer.init(obj.color, playerColors [colorOrder[obj.color]], floatArrayToVec(obj.pos), obj.gameID);
                    players.Add(obj.color, tempPlayer);
                    currentGameObjects.Add(tempPlayer as BombermanVisualObj);
                }
            }
        }
コード例 #5
0
        public void handleBoardUpdate(NetworkMessage boardMsg)
        {
            byte[]      bytes = boardMsg.reader.ReadBytesAndSize();
            BoardUpdate msg   = Deserialize <BoardUpdate> (bytes);

            if (msg.updateID < lastUpdateID)
            {
                return;
            }

            if (msg.updateID > lastUpdateID)
            {
                lastUpdateID = msg.updateID;
                localRenderer.renderNewBoard(msg);
            }

            //print ("Update : " + msg.color);

            RealtimeTCPController.gotNewBoard(BombermanOverlord.convertColorToTeam(msg.color), BombermanBoardParser.parseBoard(msg));
        }
コード例 #6
0
 public void sendBoardUpdate(int targetID, BoardUpdate b)
 {
     sendMsg(b, targetID, (short)MsgType.boardUpdate);
 }