Exemplo n.º 1
0
    /// <summary>
    /// Listens for attacks to be completed.
    /// </summary>
    /// <param name="sender">the game</param>
    /// <param name="result">the result of the attack</param>
    /// <remarks>
    /// Displays a message, plays sound and redraws the screen
    /// </remarks>
    private static void AttackCompleted(object sender, AttackResult result)
    {
        bool isHuman = false;

        isHuman = object.ReferenceEquals(_theGame.Player, HumanPlayer);

        if (isHuman)
        {
            UtilityFunctions.Message = "You " + result.ToString();
        }
        else
        {
            UtilityFunctions.Message = "The AI " + result.ToString();
        }


        switch (result.Value)
        {
        case ResultOfAttack.Destroyed:
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));

            break;

        case ResultOfAttack.GameOver:
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));

            while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink")))
            {
                SwinGame.Delay(10);
                SwinGame.RefreshScreen();
            }

            if (HumanPlayer.IsDestroyed)
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Lose"));
            }
            else
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Winner"));
            }

            break;

        case ResultOfAttack.Hit:
            PlayHitSequence(result.Row, result.Column, isHuman);
            break;

        case ResultOfAttack.Miss:
            PlayMissSequence(result.Row, result.Column, isHuman);
            break;

        case ResultOfAttack.ShotAlready:
            Audio.PlaySoundEffect(GameResources.GameSound("Error"));
            //Only use to test entering highscores
            //EndingGameController.HandleEndOfGameInput();
            break;
        }
    }
