Ejemplo n.º 1
0
        /*
         * Handling the game initilization message
        */
        private void ParseInitializeMessage(string[] tokens)
        {
            GameManager.Instance.GameEngine.PlayerNumber = int.Parse(tokens[0].Substring(1));

            // Placing the brick walls on the map
            string[] brickWallStrings = tokens[1].Split(';');
            List<BrickWall> brickWalls = new List<BrickWall>();
            foreach (string s in brickWallStrings)
            {
                string[] location = s.Split(',');
                BrickWall b = new BrickWall(int.Parse(location[0]), int.Parse(location[1]));
                brickWalls.Add(b);
            }
            GameManager.Instance.GameEngine.BrickWalls = brickWalls;

            // Placing the stone walls on the map
            string[] stoneWallStrings = tokens[2].Split(';');
            List<StoneWall> stoneWalls = new List<StoneWall>();
            foreach (string s in stoneWallStrings)
            {
                string[] location = s.Split(',');
                StoneWall b = new StoneWall(int.Parse(location[0]), int.Parse(location[1]));
                stoneWalls.Add(b);
            }
            GameManager.Instance.GameEngine.StoneWalls = stoneWalls;

            // Placing water on the map
            string[] waterStrings = tokens[3].Split(';');
            List<Water> water = new List<Water>();
            foreach (string s in waterStrings)
            {
                string[] location = s.Split(',');
                Water b = new Water(int.Parse(location[0]), int.Parse(location[1]));
                water.Add(b);
            }
            GameManager.Instance.GameEngine.Water = water;
        }
Ejemplo n.º 2
0
        /*
         * Handling game update messages
        */
        private void ParseGameMessage(string[] tokens)
        {
            // Sending the clock for the game engine
            GameManager.Instance.GameEngine.Clock();

            // Changing the location of the players on the map
            int i = 0;
            while (i < tokens.Length - 1)
            {
                string[] playerData = tokens[i].Split(';');
                Tank tank = GameManager.Instance.GameEngine.Tanks[int.Parse(playerData[0].Substring(1))];

                if (GameManager.Instance.GameEngine.Map[tank.PositionX, tank.PositionY] is Tank)
                    GameManager.Instance.GameEngine.Map[tank.PositionX, tank.PositionY] = null;

                string[] location = playerData[1].Split(',');
                tank.PositionX = int.Parse(location[0]);
                tank.PositionY = int.Parse(location[1]);
                tank.Direction = direction[int.Parse(playerData[2])];

                if (playerData[3] == "1")
                    tank.Shoot();

                tank.Health = int.Parse(playerData[4]);
                tank.Coins = int.Parse(playerData[5]);
                tank.Points = int.Parse(playerData[6]);

                if (tank.Health > 0)
                    GameManager.Instance.GameEngine.Map[tank.PositionX, tank.PositionY] = tank;

                i++;
            }

            // Updating the bricks
            string[] brickStrings = tokens[i].Split(';');
            List<BrickWall> brickWalls = new List<BrickWall>();
            foreach (string s in brickStrings)
            {
                string[] brickData = s.Split(',');
                int brickHealth = int.Parse(brickData[2]);
                if (brickHealth < 4) {
                    BrickWall b = new BrickWall(int.Parse(brickData[0]), int.Parse(brickData[1]));
                    b.Damage = brickHealth;
                    brickWalls.Add(b);
                }
            }
            GameManager.Instance.GameEngine.BrickWalls = brickWalls;

            // Updating the game by removing the collectibles from the map if necessary
            GameManager.Instance.GameEngine.UpdateGame();

            // Calling AI for move if auto mode is on
            if (GameManager.Instance.Mode == GameMode.AUTO)
                GameManager.Instance.AI.CalculateMove();
        }