/// <summary>
        /// Draws the deployment screen showing the field and the ships
        /// that the player can deploy.
        /// </summary>
        public void DrawDeployment()
        {
            UtilityFunctions.DrawField(GameController.Instance.HumanPlayer.PlayerGrid, GameController.Instance.HumanPlayer, true);

            // Draw the Left/Right and Up/Down buttons
            if (_currentDirection == Direction.LeftRight)
            {
                SwinGame.DrawBitmap(GameResources.Instance.GameImage("LeftRightButton"), LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP);
            }
            else
            {
                SwinGame.DrawBitmap(GameResources.Instance.GameImage("UpDownButton"), LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP);
            }

            // DrawShips
            foreach (ShipName sn in Enum.GetValues(typeof(ShipName)))
            {
                int i;
                i = (int)sn - 1;
                if (i >= 0)
                {
                    if (sn == _selectedShip)
                    {
                        SwinGame.DrawBitmap(GameResources.Instance.GameImage("SelectedShip"), SHIPS_LEFT, SHIPS_TOP + i * SHIPS_HEIGHT);
                    }
                }
            }

            if (GameController.Instance.HumanPlayer.ReadyToDeploy)
            {
                SwinGame.DrawBitmap(GameResources.Instance.GameImage("PlayButton"), PLAY_BUTTON_LEFT, TOP_BUTTONS_TOP);
            }

            SwinGame.DrawBitmap(GameResources.Instance.GameImage("RandomButton"), RANDOM_BUTTON_LEFT, TOP_BUTTONS_TOP);

            UtilityFunctions.Instance.DrawMessage();
        }
Esempio n. 2
0
        /// <summary>
        /// Draw the end of the game screen, shows the win/lose state
        /// </summary>
        public static void DrawEndOfGame()
        {
            Rectangle toDraw = new Rectangle();
            string    whatShouldIPrint;

            UtilityFunctions.DrawField(GameController.Instance.ComputerPlayer.PlayerGrid, GameController.Instance.ComputerPlayer, true);
            UtilityFunctions.DrawSmallField(GameController.Instance.HumanPlayer.PlayerGrid, GameController.Instance.HumanPlayer);

            toDraw.X      = 0;
            toDraw.Y      = 250;
            toDraw.Width  = SwinGame.ScreenWidth();
            toDraw.Height = SwinGame.ScreenHeight();

            if (GameController.Instance.HumanPlayer.IsDestroyed)
            {
                whatShouldIPrint = "YOU LOSE!";
            }
            else
            {
                whatShouldIPrint = "-- WINNER --";
            }

            SwinGame.DrawText(whatShouldIPrint, Color.White, Color.Transparent, GameResources.Instance.GameFont("ArialLarge"), FontAlignment.AlignCenter, toDraw); // orignialy draw text lines
        }
        /// <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;

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

            UtilityFunctions.DrawSmallField(GameController.Instance.HumanPlayer.PlayerGrid, GameController.Instance.HumanPlayer);
            UtilityFunctions.DrawDestoyedField(GameController.Instance.ComputerPlayer.PlayerGrid, GameController.Instance.ComputerPlayer);
            UtilityFunctions.Instance.DrawMessage();

            SwinGame.DrawText(GameController.Instance.HumanPlayer.Shots.ToString(), Color.White, GameResources.Instance.GameFont("Menu"), SCORES_LEFT, SHOTS_TOP);
            SwinGame.DrawText(GameController.Instance.HumanPlayer.Hits.ToString(), Color.White, GameResources.Instance.GameFont("Menu"), SCORES_LEFT, HITS_TOP);
            SwinGame.DrawText(GameController.Instance.HumanPlayer.Missed.ToString(), Color.White, GameResources.Instance.GameFont("Menu"), SCORES_LEFT, SPLASH_TOP);
        }
Esempio 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 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;
            }
            }
        }