コード例 #1
0
        /// <summary>
        /// Draws the high scores to the screen.
        /// </summary>
        public static void DrawHighScores()
        {
            const int SCORES_HEADING = 40;
            const int SCORES_TOP     = 80;
            const int SCORE_GAP      = 30;

            if (_Scores.Count == 0)
            {
                LoadScores();
            }
            SwinGame.DrawText("   High Scores   ", Color.White, GameResources.GameFont("Courier"), SCORES_LEFT, SCORES_HEADING);

            // For all of the scores
            int i;
            var loopTo = _Scores.Count - 1;

            for (i = 0; i <= loopTo; i++)
            {
                Score s;
                s = _Scores[i];

                // for scores 1 - 9 use 01 - 09
                if (i < 9)
                {
                    SwinGame.DrawText(" " + (i + 1) + ":   " + s.Name + "   " + s.Value, Color.White, GameResources.GameFont("Courier"), SCORES_LEFT, SCORES_TOP + i * SCORE_GAP);
                }
                else
                {
                    SwinGame.DrawText(i + 1 + ":   " + s.Name + "   " + s.Value, Color.White, GameResources.GameFont("Courier"), SCORES_LEFT, SCORES_TOP + i * SCORE_GAP);
                }
            }
        }
コード例 #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;

            isHuman = _theGame.Player == HumanPlayer;
            if (isHuman)
            {
                UtilityFunctions.Message = "You " + result.ToString();
            }
            else
            {
                UtilityFunctions.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(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(10);
                    SwinGame.RefreshScreen();
                }

                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;
            }
            }
        }
コード例 #3
0
        /// <summary>
        /// Draws the game during the attack phase.
        /// </summary>s
        public static void DrawDiscovery()
        {
            const int SCORES_LEFT = 172;
            const int SHOTS_TOP   = 157;
            const int HITS_TOP    = 206;
            const int SPLASH_TOP  = 256;
            const int TIMER_LEFT  = 350;
            const int TIMER_TOP   = 87;

            if ((SwinGame.KeyDown(KeyCode.LeftShiftKey) | SwinGame.KeyDown(KeyCode.RightShiftKey)) & SwinGame.KeyDown(KeyCode.CKey))
            {
                UtilityFunctions.DrawField(GameController.HumanPlayer.EnemyGrid, GameController.ComputerPlayer, true);
            }
            else
            {
                UtilityFunctions.DrawField(GameController.HumanPlayer.EnemyGrid, GameController.ComputerPlayer, false);
            }

            UtilityFunctions.DrawSmallField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer);
            UtilityFunctions.DrawMessage();
            SwinGame.DrawText(GameController.HumanPlayer.Shots.ToString(), Color.White, GameResources.GameFont("Menu"), SCORES_LEFT, SHOTS_TOP);
            SwinGame.DrawText(GameController.HumanPlayer.Hits.ToString(), Color.White, GameResources.GameFont("Menu"), SCORES_LEFT, HITS_TOP);
            SwinGame.DrawText(GameController.HumanPlayer.Missed.ToString(), Color.White, GameResources.GameFont("Menu"), SCORES_LEFT, SPLASH_TOP);
            SwinGame.DrawText("TIME LEFT: " + GameController.TimeRemaining(), Color.White, GameResources.GameFont("Menu"), TIMER_LEFT, TIMER_TOP);
        }