Exemplo n.º 1
0
        internal ShotFeedback FireShot(Player whosTurn, Shot playerShot)
        {
            List<Placement> targetFleet = _playerShips[whosTurn == Player.One ? Player.Two : Player.One];
            Vessel ship;
            int start, end, shot, segment;
            int hits = 0;
            int sunkShips = 0;

            foreach (Placement shipPlacement in targetFleet)
            {
                ship = (Vessel)shipPlacement.Vessel;

                if (shipPlacement.Orientation == Orientation.Horizontal && shipPlacement.Y == playerShot.Y)
                {
                    start = shipPlacement.X;
                    end = shipPlacement.X + (ship.Length - 1);
                    shot = playerShot.X;
                }
                else if (shipPlacement.Orientation == Orientation.Vertical && shipPlacement.X == playerShot.X)
                {
                    start = shipPlacement.Y - (ship.Length - 1);  // TODO: This should be taken care of.
                    end = shipPlacement.Y;
                    shot = playerShot.Y;
                }
                else
                    continue;

                segment = shot - start;

                if (segment < ship.Length && segment >= 0)
                {
                    ship.Hit(segment);
                    hits++;

                    if (ship.IsSunk)
                        sunkShips++;
                }

            }

            return new ShotFeedback(hits, sunkShips);
        }
Exemplo n.º 2
0
        public Shot YourTurn(IPlayerView playerView)
        {
            int xMax = playerView.GetXMax();
            int yMax = playerView.GetYMax();

            Shot fireZeMissles = new Shot(_nextShot.X, _nextShot.Y);

            _nextShot.X++;

            if (_nextShot.X > xMax)
            {
                _nextShot.Y++;
                _nextShot.X = 1;
            }

            if (_nextShot.Y > yMax)
                _nextShot.Y = 1;

            return fireZeMissles;
        }
Exemplo n.º 3
0
        internal void StartMission(Shot _lastShot)
        {
            _missionTarget = new Coordinate(_lastShot);
              _targetHits.Add(_missionTarget);
              _phase = MissionPhase.DetermineTargetOrientation;

              _eliminatedCoords.AddRange(_mothership.EliminatedCoords.Where(c => c.X == _missionTarget.X || c.Y == _missionTarget.Y));

              ProcessIntel();
        }
Exemplo n.º 4
0
        public Shot YourTurn(IPlayerView playerView)
        {
            _turn++;

            #if DEBUG
              if ((_turn % 20) == 0 && _turn < 150)
              {
            Console.WriteLine("Eliminated squares:");
            Visualizer.ConsolePrintField(_xMax, _yMax, _eliminatedCoords);
            Console.WriteLine("Ships hit:");
            Visualizer.ConsolePrintField(_xMax, _yMax, _hitRecord);
            Console.WriteLine("Firing Solution:");
            Visualizer.ConsolePrintField(_xMax, _yMax, _firingPattern);
            Console.ReadKey(true);
              }
            #endif
              Coordinate firingSolution;

              if (IsDroneDeployed)
              {
            firingSolution = _attackDrone.ContinueMission();
              }
              else
              {
            firingSolution = PickRandomFiringSolution();

            // FIXME
            if (firingSolution == null)
              firingSolution = new Coordinate(1, 1);

            _firingPattern.Remove(firingSolution);
            _eliminatedCoords.Add(firingSolution);
              }

              Shot bang = new Shot(firingSolution.X, firingSolution.Y);

              _lastShot = bang;

              return bang;
        }