Пример #1
0
        }//end method Place

        public void Attack(CPUPlayer defender, int M, int N)
        {
            hitIndicator = false;
            if (defender.GridArray[M, N] == EMPTY)
            {
                defender.GridArray[M, N] = MISS;

                //output miss message here & change return type as necessary
            }//end if
            else
            {
                switch (defender.GridArray[M, N])
                {
                case EMPTY: defender.GridArray[M, N] = MISS;
                    //output miss message here & change return type as necessary
                    break;

                case PTBOAT: defender.GridArray[M, N] = HIT;
                    defender.ptboat.GetsHit();
                    hitIndicator = true;
                    if (defender.ptboat.IsSunk == true)
                    {
                        defender.NumberOfShips--;
                    }        //end if
                    break;

                case CRUISER: defender.GridArray[M, N] = HIT;
                    defender.cruiser.GetsHit();
                    hitIndicator = true;
                    if (defender.cruiser.IsSunk == true)
                    {
                        defender.NumberOfShips--;
                    }        //end if
                    break;

                case SUBMARINE: defender.GridArray[M, N] = HIT;
                    defender.submarine.GetsHit();
                    hitIndicator = true;
                    if (defender.submarine.IsSunk == true)
                    {
                        defender.NumberOfShips--;
                    }        //end if
                    break;

                case BATTLESHIP: defender.GridArray[M, N] = HIT;
                    defender.battleship.GetsHit();
                    hitIndicator = true;
                    if (defender.battleship.IsSunk == true)
                    {
                        defender.NumberOfShips--;
                    }        //end if
                    break;

                case CARRIER: defender.GridArray[M, N] = HIT;
                    defender.carrier.GetsHit();
                    hitIndicator = true;
                    if (defender.carrier.IsSunk == true)
                    {
                        defender.NumberOfShips--;
                    }        //end if
                    break;

                default:
                    break;
                } //end switch
            }     //end else
        }
Пример #2
0
 //Constructor
 public Game()
 {
     Human = new HumanPlayer();
     Cpu   = new CPUPlayer();
 }//end constructor