Exemplo n.º 2
0
    // <summary>
    // Listens for attacks to be completed.
    // </summary>
    // <param name="sender">the game</param>
    // <param name="result">the result of the attack</param>
    // <remarks>
    // Displays a message, plays sound and redraws the screen
    // </remarks>
    private static void AttackCompleted(object sender, AttackResult result)
    {
        bool isHuman = false;

        isHuman = object.ReferenceEquals(_theGame.Player, HumanPlayer);

        if (isHuman)
        {
            UtilityFunctions.Message = "You " + result.ToString();
        }
        else
        {
            UtilityFunctions.Message = "The AI " + result.ToString();
        }

        switch (result.Value)
        {
        case ResultOfAttack.Destroyed:
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));

            break;

        case ResultOfAttack.GameOver:
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));

            //sound effect only lasts about 2 seconds
            SwinGame.RefreshScreen();
            SwinGame.Delay(2);
            // while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink"))) {
            //  // SwinGame.Delay(1);
            //  SwinGame.RefreshScreen();
            // }

            if (HumanPlayer.IsDestroyed)
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Lose"));
            }
            else
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Winner"));
            }

            break;

        case ResultOfAttack.Hit:
            PlayHitSequence(result.Row, result.Column, isHuman);
            break;

        case ResultOfAttack.Miss:
            PlayMissSequence(result.Row, result.Column, isHuman);
            break;

        case ResultOfAttack.ShotAlready:
            Audio.PlaySoundEffect(GameResources.GameSound("Error"));
            break;
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Attacks the completed.
    /// </summary>
    /// <param name="sender">Sender.</param>
    /// <param name="result">Result.</param>

    private static void AttackCompleted(object sender, AttackResult result)
    {
        bool isHuman = false;

        isHuman = object.ReferenceEquals(_theGame.Player, HumanPlayer);               /* Displays a message, plays sound and redraws the screen,
                                                                                       *                                                                        also will show to player when attack has been attaked */


        if (isHuman)
        {
            UtilityFunctions.Message = "You " + result.ToString();
        }
        else
        {
            UtilityFunctions.Message = "The AI " + result.ToString();
        }

        switch (result.Value)
        {
        case ResultOfAttack.Destroyed:
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));                                             /*if the player attacked ,the soundEffect will be played to let the player know */

            break;

        case ResultOfAttack.GameOver:
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));

            while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink")))
            {
                SwinGame.Delay(10);
                SwinGame.RefreshScreen();
            }

            if (HumanPlayer.IsDestroyed)
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Lose"));
            }
            else
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Winner"));
            }

            break;

        case ResultOfAttack.Hit:
            PlayHitSequence(result.Row, result.Column, isHuman);
            break;

        case ResultOfAttack.Miss:
            PlayMissSequence(result.Row, result.Column, isHuman);
            break;

        case ResultOfAttack.ShotAlready:
            Audio.PlaySoundEffect(GameResources.GameSound("Error"));
            break;
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// Listens for attacks to be completed.
    /// </summary>
    /// <param name="sender">the game</param>
    /// <param name="result">the result of the attack</param>
    /// <remarks>
    /// Displays a message, plays sound and redraws the screen
    /// </remarks>
    private static void AttackCompleted(object sender, AttackResult result)
    {
        bool isHuman = false;

        isHuman = object.ReferenceEquals(_theGame.Player, HumanPlayer);

        if (isHuman)
        {
            Message = "You " + result.ToString();
        }
        else
        {
            Message = "The AI " + result.ToString().Replace("the enemy's", "your");
        }

        switch (result.Value)
        {
        case ResultOfAttack.Destroyed:
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameSound("Sink"));

            break;

        case ResultOfAttack.GameOver:
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameSound("Sink"));

            while (Audio.SoundEffectPlaying(GameSound("Sink")))
            {
                SwinGame.Delay(10);
                SwinGame.RefreshScreen();
            }

            if (HumanPlayer.IsDestroyed)
            {
                Audio.PlaySoundEffect(GameSound("Lose"));
            }
            else
            {
                Audio.PlaySoundEffect(GameSound("Winner"));
            }

            break;

        case ResultOfAttack.Hit:
            PlayHitSequence(result.Row, result.Column, isHuman);
            break;

        case ResultOfAttack.Miss:
            PlayMissSequence(result.Row, result.Column, isHuman);
            break;

        case ResultOfAttack.ShotAlready:
            Audio.PlaySoundEffect(GameSound("Error"));
            break;
        }
    }
    // <summary>
    // Listens for attacks to be completed.
    // </summary>
    // <param name="sender">the game</param>
    // <param name="result">the result of the attack</param>
    // <remarks>
    // Displays a Message, plays sound and redraws the screen
    // </remarks>
    private static void AttackCompleted(object sender, AttackResult result)
    {
        bool isHuman = false;

        isHuman = object.ReferenceEquals(_theGame.Player, HumanPlayer);

        if (isHuman)   // check if the message is for ai or the user, prints beginning of message.
        {
            UtilityFunctions.Message = ("You " + result.ToString());
        }
        else
        {
            UtilityFunctions.Message = ("The AI " + result.ToString());
        }

        switch (result.Value)   // state of the result of the attack ( win or lose, ship is destroyed), and plays audio for that particular state
        {
        case ResultOfAttack.Destroyed:
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));
            break;

        case ResultOfAttack.GameOver:
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));
            while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink")))
            {
                SwinGame.Delay(10);
                SwinGame.RefreshScreen();
            }

            if (HumanPlayer.IsDestroyed)       // check if human destroyed and play audio
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Lose"));
            }
            else
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Winner"));
            }

            break;

        case ResultOfAttack.Hit:     //  check if attack hits
            PlayHitSequence(result.Row, result.Column, isHuman);
            break;

        case ResultOfAttack.Miss:
            PlayMissSequence(result.Row, result.Column, isHuman);
            break;

        case ResultOfAttack.ShotAlready:
            Audio.PlaySoundEffect(GameResources.GameSound("Error"));
            break;
        }
    }
