示例#1
0
        //allows the current player's turn to make a move
        private void PlayerMove(Player player)
        {
            string move;

            player.DrawTrackBoard();

            if (player.PlayerName == "Robot")
            {
                move = player.SelectAIMove();

                if (bships.PlayMove(player, move))
                {
                    Console.WriteLine("\nHIT! \n");
                    rw.Log = (player.PlayerName + " " + move + " Hit");
                }
                else
                {
                    Console.WriteLine("\nMISS! \n");
                    rw.Log = (player.PlayerName + " " + move + " Miss");
                }

                if (player.HitCount == 1)
                {
                    Console.WriteLine("Robot has hit " + player.HitCount + " square!\n\nPress any key to continue: ");
                }
                else
                {
                    Console.WriteLine("Robot has hit " + player.HitCount + " squares!\n\nPress any key to continue: ");
                }
                Console.ReadKey();
                Console.Clear();
            }
            else
            {
                Console.WriteLine("\n" + player.PlayerName + " please choose your move.");
                move = Console.ReadLine();

                if (bships.PlayMove(player, move))
                {
                    Console.WriteLine("\nHIT! \n");
                    rw.Log = (player.PlayerName + " " + move + " Hit");
                }
                else
                {
                    Console.WriteLine("\nMISS! \n");
                    rw.Log = (player.PlayerName + " " + move + " Miss");
                }

                if (player.HitCount == 1)
                {
                    Console.WriteLine("You've hit " + player.HitCount + " square!\n\nPress any key to continue: ");
                }
                else
                {
                    Console.WriteLine("You've hit " + player.HitCount + " squares!\n\nPress any key to continue: ");
                }
                Console.ReadKey();
                Console.Clear();
            }
        }