/// <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();
        }
        /// <summary>
        /// Draw the end of the game screen, shows the win/lose state
        /// </summary>
        public static void DrawEndOfGame()
        {
            var    toDraw = default(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.DrawTextLines(whatShouldIPrint, Color.White, Color.Transparent, GameResources.GameFont("ArialLarge"), FontAlignment.AlignCenter, toDraw);
        }
        /// <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.vk_LSHIFT) | SwinGame.KeyDown(KeyCode.vk_RSHIFT)) & SwinGame.KeyDown(KeyCode.vk_c))
            {
                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);
        }
        /// <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();
        }
        /// <summary>
        /// Handles user input for the Deployment phase of the game.
        /// </summary>
        /// <remarks>
        /// Involves selecting the ships, deloying ships, changing the direction
        /// of the ships to add, randomising deployment, end then ending
        /// deployment
        /// </remarks>
        public static void HandleDeploymentInput()
        {
            if (SwinGame.KeyTyped(KeyCode.vk_ESCAPE))
            {
                GameController.AddNewState(GameState.ViewingGameMenu);
            }

            if (SwinGame.KeyTyped(KeyCode.vk_UP) | SwinGame.KeyTyped(KeyCode.vk_DOWN))
            {
                _currentDirection = Direction.UpDown;
            }

            if (SwinGame.KeyTyped(KeyCode.vk_LEFT) | SwinGame.KeyTyped(KeyCode.vk_RIGHT))
            {
                _currentDirection = Direction.LeftRight;
            }

            if (SwinGame.KeyTyped(KeyCode.vk_r))
            {
                GameController.HumanPlayer.RandomizeDeployment();
            }

            if (SwinGame.KeyTyped(KeyCode.vk_a))
            {
                int  col, row;
                Ship the_ship;
                GameController.HumanPlayer._Ships.TryGetValue(_selectedShip, out the_ship);
                row = the_ship._row;
                col = the_ship._col - 1;
                if (col >= 0 & col < GameController.HumanPlayer.PlayerGrid.Width)
                {
                    // if in the area try to deploy
                    try
                    {
                        GameController.HumanPlayer.PlayerGrid.MoveShip(row, col, _selectedShip, _currentDirection);
                    }
                    catch (Exception ex)
                    {
                        Audio.PlaySoundEffect(GameResources.GameSound("Error"));
                        UtilityFunctions.Message = ex.Message;
                    }
                }
            }

            if (SwinGame.KeyTyped(KeyCode.vk_w))
            {
                int  col, row;
                Ship the_ship;
                GameController.HumanPlayer._Ships.TryGetValue(_selectedShip, out the_ship);
                row = the_ship._row - 1;
                col = the_ship._col;
                if (col >= 0 & col < GameController.HumanPlayer.PlayerGrid.Width)
                {
                    // if in the area try to deploy
                    try
                    {
                        GameController.HumanPlayer.PlayerGrid.MoveShip(row, col, _selectedShip, _currentDirection);
                    }
                    catch (Exception ex)
                    {
                        Audio.PlaySoundEffect(GameResources.GameSound("Error"));
                        UtilityFunctions.Message = ex.Message;
                    }
                }
            }

            if (SwinGame.KeyTyped(KeyCode.vk_d))
            {
                int  col, row;
                Ship the_ship;
                GameController.HumanPlayer._Ships.TryGetValue(_selectedShip, out the_ship);
                row = the_ship._row;
                col = the_ship._col + 1;
                if (col >= 0 & col < GameController.HumanPlayer.PlayerGrid.Width)
                {
                    // if in the area try to deploy
                    try
                    {
                        GameController.HumanPlayer.PlayerGrid.MoveShip(row, col, _selectedShip, _currentDirection);
                    }
                    catch (Exception ex)
                    {
                        Audio.PlaySoundEffect(GameResources.GameSound("Error"));
                        UtilityFunctions.Message = ex.Message;
                    }
                }
            }

            if (SwinGame.KeyTyped(KeyCode.vk_s))
            {
                int  col, row;
                Ship the_ship;
                GameController.HumanPlayer._Ships.TryGetValue(_selectedShip, out the_ship);
                row = the_ship._row + 1;
                col = the_ship._col;
                if (col >= 0 & col < GameController.HumanPlayer.PlayerGrid.Width)
                {
                    // if in the area try to deploy
                    try
                    {
                        GameController.HumanPlayer.PlayerGrid.MoveShip(row, col, _selectedShip, _currentDirection);
                    }
                    catch (Exception ex)
                    {
                        Audio.PlaySoundEffect(GameResources.GameSound("Error"));
                        UtilityFunctions.Message = ex.Message;
                    }
                }
            }

            if (SwinGame.MouseClicked(MouseButton.LeftButton))
            {
                ShipName selected;
                selected = GetShipMouseIsOver();
                if (selected != ShipName.None)
                {
                    _selectedShip = selected;
                }
                else
                {
                    DoDeployClick();
                }

                if (GameController.HumanPlayer.ReadyToDeploy & UtilityFunctions.IsMouseInRectangle(PLAY_BUTTON_LEFT, TOP_BUTTONS_TOP, PLAY_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    GameController.EndDeployment();
                }
                else if (UtilityFunctions.IsMouseInRectangle(UP_DOWN_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    _currentDirection = Direction.UpDown;
                }
                else if (UtilityFunctions.IsMouseInRectangle(LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    _currentDirection = Direction.LeftRight;
                }
                else if (UtilityFunctions.IsMouseInRectangle(RANDOM_BUTTON_LEFT, TOP_BUTTONS_TOP, RANDOM_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    GameController.HumanPlayer.RandomizeDeployment();
                }
            }
        }