Exemplo n.º 1
0
        void UpdateGameState(string data)
        {
            GameState gamestate = parseGameStateJson(data);

            Debug.Log(gamestate.board_size);
            Debug.Log(gamestate.board_size.ToString() + "-> this is teh board size");
            List <Vector3> powerupList = new List <Vector3>();
            List <Vector3> crackedList = new List <Vector3>();
            List <Vector3> stableList  = new List <Vector3>();
            List <Vector3> holeList    = new List <Vector3>();

            foreach (var powerup in gamestate.powerup_locations)
            {
                float   x             = (float)powerup.x;
                float   y             = (float)powerup.y;
                Vector3 powerupVector = new Vector3(x, y, 0f);
                powerupList.Add(powerupVector);
            }

            foreach (var cracked in gamestate.cracked_locations)
            {
                float   x             = (float)cracked.x;
                float   y             = (float)cracked.y;
                Vector3 powerupVector = new Vector3(x, y, 0f);
                crackedList.Add(powerupVector);
            }

            foreach (var stable in gamestate.hole_locations)
            {
                float   x          = (float)stable.x;
                float   y          = (float)stable.y;
                Vector3 holeVector = new Vector3(x, y, 0f);
                holeList.Add(holeVector);
            }

            if (is_first_initialize == 0)
            {
                is_first_initialize = 1;
                Debug.Log(gamestate.board_size);
                CreateBoard((int)gamestate.board_size);
                InitialiseObjects(gamestate.player_list, crackedList, powerupList, holeList);
            }
            else
            {
                boardScript.InstantiateWalls(crackedList);
                boardScript.InstantiatePowerups(powerupList);
                boardScript.InstantiateHoles(holeList);

                // move and do gamestate stuff
                foreach (var player in players)
                {
                    player.UpdatePlayerState(gamestate.player_list);
                }
            }
        }