Ejemplo n.º 1
0
        /// <summary>
        /// Checks if it is possible to place the chip on this point in vertical direction.
        /// </summary>
        ///
        /// <remarks>   Christopher, 6/19/2015. </remarks>
        ///
        /// <param name="index">        Zero-based index of the. </param>
        /// <param name="shipLength">   Length of the ship. </param>
        ///
        /// <returns>   true if it succeeds, false if it fails. </returns>

        private bool FieldIsValidVertical(int index, int shipLength)
        {
            bool isValid = false;

            if (!(ships.IsSet(App.GameViewModel.WhichShip)))
            {
                if (!(App.GameViewModel.EnemyField[index]))
                {
                    if (index - 10 * (shipLength - 1) >= 0)
                    {
                        if (index % 10 == 9 && index != 99)
                        {
                            for (int i = 0; i < shipLength; i++)
                            {
                                if (index != 9)
                                {
                                    if (App.GameViewModel.EnemyField[index - 1] != true &&
                                        App.GameViewModel.EnemyField[index + 9] != true &&
                                        App.GameViewModel.EnemyField[index - 11] != true &&
                                        App.GameViewModel.EnemyField[index + 10] != true &&
                                        App.GameViewModel.EnemyField[index - 10] != true)
                                    {
                                        index  -= 10;
                                        isValid = true;
                                    }
                                    else
                                    {
                                        isValid = false;
                                        break;
                                    }
                                }
                                else
                                {
                                    if (App.GameViewModel.EnemyField[index - 1] != true &&
                                        App.GameViewModel.EnemyField[index + 9] != true &&
                                        App.GameViewModel.EnemyField[index + 10] != true)
                                    {
                                        index  -= 10;
                                        isValid = true;
                                    }
                                    else
                                    {
                                        isValid = false;
                                        break;
                                    }
                                }
                            }
                        }
                        else if (index == 99)
                        {
                            for (int i = 0; i < shipLength; i++)
                            {
                                if (App.GameViewModel.EnemyField[index - 1] != true &&
                                    App.GameViewModel.EnemyField[index - 11] != true &&
                                    App.GameViewModel.EnemyField[index - 10] != true)
                                {
                                    index  -= 10;
                                    isValid = true;
                                }
                                else
                                {
                                    isValid = false;
                                    break;
                                }
                            }
                        }
                        else if (index > 89 && index < 99)
                        {
                            for (int i = 0; i < shipLength; i++)
                            {
                                if (App.GameViewModel.EnemyField[index - 1] != true &&
                                    App.GameViewModel.EnemyField[index + 1] != true &&
                                    App.GameViewModel.EnemyField[index - 11] != true &&
                                    App.GameViewModel.EnemyField[index - 10] != true &&
                                    App.GameViewModel.EnemyField[index - 9] != true)
                                {
                                    index  -= 10;
                                    isValid = true;
                                }
                                else
                                {
                                    isValid = false;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            for (int i = 0; i < shipLength; i++)
                            {
                                if (index > 10)
                                {
                                    if (App.GameViewModel.EnemyField[index - 1] != true &&
                                        App.GameViewModel.EnemyField[index + 9] != true &&
                                        App.GameViewModel.EnemyField[index - 9] != true &&
                                        App.GameViewModel.EnemyField[index + 1] != true &&
                                        App.GameViewModel.EnemyField[index + 10] != true &&
                                        App.GameViewModel.EnemyField[index + 11] != true &&
                                        App.GameViewModel.EnemyField[index - 10] != true &&
                                        App.GameViewModel.EnemyField[index - 11] != true)
                                    {
                                        index  -= 10;
                                        isValid = true;
                                    }
                                    else
                                    {
                                        isValid = false;
                                        break;
                                    }
                                }
                                else if (index == 10)
                                {
                                    if (App.GameViewModel.EnemyField[index + 1] != true &&
                                        App.GameViewModel.EnemyField[index + 9] != true &&
                                        App.GameViewModel.EnemyField[index - 9] != true &&
                                        App.GameViewModel.EnemyField[index + 11] != true &&
                                        App.GameViewModel.EnemyField[index + 10] != true)
                                    {
                                        index  -= 10;
                                        isValid = true;
                                    }
                                    else
                                    {
                                        isValid = false;
                                        break;
                                    }
                                }
                                else
                                {
                                    if (App.GameViewModel.EnemyField[index + 1] != true &&
                                        App.GameViewModel.EnemyField[index + 9] != true &&
                                        App.GameViewModel.EnemyField[index + 10] != true)
                                    {
                                        index  -= 10;
                                        isValid = true;
                                    }
                                    else
                                    {
                                        isValid = false;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(isValid);
        }