Exemple #1
0
 //update the brick damage
 public void UpdateBricks(int numberOfBricks, System.Drawing.Point[] brickPositions, BrickDamageLevel[] currentBrickDamageLevel)
 {
     for(int i=0;i<numberOfBricks;i++)
     {
         int tmpX=brickPositions[i].X;
         int tmpY=brickPositions[i].Y;
         if(grid[tmpX,tmpY] is CellBrick)
         {
             ((CellBrick)(grid[tmpX, tmpY])).DamageLevel = currentBrickDamageLevel[i];
         }
     }
 }
Exemple #2
0
        // Event when global update was recived
        private void messageDecoder_GameUpdateReceived(int numberOfPlayers, int[] playerNumbers, System.Drawing.Point[] playerCurrentPositions, Direction[] playerCurrentDirections, bool[] playerIsShooted, int[] playerCurrentHealth, int[] playerCurrentCoins, int[] playerCurrentPoints, int numberOfBricks, System.Drawing.Point[] brickPositions, BrickDamageLevel[] currentBrickDamageLevel)
        {
            playerManager.UpdatePlayers(numberOfPlayers, playerNumbers, playerCurrentPositions, playerCurrentDirections, playerIsShooted, playerCurrentHealth, playerCurrentCoins, playerCurrentPoints);
            gridManager.UpdateBricks(numberOfBricks, brickPositions, currentBrickDamageLevel);

            // Low accuracy collisions
            collisionManager.CheckEventCollisions(gridManager, playerManager, itemManager);

            if (!isGameStarted)
                isGameStarted = true;
            communicator.SendData(aiManager.getNextCommand(gridManager, playerManager, itemManager));
        }
        private void DecodeGameUpdate(string message)
        {
            
            string[] content = message.Split(new char[] { ':', '#' });
            int numberOfplayers = content.Length - 3;

            //Decoding player updates
            int[]  playerNumbers=new int[numberOfplayers];
            Point[] playerCurrentPositions = new Point[numberOfplayers];
            Direction[] playerCurrentDirections = new Direction[numberOfplayers];
            bool [] playerShooted = new bool[numberOfplayers];            
            int [] playerCurrentHealth = new int[numberOfplayers];
            int [] playerCurrentCoins = new int[numberOfplayers];
            int [] playerCurrentPoints = new int[numberOfplayers];

            for (int i = 0; i < numberOfplayers; i++)
            {
                string[] currentPlayerData=content[i+1].Split(';');
                playerNumbers[i] = Convert.ToInt32(currentPlayerData[0][1].ToString());
                playerCurrentPositions[i] = CoordinateToPoint(currentPlayerData[1]);
                playerCurrentDirections[i] = (Direction) Convert.ToByte(currentPlayerData[2]);
                playerShooted[i] = Convert.ToBoolean(Convert.ToInt32(currentPlayerData[3]));
                playerCurrentHealth[i] = Convert.ToInt32(currentPlayerData[4]);
                playerCurrentCoins[i] = Convert.ToInt32(currentPlayerData[5]);
                playerCurrentPoints[i] = Convert.ToInt32(currentPlayerData[6]);
            }

            //Decoding brick updates
            string[] brickUpdates = content[numberOfplayers+1].Split(';');

            int numberOfBricks = brickUpdates.Length;
            Point[] brickPositions = new Point[numberOfBricks];
            BrickDamageLevel[] currentBrickDamageLevel = new BrickDamageLevel[numberOfBricks];
            for (int i = 0; i < numberOfBricks; i++)
            {
                string[] currentBrickData = brickUpdates[i].Split(',');
                string brickCoordinate = currentBrickData[0] +"," + currentBrickData[1];
                brickPositions[i] = CoordinateToPoint(brickCoordinate);
                currentBrickDamageLevel[i] = (BrickDamageLevel)Convert.ToByte(currentBrickData[2]);
            }

            GameUpdateReceived(numberOfplayers, playerNumbers, playerCurrentPositions, playerCurrentDirections, playerShooted, playerCurrentHealth, playerCurrentCoins, playerCurrentPoints, numberOfBricks, brickPositions, currentBrickDamageLevel);

        }