Exemplo n.º 6
0
    // '' <summary>
    // '' Listens for attacks to be completed.
    // '' </summary>
    // '' <param name="sender">the game</param>
    // '' <param name="result">the result of the attack</param>
    // '' <remarks>
    // '' Displays a message, plays sound and redraws the screen
    // '' </remarks>
    private static void AttackCompleted(object sender, AttackResult result)
    {
        bool isHuman;

        isHuman = (_theGame.Player == HumanPlayer);
        if (isHuman)
        {
            Message = ("You " + result.ToString());
        }
        else
        {
            Message = ("The AI " + result.ToString());
        }

        switch (result.Value)
        {
        case ResultOfAttack.Destroyed:
            GameController.PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));
            break;

        case ResultOfAttack.GameOver:
            GameController.PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));
            while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink")))
            {
                SwinGame.Delay(10);
                SwinGame.RefreshScreen();
            }

            if (HumanPlayer.IsDestroyed)
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Lose"));
            }
            else
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Winner"));
            }

            break;

        case ResultOfAttack.Hit:
            GameController.PlayHitSequence(result.Row, result.Column, isHuman);
            break;

        case ResultOfAttack.Miss:
            GameController.PlayMissSequence(result.Row, result.Column, isHuman);
            break;

        case ResultOfAttack.ShotAlready:
            Audio.PlaySoundEffect(GameSound("Error"));
            break;
        }
    }
    /// <summary>
    /// Listens for attacks to be completed.
    /// </summary>
    /// <param name="sender">the game</param>
    /// <param name="result">the result of the attack</param>
    /// <remarks>
    /// Displays a message, plays sound and redraws the screen
    /// </remarks>
    private static void AttackCompleted(object sender, AttackResult result)
    {
        bool isHuman = false;

        isHuman = ReferenceEquals(_theGame.Player, HumanPlayer);

        if (isHuman)
        {
            UtilityFunctions.Message = "You " + result.ToString();
        }
        else
        {
            UtilityFunctions.Message = "The AI " + result.ToString();
        }

        if (result.Value == ResultOfAttack.Destroyed)
        {
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));
        }
        else if (result.Value == ResultOfAttack.GameOver)
        {
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));

            while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink")))
            {
                SwinGame.Delay((uint)10);
                SwinGame.RefreshScreen();
            }

            if (HumanPlayer.IsDestroyed)
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Lose"));
            }
            else
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Winner"));
            }
        }
        else if (result.Value == ResultOfAttack.Hit)
        {
            PlayHitSequence(result.Row, result.Column, isHuman);
        }
        else if (result.Value == ResultOfAttack.Miss)
        {
            PlayMissSequence(result.Row, result.Column, isHuman);
        }
        else if (result.Value == ResultOfAttack.ShotAlready)
        {
            Audio.PlaySoundEffect(GameResources.GameSound("Error"));
        }
    }
        public void AttackResultGameOverTest()
        {
            AttackResult attackResult = new AttackResult(ResultOfAttack.GameOver, "Game over", 0, 0);
            string       actual       = attackResult.ToString();
            string       expected     = "Game over";

            Assert.AreEqual(expected, actual);
        }
        public void AttackResulttest()
        {
            AttackResult result   = new AttackResult(ResultOfAttack.Miss, "ship1", 0, 0);
            string       actual   = result.ToString();
            string       expected = "ship1";

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 10
0
        public void AttackResultGameOverShipTest()
        {
            Ship         ship         = new Ship(ShipName.AircraftCarrier);
            AttackResult attackResult = new AttackResult(ResultOfAttack.GameOver, ship, "Game over", 0, 0);
            string       actual       = attackResult.ToString();
            string       expected     = "Game over " + ship.Name;

            Assert.AreEqual(expected, actual);
        }
        public void ToStringFunction()
        {
            Ship         _ship    = new Ship(ShipName.Battleship);
            AttackResult att      = new AttackResult(ResultOfAttack.Hit, _ship, "hello", 100, 200);
            string       expected = "hello Battleship";
            string       actual   = att.ToString();

            Assert.AreEqual(expected, actual, "correct answer is hello Battleship");
        }
Exemplo n.º 12
0
    // <summary>
    // Listens for attacks to be completed.
    // </summary>
    // <param name="sender">the game</param>
    // <param name="result">the result of the attack</param>
    // <remarks>
    // Displays a message, plays sound and redraws the screen
    // </remarks>
    private static void AttackCompleted(object sender, AttackResult result)
    {
        bool isHuman;

        isHuman = _theGame.Player == HumanPlayer;

        if (isHuman)
        {
            UtilityFunctions.Message = "You " + result.ToString();
        }
        else
        {
            UtilityFunctions.Message = "The AI " + result.ToString();
        }

        switch (result.Value)
        {
        case var @case when @case == ResultOfAttack.Destroyed:
        {
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));
            break;
        }

        case var case1 when case1 == ResultOfAttack.GameOver:
        {
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));

            while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink")))
            {
                SwinGame.Delay(3);
                SwinGame.RefreshScreen();
                EndingGameController.DrawEndOfGame();        // fixed the delay issue with the audio sound effect when the game ends
            }

            if (HumanPlayer.IsDestroyed)
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Lose"));
            }
            else
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Winner"));
            }
            break;
        }

        case var case2 when case2 == ResultOfAttack.Hit:
        {
            PlayHitSequence(result.Row, result.Column, isHuman);
            break;
        }

        case var case3 when case3 == ResultOfAttack.Miss:
        {
            PlayMissSequence(result.Row, result.Column, isHuman);
            break;
        }

        case var case4 when case4 == ResultOfAttack.ShotAlready:
        {
            Audio.PlaySoundEffect(GameResources.GameSound("Error"));
            break;
        }
        }
    }
