コード例 #1
0
    /// <summary>
    /// Shoot at a given row/column
    /// </summary>
    /// <param name="row">the row to attack</param>
    /// <param name="col">the column to attack</param>
    /// <returns>the result of the attack</returns>
    internal AttackResult Shoot(int row, int col)
    {
        AttackResult result = default(AttackResult);

        result = EnemyGrid.HitTile(row, col);

        switch (result.Value)
        {
        case ResultOfAttack.Destroyed:
            _shots++;
            _hits++;
            break;

        case ResultOfAttack.ShotAlready:
            break;

        case ResultOfAttack.Hit:
            _hits++;
            _shots++;
            break;

        case ResultOfAttack.Miss:
            _misses++;
            _shots++;
            break;
        }

        return(result);
    }
コード例 #2
0
ファイル: Player.cs プロジェクト: obadiah0313/Battleship
    /// <summary>
    /// Shoot at a given row/column
    /// </summary>
    /// <param name="row">the row to attack</param>
    /// <param name="col">the column to attack</param>
    /// <returns>the result of the attack</returns>
    internal AttackResult Shoot(int row, int col)
    {
        _shots += 1;
        AttackResult result = default(AttackResult);

        result = EnemyGrid.HitTile(row, col);

        switch (result.Value)
        {
        case ResultOfAttack.Destroyed:
        case ResultOfAttack.Hit:
            _hits += 1;
            if (GameController.ComputerPlayer.ToString().Equals("AIMediumPlayer"))
            {
                Available = 10;
            }
            else if (GameController.ComputerPlayer.ToString().Equals("AIHardPlayer"))
            {
                Available = 5;
            }
            break;

        case ResultOfAttack.Miss:
            _misses += 1;
            _avail  -= 1;
            break;
        }
        return(result);
    }
コード例 #3
0
ファイル: Player.cs プロジェクト: gianni35011/Battleship
        /// <summary>
        /// Shoot at a given row/column
        /// </summary>
        /// <param name="row">the row to attack</param>
        /// <param name="col">the column to attack</param>
        /// <returns>the result of the attack</returns>
        internal AttackResult Shoot(int row, int col)
        {
            _shots += 1;
            AttackResult result;

            result = EnemyGrid.HitTile(row, col);

            switch (result.Value)
            {
            case ResultOfAttack.Destroyed:
            case ResultOfAttack.Hit:
            {
                _hits += 1;
                break;
            }

            case ResultOfAttack.Miss:
            {
                _misses += 1;
                break;
            }
            }

            return(result);
        }
コード例 #4
0
    /// <summary>
    /// Shoot at a given row/column
    /// </summary>
    /// <param name="row">the row to attack</param>
    /// <param name="col">the column to attack</param>
    /// <returns>the result of the attack</returns>
    internal AttackResult Shoot(int row, int col)
    {
        //_shots += 1;
        // SV: bug fix 26 - if player has already shot a spot, they cannot shoot at it again

        AttackResult result = default(AttackResult);

        result = EnemyGrid.HitTile(row, col);

        // SV: bug fix 26 - moved _shots+=1 to be conditional + not count ShotAlready
        if (result.Value != ResultOfAttack.ShotAlready)
        {
            _shots += 1;
        }

        switch (result.Value)
        {
        case ResultOfAttack.Destroyed:
        case ResultOfAttack.Hit:
            _hits += 1;
            break;

        case ResultOfAttack.Miss:
            _misses += 1;
            break;
        }

        return(result);
    }
コード例 #5
0
ファイル: Player.cs プロジェクト: PanMaster13/Battleship
    /// <summary>
    /// Shoot at a given row/column
    /// </summary>
    /// <param name="row">the row to attack</param>
    /// <param name="col">the column to attack</param>
    /// <returns>the result of the attack</returns>
    internal AttackResult Shoot(int row, int col)
    {
        _shots++;
        AttackResult result = default(AttackResult);

        result = EnemyGrid.HitTile(row, col);

        if ((result.Value == ResultOfAttack.Destroyed) || (result.Value == ResultOfAttack.Hit))
        {
            _hits++;
        }
        else if (result.Value == ResultOfAttack.Miss)
        {
            _misses++;
        }

        return(result);
    }
コード例 #6
0
ファイル: Player.cs プロジェクト: mrzeals/BattleShip
    /// <summary>
    /// Shoot at a given row/column
    /// </summary>
    /// <param name="row">the row to attack</param>
    /// <param name="col">the column to attack</param>
    /// <returns>the result of the attack</returns>
    internal AttackResult Shoot(int row, int col)
    {
        AttackResult result = EnemyGrid.HitTile(row, col);

        //fixed by Voon.
        switch (result.Value)
        {
        case ResultOfAttack.Destroyed:
        case ResultOfAttack.Hit:
            _shots += 1;
            _hits  += 1;
            break;

        case ResultOfAttack.Miss:
            _shots  += 1;
            _misses += 1;
            break;
        }

        return(result);
    }
コード例 #7
0
ファイル: Player.cs プロジェクト: ChinSinclair/Battleship
    /// <summary>
    /// Shoot at a given row/column
    /// </summary>
    /// <param name="row">the row to attack</param>
    /// <param name="col">the column to attack</param>
    /// <returns>the result of the attack</returns>
    internal AttackResult Shoot(int row, int col)
    {
        _shots += 1;
        AttackResult result = default(AttackResult);

        result = EnemyGrid.HitTile(row, col);

        switch (result.Value)
        {
        case ResultOfAttack.Destroyed:
        case ResultOfAttack.Hit:
            _hits += 1;
            break;

        case ResultOfAttack.Miss:
            _misses += 1;
            break;
        }

        if (_playerGrid.ShipsKilled > 1)
        {
            if (win == 0)
            {
                SwinGame.StopMusic();
                SwinGame.PlayMusic(GameResources.GameMusic("deadlock"));
            }
            win++;
        }
        if (_playerGrid.ShipsKilled > 3)
        {
            if (winning == 0)
            {
                SwinGame.StopMusic();
                SwinGame.PlayMusic(GameResources.GameMusic("final"));
            }
            winning++;
        }

        return(result);
    }
