コード例 #1
0
ファイル: Game.cs プロジェクト: lumyslinski/battleships
        public ShootResponse Shoot(string target)
        {
            var response = new ShootResponse();
            var position = new ShipPosition(target);

            if (position.Row != GridRows.Undefined && position.Column != -1)
            {
                response = ShootAtPosition(position);
            }
            else
            {
                response.SetError("Can not get target. Try again!");
            }
            return(response);
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: lumyslinski/battleships
        public ShootResponse ShootAtPosition(ShipPosition position)
        {
            var response = new ShootResponse();
            var place    = this.GridManager.GetPlace(position);

            place.ShootShip();
            if (place.State == GridStates.Hit)
            {
                if (place.Ship.IsSunk)
                {
                    response.SetStatus(place.State, string.Format("{0}, ship is {1} and is sinking now!", place.State, place.Ship.Name));
                }
                else
                {
                    response.SetStatus(place.State, string.Format("{0}, ship is {1}", place.State, place.Ship.Name));
                }
            }
            else
            {
                response.SetStatus(place.State);
            }
            return(response);
        }