Exemple #1
0
        /// <summary>
        /// This method handles the main game loop
        /// </summary>
        private void GameLoop()
        {
            Stream      endMusic;
            SoundPlayer soundPlayer;
            bool        exitGame = false;

            rendering.DrawGameWindow();
            rendering.DrawGameScreens(player);
            player.PlaceShips(rendering);
            computer.PlaceShips();
            turn = 0;
            while (!exitGame) //main game loop
            {
                rendering.DrawGameScreens(player);
                rendering.DrawInfoBox(player, computer, turn);
                player.TakeShot(computer, rendering);
                System.Threading.Thread.Sleep(1000);
                rendering.DrawGameScreens(player);
                computer.TakeShot(player, rendering);
                System.Threading.Thread.Sleep(1000);
                if (player.AllShipsDestroyed())
                {
                    endMusic    = Battleships.Properties.Resources.BattleshipsLoss;
                    soundPlayer = new SoundPlayer(endMusic);
                    soundPlayer.Play();
                    rendering.DrawVictoryScreen(1);
                    Console.ReadLine();
                    soundPlayer.Stop();
                    endMusic.Dispose();
                    soundPlayer.Dispose();
                    exitGame = true;
                }
                if (computer.AllShipsDestroyed())
                {
                    endMusic    = Battleships.Properties.Resources.BattleshipsVictory;
                    soundPlayer = new SoundPlayer(endMusic);
                    soundPlayer.Play();
                    rendering.DrawVictoryScreen(0);
                    Console.ReadLine();
                    soundPlayer.Stop();
                    endMusic.Dispose();
                    soundPlayer.Dispose();
                    exitGame = true;
                }
                turn++;
            }
        }
Exemple #2
0
        private bool TakeMove(Player hero, Player enemy)
        {
            bool wasHit;

            do
            {
                var guessedCell = hero.TakeShot();
                wasHit = enemy.CheckForHit(guessedCell);

                if (wasHit && enemy.Dead())
                {
                    return true;
                }
            } while (wasHit);

            return false;
        }
Exemple #3
0
        private bool TakeMove(Player hero, Player enemy)
        {
            bool wasHit;

            do
            {
                var guessedCell = hero.TakeShot();
                wasHit = enemy.CheckForHit(guessedCell);

                if (wasHit && enemy.Dead())
                {
                    return(true);
                }
            } while (wasHit);

            return(false);
        }