Exemplo n.º 13
0
    ///<summary>
    ///AttackCompleted listens for attacks to be completed.
    ///It will display a message, play a sound and redraw the screen.
    ///</summary>
    ///<param name="sender">The current game Object.</param>
    ///<param name="result">The result of the attack.</param>
    private static void AttackCompleted(object sender, AttackResult result)
    {
        bool isHuman;

        isHuman = _theGame.Player == HumanPlayer;

        if (isHuman)
        {
            UtilityFunctions.Message = "You " + result.ToString();
        }
        else
        {
            UtilityFunctions.Message = "The AI " + result.ToString();
        }

        switch (result.Value)
        {
        case ResultOfAttack.Destroyed:
        {
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));
            if (isHuman)
            {
                aiShipsLeft--;
            }
            else
            {
                humanShipsLeft--;
            }
            break;
        }

        case ResultOfAttack.GameOver:
        {
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));

            while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink")))
            {
                SwinGame.RefreshScreen();
            }

            if (_human.IsDestroyed)
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Lose"));
            }
            else
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Winner"));
            }
            break;
        }

        case ResultOfAttack.Hit:
        {
            PlayHitSequence(result.Row, result.Column, isHuman);
            break;
        }

        case ResultOfAttack.Miss:
        {
            PlayMissSequence(result.Row, result.Column, isHuman);
            break;
        }

        case ResultOfAttack.ShotAlready:
        {
            Audio.PlaySoundEffect(GameResources.GameSound("Error"));
            break;
        }
        }
    }
Exemplo n.º 14
0
    /// <summary>
    /// Listens for attacks to be completed.
    /// </summary>
    /// <param name="sender">the game</param>
    /// <param name="result">the result of the attack</param>
    /// <remarks>
    /// Displays a message, plays sound and redraws the screen
    /// </remarks>
    private static void AttackCompleted(object sender, AttackResult result)
    {
        bool isHuman;

        isHuman = _theGame.Player == HumanPlayer;
        if (isHuman)
        {
            Message = "You " + result.ToString();
        }
        else
        {
            Message = "The AI " + result.ToString();
        }

        var switchExpr = result.Value;

        switch (switchExpr)
        {
        case var @case when @case == ResultOfAttack.Destroyed:
        {
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameSound["Sink"]);
            break;
        }

        case var case1 when case1 == ResultOfAttack.GameOver:
        {
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameSound["Sink"]);
            while (Audio.SoundEffectPlaying(GameSound["Sink"]))
            {
                SwinGame.Delay(10);
                SwinGame.RefreshScreen();
            }

            if (HumanPlayer.IsDestroyed)
            {
                Audio.PlaySoundEffect(GameSound["Lose"]);
            }
            else
            {
                Audio.PlaySoundEffect(GameSound["Winner"]);
            }

            break;
        }

        case var case2 when case2 == ResultOfAttack.Hit:
        {
            PlayHitSequence(result.Row, result.Column, isHuman);
            break;
        }

        case var case3 when case3 == ResultOfAttack.Miss:
        {
            PlayMissSequence(result.Row, result.Column, isHuman);
            break;
        }

        case var case4 when case4 == ResultOfAttack.ShotAlready:
        {
            Audio.PlaySoundEffect(GameSound["Error"]);
            break;
        }
        }
    }
