Пример #1
0
 /// <summary>
 /// Play Move by Computer
 /// </summary>
 /// <returns>GameMove</returns>
 public GameMove PlayMove()
 {
     LastMove = new GameMove();
     if (Player.ToLowerInvariant() == COMPUTER.ToLowerInvariant())
     {
         var randomCell = RandomiseCellForComputerToPlay();
         LastMove = PlayMove(randomCell.DisplayName);
         LastMove.TimeMovePlayed = DateTime.UtcNow;
         System.Threading.Thread.Sleep(500);
     }
     return(LastMove);
 }
Пример #2
0
        /// <summary>
        /// Player Move
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public GameMove PlayMove(string input)
        {
            LastMove        = new GameMove();
            LastMove.Player = Player;
            LastMove.Move   = input;
            var cellToPlay = (from c in Board.Cells
                              where c.Key.ToLowerInvariant() == input.ToLowerInvariant()
                              select c).FirstOrDefault();

            if (cellToPlay.Value == null) //cannot find cell on board
            {
                LastMove.Message = "Invalid Move";
                LastMove.Status  = MoveStatus.Invalid;
            }
            else
            {
                if (cellToPlay.Value.IsSea || cellToPlay.Value.IsHit)
                {
                    LastMove.Status  = MoveStatus.HasAlreadyBeenPlayed;
                    LastMove.Message = "This Move has been alreay played....";
                }
                else if (cellToPlay.Value.HasShip)
                {
                    cellToPlay.Value.IsHit = true;
                    LastMove.Status        = MoveStatus.Success;
                    LastMove.Message       = "You hit a ship!";

                    bool hasSunkAShip = CheckIfPlayerHasSunkAShip(input);
                    if (hasSunkAShip)
                    {
                        LastMove.Message += ", Also You have sunk it!!!!!!";
                    }
                }
                else
                {
                    cellToPlay.Value.IsSea = true;
                    LastMove.Status        = MoveStatus.Failure;
                    LastMove.Message       = "You hit Sea! Better luck next time";
                }
            }
            LastMove.TimeMovePlayed = DateTime.UtcNow;
            return(LastMove);
        }
Пример #3
0
        /// <summary>
        /// Player Move
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public GameMove PlayMove(string input)
        {
            LastMove = new GameMove();
            LastMove.Player = Player;
            LastMove.Move = input;
            var cellToPlay = (from c in Board.Cells
                              where c.Key.ToLowerInvariant() == input.ToLowerInvariant()
                              select c).FirstOrDefault();

            if (cellToPlay.Value == null) //cannot find cell on board
            {
                LastMove.Message = "Invalid Move";
                LastMove.Status = MoveStatus.Invalid;
            }
            else
            {
                if (cellToPlay.Value.IsSea || cellToPlay.Value.IsHit)
                {
                    LastMove.Status = MoveStatus.HasAlreadyBeenPlayed;
                    LastMove.Message = "This Move has been alreay played....";

                }
                else if (cellToPlay.Value.HasShip)
                {
                    cellToPlay.Value.IsHit = true;
                    LastMove.Status = MoveStatus.Success;
                    LastMove.Message = "You hit a ship!";

                    bool hasSunkAShip = CheckIfPlayerHasSunkAShip(input);
                    if (hasSunkAShip)
                    {
                        LastMove.Message += ", Also You have sunk it!!!!!!";
                    }
                }
                else
                {
                    cellToPlay.Value.IsSea = true;
                    LastMove.Status = MoveStatus.Failure;
                    LastMove.Message = "You hit Sea! Better luck next time";
                }
            }
            LastMove.TimeMovePlayed = DateTime.UtcNow;
            return LastMove;
        }
Пример #4
0
 /// <summary>
 /// Play Move by Computer
 /// </summary>
 /// <returns>GameMove</returns>
 public GameMove PlayMove()
 {
     LastMove = new GameMove();
     if (Player.ToLowerInvariant() == COMPUTER.ToLowerInvariant())
     {
         var randomCell = RandomiseCellForComputerToPlay();
         LastMove = PlayMove(randomCell.DisplayName);
         LastMove.TimeMovePlayed = DateTime.UtcNow;
         System.Threading.Thread.Sleep(500);
     }
     return LastMove;
 }