Example #1
0
 public void Attacked(string data)
 {
     _localPlayer.CanAttack = true;
     _view.SetGameStatus("You can attack!");
     _currentAttackPoint = new MatrixCoordinate(int.Parse(data[1].ToString()), int.Parse(data[2].ToString()));
     if (_localPlayer.PlaneMatrix[_currentAttackPoint.Row, _currentAttackPoint.Column] == 0)
     {
         _network.SendData(DataType.AttackResponse, "m" + _currentAttackPoint);
         _playerPanelEngine.UpdateTile(_currentAttackPoint.Row, _currentAttackPoint.Column, Color.Cyan);
         _localPlayer.PlaneMatrix[_currentAttackPoint.Row, _currentAttackPoint.Column] = 4; // 4 - plane miss
         return;
     }
     _localPlayer.PlanesList.ForEach(plane =>
     {
         if (PlaneContains(_currentAttackPoint, plane))
         {
             var killPointToFind = GetKillPoint(plane);
             if (killPointToFind != null)
             {
                 _network.SendData(DataType.AttackResponse, "h" + _currentAttackPoint);
                 _playerPanelEngine.UpdateTile(_currentAttackPoint.Row, _currentAttackPoint.Column, Color.Red);
                 plane.KillPoints.Remove(killPointToFind);
                 if (plane.KillPoints.Count == 0)
                 {
                     _localPlayer.PlanesAlive--;
                     _network.SendData(DataType.AttackResponse,
                         "d" + plane.Orientation[0] + plane.PlaneStartPosition);
                     BuildDestroyedPlane(plane, true);
                 }
             }
             else
             {
                 _network.SendData(DataType.AttackResponse, "h" + _currentAttackPoint);
                 _playerPanelEngine.UpdateTile(_currentAttackPoint.Row, _currentAttackPoint.Column, Color.Red);
             }
             _localPlayer.PlaneMatrix[_currentAttackPoint.Row, _currentAttackPoint.Column] = 3; // 3 - hit plane
         }
     });
     CheckGameEnd();
 }
Example #2
0
 public void UpdateTile(MouseEventArgs args)
 {
     _view.StopTimer();
     for (var i = 0; i < _engine.TilesNumberOfRows; i++)
     {
         for (var j = 0; j < _engine.TilesNumberOfCollumns; j++)
         {
             if (!_engine.Tiles[i, j].Rectangle.Contains(args.Location)) continue;
             var matrixCoordinate = new MatrixCoordinate(i, j);
             switch (args.Button)
             {
                 case MouseButtons.Left:
                     if (Plane.PlaneMatrix[i, j] == 1)
                     {
                         _engine.UpdateTile(i, j, Color.Red);
                         Plane.PlaneMatrix[i, j] = 2;
                         Plane.KillPoints.Add(matrixCoordinate);
                         return;
                     }
                     break;
                 case MouseButtons.Right:
                     if (Plane.PlaneMatrix[i, j] == 2)
                     {
                         _engine.UpdateTile(i, j, Color.Blue);
                         Plane.PlaneMatrix[i, j] = 1;
                         Plane.KillPoints.Remove(
                             Plane.KillPoints.Find(
                                 points =>
                                     matrixCoordinate.Column == points.Column &&
                                     matrixCoordinate.Row == points.Row));
                         return;
                     }
                     break;
             }
         }
     }
 }
Example #3
0
 private Plane GetPlaneRotation(MatrixCoordinate tileLocation)
 {
     var plane = new Plane
     {
         PlaneMatrix = _planeTemplate.PlaneMatrix,
         KillPoints = _planeTemplate.KillPoints.ToList()
     };
     var planeRotator = new PlaneRotator();
     switch (_planeOrientation)
     {
         case "up":
             if (tileLocation.Row <= 6 && tileLocation.Column >= 1 && tileLocation.Column <= 8)
             {
                 tileLocation.Column -= 1;
                 BuildPlane(tileLocation, plane);
             }
             break;
         case "down":
             if (tileLocation.Row >= 3 && tileLocation.Column >= 1 && tileLocation.Column <= 8)
             {
                 tileLocation.Column -= 1;
                 tileLocation.Row -= 3;
                 planeRotator.SetPlaneDown(plane);
                 BuildPlane(tileLocation, plane);
             }
             break;
         case "right":
             if (tileLocation.Column >= 3 && tileLocation.Row >= 1 && tileLocation.Row <= 8)
             {
                 tileLocation.Column -= 3;
                 tileLocation.Row -= 1;
                 planeRotator.SetPlaneRight(plane);
                 BuildPlane(tileLocation, plane);
             }
             break;
         case "left":
             if (tileLocation.Column <= 6 && tileLocation.Row >= 1 && tileLocation.Row <= 8)
             {
                 tileLocation.Row -= 1;
                 planeRotator.SetPlaneLeft(plane);
                 BuildPlane(tileLocation, plane);
             }
             break;
     }
     return plane;
 }
