Esempio n. 1
0
        public ShotResult ShootAtOpponent(Guid shooterPlayerId, GridCoordinate coordinate)
        {
            if (this.IsStarted == true)
            {
                IPlayer shooter = this.GetPlayerById(shooterPlayerId);
                IPlayer victim  = this.GetOpponent(shooter);

                if (shooter.HasBombsLoaded)
                {
                    ShotResult result = shooter.ShootAt(victim, coordinate);
                    if (victim is ComputerPlayer)
                    {
                        ((ComputerPlayer)victim).ShootAutomatically(shooter);
                    }
                    return(result);
                }
                else
                {
                    return(ShotResult.CreateMisfire("Player has no bombs loaded"));
                }
            }
            else
            {
                return(ShotResult.CreateMisfire("Game has not begun"));
            }
        }
Esempio n. 2
0
        public ShotResult ShootAtOpponent(Guid shooterPlayerId, GridCoordinate coordinate)
        {
            /* Check if the game is started */
            if (this.IsStarted == true)
            {
                /* Get the player */
                IPlayer player = GetPlayerById(shooterPlayerId);

                if (player == null)
                {
                    /* No bombs loaded */
                    return(ShotResult.CreateMisfire("Player unknown"));
                }

                if (player.HasBombsLoaded == false)
                {
                    /* No bombs loaded */
                    return(ShotResult.CreateMisfire("No bombs loaded"));
                }

                /* Get opponent */
                IPlayer opponent = GetOpponent(player);

                /* Shoot at the opponent */
                ShotResult result = player.ShootAt(opponent, coordinate);

                /* Reload bombs of opponent */
                opponent.ReloadBombs();

                /* Check if opponent is computer */
                if (opponent is ComputerPlayer)
                {
                    /* Upcast IPlayer to ComputerPlayer */
                    ComputerPlayer computer = (ComputerPlayer)opponent;

                    /* Let the computer */
                    computer.ShootAutomatically(player);

                    /* Reload bombs of player in case of computer */
                    player.ReloadBombs();
                }
                return(result);
            }
            else
            {
                return(ShotResult.CreateMisfire("game not started"));
            }
        }
Esempio n. 3
0
        public ShotResult ShootAt(IPlayer opponent, GridCoordinate coordinate)
        {
            if (HasBombsLoaded == true)
            {
                this._HasBombsLoaded = false;
                IGridSquare square = opponent.Grid.Shoot(coordinate);
                opponent.ReloadBombs();

                if (square.Status == GridSquareStatus.Hit)
                {
                    return(ShotResult.CreateHit(opponent.Fleet.FindShipAtCoordinate(coordinate), this.settings.MustReportSunkenShip));
                }
                if (square.Status == GridSquareStatus.Miss)
                {
                    return(ShotResult.CreateMissed());
                }
                return(ShotResult.CreateMissed());
            }
            else
            {
                return(ShotResult.CreateMisfire("You have no bombs loaded"));
            }
        }
        public ShotResult ShootAt(IPlayer opponent, GridCoordinate coordinate)
        {
            /* Get the grid of the opponent & shoot */
            IGridSquare square = opponent.Grid.Shoot(coordinate);

            /* Bomb has been shot */
            this.nrOfBombsLoaded = 0;

            /* The grid square informas about the result of the shot */
            if (square.Status == GridSquareStatus.Hit)
            {
                /* Ship hit */
                return(ShotResult.CreateHit(opponent.Fleet.FindShipAtCoordinate(coordinate), mustReportSunkenShip));
            }
            else if (square.Status == GridSquareStatus.Miss)
            {
                /* Missed */
                return(ShotResult.CreateMissed());
            }
            else
            {
                return(ShotResult.CreateMisfire("out of bound"));
            }
        }