コード例 #8
0
ファイル: Player.cs プロジェクト: Penta305/Battleships
    // Shoot at a given row/column
    public AttackResult Shoot(int row, int col)
    {
        _shots += 0;
        AttackResult result = default(AttackResult);

        result = EnemyGrid.HitTile(row, col);

        switch (result.Value)
        {
        case ResultOfAttack.Destroyed:
        case ResultOfAttack.Hit:
            _hits  += 1;
            _shots += 1;
            break;

        case ResultOfAttack.Miss:
            _misses += 1;
            _shots  += 1;
            break;
        }

        return(result);
    }
コード例 #9
0
    /// <summary>
    /// Shoot at a given row/column
    /// </summary>
    /// <param name="row">the row to attack</param>
    /// <param name="col">the column to attack</param>
    /// <returns>the result of the attack</returns>
    internal AttackResult Shoot(int row, int col)
    {
        if (!_playerGrid._GameTiles[row, col].Shot)
        {
            _shots += 1;
        }
        AttackResult result = default(AttackResult);

        result = EnemyGrid.HitTile(row, col);

        switch (result.Value)
        {
        case ResultOfAttack.Destroyed:
        case ResultOfAttack.Hit:
            _hits += 1;
            break;

        case ResultOfAttack.Miss:
            _misses += 1;
            break;
        }

        return(result);
    }
コード例 #10
0
        /// <summary>
        /// Shoot at a given row/column
        /// </summary>
        /// <param name="row">the row to attack</param>
        /// <param name="col">the column to attack</param>
        /// <returns>the result of the attack</returns>
        internal AttackResult Shoot(int row, int col)
        {
            AttackResult result = default(AttackResult);

            result = EnemyGrid.HitTile(row, col);
            if (result.Value.Equals(ResultOfAttack.ShotAlready) == false)
            {
                _shots += 1;
            }

            switch (result.Value)
            {
            case ResultOfAttack.Destroyed:
            case ResultOfAttack.Hit:
                _hits += 1;
                break;

            case ResultOfAttack.Miss:
                _misses += 1;
                break;
            }

            return(result);
        }
コード例 #11
0
ファイル: Player.cs プロジェクト: YichenGuan6/BattleShip
    /// <summary>
    /// Shoot at a given row/column
    /// </summary>
    /// <param name="row">the row to attack</param>
    /// <param name="col">the column to attack</param>
    /// <returns>the result of the attack</returns>
    internal AttackResult Shoot(int row, int col)
    {
        _shots += 1;
        if (_Random.Next(0, 10) == 7)
        {
            List <AttackResult> results = new List <AttackResult> ();
            results.Add(EnemyGrid.HitTile(row, col));
            if (row == 0 && col == 0)
            {
                results.Add(EnemyGrid.HitTile(row + 1, col));
                results.Add(EnemyGrid.HitTile(row, col + 1));
                results.Add(EnemyGrid.HitTile(row + 1, col + 1));
            }
            else if (row == 0 && col == PlayerGrid.Width - 1)
            {
                results.Add(EnemyGrid.HitTile(row + 1, col));
                results.Add(EnemyGrid.HitTile(row, col - 1));
                results.Add(EnemyGrid.HitTile(row + 1, col - 1));
            }
            else if (row == PlayerGrid.Height - 1 && col == 0)
            {
                results.Add(EnemyGrid.HitTile(row - 1, col));
                results.Add(EnemyGrid.HitTile(row, col + 1));
                results.Add(EnemyGrid.HitTile(row - 1, col + 1));
            }
            else if (row == PlayerGrid.Height - 1 && col == PlayerGrid.Width - 1)
            {
                results.Add(EnemyGrid.HitTile(row - 1, col));
                results.Add(EnemyGrid.HitTile(row, col - 1));
                results.Add(EnemyGrid.HitTile(row - 1, col - 1));
            }
            else
            {
                results.Add(EnemyGrid.HitTile(row + 1, col));
                results.Add(EnemyGrid.HitTile(row - 1, col));
                results.Add(EnemyGrid.HitTile(row, col + 1));
                results.Add(EnemyGrid.HitTile(row, col - 1));
                results.Add(EnemyGrid.HitTile(row + 1, col + 1));
                results.Add(EnemyGrid.HitTile(row - 1, col - 1));
                results.Add(EnemyGrid.HitTile(row + 1, col - 1));
                results.Add(EnemyGrid.HitTile(row - 1, col + 1));
            }
            AttackResult resultReturn = null;
            foreach (AttackResult listResult in results)
            {
                if (listResult.Value == ResultOfAttack.Destroyed || listResult.Value == ResultOfAttack.Hit)
                {
                    resultReturn = listResult;
                    _hits       += 1;
                }
                else if (listResult.Value == ResultOfAttack.Miss)
                {
                    _misses += 1;
                }
            }
            return(resultReturn ?? results [0]);
        }
        AttackResult result = default(AttackResult);

        result = EnemyGrid.HitTile(row, col);

        switch (result.Value)
        {
        case ResultOfAttack.Destroyed:
        case ResultOfAttack.Hit:
            _hits += 1;
            break;

        case ResultOfAttack.Miss:
            _misses += 1;
            break;
        }

        return(result);
    }