Example #4
0
 private bool CheckPlaneDuplicates(MatrixCoordinate matrixCoordinate, Plane plane)
 {
     var row = 0;
     for (var i = matrixCoordinate.Row; i < matrixCoordinate.Row + plane.NumberOfRows; i++, row++)
     {
         var column = 0;
         for (var j = matrixCoordinate.Column;
             j < matrixCoordinate.Column + plane.NumberOfColumns;
             j++, column++)
         {
             if (_localPlayer.PlaneMatrix[i, j] == 0 ||
                 plane.PlaneMatrix[row, column] != 1 && plane.PlaneMatrix[row, column] != 2) continue;
             MessageBox.Show(@"Planes intersecting, retry!");
             return true;
         }
     }
     return false;
 }
Example #5
0
 private void BuildPlane(MatrixCoordinate matrixCoordinate, Plane plane)
 {
     if (CheckPlaneDuplicates(matrixCoordinate, plane)) return;
     _localPlayer.PlanesAlive++;
     _localPlayer.PlanesList.Add(plane);
     var row = 0;
     for (var i = matrixCoordinate.Row; i < matrixCoordinate.Row + plane.NumberOfRows; i++, row++)
     {
         var column = 0;
         for (var j = matrixCoordinate.Column;
             j < matrixCoordinate.Column + plane.NumberOfColumns;
             j++, column++)
         {
             if (plane.PlaneMatrix[row, column] == 0) continue;
             _playerPanelEngine.UpdateTile(i, j, Color.Blue);
             _localPlayer.PlaneMatrix[i, j] = plane.PlaneMatrix[row, column];
         }
     }
 }
Example #6
0
        private void BuildOponentPlane(MatrixCoordinate startCoordinate, string direction)
        {
            var plane = new Plane();
            var planeRotator = new PlaneRotator();
            switch (direction)
            {
                case "up":

                    break;
                case "down":
                    planeRotator.SetPlaneDown(plane);
                    break;
                case "right":
                    planeRotator.SetPlaneRight(plane);
                    break;
                case "left":
                    planeRotator.SetPlaneLeft(plane);
                    break;
            }
            plane.PlaneStartPosition = startCoordinate;
            BuildDestroyedPlane(plane, false);
        }
Example #7
0
 private static bool PlaneContains(MatrixCoordinate hitpoint, Plane plane)
 {
     return hitpoint.Row >= plane.PlaneStartPosition.Row &&
            hitpoint.Row <= plane.PlaneStartPosition.Row + plane.NumberOfRows &&
            hitpoint.Column >= plane.PlaneStartPosition.Column &&
            hitpoint.Column <= plane.PlaneStartPosition.Column + plane.NumberOfColumns;
 }
Example #8
0
 public void AttackResponse(string data)
 {
     if (data[1] == 'h')
     {
         var matrixCoordonate = new MatrixCoordinate(int.Parse(data[2].ToString()), int.Parse(data[3].ToString()));
         _oponentPanelEngine.UpdateTile(matrixCoordonate.Row, matrixCoordonate.Column, Color.Red);
         _localPlayer.OponentPlaneMatrix[matrixCoordonate.Row, matrixCoordonate.Column] = 3; // 3 - hit
     }
     if (data[1] == 'm')
     {
         var matrixCoordonate = new MatrixCoordinate(int.Parse(data[2].ToString()), int.Parse(data[3].ToString()));
         _oponentPanelEngine.UpdateTile(matrixCoordonate.Row, matrixCoordonate.Column, Color.Cyan);
         _localPlayer.OponentPlaneMatrix[matrixCoordonate.Row, matrixCoordonate.Column] = 4; // 3 - miss
     }
     if (data[1] == 'd')
     {
         _oponent.PlanesAlive--;
         var matrixCoordonate = new MatrixCoordinate(int.Parse(data[3].ToString()), int.Parse(data[4].ToString()));
         if (data[2] == 'u')
             BuildOponentPlane(matrixCoordonate, "up");
         if (data[2] == 'd')
             BuildOponentPlane(matrixCoordonate, "down");
         if (data[2] == 'l')
             BuildOponentPlane(matrixCoordonate, "left");
         if (data[2] == 'r')
             BuildOponentPlane(matrixCoordonate, "right");
     }
     CheckGameEnd();
 }