Exemplo n.º 1
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 static void ReadHighScore(int value)
        {
            const int ENTRY_TOP = 500;

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

            // is it a high score
            if ((value > _Scores[(_Scores.Count - 1)].Value))
            {
                Score s = new Score();
                s.Value = value;
                GameController.AddNewState(GameState.ViewingHighScores);
                int x;
                x = (SCORES_LEFT + SwinGame.TextWidth(GameResources.GameFont("Courier"), "Name: "));
                SwinGame.StartReadingText(Color.White, NAME_WIDTH, GameResources.GameFont("Courier"), x, ENTRY_TOP);
                // Read the text from the user
                while (SwinGame.ReadingText())
                {
                    SwinGame.ProcessEvents();
                    UtilityFunctions.DrawBackground();
                    HighScoreController.DrawHighScores();
                    SwinGame.DrawText("Name: ", Color.White, GameResources.GameFont("Courier"), SCORES_LEFT, ENTRY_TOP);
                    SwinGame.RefreshScreen();
                }

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

                _Scores.RemoveAt((_Scores.Count - 1));
                _Scores.Add(s);
                _Scores.Sort();
                GameController.EndCurrentState();
            }
        }
Exemplo n.º 2
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 static void DrawScreen()
        {
            UtilityFunctions.DrawBackground();

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

            case GameState.ViewingGameMenu:
                MenuController.DrawGameMenu();
                break;

            case GameState.AlteringSettings:
                MenuController.DrawSettings();
                break;

            case GameState.Deploying:
                DeploymentController.DrawDeployment();
                break;

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

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

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

            UtilityFunctions.DrawAnimations();

            SwinGame.RefreshScreen();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles the user SwinGame.
        /// </summary>
        /// <remarks>
        /// Reads key and mouse input and converts these into
        /// actions for the game to perform. The actions
        /// performed depend upon the state of the game.
        /// </remarks>
        public static void HandleUserInput()
        {
            //Read incoming input events
            SwinGame.ProcessEvents();

            switch (CurrentState)
            {
            case GameState.ViewingMainMenu:
                MenuController.HandleMainMenuInput();
                break;

            case GameState.ViewingGameMenu:
                MenuController.HandleGameMenuInput();
                break;

            case GameState.AlteringSettings:
                MenuController.HandleSetupMenuInput();
                break;

            case GameState.Deploying:
                DeploymentController.HandleDeploymentInput();
                break;

            case GameState.Discovering:
                DiscoveryController.HandleDiscoveryInput();
                break;

            case GameState.EndingGame:
                EndingGameController.HandleEndOfGameInput();
                break;

            case GameState.ViewingHighScores:
                HighScoreController.HandleHighScoreInput();
                break;
            }

            UtilityFunctions.UpdateAnimations();
        }
Exemplo n.º 4
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;

            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);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     ''' Draws the deployment screen showing the field and the ships
        ///     ''' that the player can deploy.
        ///     ''' </summary>
        public static void DrawDeployment()
        {
            UtilityFunctions.DrawField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer, true);

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

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

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

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

            UtilityFunctions.DrawMessage();
        }
Exemplo n.º 6
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.ComputerPlayer.PlayerGrid, GameController.ComputerPlayer, true);
            UtilityFunctions.DrawSmallField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer);

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

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

            SwinGame.DrawText(whatShouldIPrint, Color.White, Color.Transparent, GameResources.GameFont("ArialLarge"), FontAlignment.AlignCenter, toDraw);
        }