Exemplo n.º 15
0
    /// <summary>
    ///     ''' Listens for attacks to be completed.
    ///     ''' </summary>
    ///     ''' <param name="sender">the game</param>
    ///     ''' <param name="result">the result of the attack</param>
    ///     ''' <remarks>
    ///     ''' Displays a message, plays sound and redraws the screen
    ///     ''' </remarks>
    private static void AttackCompleted(object sender, AttackResult result)
    {
        bool isHuman;

        isHuman = _theGame.Player == HumanPlayer;



        if (isHuman)
        {
            UtilityFunctions.Message = "You " + result.ToString();
        }
        else
        {
            UtilityFunctions.Message = "The AI " + result.ToString();
        }

        switch (result.Value)
        {
        case ResultOfAttack.Destroyed: {
            PlayHitSequence(result.Row, result.Column, isHuman);


            Audio.PlaySoundEffect(GameResources.GameSound("Shipdestroyed"));


            if (isHuman)
            {
                shipleft--;
                showshipleft = ("There are " + shipleft.ToString() + " enemy Ship left");
            }

            break;
        }

        case ResultOfAttack.GameOver: {
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));

            while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink")))
            {
                SwinGame.Delay(2);
                SwinGame.RefreshScreen();
            }
            if (HumanPlayer.IsDestroyed)
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Lose"));
            }
            else
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Winner"));
            }
            break;
        }


        case ResultOfAttack.Hit: {
            PlayHitSequence(result.Row, result.Column, isHuman);
            break;
        }

        case ResultOfAttack.Miss: {
            if (isHuman)
            {
                missleft--;
                showmissleft = ("You can only miss " + missleft.ToString() + " more times");
            }
            PlayMissSequence(result.Row, result.Column, isHuman);
            break;
        }

        case ResultOfAttack.ShotAlready: {
            Audio.PlaySoundEffect(GameResources.GameSound("Error"));
            break;
        }
        }
    }
Exemplo n.º 16
0
    /// <summary>
    /// Listens for attacks to be completed.
    /// </summary>
    /// <param name="sender">the game</param>
    /// <param name="result">the result of the attack</param>
    /// <remarks>
    /// Displays a message, plays sound and redraws the screen
    /// </remarks>
    private static void AttackCompleted(object sender, AttackResult result)
    {
        bool isHuman = false;

        isHuman = object.ReferenceEquals(_theGame.Player, HumanPlayer);

        if (isHuman)
        {
            Message = "You " + result.ToString();
        }
        else
        {
            Message = "The AI " + result.ToString();
        }

        if (Message == "The AI missed")
        {
            WhoseTurnMessage = "It is your turn!";
        }
        else if (Message == "You missed")
        {
            WhoseTurnMessage = "Computer is thinking....";
        }
        else if (Message == "You hit something!")
        {
            WhoseTurnMessage = "Go on, have another go..";
        }
        else
        {
            WhoseTurnMessage = "";
        }

        switch (result.Value)
        {
        case ResultOfAttack.Destroyed:
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameSound("Sink"));

            break;

        case ResultOfAttack.GameOver:
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameSound("Sink"));

            while (Audio.SoundEffectPlaying(GameSound("Sink")))
            {
                SwinGame.Delay(10);
                SwinGame.RefreshScreen();
            }

            if (HumanPlayer.IsDestroyed)
            {
                Audio.PlaySoundEffect(GameSound("Lose"));
            }
            else
            {
                Audio.PlaySoundEffect(GameSound("Winner"));
            }

            break;

        case ResultOfAttack.Hit:
            PlayHitSequence(result.Row, result.Column, isHuman);
            break;

        case ResultOfAttack.Miss:
            PlayMissSequence(result.Row, result.Column, isHuman);

            break;

        case ResultOfAttack.ShotAlready:
            Audio.PlaySoundEffect(GameSound("Error"));
            break;
        }
    }
