示例#1
0
        private bool IsSunk(ShipsField field)
        {
            switch (field.ShipType)
            {
            case ShipType.Ship2:
                if (field.PartsDestroyed == 2)
                {
                    return(true);
                }
                break;

            case ShipType.Ship3:
                if (field.PartsDestroyed == 3)
                {
                    return(true);
                }
                break;

            case ShipType.Ship4:
                if (field.PartsDestroyed == 4)
                {
                    return(true);
                }
                break;
            }
            return(false);
        }
示例#2
0
 private ShipsField[][] CreateBoard()
 {
     ShipsField[][] board = new ShipsField[10] [];
     for (var i = 0; i < 10; i++)
     {
         board[i] = new ShipsField[10];
         for (var j = 0; j < 10; j++)
         {
             board[i][j] = new ShipsField
             {
                 IntCoordinates  = i,
                 CharCoordinates = Convert.ToChar(j + 65)
             };
         }
     }
     return(board);
 }
示例#3
0
        private ValueTuple <string, ShipsBoard> Shoot(int intCoordinates, char charCoordinates, ShipsBoard board, ShipsGameStatus gameStatus)
        {
            int        i     = charCoordinates - 'A';
            ShipsField field = board.Board[intCoordinates - 1][i];
            string     message;

            field.TriedToShoot = true;
            var move = new Move
            {
                Field    = field,
                PlayerId = board.PlayerId
            };

            gameStatus.CurrentMove = move;
            if (field.IsShip)
            {
                field.IsShot = true;
                field.PartsDestroyed++;
                if (field.ShipType == ShipType.Ship1 || IsSunk(field))
                {
                    field.IsSunk = true;
                    message      = "Congrats! Ship sunk!";
                    board.ShipsSunk++;
                }
                else
                {
                    message = "Great! You shot this ship!";
                }
            }
            else
            {
                message = "Nothing there, try again!";
            }

            board.Board[intCoordinates - 1][i] = field;
            return(message, board);
        }