예제 #1
0
        /// <summary>
        /// Draws the current state of the game to the screen.
        /// </summary>
        /// <remarks>
        /// What is drawn depends upon the state of the game.
        /// </remarks>
        public void DrawScreen()
        {
            UtilityFunctions.DrawBackground();

            switch (CurrentState)
            {
            case GameState.ViewingMainMenu:
            {
                MenuController.Instance.DrawMainMenu();
                break;
            }

            case GameState.ViewingGameMenu:
            {
                MenuController.Instance.DrawGameMenu();
                break;
            }

            case GameState.AlteringSettings:
            {
                MenuController.Instance.DrawSettings();
                break;
            }

            case GameState.Deploying:
            {
                DeploymentController.Instance.DrawDeployment();
                break;
            }

            case GameState.Discovering:
            {
                DiscoveryController.DrawDiscovery();
                break;
            }

            case GameState.EndingGame:
            {
                EndingGameController.DrawEndOfGame();
                break;
            }

            case GameState.ViewingHighScores:
            {
                HighScoreController.Instance.DrawHighScores();
                break;
            }
            }

            UtilityFunctions.Instance.DrawAnimations();

            SwinGame.RefreshScreen();
        }
예제 #2
0
        /// <summary>
        /// Read the user's name for their highsSwinGame.
        /// </summary>
        /// <param name="value">the player's sSwinGame.</param>
        /// <remarks>
        /// This verifies if the score is a highsSwinGame.
        /// </remarks>
        public void ReadHighScore(int value)
        {
            const int ENTRY_TOP = 500;

            if (_Scores.Count == 0)
            {
                LoadScores();
            }

            // is it a high score
            if (value > _Scores[_Scores.Count - 1].Value)
            {
                Score s = new Score();
                s.Value = value;

                GameController.Instance.AddNewState(GameState.ViewingHighScores);

                int x;
                x = SCORES_LEFT + SwinGame.TextWidth(GameResources.Instance.GameFont("Courier"), "Name: ");

                SwinGame.StartReadingText(Color.White, NAME_WIDTH, GameResources.Instance.GameFont("Courier"), x, ENTRY_TOP);

                // Read the text from the user
                while (SwinGame.ReadingText())
                {
                    SwinGame.ProcessEvents();

                    UtilityFunctions.DrawBackground();
                    DrawHighScores();
                    SwinGame.DrawText("Name: ", Color.White, GameResources.Instance.GameFont("Courier"), SCORES_LEFT, ENTRY_TOP);
                    SwinGame.RefreshScreen();
                }

                s.Name = SwinGame.TextReadAsASCII();

                if (s.Name.Length < 3)
                {
                    s.Name = s.Name + new string(System.Convert.ToChar(" "), 3 - s.Name.Length);
                }

                _Scores.RemoveAt(_Scores.Count - 1);
                _Scores.Add(s);
                _Scores.Sort();
                SaveScores();
                GameController.Instance.EndCurrentState();
            }
        }
예제 #3
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 void AttackCompleted(object sender, AttackResult result)
        {
            bool isHuman;

            isHuman = _theGame.Player == HumanPlayer;

            if (isHuman)
            {
                if (result.Value == ResultOfAttack.Destroyed)
                {
                    UtilityFunctions.MESSAGE_COLOR    = Color.Green;
                    UtilityFunctions.Instance.Message = "You " + result.ToString();
                }
                else
                {
                    UtilityFunctions.MESSAGE_COLOR = Color.White;
                }
                UtilityFunctions.Instance.Message = "You " + result.ToString();
            }
            else
            {
                if (result.Value == ResultOfAttack.Destroyed)
                {
                    UtilityFunctions.MESSAGE_COLOR = Color.Red;
                }
                else
                {
                    UtilityFunctions.MESSAGE_COLOR = Color.Blue;
                }
                UtilityFunctions.Instance.Message = "The AI " + result.ToString();
            }

            switch (result.Value)
            {
            case ResultOfAttack.Destroyed:
            {
                PlayHitSequence(result.Row, result.Column, isHuman);
                Color flashColor;
                if (isHuman)
                {
                    flashColor = SwinGame.RGBAColor(0, 255, 0, 127);
                }
                else
                {
                    flashColor = SwinGame.RGBAColor(255, 0, 0, 127);
                };
                Audio.PlaySoundEffect(GameResources.Instance.GameSound("Sink"));
                SwinGame.FillRectangle(flashColor, 0, 0, 800, 600);
                SwinGame.RefreshScreen();
                SwinGame.Delay(150);

                UtilityFunctions.DrawBackground();
                DiscoveryController.DrawDiscovery();
                SwinGame.RefreshScreen();
                SwinGame.Delay(100);

                SwinGame.FillRectangle(flashColor, 0, 0, 800, 600);
                SwinGame.RefreshScreen();
                SwinGame.Delay(150);

                break;
            }

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

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

                if (HumanPlayer.IsDestroyed)
                {
                    Audio.PlaySoundEffect(GameResources.Instance.GameSound("Lose"));
                }
                else
                {
                    Audio.PlaySoundEffect(GameResources.Instance.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.Instance.GameSound("Error"));
                break;
            }
            }
        }