Exemplo n.º 17
0
    /// <summary>
    /// Listens for attacks to be completed.
    /// </summary>
    /// <param name="sender">the game</param>
    /// <param name="result">the result of the attack</param>
    /// <remarks>
    /// Displays a message, plays sound and redraws the screen
    /// </remarks>
    private static void AttackCompleted(object sender, AttackResult result)
    {
        int  randomLose    = rnd.Next(1, 3);
        int  randomDestroy = rnd.Next(1, 4);
        bool isHuman       = false;

        isHuman = ReferenceEquals(_theGame.Player, HumanPlayer);

        if (isHuman)
        {
            UtilityFunctions.Message = "You " + result.ToString();
        }
        else
        {
            UtilityFunctions.Message = "The AI " + result.ToString();
        }

        if (result.Value == ResultOfAttack.Destroyed)
        {
            PlayHitSequence(System.Convert.ToInt32(result.Row), System.Convert.ToInt32(result.Column), isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));

            if (randomDestroy == 1)
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Destroy1"));
            }

            else if (randomDestroy == 2)
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Destroy2"));
            }

            else if (randomDestroy == 3)
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Destroy3"));
            }

            else
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Destroy4"));
            }
        }
        else if (result.Value == ResultOfAttack.GameOver)
        {
            PlayHitSequence(System.Convert.ToInt32(result.Row), System.Convert.ToInt32(result.Column), isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));

            while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink")))
            {
                SwinGame.Delay(10);
                SwinGame.RefreshScreen();
            }

            if (HumanPlayer.IsDestroyed)
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Lose"));
                if (randomLose == 1)
                {
                    Audio.PlaySoundEffect(GameResources.GameSound("Lose1"));
                }
                else
                {
                    Audio.PlaySoundEffect(GameResources.GameSound("Lose2"));
                }
            }
            else
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Winner"));
                Audio.PlaySoundEffect(GameResources.GameSound("Win1"));
            }
        }
        else if (result.Value == ResultOfAttack.Hit)
        {
            PlayHitSequence(System.Convert.ToInt32(result.Row), System.Convert.ToInt32(result.Column), isHuman);
        }
        else if (result.Value == ResultOfAttack.Miss)
        {
            PlayMissSequence(System.Convert.ToInt32(result.Row), System.Convert.ToInt32(result.Column), isHuman);
        }
        else if (result.Value == ResultOfAttack.ShotAlready)
        {
            Audio.PlaySoundEffect(GameResources.GameSound("Error"));
        }
    }
Exemplo n.º 18
0
    /// <summary>
    /// Listens for attacks to be completed.
    /// </summary>
    /// <remarks>
    /// Displays a message, plays sound and redraws the screen
    /// </remarks>
    private static void AttackCompleted(object sender, AttackResult result)
    {
        bool isHuman = false;

        isHuman = object.ReferenceEquals(_theGame.Player, HumanPlayer);

        if (isHuman)
        {
            UtilityFunctions.Message = "You " + result.ToString();
        }
        else
        {
            UtilityFunctions.Message = "The AI " + result.ToString();
        }

        switch (result.Value)
        {
        ///if result of attack destroys ship, plays a hit sequence and sink audio
        case ResultOfAttack.Destroyed:
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));

            break;

        ///if the game is over, plays a hit sequence and sink audio.
        case ResultOfAttack.GameOver:
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));

            while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink")))
            {
                SwinGame.Delay(10);
                SwinGame.RefreshScreen();
            }
            ///if the human ship is destroyed, play lose audio, else play win audio.
            if (HumanPlayer.IsDestroyed)
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Lose"));
            }
            else
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Winner"));
            }

            break;

        /// if result of attack hits a ship, play the hit sequence
        case ResultOfAttack.Hit:
            PlayHitSequence(result.Row, result.Column, isHuman);
            break;

        /// if result of attack miss a ship, play the miss sequence
        case ResultOfAttack.Miss:
            PlayMissSequence(result.Row, result.Column, isHuman);
            break;

        /// if result of attack is hit already, play the error audio
        case ResultOfAttack.ShotAlready:
            Audio.PlaySoundEffect(GameResources.GameSound("Error"));
            break;
        }
    }
Exemplo n.º 19
0
	/// <summary>
	/// Listens for attacks to be completed.
	/// </summary>
	/// <param name="sender">the game</param>
	/// <param name="result">the result of the attack</param>
	/// <remarks>
	/// Displays a message, plays sound and redraws the screen
	/// </remarks>
	private static void AttackCompleted(object sender, AttackResult result)
	{
		bool isHuman = false;
		isHuman = object.ReferenceEquals(_theGame.Player, HumanPlayer);

		if (isHuman) {
			Message = "You " + result.ToString();
		} else {
			Message = "The AI " + result.ToString();
		}

		switch (result.Value) {
			case ResultOfAttack.Destroyed:
				PlayHitSequence(result.Row, result.Column, isHuman);
				Audio.PlaySoundEffect(GameSound("Sink"));

				break;
			case ResultOfAttack.GameOver:
				PlayHitSequence(result.Row, result.Column, isHuman);
				Audio.PlaySoundEffect(GameSound("Sink"));

				while (Audio.SoundEffectPlaying(GameSound("Sink"))) {
					SwinGame.Delay(10);
					SwinGame.RefreshScreen();
				}

				if (HumanPlayer.IsDestroyed) {
					Audio.PlaySoundEffect(GameSound("Lose"));
				} else {
					Audio.PlaySoundEffect(GameSound("Winner"));
				}

				break;
			case ResultOfAttack.Hit:
				PlayHitSequence(result.Row, result.Column, isHuman);
				break;
			case ResultOfAttack.Miss:
				PlayMissSequence(result.Row, result.Column, isHuman);
				break;
			case ResultOfAttack.ShotAlready:
				Audio.PlaySoundEffect(GameSound("Error"));
				break;
		}
	}
Exemplo n.º 20
0
    /// <summary>
    ///     ''' Listens for attacks to be completed.
    ///     ''' </summary>
    ///     ''' <param name="sender">the game</param>
    ///     ''' <param name="result">the result of the attack</param>
    ///     ''' <remarks>
    ///     ''' Displays a message, plays sound and redraws the screen
    ///     ''' </remarks>
    private static void AttackCompleted(object sender, AttackResult result)
    {
        bool isHuman;

        isHuman = _theGame.Player == HumanPlayer;

        if (isHuman)
        {
            UtilityFunctions.Message = "You " + result.ToString();
        }
        else
        {
            UtilityFunctions.Message = "The AI " + result.ToString();
        }

        switch (result.Value)
        {
        case ResultOfAttack.Destroyed:
        {
            PlayHitSequence(result.Row, result.Column, isHuman);
            switch (result.Ship.Name)
            {
            case ("Tug"):
                Audio.PlaySoundEffect(GameResources.GameSound("Sink"));
                break;

            case ("Submarine"):
                Audio.PlaySoundEffect(GameResources.GameSound("Sink1"));
                break;

            case ("Destroyer"):
                Audio.PlaySoundEffect(GameResources.GameSound("Sink2"));
                break;

            case ("Battleship"):
                Audio.PlaySoundEffect(GameResources.GameSound("Sink3"));
                break;

            case ("Aircraft Carrier"):
                Audio.PlaySoundEffect(GameResources.GameSound("Sink4"));
                break;
            }
            break;
        }

        case ResultOfAttack.GameOver:
        {
            PlayHitSequence(result.Row, result.Column, isHuman);
            Audio.PlaySoundEffect(GameResources.GameSound("Sink"));

            while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink")))
            {
                SwinGame.Delay(10);
                SwinGame.RefreshScreen();
            }

            if (HumanPlayer.IsDestroyed)
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Lose"));
            }
            else
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Winner"));
            }
            break;
        }

        case ResultOfAttack.Hit:
        {
            PlayHitSequence(result.Row, result.Column, isHuman);
            break;
        }

        case ResultOfAttack.Miss:
        {
            PlayMissSequence(result.Row, result.Column, isHuman);
            break;
        }

        case ResultOfAttack.ShotAlready:
        {
            Audio.PlaySoundEffect(GameResources.GameSound("Error"));
            break;
        }
        }
    }